From f5119d262ad15be5964fbc3095bd0ea093853d62 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 31 Oct 2025 15:00:33 +0100 Subject: [PATCH] fix: better handle exchange url launching --- lib/buy/sell_buy_states.dart | 6 +++- lib/core/wallet_loading_service.dart | 6 +++- lib/src/screens/buy/buy_sell_page.dart | 9 ++--- lib/view_model/buy/buy_sell_view_model.dart | 37 ++++++++++++++------- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/lib/buy/sell_buy_states.dart b/lib/buy/sell_buy_states.dart index 26ea20205..142e13f80 100644 --- a/lib/buy/sell_buy_states.dart +++ b/lib/buy/sell_buy_states.dart @@ -17,4 +17,8 @@ class BuySellQuotLoading extends BuySellQuotLoadingState {} class BuySellQuotLoaded extends BuySellQuotLoadingState {} -class BuySellQuotFailed extends BuySellQuotLoadingState {} \ No newline at end of file +class BuySellQuotFailed extends BuySellQuotLoadingState { + final String? errorMessage; + + BuySellQuotFailed({this.errorMessage}); +} \ No newline at end of file diff --git a/lib/core/wallet_loading_service.dart b/lib/core/wallet_loading_service.dart index 4284671c3..1432ce6f3 100644 --- a/lib/core/wallet_loading_service.dart +++ b/lib/core/wallet_loading_service.dart @@ -131,7 +131,11 @@ class WalletLoadingService { alertContent: S.of(context).corrupted_seed_notice, leftButtonText: S.of(context).cancel, rightButtonText: S.of(context).show_seed, - actionLeftButton: () => Navigator.of(context).pop(), + actionLeftButton: () { + if (context.mounted && Navigator.of(context).canPop()) { + Navigator.of(context).pop(); + } + }, actionRightButton: () => showSeedsPopup(context, msg), ); }); diff --git a/lib/src/screens/buy/buy_sell_page.dart b/lib/src/screens/buy/buy_sell_page.dart index af29d02b2..53c8cdec9 100644 --- a/lib/src/screens/buy/buy_sell_page.dart +++ b/lib/src/screens/buy/buy_sell_page.dart @@ -148,7 +148,7 @@ class BuySellPage extends BasePage { bottomSection: Observer( builder: (_) => Column( children: [ - if (buySellViewModel.isBuySellQuotFailed) + if (buySellViewModel.isBuySellQuoteFailed) Padding( padding: EdgeInsets.only(bottom: 15), child: Row( @@ -166,7 +166,8 @@ class BuySellPage extends BasePage { Expanded( flex: 8, child: Text( - S.of(context).buy_sell_pair_is_not_supported_warning, + buySellViewModel.buySellQuoteFailedError ?? + S.of(context).buy_sell_pair_is_not_supported_warning, textAlign: TextAlign.center, softWrap: true, overflow: TextOverflow.ellipsis, @@ -188,9 +189,9 @@ class BuySellPage extends BasePage { }, color: Theme.of(context).colorScheme.primary, textColor: Theme.of(context).colorScheme.onPrimary, - isDisabled: buySellViewModel.isBuySellQuotFailed, + isDisabled: buySellViewModel.isBuySellQuoteFailed, isLoading: - !buySellViewModel.isReadyToTrade && !buySellViewModel.isBuySellQuotFailed, + !buySellViewModel.isReadyToTrade && !buySellViewModel.isBuySellQuoteFailed, ), ], ), diff --git a/lib/view_model/buy/buy_sell_view_model.dart b/lib/view_model/buy/buy_sell_view_model.dart index 601fca524..76e6e9edf 100644 --- a/lib/view_model/buy/buy_sell_view_model.dart +++ b/lib/view_model/buy/buy_sell_view_model.dart @@ -157,7 +157,12 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S } @computed - bool get isBuySellQuotFailed => buySellQuotState is BuySellQuotFailed; + bool get isBuySellQuoteFailed => buySellQuotState is BuySellQuotFailed; + + @computed + String? get buySellQuoteFailedError => buySellQuotState is BuySellQuotFailed + ? (buySellQuotState as BuySellQuotFailed).errorMessage + : null; @action void reset() { @@ -201,10 +206,10 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S final enteredAmount = double.tryParse(amount.replaceAll(',', '.')) ?? 0; - if (!isReadyToTrade && !isBuySellQuotFailed) { + if (!isReadyToTrade && !isBuySellQuoteFailed) { cryptoAmount = S.current.fetching; return; - } else if (isBuySellQuotFailed) { + } else if (isBuySellQuoteFailed) { cryptoAmount = ''; return; } @@ -232,10 +237,10 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S final enteredAmount = double.tryParse(amount.replaceAll(',', '.')) ?? 0; - if (!isReadyToTrade && !isBuySellQuotFailed) { + if (!isReadyToTrade && !isBuySellQuoteFailed) { fiatAmount = S.current.fetching; return; - } else if (isBuySellQuotFailed) { + } else if (isBuySellQuoteFailed) { fiatAmount = ''; return; } @@ -478,12 +483,20 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S @action Future launchTrade(BuildContext context) async { final provider = selectedQuote!.provider; - await provider.launchProvider( - context: context, - quote: selectedQuote!, - amount: amount, - isBuyAction: isBuyAction, - cryptoCurrencyAddress: cryptoCurrencyAddress, - ); + try { + await provider.launchProvider( + context: context, + quote: selectedQuote!, + amount: amount, + isBuyAction: isBuyAction, + cryptoCurrencyAddress: cryptoCurrencyAddress, + ); + } catch (e) { + if (e.toString().contains("403")) { + buySellQuotState = BuySellQuotFailed(errorMessage: "Using Tor is not supported"); + } else { + buySellQuotState = BuySellQuotFailed(errorMessage: "Something went wrong please try again later"); + } + } } }