mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-29 11:44:01 +01:00
fix: restore direct MoonPay purchases in Hash Bags 1.0.6
This commit is contained in:
committed by
John Winter Murphy
parent
4c1426f8ab
commit
13a2908e8a
@@ -186,7 +186,7 @@ class MoonPayProvider extends BuyProvider {
|
|||||||
final moonPayMethods = await fetchMoonPayPaymentMethods(
|
final moonPayMethods = await fetchMoonPayPaymentMethods(
|
||||||
currencyCode: fiatCurrency,
|
currencyCode: fiatCurrency,
|
||||||
transactionType: isBuyAction ? "buy" : "sell",
|
transactionType: isBuyAction ? "buy" : "sell",
|
||||||
);
|
).timeout(const Duration(seconds: 5));
|
||||||
|
|
||||||
for (final method in moonPayMethods) {
|
for (final method in moonPayMethods) {
|
||||||
if (!method.active) {
|
if (!method.active) {
|
||||||
@@ -201,6 +201,9 @@ class MoonPayProvider extends BuyProvider {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
printV("Error fetching payment methods: $e");
|
printV("Error fetching payment methods: $e");
|
||||||
|
// The existing signer may not offer method lookup. Let MoonPay quote a
|
||||||
|
// purchase without a method filter and enforce availability in checkout.
|
||||||
|
return isBuyAction ? [PaymentMethod.all()] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return paymentMethods;
|
return paymentMethods;
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ import "package:hash_wallet/new-ui/pages/seed/show_keys_disclaimer_page.dart";
|
|||||||
import 'package:hash_wallet/new-ui/viewmodels/charts/charts_bloc.dart';
|
import 'package:hash_wallet/new-ui/viewmodels/charts/charts_bloc.dart';
|
||||||
import 'package:hash_wallet/new-ui/viewmodels/lightning_username/lightning_username_bloc.dart';
|
import 'package:hash_wallet/new-ui/viewmodels/lightning_username/lightning_username_bloc.dart';
|
||||||
import 'package:hash_wallet/new-ui/widgets/addresses_page/address_label_input.dart';
|
import 'package:hash_wallet/new-ui/widgets/addresses_page/address_label_input.dart';
|
||||||
import 'package:hash_wallet/new-ui/widgets/buy_sell/buy_sell_selector_modal.dart';
|
|
||||||
import 'package:hash_wallet/new-ui/widgets/coins_page/assets_history/transaction_details_modal.dart';
|
import 'package:hash_wallet/new-ui/widgets/coins_page/assets_history/transaction_details_modal.dart';
|
||||||
import 'package:hash_wallet/new-ui/widgets/receive_page/receive_label_modal.dart';
|
import 'package:hash_wallet/new-ui/widgets/receive_page/receive_label_modal.dart';
|
||||||
import 'package:hash_wallet/new-ui/pages/swap_page.dart';
|
import 'package:hash_wallet/new-ui/pages/swap_page.dart';
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import "package:hash_wallet/new-ui/pages/seed/seed_backup_reminder_page.dart";
|
|||||||
import "package:hash_wallet/new-ui/pages/send_page.dart";
|
import "package:hash_wallet/new-ui/pages/send_page.dart";
|
||||||
import "package:hash_wallet/new-ui/pages/settings_page.dart";
|
import "package:hash_wallet/new-ui/pages/settings_page.dart";
|
||||||
import "package:hash_wallet/new-ui/pages/wallet_accounts_page.dart";
|
import "package:hash_wallet/new-ui/pages/wallet_accounts_page.dart";
|
||||||
import "package:hash_wallet/new-ui/widgets/buy_sell/buy_sell_selector_modal.dart";
|
|
||||||
import "package:hash_wallet/new-ui/widgets/coins_page/action_row/coin_action_row.dart";
|
import "package:hash_wallet/new-ui/widgets/coins_page/action_row/coin_action_row.dart";
|
||||||
import "package:hash_wallet/new-ui/widgets/coins_page/assets_history/assets_history_section.dart";
|
import "package:hash_wallet/new-ui/widgets/coins_page/assets_history/assets_history_section.dart";
|
||||||
import "package:hash_wallet/new-ui/widgets/coins_page/cards/balance_card.dart";
|
import "package:hash_wallet/new-ui/widgets/coins_page/cards/balance_card.dart";
|
||||||
|
|||||||
@@ -1,154 +0,0 @@
|
|||||||
import "package:hash_wallet/di.dart";
|
|
||||||
import "package:hash_wallet/generated/i18n.dart";
|
|
||||||
import "package:hash_wallet/main.dart";
|
|
||||||
import "package:hash_wallet/new-ui/modal_navigator.dart";
|
|
||||||
import "package:hash_wallet/new-ui/pages/buy_sell/buy_sell_amount_page.dart";
|
|
||||||
import "package:hash_wallet/new-ui/viewmodels/charts/charts_bloc.dart";
|
|
||||||
import "package:hash_wallet/src/widgets/hash_image_widget.dart";
|
|
||||||
import "package:hash_wallet/themes/core/theme_extension.dart";
|
|
||||||
import "package:hash_wallet/view_model/buy/buy_sell_view_model.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
|
|
||||||
class BuySellSelectorModal extends StatelessWidget {
|
|
||||||
const BuySellSelectorModal({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) => Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(18)),
|
|
||||||
gradient: LinearGradient(
|
|
||||||
colors: [
|
|
||||||
Theme.of(context).colorScheme.surface,
|
|
||||||
Theme.of(context).colorScheme.surfaceDim,
|
|
||||||
],
|
|
||||||
begin: Alignment.topCenter,
|
|
||||||
end: Alignment.bottomCenter,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: SafeArea(
|
|
||||||
top: false,
|
|
||||||
child: Column(
|
|
||||||
spacing: 24,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const SizedBox.shrink(),
|
|
||||||
Text(
|
|
||||||
S.of(context).buy_or_sell,
|
|
||||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
S.of(context).buy_or_sell_desc,
|
|
||||||
style:
|
|
||||||
TextStyle(fontSize: 12, color: Theme.of(context).colorScheme.onSurfaceVariant),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 18),
|
|
||||||
child: Column(
|
|
||||||
spacing: 12,
|
|
||||||
children: [
|
|
||||||
BuySellSelectorModalButton(
|
|
||||||
title: S.of(context).buy_crypto,
|
|
||||||
description: S.of(context).buy_crypto_desc,
|
|
||||||
iconPath: "assets/new-ui/plus.svg",
|
|
||||||
onTap: () => openBuySellPage(context, BuySellPageMode.buy),
|
|
||||||
),
|
|
||||||
BuySellSelectorModalButton(
|
|
||||||
title: S.of(context).sell_crypto,
|
|
||||||
description: S.of(context).sell_crypto_desc,
|
|
||||||
iconPath: "assets/new-ui/sell.svg",
|
|
||||||
onTap: () => openBuySellPage(context, BuySellPageMode.sell),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox.shrink(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void openBuySellPage(BuildContext context, BuySellPageMode mode) {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
final page = getIt.get<NewBuySellAmountPage>(param1: NewBuySellParams(mode: mode));
|
|
||||||
showModalBottomSheet(
|
|
||||||
useSafeArea: true,
|
|
||||||
isScrollControlled: true,
|
|
||||||
context: navigatorKey.currentContext!,
|
|
||||||
builder: (modalContext) => ModalNavigator(
|
|
||||||
rootPage: page,
|
|
||||||
parentContext: modalContext,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BuySellSelectorModalButton extends StatelessWidget {
|
|
||||||
const BuySellSelectorModalButton({
|
|
||||||
required this.title,
|
|
||||||
required this.description,
|
|
||||||
required this.iconPath,
|
|
||||||
required this.onTap,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
final String description;
|
|
||||||
final String iconPath;
|
|
||||||
final VoidCallback onTap;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) => GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
border: Border.all(
|
|
||||||
width: 1,
|
|
||||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
|
||||||
),
|
|
||||||
gradient: LinearGradient(
|
|
||||||
colors: [
|
|
||||||
context.customColors.cardGradientColorPrimary,
|
|
||||||
context.customColors.cardGradientColorSecondary,
|
|
||||||
],
|
|
||||||
begin: Alignment.topCenter,
|
|
||||||
end: Alignment.bottomCenter,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24),
|
|
||||||
child: Row(
|
|
||||||
spacing: 20,
|
|
||||||
children: [
|
|
||||||
HashImageWidget(
|
|
||||||
imageUrl: iconPath,
|
|
||||||
width: 55,
|
|
||||||
height: 55,
|
|
||||||
colorFilter: ColorFilter.mode(
|
|
||||||
Theme.of(context).colorScheme.onSurfaceVariant,
|
|
||||||
BlendMode.srcIn,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Column(
|
|
||||||
spacing: 8,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: const TextStyle(fontWeight: FontWeight.w500, fontSize: 16),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
description,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import "package:hash_wallet/di.dart";
|
import "package:hash_wallet/di.dart";
|
||||||
|
import "package:hash_wallet/entities/provider_types.dart";
|
||||||
import "package:hash_wallet/generated/i18n.dart";
|
import "package:hash_wallet/generated/i18n.dart";
|
||||||
import "package:hash_wallet/main.dart";
|
import "package:hash_wallet/main.dart";
|
||||||
import "package:hash_wallet/new-ui/modal_navigator.dart";
|
import "package:hash_wallet/new-ui/modal_navigator.dart";
|
||||||
@@ -57,7 +58,7 @@ class ChartModal extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
spacing: MediaQuery.of(context).size.width * 0.05,
|
spacing: MediaQuery.of(context).size.width * 0.05,
|
||||||
children: [
|
children: [
|
||||||
if (canOpenBuySell) ...[
|
if (canOpenBuySell && ProvidersHelper.getAvailableBuyProviderTypes().isNotEmpty)
|
||||||
CoinActionButton(
|
CoinActionButton(
|
||||||
icon: HashImageWidget(
|
icon: HashImageWidget(
|
||||||
width: 36,
|
width: 36,
|
||||||
@@ -71,6 +72,7 @@ class ChartModal extends StatelessWidget {
|
|||||||
label: S.of(context).buy,
|
label: S.of(context).buy,
|
||||||
action: () => openBuySellPage(context, BuySellPageMode.buy),
|
action: () => openBuySellPage(context, BuySellPageMode.buy),
|
||||||
),
|
),
|
||||||
|
if (canOpenBuySell && ProvidersHelper.getAvailableSellProviderTypes().isNotEmpty)
|
||||||
CoinActionButton(
|
CoinActionButton(
|
||||||
icon: HashImageWidget(
|
icon: HashImageWidget(
|
||||||
width: 36,
|
width: 36,
|
||||||
@@ -84,7 +86,6 @@ class ChartModal extends StatelessWidget {
|
|||||||
label: S.of(context).sell,
|
label: S.of(context).sell,
|
||||||
action: () => openBuySellPage(context, BuySellPageMode.sell),
|
action: () => openBuySellPage(context, BuySellPageMode.sell),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
CoinActionButton(
|
CoinActionButton(
|
||||||
icon: HashImageWidget(
|
icon: HashImageWidget(
|
||||||
imageUrl: "assets/new-ui/exchange.svg",
|
imageUrl: "assets/new-ui/exchange.svg",
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import 'package:hash_wallet/entities/provider_types.dart';
|
|||||||
import 'package:hash_wallet/generated/i18n.dart';
|
import 'package:hash_wallet/generated/i18n.dart';
|
||||||
import 'package:hash_wallet/new-ui/modal_navigator.dart';
|
import 'package:hash_wallet/new-ui/modal_navigator.dart';
|
||||||
import 'package:hash_wallet/new-ui/pages/send_page.dart';
|
import 'package:hash_wallet/new-ui/pages/send_page.dart';
|
||||||
import 'package:hash_wallet/new-ui/widgets/buy_sell/buy_sell_selector_modal.dart';
|
|
||||||
import 'package:hash_wallet/routes.dart';
|
import 'package:hash_wallet/routes.dart';
|
||||||
import 'package:hash_wallet/utils/payment_request.dart';
|
import 'package:hash_wallet/utils/payment_request.dart';
|
||||||
import 'package:hash_wallet/utils/responsive_layout_util.dart';
|
import 'package:hash_wallet/utils/responsive_layout_util.dart';
|
||||||
@@ -214,10 +213,7 @@ class _CardsViewState extends State<CardsView> {
|
|||||||
label: S.current.buy,
|
label: S.current.buy,
|
||||||
icon: Icons.arrow_forward_ios_rounded,
|
icon: Icons.arrow_forward_ios_rounded,
|
||||||
iconSize: 12,
|
iconSize: 12,
|
||||||
onTap: () {
|
onTap: () => Navigator.of(context).pushNamed(Routes.buySellPage),
|
||||||
showModalBottomSheet(
|
|
||||||
context: context, builder: (context) => BuySellSelectorModal());
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
: [];
|
: [];
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import "package:hash_wallet/new-ui/pages/seed/show_keys_disclaimer_page.dart";
|
|||||||
import "package:hash_wallet/new-ui/pages/receive_page.dart";
|
import "package:hash_wallet/new-ui/pages/receive_page.dart";
|
||||||
import 'package:hash_wallet/new-ui/pages/send_page.dart';
|
import 'package:hash_wallet/new-ui/pages/send_page.dart';
|
||||||
import "package:hash_wallet/new-ui/pages/swap_page.dart";
|
import "package:hash_wallet/new-ui/pages/swap_page.dart";
|
||||||
import "package:hash_wallet/new-ui/widgets/buy_sell/buy_sell_selector_modal.dart";
|
|
||||||
import 'package:hash_wallet/new-ui/widgets/hardware_wallet/sync_key_images_sheet.dart';
|
import 'package:hash_wallet/new-ui/widgets/hardware_wallet/sync_key_images_sheet.dart';
|
||||||
import 'package:hash_wallet/order/order.dart';
|
import 'package:hash_wallet/order/order.dart';
|
||||||
import 'package:hash_wallet/core/new_wallet_type_arguments.dart';
|
import 'package:hash_wallet/core/new_wallet_type_arguments.dart';
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import 'package:hash_wallet/entities/fiat_currency.dart';
|
|||||||
import 'package:hash_wallet/entities/provider_types.dart';
|
import 'package:hash_wallet/entities/provider_types.dart';
|
||||||
import 'package:hash_wallet/generated/i18n.dart';
|
import 'package:hash_wallet/generated/i18n.dart';
|
||||||
import "package:hash_wallet/new-ui/pages/buy_sell/buy_sell_amount_page.dart";
|
import "package:hash_wallet/new-ui/pages/buy_sell/buy_sell_amount_page.dart";
|
||||||
import 'package:hash_wallet/new-ui/widgets/buy_sell/buy_sell_selector_modal.dart';
|
|
||||||
import 'package:hash_wallet/routes.dart';
|
import 'package:hash_wallet/routes.dart';
|
||||||
import 'package:hash_wallet/store/app_store.dart';
|
import 'package:hash_wallet/store/app_store.dart';
|
||||||
import 'package:hash_wallet/store/dashboard/fiat_conversion_store.dart';
|
import 'package:hash_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
@@ -456,6 +455,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
|
|||||||
paymentMethods = ObservableList<PaymentMethod>.of(tempPaymentMethods);
|
paymentMethods = ObservableList<PaymentMethod>.of(tempPaymentMethods);
|
||||||
|
|
||||||
if (paymentMethods.isNotEmpty) {
|
if (paymentMethods.isNotEmpty) {
|
||||||
|
paymentMethods.removeWhere((method) => method.paymentMethodType == PaymentType.all);
|
||||||
paymentMethods.insert(0, PaymentMethod.all());
|
paymentMethods.insert(0, PaymentMethod.all());
|
||||||
selectedPaymentMethod = paymentMethods.first;
|
selectedPaymentMethod = paymentMethods.first;
|
||||||
selectedPaymentMethod!.isSelected = true;
|
selectedPaymentMethod!.isSelected = true;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
name: hash_wallet
|
name: hash_wallet
|
||||||
description: Hash Bags — a noncustodial multi-currency wallet by Such Software LLC.
|
description: Hash Bags — a noncustodial multi-currency wallet by Such Software LLC.
|
||||||
version: 1.0.5+18
|
version: 1.0.6+19
|
||||||
publish_to: none
|
publish_to: none
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.0
|
sdk: ^3.5.0
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import 'package:cw_core/balance.dart';
|
||||||
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
|
import 'package:cw_core/transaction_history.dart';
|
||||||
|
import 'package:cw_core/transaction_info.dart';
|
||||||
|
import 'package:cw_core/wallet_base.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:hash_wallet/buy/moonpay/moonpay_payment_methods.dart';
|
||||||
|
import 'package:hash_wallet/buy/moonpay/moonpay_provider.dart';
|
||||||
|
import 'package:hash_wallet/buy/payment_method.dart';
|
||||||
|
import 'package:hash_wallet/store/app_store.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
|
||||||
|
class _MockAppStore extends Mock implements AppStore {}
|
||||||
|
|
||||||
|
class _MockWallet extends Mock
|
||||||
|
implements WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> {}
|
||||||
|
|
||||||
|
class _MoonPayProvider extends MoonPayProvider {
|
||||||
|
_MoonPayProvider(this.lookup) : super(appStore: _MockAppStore(), wallet: _MockWallet());
|
||||||
|
|
||||||
|
final Future<List<MoonPayPaymentMethod>> Function() lookup;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<MoonPayPaymentMethod>> fetchMoonPayPaymentMethods({
|
||||||
|
required String currencyCode,
|
||||||
|
String transactionType = 'buy',
|
||||||
|
}) =>
|
||||||
|
lookup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('MoonPay can quote a buy without a method filter when lookup fails', () async {
|
||||||
|
final provider = _MoonPayProvider(() async => throw StateError('Lookup unavailable'));
|
||||||
|
|
||||||
|
final buyMethods = await provider.getAvailablePaymentTypes('USD', CryptoCurrency.btc, true);
|
||||||
|
final sellMethods = await provider.getAvailablePaymentTypes('USD', CryptoCurrency.btc, false);
|
||||||
|
|
||||||
|
expect(buyMethods.map((method) => method.paymentMethodType), [PaymentType.all]);
|
||||||
|
expect(sellMethods, isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('MoonPay respects a successful response that offers no payment methods', () async {
|
||||||
|
final provider = _MoonPayProvider(() async => []);
|
||||||
|
|
||||||
|
expect(await provider.getAvailablePaymentTypes('USD', CryptoCurrency.btc, true), isEmpty);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import 'package:cw_core/balance.dart';
|
||||||
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
|
import 'package:cw_core/transaction_history.dart';
|
||||||
|
import 'package:cw_core/transaction_info.dart';
|
||||||
|
import 'package:cw_core/wallet_base.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:hash_wallet/di.dart';
|
||||||
|
import 'package:hash_wallet/generated/i18n.dart';
|
||||||
|
import 'package:hash_wallet/locales/locale.dart';
|
||||||
|
import 'package:hash_wallet/new-ui/viewmodels/charts/charts_bloc.dart';
|
||||||
|
import 'package:hash_wallet/new-ui/widgets/charts_page/chart_modal.dart';
|
||||||
|
import 'package:hash_wallet/store/app_store.dart';
|
||||||
|
import 'package:hash_wallet/themes/core/theme_store.dart';
|
||||||
|
import 'package:mobx/mobx.dart' show ObservableMap;
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
|
||||||
|
class _MockAppStore extends Mock implements AppStore {}
|
||||||
|
|
||||||
|
class _MockWallet extends Mock
|
||||||
|
implements WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> {}
|
||||||
|
|
||||||
|
class _MockBalance extends Mock implements Balance {}
|
||||||
|
|
||||||
|
class _MockChartsBloc extends Mock implements ChartsBloc {}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Chart actions offer swaps without advertising an unavailable off-ramp',
|
||||||
|
(tester) async {
|
||||||
|
final appStore = _MockAppStore();
|
||||||
|
final wallet = _MockWallet();
|
||||||
|
when(() => appStore.wallet).thenReturn(wallet);
|
||||||
|
when(() => wallet.balance).thenReturn(ObservableMap.of({CryptoCurrency.btc: _MockBalance()}));
|
||||||
|
final bloc = _MockChartsBloc();
|
||||||
|
when(() => bloc.state).thenReturn(const ChartsInitial());
|
||||||
|
when(() => bloc.stream).thenAnswer((_) => const Stream<ChartsState>.empty());
|
||||||
|
getIt.registerSingleton<AppStore>(appStore);
|
||||||
|
getIt.registerSingleton(ThemeStore());
|
||||||
|
addTearDown(() async {
|
||||||
|
await getIt.unregister<ThemeStore>();
|
||||||
|
await getIt.unregister<AppStore>();
|
||||||
|
});
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
localizationsDelegates: localizationDelegates,
|
||||||
|
supportedLocales: S.delegate.supportedLocales,
|
||||||
|
home: Scaffold(
|
||||||
|
body: ChartModal(bloc: bloc, currency: CryptoCurrency.btc, isFavorite: false),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(find.text(S.current.swap), findsOneWidget);
|
||||||
|
expect(find.text(S.current.sell), findsNothing);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user