fix: better handle exchange url launching

This commit is contained in:
OmarHatem
2025-10-31 15:00:33 +01:00
parent 3f9840233a
commit f5119d262a
4 changed files with 40 additions and 18 deletions
+5 -1
View File
@@ -17,4 +17,8 @@ class BuySellQuotLoading extends BuySellQuotLoadingState {}
class BuySellQuotLoaded extends BuySellQuotLoadingState {}
class BuySellQuotFailed extends BuySellQuotLoadingState {}
class BuySellQuotFailed extends BuySellQuotLoadingState {
final String? errorMessage;
BuySellQuotFailed({this.errorMessage});
}
+5 -1
View File
@@ -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),
);
});
+5 -4
View File
@@ -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,
),
],
),
+25 -12
View File
@@ -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<void> 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");
}
}
}
}