2021-04-12 21:22:22 +03:00
|
|
|
import 'dart:convert';
|
2024-11-09 21:00:56 +02:00
|
|
|
import 'dart:developer';
|
2024-03-25 13:16:57 -05:00
|
|
|
|
|
|
|
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
|
|
|
import 'package:cake_wallet/buy/buy_exception.dart';
|
|
|
|
import 'package:cake_wallet/buy/buy_provider.dart';
|
|
|
|
import 'package:cake_wallet/buy/buy_provider_description.dart';
|
2024-11-09 21:00:56 +02:00
|
|
|
import 'package:cake_wallet/buy/buy_quote.dart';
|
2024-03-25 13:16:57 -05:00
|
|
|
import 'package:cake_wallet/buy/order.dart';
|
2025-03-29 07:46:16 +02:00
|
|
|
import 'package:cake_wallet/buy/pairs_utils.dart';
|
2024-11-09 21:00:56 +02:00
|
|
|
import 'package:cake_wallet/buy/payment_method.dart';
|
|
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
2024-03-25 13:16:57 -05:00
|
|
|
import 'package:cake_wallet/exchange/trade_state.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2023-06-14 02:15:10 +03:00
|
|
|
import 'package:cake_wallet/palette.dart';
|
2023-12-28 21:20:59 +02:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
New themes (#2239)
* Add theme base v2
* Initial new theme base files
* Typos
* Fixes
* Update theme files
* feat: Migrate to Material 3 Theming
Foundation, Theme Data Refactor, and First Extension Cleanup Batch.
This commit completes the first major phase of migrating to Material 3 theming by setting up the foundations for material 3 integration and begins the initial migration, removing custom theme extensions, updating theme data, and refactoring all relevant widget and page theming to use Material 3’s built-in color and typography tokens.
These changes:
- Lays the groundwork for Material 3 theming by restructuring the app’s theme configuration to use Material 3’s ColorScheme and TextTheme as the primary sources of color and typography throughout the app.
- Refactors the core theme config files by removing legacy custom color roles ensuring all color definitions now map directly to Material 3’s role.
- Begins the first batch migration of custom theme extensions (InfoTheme, PlaceholderTheme, KeyboardTheme, PinCodeTheme) and updates all affected widgets and pages to use Material 3 color and typography tokens instead of the custom properties.
- Cleans up the codebase by deleting the files of the initial set of migrated extensions and eliminating all related imports and usages.
* feat: Migrate to Material 3 Theming.
This change:
- Updates the themes README.md file to reflect the current structure and give more information based on the first major phase that was completed.
* feat: Migrate to Material 3 Theming
Deleting previous theme extensions
* feat: Migrate to Material 3 Theming
Another batch of migrations from existing extensions
* feat: Migration to Material 3 Theming
Third Migration batch for theme extensions
* fwat: Migration to Material 3 Theming
Final Migration batch for previous theme extensions
* Update onboarding hero
* Update button radius
* Add surfaceContainer to light theme
* feat(themes): Migrate to Material 3 Theming
This change:
- Adds new set of hero images
- Modifies the core structure for the themes
- Add missing color tokens to the theme classes
- Adds a CustomThemeColor class for custom color tokens
- Modifies the themelist to have a fall back for previous theme implementation
- Adds localization for some texts
- Modifies the flow for loading the theme on app start
- Add a WidgetsBindingObserver that listens for changes in the device theme and updates the app theme when there is a change
- Registers the themeStore as a Singleton for codebase wide use
* feat(themes): Migrate to Material 3 theming
This change:
- Migrates UI flows across the app to the new themes
- Confirms styling and typography of components across the app uses the new themes
- Remove instances of Palette use
- Switch TextStyles across the app to use theme text styles
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adjusts bottomsheets styling and removes duplicate close button
- Removes more themedata extensions from the previous implementation
* - Remove outlines from cards and dock
- Update menu colors
- Update padding/divider size for cards
* - Update PIN screen
- Fix navigation dock shadow
- Update wallet screen colors
* Update border radius --skip-ci
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adds gradient backgrounds to the dashbaord and balance cards.
- Migrates the input fields across the app to BaseTextFormFields.
- Removes dependence of input fields on individual styling, focusing instead on using theme defined InputDecoration styling with adjustments on individual components where needed.
- Applies new theme styling to BaseTextFormField, AddressTextField and CurrencyAmountTextField.
* - Switch some hero images to PNG
- Fix nagivation_dock shadow
- Minor fixes
* feat: Add fallback to previous underline styling in central widgets
This change:
- Adds a fallback to CurrencyAmountTextField, AddressTextField, and BaseTextFormField, allowing them use the previous theme styling.
- Adds localization for new texts
* feat(themes): Update warning box colors for dark and light themes
* feat(themes): Relaod themes when user restores from backup, ensuring the user previous theme preference is used.
* feat(themes): Handle themes logic during restore from backup
This change:
- Refactors theme loading logic to handle backup restore edgecase
- Refreshes the theme based on the user saved preference during restore from backup flow
* Fix card gradients and spacing
* Fix even more radiuses
Test new icons for navigation_dock.dart
* Update onboarding flow backgrounds
Fix swap icon clipping
Fix some text colors
Add more hero images
* Fix incorrect color for light theme
* Fix more hero images and cleanup
* Update text field icons
Fix info box CTA colors
Fix sync indicator colors
* Update toggle colors
Update dark theme colors (minor)
Update crypto_balance_widget.dart icon
* Update page transitions in router.dart
Fix some colors
* feat(themes): Display label by default for filled textfields
* feat(themes): Refactor theme handling across various components
This change:
- Fixes issue with themeMode resetting to system mode when app is restarted causing a UI glitch
- Updates theme checks from `currentTheme.type == ThemeType.dark` to `currentTheme.isDark` for consistency
- Adjusts UI components to use the theme directly from the themeStore
* feat(themes): Add animating tagline to the create pin welcome screen
* Revert text fields label temporarily, fix a couple colors, and cleanup some images
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Blazebrain <davidadegoke16@gmail.com>
2025-05-25 20:11:45 +00:00
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
|
|
import 'package:cake_wallet/themes/core/material_base_theme.dart';
|
2025-06-20 21:56:18 +02:00
|
|
|
import 'package:cw_core/utils/proxy_wrapper.dart';
|
2024-03-25 13:16:57 -05:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2021-12-24 14:37:24 +02:00
|
|
|
import 'package:cw_core/wallet_base.dart';
|
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2024-12-09 12:23:59 -06:00
|
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
2024-03-25 13:16:57 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2023-12-28 21:20:59 +02:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2021-12-08 12:46:01 +00:00
|
|
|
|
2024-03-28 06:30:41 -07:00
|
|
|
class MoonPayProvider extends BuyProvider {
|
|
|
|
MoonPayProvider({
|
New themes (#2239)
* Add theme base v2
* Initial new theme base files
* Typos
* Fixes
* Update theme files
* feat: Migrate to Material 3 Theming
Foundation, Theme Data Refactor, and First Extension Cleanup Batch.
This commit completes the first major phase of migrating to Material 3 theming by setting up the foundations for material 3 integration and begins the initial migration, removing custom theme extensions, updating theme data, and refactoring all relevant widget and page theming to use Material 3’s built-in color and typography tokens.
These changes:
- Lays the groundwork for Material 3 theming by restructuring the app’s theme configuration to use Material 3’s ColorScheme and TextTheme as the primary sources of color and typography throughout the app.
- Refactors the core theme config files by removing legacy custom color roles ensuring all color definitions now map directly to Material 3’s role.
- Begins the first batch migration of custom theme extensions (InfoTheme, PlaceholderTheme, KeyboardTheme, PinCodeTheme) and updates all affected widgets and pages to use Material 3 color and typography tokens instead of the custom properties.
- Cleans up the codebase by deleting the files of the initial set of migrated extensions and eliminating all related imports and usages.
* feat: Migrate to Material 3 Theming.
This change:
- Updates the themes README.md file to reflect the current structure and give more information based on the first major phase that was completed.
* feat: Migrate to Material 3 Theming
Deleting previous theme extensions
* feat: Migrate to Material 3 Theming
Another batch of migrations from existing extensions
* feat: Migration to Material 3 Theming
Third Migration batch for theme extensions
* fwat: Migration to Material 3 Theming
Final Migration batch for previous theme extensions
* Update onboarding hero
* Update button radius
* Add surfaceContainer to light theme
* feat(themes): Migrate to Material 3 Theming
This change:
- Adds new set of hero images
- Modifies the core structure for the themes
- Add missing color tokens to the theme classes
- Adds a CustomThemeColor class for custom color tokens
- Modifies the themelist to have a fall back for previous theme implementation
- Adds localization for some texts
- Modifies the flow for loading the theme on app start
- Add a WidgetsBindingObserver that listens for changes in the device theme and updates the app theme when there is a change
- Registers the themeStore as a Singleton for codebase wide use
* feat(themes): Migrate to Material 3 theming
This change:
- Migrates UI flows across the app to the new themes
- Confirms styling and typography of components across the app uses the new themes
- Remove instances of Palette use
- Switch TextStyles across the app to use theme text styles
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adjusts bottomsheets styling and removes duplicate close button
- Removes more themedata extensions from the previous implementation
* - Remove outlines from cards and dock
- Update menu colors
- Update padding/divider size for cards
* - Update PIN screen
- Fix navigation dock shadow
- Update wallet screen colors
* Update border radius --skip-ci
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adds gradient backgrounds to the dashbaord and balance cards.
- Migrates the input fields across the app to BaseTextFormFields.
- Removes dependence of input fields on individual styling, focusing instead on using theme defined InputDecoration styling with adjustments on individual components where needed.
- Applies new theme styling to BaseTextFormField, AddressTextField and CurrencyAmountTextField.
* - Switch some hero images to PNG
- Fix nagivation_dock shadow
- Minor fixes
* feat: Add fallback to previous underline styling in central widgets
This change:
- Adds a fallback to CurrencyAmountTextField, AddressTextField, and BaseTextFormField, allowing them use the previous theme styling.
- Adds localization for new texts
* feat(themes): Update warning box colors for dark and light themes
* feat(themes): Relaod themes when user restores from backup, ensuring the user previous theme preference is used.
* feat(themes): Handle themes logic during restore from backup
This change:
- Refactors theme loading logic to handle backup restore edgecase
- Refreshes the theme based on the user saved preference during restore from backup flow
* Fix card gradients and spacing
* Fix even more radiuses
Test new icons for navigation_dock.dart
* Update onboarding flow backgrounds
Fix swap icon clipping
Fix some text colors
Add more hero images
* Fix incorrect color for light theme
* Fix more hero images and cleanup
* Update text field icons
Fix info box CTA colors
Fix sync indicator colors
* Update toggle colors
Update dark theme colors (minor)
Update crypto_balance_widget.dart icon
* Update page transitions in router.dart
Fix some colors
* feat(themes): Display label by default for filled textfields
* feat(themes): Refactor theme handling across various components
This change:
- Fixes issue with themeMode resetting to system mode when app is restarted causing a UI glitch
- Updates theme checks from `currentTheme.type == ThemeType.dark` to `currentTheme.isDark` for consistency
- Adjusts UI components to use the theme directly from the themeStore
* feat(themes): Add animating tagline to the create pin welcome screen
* Revert text fields label temporarily, fix a couple colors, and cleanup some images
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Blazebrain <davidadegoke16@gmail.com>
2025-05-25 20:11:45 +00:00
|
|
|
required AppStore appStore,
|
2024-01-01 15:05:37 +02:00
|
|
|
required WalletBase wallet,
|
|
|
|
bool isTestEnvironment = false,
|
2024-03-28 06:30:41 -07:00
|
|
|
}) : baseSellUrl = isTestEnvironment ? _baseSellTestUrl : _baseSellProductUrl,
|
|
|
|
baseBuyUrl = isTestEnvironment ? _baseBuyTestUrl : _baseBuyProductUrl,
|
New themes (#2239)
* Add theme base v2
* Initial new theme base files
* Typos
* Fixes
* Update theme files
* feat: Migrate to Material 3 Theming
Foundation, Theme Data Refactor, and First Extension Cleanup Batch.
This commit completes the first major phase of migrating to Material 3 theming by setting up the foundations for material 3 integration and begins the initial migration, removing custom theme extensions, updating theme data, and refactoring all relevant widget and page theming to use Material 3’s built-in color and typography tokens.
These changes:
- Lays the groundwork for Material 3 theming by restructuring the app’s theme configuration to use Material 3’s ColorScheme and TextTheme as the primary sources of color and typography throughout the app.
- Refactors the core theme config files by removing legacy custom color roles ensuring all color definitions now map directly to Material 3’s role.
- Begins the first batch migration of custom theme extensions (InfoTheme, PlaceholderTheme, KeyboardTheme, PinCodeTheme) and updates all affected widgets and pages to use Material 3 color and typography tokens instead of the custom properties.
- Cleans up the codebase by deleting the files of the initial set of migrated extensions and eliminating all related imports and usages.
* feat: Migrate to Material 3 Theming.
This change:
- Updates the themes README.md file to reflect the current structure and give more information based on the first major phase that was completed.
* feat: Migrate to Material 3 Theming
Deleting previous theme extensions
* feat: Migrate to Material 3 Theming
Another batch of migrations from existing extensions
* feat: Migration to Material 3 Theming
Third Migration batch for theme extensions
* fwat: Migration to Material 3 Theming
Final Migration batch for previous theme extensions
* Update onboarding hero
* Update button radius
* Add surfaceContainer to light theme
* feat(themes): Migrate to Material 3 Theming
This change:
- Adds new set of hero images
- Modifies the core structure for the themes
- Add missing color tokens to the theme classes
- Adds a CustomThemeColor class for custom color tokens
- Modifies the themelist to have a fall back for previous theme implementation
- Adds localization for some texts
- Modifies the flow for loading the theme on app start
- Add a WidgetsBindingObserver that listens for changes in the device theme and updates the app theme when there is a change
- Registers the themeStore as a Singleton for codebase wide use
* feat(themes): Migrate to Material 3 theming
This change:
- Migrates UI flows across the app to the new themes
- Confirms styling and typography of components across the app uses the new themes
- Remove instances of Palette use
- Switch TextStyles across the app to use theme text styles
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adjusts bottomsheets styling and removes duplicate close button
- Removes more themedata extensions from the previous implementation
* - Remove outlines from cards and dock
- Update menu colors
- Update padding/divider size for cards
* - Update PIN screen
- Fix navigation dock shadow
- Update wallet screen colors
* Update border radius --skip-ci
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adds gradient backgrounds to the dashbaord and balance cards.
- Migrates the input fields across the app to BaseTextFormFields.
- Removes dependence of input fields on individual styling, focusing instead on using theme defined InputDecoration styling with adjustments on individual components where needed.
- Applies new theme styling to BaseTextFormField, AddressTextField and CurrencyAmountTextField.
* - Switch some hero images to PNG
- Fix nagivation_dock shadow
- Minor fixes
* feat: Add fallback to previous underline styling in central widgets
This change:
- Adds a fallback to CurrencyAmountTextField, AddressTextField, and BaseTextFormField, allowing them use the previous theme styling.
- Adds localization for new texts
* feat(themes): Update warning box colors for dark and light themes
* feat(themes): Relaod themes when user restores from backup, ensuring the user previous theme preference is used.
* feat(themes): Handle themes logic during restore from backup
This change:
- Refactors theme loading logic to handle backup restore edgecase
- Refreshes the theme based on the user saved preference during restore from backup flow
* Fix card gradients and spacing
* Fix even more radiuses
Test new icons for navigation_dock.dart
* Update onboarding flow backgrounds
Fix swap icon clipping
Fix some text colors
Add more hero images
* Fix incorrect color for light theme
* Fix more hero images and cleanup
* Update text field icons
Fix info box CTA colors
Fix sync indicator colors
* Update toggle colors
Update dark theme colors (minor)
Update crypto_balance_widget.dart icon
* Update page transitions in router.dart
Fix some colors
* feat(themes): Display label by default for filled textfields
* feat(themes): Refactor theme handling across various components
This change:
- Fixes issue with themeMode resetting to system mode when app is restarted causing a UI glitch
- Updates theme checks from `currentTheme.type == ThemeType.dark` to `currentTheme.isDark` for consistency
- Adjusts UI components to use the theme directly from the themeStore
* feat(themes): Add animating tagline to the create pin welcome screen
* Revert text fields label temporarily, fix a couple colors, and cleanup some images
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Blazebrain <davidadegoke16@gmail.com>
2025-05-25 20:11:45 +00:00
|
|
|
this._appStore = appStore,
|
2025-03-29 07:46:16 +02:00
|
|
|
super(
|
|
|
|
wallet: wallet,
|
|
|
|
isTestEnvironment: isTestEnvironment,
|
|
|
|
ledgerVM: null,
|
|
|
|
supportedCryptoList: supportedCryptoToFiatPairs(
|
|
|
|
notSupportedCrypto: _notSupportedCrypto, notSupportedFiat: _notSupportedFiat),
|
|
|
|
supportedFiatList: supportedFiatToCryptoPairs(
|
|
|
|
notSupportedFiat: _notSupportedFiat, notSupportedCrypto: _notSupportedCrypto));
|
2023-12-28 21:20:59 +02:00
|
|
|
|
New themes (#2239)
* Add theme base v2
* Initial new theme base files
* Typos
* Fixes
* Update theme files
* feat: Migrate to Material 3 Theming
Foundation, Theme Data Refactor, and First Extension Cleanup Batch.
This commit completes the first major phase of migrating to Material 3 theming by setting up the foundations for material 3 integration and begins the initial migration, removing custom theme extensions, updating theme data, and refactoring all relevant widget and page theming to use Material 3’s built-in color and typography tokens.
These changes:
- Lays the groundwork for Material 3 theming by restructuring the app’s theme configuration to use Material 3’s ColorScheme and TextTheme as the primary sources of color and typography throughout the app.
- Refactors the core theme config files by removing legacy custom color roles ensuring all color definitions now map directly to Material 3’s role.
- Begins the first batch migration of custom theme extensions (InfoTheme, PlaceholderTheme, KeyboardTheme, PinCodeTheme) and updates all affected widgets and pages to use Material 3 color and typography tokens instead of the custom properties.
- Cleans up the codebase by deleting the files of the initial set of migrated extensions and eliminating all related imports and usages.
* feat: Migrate to Material 3 Theming.
This change:
- Updates the themes README.md file to reflect the current structure and give more information based on the first major phase that was completed.
* feat: Migrate to Material 3 Theming
Deleting previous theme extensions
* feat: Migrate to Material 3 Theming
Another batch of migrations from existing extensions
* feat: Migration to Material 3 Theming
Third Migration batch for theme extensions
* fwat: Migration to Material 3 Theming
Final Migration batch for previous theme extensions
* Update onboarding hero
* Update button radius
* Add surfaceContainer to light theme
* feat(themes): Migrate to Material 3 Theming
This change:
- Adds new set of hero images
- Modifies the core structure for the themes
- Add missing color tokens to the theme classes
- Adds a CustomThemeColor class for custom color tokens
- Modifies the themelist to have a fall back for previous theme implementation
- Adds localization for some texts
- Modifies the flow for loading the theme on app start
- Add a WidgetsBindingObserver that listens for changes in the device theme and updates the app theme when there is a change
- Registers the themeStore as a Singleton for codebase wide use
* feat(themes): Migrate to Material 3 theming
This change:
- Migrates UI flows across the app to the new themes
- Confirms styling and typography of components across the app uses the new themes
- Remove instances of Palette use
- Switch TextStyles across the app to use theme text styles
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adjusts bottomsheets styling and removes duplicate close button
- Removes more themedata extensions from the previous implementation
* - Remove outlines from cards and dock
- Update menu colors
- Update padding/divider size for cards
* - Update PIN screen
- Fix navigation dock shadow
- Update wallet screen colors
* Update border radius --skip-ci
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adds gradient backgrounds to the dashbaord and balance cards.
- Migrates the input fields across the app to BaseTextFormFields.
- Removes dependence of input fields on individual styling, focusing instead on using theme defined InputDecoration styling with adjustments on individual components where needed.
- Applies new theme styling to BaseTextFormField, AddressTextField and CurrencyAmountTextField.
* - Switch some hero images to PNG
- Fix nagivation_dock shadow
- Minor fixes
* feat: Add fallback to previous underline styling in central widgets
This change:
- Adds a fallback to CurrencyAmountTextField, AddressTextField, and BaseTextFormField, allowing them use the previous theme styling.
- Adds localization for new texts
* feat(themes): Update warning box colors for dark and light themes
* feat(themes): Relaod themes when user restores from backup, ensuring the user previous theme preference is used.
* feat(themes): Handle themes logic during restore from backup
This change:
- Refactors theme loading logic to handle backup restore edgecase
- Refreshes the theme based on the user saved preference during restore from backup flow
* Fix card gradients and spacing
* Fix even more radiuses
Test new icons for navigation_dock.dart
* Update onboarding flow backgrounds
Fix swap icon clipping
Fix some text colors
Add more hero images
* Fix incorrect color for light theme
* Fix more hero images and cleanup
* Update text field icons
Fix info box CTA colors
Fix sync indicator colors
* Update toggle colors
Update dark theme colors (minor)
Update crypto_balance_widget.dart icon
* Update page transitions in router.dart
Fix some colors
* feat(themes): Display label by default for filled textfields
* feat(themes): Refactor theme handling across various components
This change:
- Fixes issue with themeMode resetting to system mode when app is restarted causing a UI glitch
- Updates theme checks from `currentTheme.type == ThemeType.dark` to `currentTheme.isDark` for consistency
- Adjusts UI components to use the theme directly from the themeStore
* feat(themes): Add animating tagline to the create pin welcome screen
* Revert text fields label temporarily, fix a couple colors, and cleanup some images
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Blazebrain <davidadegoke16@gmail.com>
2025-05-25 20:11:45 +00:00
|
|
|
final AppStore _appStore;
|
2021-12-08 12:46:01 +00:00
|
|
|
|
2024-03-28 06:30:41 -07:00
|
|
|
static const _baseSellTestUrl = 'sell-sandbox.moonpay.com';
|
|
|
|
static const _baseSellProductUrl = 'sell.moonpay.com';
|
|
|
|
static const _baseBuyTestUrl = 'buy-staging.moonpay.com';
|
|
|
|
static const _baseBuyProductUrl = 'buy.moonpay.com';
|
2024-03-25 13:16:57 -05:00
|
|
|
static const _cIdBaseUrl = 'exchange-helper.cakewallet.com';
|
2024-03-28 06:30:41 -07:00
|
|
|
static const _apiUrl = 'https://api.moonpay.com';
|
2024-11-09 21:00:56 +02:00
|
|
|
static const _baseUrl = 'api.moonpay.com';
|
|
|
|
static const _currenciesPath = '/v3/currencies';
|
|
|
|
static const _buyQuote = '/buy_quote';
|
|
|
|
static const _sellQuote = '/sell_quote';
|
|
|
|
|
|
|
|
static const _transactionsSuffix = '/v1/transactions';
|
|
|
|
|
2025-03-29 07:46:16 +02:00
|
|
|
static const List<CryptoCurrency> _notSupportedCrypto = [];
|
|
|
|
static const List<FiatCurrency> _notSupportedFiat = [];
|
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
final String baseBuyUrl;
|
|
|
|
final String baseSellUrl;
|
2023-12-28 21:20:59 +02:00
|
|
|
|
2024-01-01 15:05:37 +02:00
|
|
|
@override
|
|
|
|
String get providerDescription =>
|
|
|
|
'MoonPay offers a fast and simple way to buy and sell cryptocurrencies';
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get title => 'MoonPay';
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get lightIcon => 'assets/images/moonpay_light.png';
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get darkIcon => 'assets/images/moonpay_dark.png';
|
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
@override
|
|
|
|
bool get isAggregator => false;
|
|
|
|
|
|
|
|
static String get _apiKey => secrets.moonPayApiKey;
|
|
|
|
|
|
|
|
String get currencyCode => walletTypeToCryptoCurrency(wallet.type).title.toLowerCase();
|
|
|
|
|
|
|
|
String get trackUrl => baseBuyUrl + '/transaction_receipt?transactionId=';
|
|
|
|
|
|
|
|
static String get _exchangeHelperApiKey => secrets.exchangeHelperApiKey;
|
|
|
|
|
New themes (#2239)
* Add theme base v2
* Initial new theme base files
* Typos
* Fixes
* Update theme files
* feat: Migrate to Material 3 Theming
Foundation, Theme Data Refactor, and First Extension Cleanup Batch.
This commit completes the first major phase of migrating to Material 3 theming by setting up the foundations for material 3 integration and begins the initial migration, removing custom theme extensions, updating theme data, and refactoring all relevant widget and page theming to use Material 3’s built-in color and typography tokens.
These changes:
- Lays the groundwork for Material 3 theming by restructuring the app’s theme configuration to use Material 3’s ColorScheme and TextTheme as the primary sources of color and typography throughout the app.
- Refactors the core theme config files by removing legacy custom color roles ensuring all color definitions now map directly to Material 3’s role.
- Begins the first batch migration of custom theme extensions (InfoTheme, PlaceholderTheme, KeyboardTheme, PinCodeTheme) and updates all affected widgets and pages to use Material 3 color and typography tokens instead of the custom properties.
- Cleans up the codebase by deleting the files of the initial set of migrated extensions and eliminating all related imports and usages.
* feat: Migrate to Material 3 Theming.
This change:
- Updates the themes README.md file to reflect the current structure and give more information based on the first major phase that was completed.
* feat: Migrate to Material 3 Theming
Deleting previous theme extensions
* feat: Migrate to Material 3 Theming
Another batch of migrations from existing extensions
* feat: Migration to Material 3 Theming
Third Migration batch for theme extensions
* fwat: Migration to Material 3 Theming
Final Migration batch for previous theme extensions
* Update onboarding hero
* Update button radius
* Add surfaceContainer to light theme
* feat(themes): Migrate to Material 3 Theming
This change:
- Adds new set of hero images
- Modifies the core structure for the themes
- Add missing color tokens to the theme classes
- Adds a CustomThemeColor class for custom color tokens
- Modifies the themelist to have a fall back for previous theme implementation
- Adds localization for some texts
- Modifies the flow for loading the theme on app start
- Add a WidgetsBindingObserver that listens for changes in the device theme and updates the app theme when there is a change
- Registers the themeStore as a Singleton for codebase wide use
* feat(themes): Migrate to Material 3 theming
This change:
- Migrates UI flows across the app to the new themes
- Confirms styling and typography of components across the app uses the new themes
- Remove instances of Palette use
- Switch TextStyles across the app to use theme text styles
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adjusts bottomsheets styling and removes duplicate close button
- Removes more themedata extensions from the previous implementation
* - Remove outlines from cards and dock
- Update menu colors
- Update padding/divider size for cards
* - Update PIN screen
- Fix navigation dock shadow
- Update wallet screen colors
* Update border radius --skip-ci
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adds gradient backgrounds to the dashbaord and balance cards.
- Migrates the input fields across the app to BaseTextFormFields.
- Removes dependence of input fields on individual styling, focusing instead on using theme defined InputDecoration styling with adjustments on individual components where needed.
- Applies new theme styling to BaseTextFormField, AddressTextField and CurrencyAmountTextField.
* - Switch some hero images to PNG
- Fix nagivation_dock shadow
- Minor fixes
* feat: Add fallback to previous underline styling in central widgets
This change:
- Adds a fallback to CurrencyAmountTextField, AddressTextField, and BaseTextFormField, allowing them use the previous theme styling.
- Adds localization for new texts
* feat(themes): Update warning box colors for dark and light themes
* feat(themes): Relaod themes when user restores from backup, ensuring the user previous theme preference is used.
* feat(themes): Handle themes logic during restore from backup
This change:
- Refactors theme loading logic to handle backup restore edgecase
- Refreshes the theme based on the user saved preference during restore from backup flow
* Fix card gradients and spacing
* Fix even more radiuses
Test new icons for navigation_dock.dart
* Update onboarding flow backgrounds
Fix swap icon clipping
Fix some text colors
Add more hero images
* Fix incorrect color for light theme
* Fix more hero images and cleanup
* Update text field icons
Fix info box CTA colors
Fix sync indicator colors
* Update toggle colors
Update dark theme colors (minor)
Update crypto_balance_widget.dart icon
* Update page transitions in router.dart
Fix some colors
* feat(themes): Display label by default for filled textfields
* feat(themes): Refactor theme handling across various components
This change:
- Fixes issue with themeMode resetting to system mode when app is restarted causing a UI glitch
- Updates theme checks from `currentTheme.type == ThemeType.dark` to `currentTheme.isDark` for consistency
- Adjusts UI components to use the theme directly from the themeStore
* feat(themes): Add animating tagline to the create pin welcome screen
* Revert text fields label temporarily, fix a couple colors, and cleanup some images
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Blazebrain <davidadegoke16@gmail.com>
2025-05-25 20:11:45 +00:00
|
|
|
static String themeToMoonPayTheme(MaterialThemeBase theme) {
|
2023-06-14 02:15:10 +03:00
|
|
|
switch (theme.type) {
|
|
|
|
case ThemeType.light:
|
|
|
|
return 'light';
|
|
|
|
case ThemeType.dark:
|
|
|
|
return 'dark';
|
|
|
|
}
|
|
|
|
}
|
2023-12-28 21:20:59 +02:00
|
|
|
|
2024-03-25 13:16:57 -05:00
|
|
|
Future<String> getMoonpaySignature(String query) async {
|
|
|
|
final uri = Uri.https(_cIdBaseUrl, "/api/moonpay");
|
|
|
|
|
2025-06-20 21:56:18 +02:00
|
|
|
final response = await ProxyWrapper().post(
|
|
|
|
clearnetUri: uri,
|
|
|
|
headers: {'Content-Type': 'application/json', 'x-api-key': _exchangeHelperApiKey},
|
|
|
|
body: json.encode({'query': query}),
|
|
|
|
);
|
|
|
|
|
2024-03-25 13:16:57 -05:00
|
|
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
return (jsonDecode(response.body) as Map<String, dynamic>)['signature'] as String;
|
|
|
|
} else {
|
|
|
|
throw Exception(
|
|
|
|
'Provider currently unavailable. Status: ${response.statusCode} ${response.body}');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
Future<Map<String, dynamic>> fetchFiatCredentials(
|
|
|
|
String fiatCurrency, String cryptocurrency, String? paymentMethod) async {
|
|
|
|
final params = {'baseCurrencyCode': fiatCurrency.toLowerCase(), 'apiKey': _apiKey};
|
2023-06-14 02:15:10 +03:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
if (paymentMethod != null) params['paymentMethod'] = paymentMethod;
|
2024-03-28 06:30:41 -07:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
final path = '$_currenciesPath/${cryptocurrency.toLowerCase()}/limits';
|
|
|
|
final url = Uri.https(_baseUrl, path, params);
|
2023-12-28 21:20:59 +02:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
try {
|
2025-06-20 21:56:18 +02:00
|
|
|
final response = await ProxyWrapper().get(
|
|
|
|
clearnetUri: url,
|
|
|
|
headers: {'accept': 'application/json'},
|
|
|
|
);
|
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
if (response.statusCode == 200) {
|
|
|
|
return jsonDecode(response.body) as Map<String, dynamic>;
|
|
|
|
} else {
|
2024-12-09 12:23:59 -06:00
|
|
|
printV('MoonPay does not support fiat: $fiatCurrency');
|
2024-11-09 21:00:56 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2024-12-09 12:23:59 -06:00
|
|
|
printV('MoonPay Error fetching fiat currencies: $e');
|
2024-11-09 21:00:56 +02:00
|
|
|
return {};
|
2021-12-08 12:46:01 +00:00
|
|
|
}
|
2024-11-09 21:00:56 +02:00
|
|
|
}
|
2021-12-08 12:46:01 +00:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
Future<List<PaymentMethod>> getAvailablePaymentTypes(
|
2025-03-06 19:39:41 +02:00
|
|
|
String fiatCurrency, CryptoCurrency cryptoCurrency, bool isBuyAction) async {
|
2024-11-09 21:00:56 +02:00
|
|
|
final List<PaymentMethod> paymentMethods = [];
|
|
|
|
|
|
|
|
if (isBuyAction) {
|
2025-03-07 02:48:22 +02:00
|
|
|
final fiatBuyCredentials =
|
|
|
|
await fetchFiatCredentials(fiatCurrency, cryptoCurrency.title, null);
|
2024-11-09 21:00:56 +02:00
|
|
|
if (fiatBuyCredentials.isNotEmpty) {
|
|
|
|
final paymentMethod = fiatBuyCredentials['paymentMethod'] as String?;
|
|
|
|
paymentMethods.add(PaymentMethod.fromMoonPayJson(
|
|
|
|
fiatBuyCredentials, _getPaymentTypeByString(paymentMethod)));
|
|
|
|
return paymentMethods;
|
|
|
|
}
|
|
|
|
}
|
2024-03-28 06:30:41 -07:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
return paymentMethods;
|
2021-12-08 12:46:01 +00:00
|
|
|
}
|
2023-12-28 21:20:59 +02:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
@override
|
|
|
|
Future<List<Quote>?> fetchQuote(
|
|
|
|
{required CryptoCurrency cryptoCurrency,
|
|
|
|
required FiatCurrency fiatCurrency,
|
|
|
|
required double amount,
|
|
|
|
required bool isBuyAction,
|
|
|
|
required String walletAddress,
|
|
|
|
PaymentType? paymentType,
|
2025-05-15 19:48:06 +03:00
|
|
|
String? customPaymentMethodType,
|
2024-11-09 21:00:56 +02:00
|
|
|
String? countryCode}) async {
|
|
|
|
String? paymentMethod;
|
|
|
|
|
|
|
|
if (paymentType != null && paymentType != PaymentType.all) {
|
|
|
|
paymentMethod = normalizePaymentMethod(paymentType);
|
|
|
|
if (paymentMethod == null) paymentMethod = paymentType.name;
|
|
|
|
} else {
|
|
|
|
paymentMethod = 'credit_debit_card';
|
|
|
|
}
|
|
|
|
|
|
|
|
final action = isBuyAction ? 'buy' : 'sell';
|
|
|
|
|
|
|
|
final formattedCryptoCurrency = _normalizeCurrency(cryptoCurrency);
|
|
|
|
final baseCurrencyCode =
|
|
|
|
isBuyAction ? fiatCurrency.name.toLowerCase() : cryptoCurrency.title.toLowerCase();
|
2021-04-13 21:40:44 +03:00
|
|
|
|
2024-03-28 06:30:41 -07:00
|
|
|
final params = {
|
2024-11-09 21:00:56 +02:00
|
|
|
'baseCurrencyCode': baseCurrencyCode,
|
2025-03-06 01:41:23 +02:00
|
|
|
'baseCurrencyAmount': amount.toStringAsFixed(2),
|
2024-11-09 21:00:56 +02:00
|
|
|
'paymentMethod': paymentMethod,
|
|
|
|
'areFeesIncluded': 'false',
|
|
|
|
'apiKey': _apiKey
|
|
|
|
};
|
|
|
|
|
|
|
|
log('MoonPay: Fetching $action quote: ${isBuyAction ? formattedCryptoCurrency : fiatCurrency.name.toLowerCase()} -> ${isBuyAction ? baseCurrencyCode : formattedCryptoCurrency}, amount: $amount, paymentMethod: $paymentMethod');
|
|
|
|
|
|
|
|
final quotePath = isBuyAction ? _buyQuote : _sellQuote;
|
|
|
|
|
|
|
|
final path = '$_currenciesPath/$formattedCryptoCurrency$quotePath';
|
|
|
|
final url = Uri.https(_baseUrl, path, params);
|
|
|
|
try {
|
2025-06-20 21:56:18 +02:00
|
|
|
final response = await ProxyWrapper().get(clearnetUri: url);
|
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
if (response.statusCode == 200) {
|
|
|
|
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
|
|
|
|
|
|
|
// Check if the response is for the correct fiat currency
|
|
|
|
if (isBuyAction) {
|
|
|
|
final fiatCurrencyCode = data['baseCurrencyCode'] as String?;
|
|
|
|
if (fiatCurrencyCode == null || fiatCurrencyCode != fiatCurrency.name.toLowerCase())
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
final quoteCurrency = data['quoteCurrency'] as Map<String, dynamic>?;
|
|
|
|
if (quoteCurrency == null || quoteCurrency['code'] != fiatCurrency.name.toLowerCase())
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final paymentMethods = data['paymentMethod'] as String?;
|
|
|
|
final quote =
|
|
|
|
Quote.fromMoonPayJson(data, isBuyAction, _getPaymentTypeByString(paymentMethods));
|
|
|
|
|
|
|
|
quote.setFiatCurrency = fiatCurrency;
|
|
|
|
quote.setCryptoCurrency = cryptoCurrency;
|
|
|
|
|
|
|
|
return [quote];
|
|
|
|
} else {
|
2024-12-09 12:23:59 -06:00
|
|
|
printV('Moon Pay: Error fetching buy quote: ');
|
2024-11-09 21:00:56 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2024-12-09 12:23:59 -06:00
|
|
|
printV('Moon Pay: Error fetching buy quote: $e');
|
2024-11-09 21:00:56 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void>? launchProvider(
|
|
|
|
{required BuildContext context,
|
|
|
|
required Quote quote,
|
|
|
|
required double amount,
|
|
|
|
required bool isBuyAction,
|
|
|
|
required String cryptoCurrencyAddress,
|
|
|
|
String? countryCode}) async {
|
|
|
|
final Map<String, String> params = {
|
New themes (#2239)
* Add theme base v2
* Initial new theme base files
* Typos
* Fixes
* Update theme files
* feat: Migrate to Material 3 Theming
Foundation, Theme Data Refactor, and First Extension Cleanup Batch.
This commit completes the first major phase of migrating to Material 3 theming by setting up the foundations for material 3 integration and begins the initial migration, removing custom theme extensions, updating theme data, and refactoring all relevant widget and page theming to use Material 3’s built-in color and typography tokens.
These changes:
- Lays the groundwork for Material 3 theming by restructuring the app’s theme configuration to use Material 3’s ColorScheme and TextTheme as the primary sources of color and typography throughout the app.
- Refactors the core theme config files by removing legacy custom color roles ensuring all color definitions now map directly to Material 3’s role.
- Begins the first batch migration of custom theme extensions (InfoTheme, PlaceholderTheme, KeyboardTheme, PinCodeTheme) and updates all affected widgets and pages to use Material 3 color and typography tokens instead of the custom properties.
- Cleans up the codebase by deleting the files of the initial set of migrated extensions and eliminating all related imports and usages.
* feat: Migrate to Material 3 Theming.
This change:
- Updates the themes README.md file to reflect the current structure and give more information based on the first major phase that was completed.
* feat: Migrate to Material 3 Theming
Deleting previous theme extensions
* feat: Migrate to Material 3 Theming
Another batch of migrations from existing extensions
* feat: Migration to Material 3 Theming
Third Migration batch for theme extensions
* fwat: Migration to Material 3 Theming
Final Migration batch for previous theme extensions
* Update onboarding hero
* Update button radius
* Add surfaceContainer to light theme
* feat(themes): Migrate to Material 3 Theming
This change:
- Adds new set of hero images
- Modifies the core structure for the themes
- Add missing color tokens to the theme classes
- Adds a CustomThemeColor class for custom color tokens
- Modifies the themelist to have a fall back for previous theme implementation
- Adds localization for some texts
- Modifies the flow for loading the theme on app start
- Add a WidgetsBindingObserver that listens for changes in the device theme and updates the app theme when there is a change
- Registers the themeStore as a Singleton for codebase wide use
* feat(themes): Migrate to Material 3 theming
This change:
- Migrates UI flows across the app to the new themes
- Confirms styling and typography of components across the app uses the new themes
- Remove instances of Palette use
- Switch TextStyles across the app to use theme text styles
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adjusts bottomsheets styling and removes duplicate close button
- Removes more themedata extensions from the previous implementation
* - Remove outlines from cards and dock
- Update menu colors
- Update padding/divider size for cards
* - Update PIN screen
- Fix navigation dock shadow
- Update wallet screen colors
* Update border radius --skip-ci
* feat(themes): Migrate to Material 3 Theming.
This change:
- Adds gradient backgrounds to the dashbaord and balance cards.
- Migrates the input fields across the app to BaseTextFormFields.
- Removes dependence of input fields on individual styling, focusing instead on using theme defined InputDecoration styling with adjustments on individual components where needed.
- Applies new theme styling to BaseTextFormField, AddressTextField and CurrencyAmountTextField.
* - Switch some hero images to PNG
- Fix nagivation_dock shadow
- Minor fixes
* feat: Add fallback to previous underline styling in central widgets
This change:
- Adds a fallback to CurrencyAmountTextField, AddressTextField, and BaseTextFormField, allowing them use the previous theme styling.
- Adds localization for new texts
* feat(themes): Update warning box colors for dark and light themes
* feat(themes): Relaod themes when user restores from backup, ensuring the user previous theme preference is used.
* feat(themes): Handle themes logic during restore from backup
This change:
- Refactors theme loading logic to handle backup restore edgecase
- Refreshes the theme based on the user saved preference during restore from backup flow
* Fix card gradients and spacing
* Fix even more radiuses
Test new icons for navigation_dock.dart
* Update onboarding flow backgrounds
Fix swap icon clipping
Fix some text colors
Add more hero images
* Fix incorrect color for light theme
* Fix more hero images and cleanup
* Update text field icons
Fix info box CTA colors
Fix sync indicator colors
* Update toggle colors
Update dark theme colors (minor)
Update crypto_balance_widget.dart icon
* Update page transitions in router.dart
Fix some colors
* feat(themes): Display label by default for filled textfields
* feat(themes): Refactor theme handling across various components
This change:
- Fixes issue with themeMode resetting to system mode when app is restarted causing a UI glitch
- Updates theme checks from `currentTheme.type == ThemeType.dark` to `currentTheme.isDark` for consistency
- Adjusts UI components to use the theme directly from the themeStore
* feat(themes): Add animating tagline to the create pin welcome screen
* Revert text fields label temporarily, fix a couple colors, and cleanup some images
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Co-authored-by: Blazebrain <davidadegoke16@gmail.com>
2025-05-25 20:11:45 +00:00
|
|
|
'theme': themeToMoonPayTheme(_appStore.themeStore.currentTheme),
|
|
|
|
'language': _appStore.settingsStore.languageCode,
|
|
|
|
'colorCode': _appStore.themeStore.currentTheme.isDark
|
2024-03-28 06:30:41 -07:00
|
|
|
? '#${Palette.blueCraiola.value.toRadixString(16).substring(2, 8)}'
|
|
|
|
: '#${Palette.moderateSlateBlue.value.toRadixString(16).substring(2, 8)}',
|
2024-11-09 21:00:56 +02:00
|
|
|
'baseCurrencyCode': isBuyAction ? quote.fiatCurrency.name : quote.cryptoCurrency.name,
|
2025-03-06 01:41:23 +02:00
|
|
|
'baseCurrencyAmount': amount.toStringAsFixed(2),
|
2024-11-09 21:00:56 +02:00
|
|
|
'walletAddress': cryptoCurrencyAddress,
|
2024-04-08 10:42:27 -07:00
|
|
|
'lockAmount': 'false',
|
2024-03-28 06:30:41 -07:00
|
|
|
'showAllCurrencies': 'false',
|
|
|
|
'showWalletAddressForm': 'false',
|
2024-11-09 21:00:56 +02:00
|
|
|
if (isBuyAction)
|
|
|
|
'enabledPaymentMethods': normalizePaymentMethod(quote.paymentType) ??
|
|
|
|
'credit_debit_card,apple_pay,google_pay,samsung_pay,sepa_bank_transfer,gbp_bank_transfer,gbp_open_banking_payment',
|
|
|
|
if (!isBuyAction) 'refundWalletAddress': cryptoCurrencyAddress
|
2024-03-28 06:30:41 -07:00
|
|
|
};
|
2021-04-12 21:22:22 +03:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
if (isBuyAction) params['currencyCode'] = quote.cryptoCurrency.name;
|
|
|
|
if (!isBuyAction) params['quoteCurrencyCode'] = quote.cryptoCurrency.name;
|
|
|
|
|
|
|
|
try {
|
2025-03-07 02:48:22 +02:00
|
|
|
final uri = await requestMoonPayUrl(
|
|
|
|
walletAddress: cryptoCurrencyAddress,
|
|
|
|
isBuyAction: isBuyAction,
|
|
|
|
amount: amount.toString(),
|
|
|
|
params: params);
|
|
|
|
|
|
|
|
if (await canLaunchUrl(uri)) {
|
|
|
|
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
|
|
|
} else {
|
|
|
|
throw Exception('Could not launch URL');
|
2024-11-09 21:00:56 +02:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
if (context.mounted) {
|
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: 'MoonPay',
|
|
|
|
alertContent: 'The MoonPay service is currently unavailable: $e',
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2024-03-28 06:30:41 -07:00
|
|
|
}
|
2024-11-09 21:00:56 +02:00
|
|
|
}
|
2021-04-12 21:22:22 +03:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
Future<Uri> requestMoonPayUrl({
|
|
|
|
required String walletAddress,
|
|
|
|
required bool isBuyAction,
|
|
|
|
required Map<String, String> params,
|
|
|
|
String? amount,
|
|
|
|
}) async {
|
|
|
|
if (_apiKey.isNotEmpty) params['apiKey'] = _apiKey;
|
2021-06-01 21:03:35 +03:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
final baseUrl = isBuyAction ? baseBuyUrl : baseSellUrl;
|
|
|
|
final originalUri = Uri.https(baseUrl, '', params);
|
|
|
|
|
|
|
|
if (isTestEnvironment) return originalUri;
|
2021-06-01 21:03:35 +03:00
|
|
|
|
2024-03-28 06:30:41 -07:00
|
|
|
final signature = await getMoonpaySignature('?${originalUri.query}');
|
|
|
|
final query = Map<String, dynamic>.from(originalUri.queryParameters);
|
|
|
|
query['signature'] = signature;
|
|
|
|
final signedUri = originalUri.replace(queryParameters: query);
|
|
|
|
return signedUri;
|
2021-04-12 21:22:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Order> findOrderById(String id) async {
|
2024-01-01 15:05:37 +02:00
|
|
|
final url = _apiUrl + _transactionsSuffix + '/$id' + '?apiKey=' + _apiKey;
|
2022-10-12 13:09:57 -04:00
|
|
|
final uri = Uri.parse(url);
|
2025-06-20 21:56:18 +02:00
|
|
|
final response = await ProxyWrapper().get(clearnetUri: uri);
|
|
|
|
|
2021-04-12 21:22:22 +03:00
|
|
|
|
|
|
|
if (response.statusCode != 200) {
|
2024-01-01 15:05:37 +02:00
|
|
|
throw BuyException(title: providerDescription, content: 'Transaction $id is not found!');
|
2021-04-12 21:22:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
|
|
|
final status = responseJSON['status'] as String;
|
2021-04-14 21:23:10 +03:00
|
|
|
final state = TradeState.deserialize(raw: status);
|
|
|
|
final createdAtRaw = responseJSON['createdAt'] as String;
|
|
|
|
final createdAt = DateTime.parse(createdAtRaw).toLocal();
|
2021-04-12 21:22:22 +03:00
|
|
|
final amount = responseJSON['quoteCurrencyAmount'] as double;
|
|
|
|
|
|
|
|
return Order(
|
|
|
|
id: id,
|
2023-12-28 21:20:59 +02:00
|
|
|
provider: BuyProviderDescription.moonPay,
|
2021-04-12 21:22:22 +03:00
|
|
|
transferId: id,
|
|
|
|
state: state,
|
|
|
|
createdAt: createdAt,
|
|
|
|
amount: amount.toString(),
|
2023-12-28 21:20:59 +02:00
|
|
|
receiveAddress: wallet.walletAddresses.address,
|
2024-01-01 15:05:37 +02:00
|
|
|
walletId: wallet.id);
|
2021-04-12 21:22:22 +03:00
|
|
|
}
|
2021-06-01 21:03:35 +03:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
String _normalizeCurrency(CryptoCurrency currency) {
|
|
|
|
if (currency.tag == 'POLY') {
|
|
|
|
return '${currency.title.toLowerCase()}_polygon';
|
|
|
|
}
|
2021-06-01 21:03:35 +03:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
if (currency.tag == 'TRX') {
|
|
|
|
return '${currency.title.toLowerCase()}_trx';
|
2021-06-01 21:03:35 +03:00
|
|
|
}
|
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
return currency.toString().toLowerCase();
|
2021-06-01 21:03:35 +03:00
|
|
|
}
|
2023-12-28 21:20:59 +02:00
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
String? normalizePaymentMethod(PaymentType paymentMethod) {
|
|
|
|
switch (paymentMethod) {
|
|
|
|
case PaymentType.creditCard:
|
|
|
|
return 'credit_debit_card';
|
|
|
|
case PaymentType.debitCard:
|
|
|
|
return 'credit_debit_card';
|
|
|
|
case PaymentType.ach:
|
|
|
|
return 'ach_bank_transfer';
|
|
|
|
case PaymentType.applePay:
|
|
|
|
return 'apple_pay';
|
|
|
|
case PaymentType.googlePay:
|
|
|
|
return 'google_pay';
|
|
|
|
case PaymentType.sepa:
|
|
|
|
return 'sepa_bank_transfer';
|
|
|
|
case PaymentType.paypal:
|
|
|
|
return 'paypal';
|
|
|
|
case PaymentType.sepaOpenBankingPayment:
|
|
|
|
return 'sepa_open_banking_payment';
|
|
|
|
case PaymentType.gbpOpenBankingPayment:
|
|
|
|
return 'gbp_open_banking_payment';
|
|
|
|
case PaymentType.lowCostAch:
|
|
|
|
return 'low_cost_ach';
|
|
|
|
case PaymentType.mobileWallet:
|
|
|
|
return 'mobile_wallet';
|
|
|
|
case PaymentType.pixInstantPayment:
|
|
|
|
return 'pix_instant_payment';
|
|
|
|
case PaymentType.yellowCardBankTransfer:
|
|
|
|
return 'yellow_card_bank_transfer';
|
|
|
|
case PaymentType.fiatBalance:
|
|
|
|
return 'fiat_balance';
|
|
|
|
default:
|
|
|
|
return null;
|
2024-03-28 06:30:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-09 21:00:56 +02:00
|
|
|
PaymentType _getPaymentTypeByString(String? paymentMethod) {
|
|
|
|
switch (paymentMethod) {
|
|
|
|
case 'ach_bank_transfer':
|
|
|
|
return PaymentType.ach;
|
|
|
|
case 'apple_pay':
|
|
|
|
return PaymentType.applePay;
|
|
|
|
case 'credit_debit_card':
|
|
|
|
return PaymentType.creditCard;
|
|
|
|
case 'fiat_balance':
|
|
|
|
return PaymentType.fiatBalance;
|
|
|
|
case 'gbp_open_banking_payment':
|
|
|
|
return PaymentType.gbpOpenBankingPayment;
|
|
|
|
case 'google_pay':
|
|
|
|
return PaymentType.googlePay;
|
|
|
|
case 'low_cost_ach':
|
|
|
|
return PaymentType.lowCostAch;
|
|
|
|
case 'mobile_wallet':
|
|
|
|
return PaymentType.mobileWallet;
|
|
|
|
case 'paypal':
|
|
|
|
return PaymentType.paypal;
|
|
|
|
case 'pix_instant_payment':
|
|
|
|
return PaymentType.pixInstantPayment;
|
|
|
|
case 'sepa_bank_transfer':
|
|
|
|
return PaymentType.sepa;
|
|
|
|
case 'sepa_open_banking_payment':
|
|
|
|
return PaymentType.sepaOpenBankingPayment;
|
|
|
|
case 'yellow_card_bank_transfer':
|
|
|
|
return PaymentType.yellowCardBankTransfer;
|
|
|
|
default:
|
2025-05-15 19:48:06 +03:00
|
|
|
return PaymentType.unknown;
|
2024-03-28 06:30:41 -07:00
|
|
|
}
|
|
|
|
}
|
2024-01-01 15:05:37 +02:00
|
|
|
}
|