From 2b228f736e20b66544c6bae3f7152a87af67679c Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 23 Jun 2023 12:57:14 -0600 Subject: [PATCH 01/10] fix: amount string parse bug on desktop send view --- .../wallet_view/sub_widgets/desktop_send.dart | 42 +++++-------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart index 76ac3fef9..d3588325c 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart @@ -9,7 +9,6 @@ */ import 'dart:async'; -import 'dart:math'; import 'package:bip47/bip47.dart'; import 'package:cw_core/monero_transaction_priority.dart'; @@ -462,27 +461,11 @@ class _DesktopSendState extends ConsumerState { void _cryptoAmountChanged() async { if (!_cryptoAmountChangeLock) { - String cryptoAmount = cryptoAmountController.text; - if (cryptoAmount.isNotEmpty && - cryptoAmount != "." && - cryptoAmount != ",") { - if (cryptoAmount.startsWith("~")) { - cryptoAmount = cryptoAmount.substring(1); - } - if (cryptoAmount.contains(" ")) { - cryptoAmount = cryptoAmount.split(" ").first; - } - - // ensure we don't shift past minimum atomic value - final shift = min(ref.read(pAmountUnit(coin)).shift, coin.decimals); - - _amountToSend = cryptoAmount.contains(",") - ? Decimal.parse(cryptoAmount.replaceFirst(",", ".")) - .shift(0 - shift) - .toAmount(fractionDigits: coin.decimals) - : Decimal.parse(cryptoAmount) - .shift(0 - shift) - .toAmount(fractionDigits: coin.decimals); + final cryptoAmount = ref.read(pAmountFormatter(coin)).tryParse( + cryptoAmountController.text, + ); + if (cryptoAmount != null) { + _amountToSend = cryptoAmount; if (_cachedAmountToSend != null && _cachedAmountToSend == _amountToSend) { return; @@ -677,15 +660,12 @@ class _DesktopSendState extends ConsumerState { } void fiatTextFieldOnChanged(String baseAmountString) { - if (baseAmountString.isNotEmpty && - baseAmountString != "." && - baseAmountString != ",") { - final baseAmount = baseAmountString.contains(",") - ? Decimal.parse(baseAmountString.replaceFirst(",", ".")) - .toAmount(fractionDigits: 2) - : Decimal.parse(baseAmountString).toAmount(fractionDigits: 2); - - var _price = + final baseAmount = Amount.tryParseFiatString( + baseAmountString, + locale: ref.read(localeServiceChangeNotifierProvider).locale, + ); + if (baseAmount != null) { + final _price = ref.read(priceAnd24hChangeNotifierProvider).getPrice(coin).item1; if (_price == Decimal.zero) { From 3a9f5671507a51b22419fbeac443fa01dff996a5 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 23 Jun 2023 12:59:43 -0600 Subject: [PATCH 02/10] fix: amount input formatter case when trying to input an amount less than one starting with a zero instead of the decimal separator, edge case allowing more decimal places than the coin has, and pasting certain amounts --- .../amount/amount_input_formatter.dart | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/utilities/amount/amount_input_formatter.dart b/lib/utilities/amount/amount_input_formatter.dart index c3157c6fa..dfc2b5732 100644 --- a/lib/utilities/amount/amount_input_formatter.dart +++ b/lib/utilities/amount/amount_input_formatter.dart @@ -38,7 +38,15 @@ class AmountInputFormatter extends TextInputFormatter { if (parts.length > 2) { return oldValue; } + + final fractionDigits = + unit == null ? decimals : max(decimals - unit!.shift, 0); + if (newText.startsWith(decimalSeparator)) { + if (newText.length - 1 > fractionDigits) { + newText = newText.substring(0, fractionDigits + 1); + } + return TextEditingValue( text: newText, selection: TextSelection.collapsed( @@ -54,28 +62,24 @@ class AmountInputFormatter extends TextInputFormatter { fraction = ""; } - final fractionDigits = - unit == null ? decimals : max(decimals - unit!.shift, 0); - if (fraction.length > fractionDigits) { - return oldValue; + fraction = fraction.substring(0, fractionDigits); } } - if (newText.trim() == '' || newText.trim() == '0') { - return newValue.copyWith(text: ''); - } else if (BigInt.parse(newText) < BigInt.one) { - return newValue.copyWith(text: ''); + String newString; + final val = BigInt.tryParse(newText); + if (val == null || val < BigInt.one) { + newString = newText; + } else { + // insert group separator + final regex = RegExp(r'\B(?=(\d{3})+(?!\d))'); + newString = newText.replaceAllMapped( + regex, + (m) => "${m.group(0)}${numberSymbols?.GROUP_SEP ?? ","}", + ); } - // insert group separator - final regex = RegExp(r'\B(?=(\d{3})+(?!\d))'); - - String newString = newText.replaceAllMapped( - regex, - (m) => "${m.group(0)}${numberSymbols?.GROUP_SEP ?? ","}", - ); - if (fraction != null) { newString += decimalSeparator; if (fraction.isNotEmpty) { From c784d2cf048308f252fcd9726b30f22584d4df88 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 23 Jun 2023 13:35:19 -0600 Subject: [PATCH 03/10] fix: disable fee selection for firo private send on desktop --- .../wallet_view/sub_widgets/desktop_send.dart | 211 ++++++++++-------- lib/widgets/desktop/desktop_fee_dialog.dart | 56 ++++- 2 files changed, 167 insertions(+), 100 deletions(-) diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart index d3588325c..a6d58c667 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart @@ -1369,7 +1369,10 @@ class _DesktopSendState extends ConsumerState { ), if (!([Coin.nano, Coin.banano, Coin.epicCash].contains(coin))) ConditionalParent( - condition: coin.isElectrumXCoin, + condition: coin.isElectrumXCoin && + !(((coin == Coin.firo || coin == Coin.firoTestNet) && + ref.read(publicPrivateBalanceStateProvider.state).state == + "Private")), builder: (child) => Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -1421,72 +1424,117 @@ class _DesktopSendState extends ConsumerState { ), if (!([Coin.nano, Coin.banano, Coin.epicCash].contains(coin))) if (!isCustomFee) - (feeSelectionResult?.$2 == null) - ? FutureBuilder( - future: ref.watch( - walletsChangeNotifierProvider.select( - (value) => value.getManager(walletId).fees, + Padding( + padding: const EdgeInsets.all(10), + child: (feeSelectionResult?.$2 == null) + ? FutureBuilder( + future: ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManager(walletId).fees, + ), ), - ), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - return DesktopFeeItem( - feeObject: snapshot.data, - feeRateType: FeeRateType.average, - walletId: walletId, - feeFor: ({ - required Amount amount, - required FeeRateType feeRateType, - required int feeRate, - required Coin coin, - }) async { - if (ref - .read(feeSheetSessionCacheProvider) - .average[amount] == - null) { - final manager = ref - .read(walletsChangeNotifierProvider) - .getManager(walletId); + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + return DesktopFeeItem( + feeObject: snapshot.data, + feeRateType: FeeRateType.average, + walletId: walletId, + isButton: false, + feeFor: ({ + required Amount amount, + required FeeRateType feeRateType, + required int feeRate, + required Coin coin, + }) async { + if (ref + .read(feeSheetSessionCacheProvider) + .average[amount] == + null) { + final manager = ref + .read(walletsChangeNotifierProvider) + .getManager(walletId); - if (coin == Coin.monero || coin == Coin.wownero) { - final fee = await manager.estimateFeeFor(amount, - MoneroTransactionPriority.regular.raw!); - ref - .read(feeSheetSessionCacheProvider) - .average[amount] = fee; - } else if ((coin == Coin.firo || - coin == Coin.firoTestNet) && + if (coin == Coin.monero || + coin == Coin.wownero) { + final fee = await manager.estimateFeeFor( + amount, + MoneroTransactionPriority.regular.raw!); ref - .read( - publicPrivateBalanceStateProvider - .state) - .state != - "Private") { - ref - .read(feeSheetSessionCacheProvider) - .average[amount] = - await (manager.wallet as FiroWallet) - .estimateFeeForPublic(amount, feeRate); - } else { - ref - .read(feeSheetSessionCacheProvider) - .average[amount] = - await manager.estimateFeeFor( - amount, feeRate); + .read(feeSheetSessionCacheProvider) + .average[amount] = fee; + } else if ((coin == Coin.firo || + coin == Coin.firoTestNet) && + ref + .read( + publicPrivateBalanceStateProvider + .state) + .state != + "Private") { + ref + .read(feeSheetSessionCacheProvider) + .average[amount] = await (manager.wallet + as FiroWallet) + .estimateFeeForPublic(amount, feeRate); + } else { + ref + .read(feeSheetSessionCacheProvider) + .average[amount] = + await manager.estimateFeeFor( + amount, feeRate); + } } - } - return ref - .read(feeSheetSessionCacheProvider) - .average[amount]!; - }, - isSelected: true, - ); - } else { - return Row( + return ref + .read(feeSheetSessionCacheProvider) + .average[amount]!; + }, + isSelected: true, + ); + } else { + return Row( + children: [ + AnimatedText( + stringsToLoopThrough: stringsToLoopThrough, + style: STextStyles.desktopTextExtraExtraSmall( + context) + .copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveText, + ), + ), + ], + ); + } + }, + ) + : (coin == Coin.firo || coin == Coin.firoTestNet) && + ref + .watch( + publicPrivateBalanceStateProvider.state) + .state == + "Private" + ? Text( + "~${ref.watch(pAmountFormatter(coin)).format( + Amount( + rawValue: BigInt.parse("3794"), + fractionDigits: coin.decimals, + ), + indicatePrecisionLoss: false, + )}", + style: STextStyles.desktopTextExtraExtraSmall(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveText, + ), + textAlign: TextAlign.left, + ) + : Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - AnimatedText( - stringsToLoopThrough: stringsToLoopThrough, + Text( + feeSelectionResult?.$2 ?? "", style: STextStyles.desktopTextExtraExtraSmall( context) .copyWith( @@ -1494,36 +1542,21 @@ class _DesktopSendState extends ConsumerState { .extension()! .textFieldActiveText, ), + textAlign: TextAlign.left, + ), + Text( + feeSelectionResult?.$3 ?? "", + style: STextStyles.desktopTextExtraExtraSmall( + context) + .copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveSearchIconRight, + ), ), ], - ); - } - }, - ) - : Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - feeSelectionResult?.$2 ?? "", - style: STextStyles.desktopTextExtraExtraSmall(context) - .copyWith( - color: Theme.of(context) - .extension()! - .textFieldActiveText, ), - textAlign: TextAlign.left, - ), - Text( - feeSelectionResult?.$3 ?? "", - style: STextStyles.desktopTextExtraExtraSmall(context) - .copyWith( - color: Theme.of(context) - .extension()! - .textFieldActiveSearchIconRight, - ), - ), - ], - ), + ), if (isCustomFee) Padding( padding: const EdgeInsets.only( diff --git a/lib/widgets/desktop/desktop_fee_dialog.dart b/lib/widgets/desktop/desktop_fee_dialog.dart index f2c8c9fba..d9bf51190 100644 --- a/lib/widgets/desktop/desktop_fee_dialog.dart +++ b/lib/widgets/desktop/desktop_fee_dialog.dart @@ -16,6 +16,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/animated_text.dart'; +import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; @@ -234,6 +235,7 @@ class DesktopFeeItem extends ConsumerStatefulWidget { required this.walletId, required this.feeFor, required this.isSelected, + this.isButton = true, }) : super(key: key); final FeeObject? feeObject; @@ -246,6 +248,7 @@ class DesktopFeeItem extends ConsumerStatefulWidget { required Coin coin, }) feeFor; final bool isSelected; + final bool isButton; @override ConsumerState createState() => _DesktopFeeItemState(); @@ -291,19 +294,50 @@ class _DesktopFeeItemState extends ConsumerState { Widget build(BuildContext context) { debugPrint("BUILD: $runtimeType : ${widget.feeRateType}"); - return MaterialButton( - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - onPressed: () { - Navigator.of(context).pop( - ( - widget.feeRateType, - feeString, - timeString, - ), - ); - }, + return ConditionalParent( + condition: widget.isButton, + builder: (child) => MaterialButton( + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + onPressed: () { + Navigator.of(context).pop( + ( + widget.feeRateType, + feeString, + timeString, + ), + ); + }, + child: child, + ), child: Builder( builder: (_) { + if (!widget.isButton) { + final coin = ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManager(widget.walletId).coin, + ), + ); + if ((coin == Coin.firo || coin == Coin.firoTestNet) && + ref.watch(publicPrivateBalanceStateProvider.state).state == + "Private") { + return Text( + "~${ref.watch(pAmountFormatter(coin)).format( + Amount( + rawValue: BigInt.parse("3794"), + fractionDigits: coin.decimals, + ), + indicatePrecisionLoss: false, + )}", + style: STextStyles.desktopTextExtraExtraSmall(context).copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveText, + ), + textAlign: TextAlign.left, + ); + } + } + if (widget.feeRateType == FeeRateType.custom) { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, From b64b5cdb9b7b54a2ed461cecab64b48f7f7e8524 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 23 Jun 2023 15:27:09 -0600 Subject: [PATCH 04/10] fix: use proper uri builder function --- lib/pages/receive_view/receive_view.dart | 7 ++++++- .../wallet_view/sub_widgets/desktop_receive.dart | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/pages/receive_view/receive_view.dart b/lib/pages/receive_view/receive_view.dart index 063f2b2cd..d77e0e244 100644 --- a/lib/pages/receive_view/receive_view.dart +++ b/lib/pages/receive_view/receive_view.dart @@ -22,6 +22,7 @@ import 'package:stackwallet/pages/receive_view/generate_receiving_uri_qr_code_vi import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/route_generator.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/address_utils.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/constants.dart'; @@ -337,7 +338,11 @@ class _ReceiveViewState extends ConsumerState { child: Column( children: [ QrImageView( - data: "${coin.uriScheme}:$receivingAddress", + data: AddressUtils.buildUriString( + coin, + receivingAddress, + {}, + ), size: MediaQuery.of(context).size.width / 2, foregroundColor: Theme.of(context) .extension()! diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_receive.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_receive.dart index 7b972eab3..292517699 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_receive.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_receive.dart @@ -21,6 +21,7 @@ import 'package:stackwallet/pages/token_view/token_view.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/route_generator.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/address_utils.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/constants.dart'; @@ -236,7 +237,11 @@ class _DesktopReceiveState extends ConsumerState { ), Center( child: QrImageView( - data: "${coin.uriScheme}:$receivingAddress", + data: AddressUtils.buildUriString( + coin, + receivingAddress, + {}, + ), size: 200, foregroundColor: Theme.of(context).extension()!.accentColorDark, From 7b160b9a55ee716aa42bad345d2196f758e9093f Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 23 Jun 2023 15:36:33 -0600 Subject: [PATCH 05/10] strip prefixes for cashaddrs before generating uris --- lib/utilities/address_utils.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utilities/address_utils.dart b/lib/utilities/address_utils.dart index 93f776d98..454391f56 100644 --- a/lib/utilities/address_utils.dart +++ b/lib/utilities/address_utils.dart @@ -126,7 +126,17 @@ class AddressUtils { String address, Map params, ) { - String uriString = "${coin.uriScheme}:$address"; + // TODO: other sanitation as well ? + String sanitizedAddress = address; + if (coin == Coin.bitcoincash || + coin == Coin.bitcoincashTestnet || + coin == Coin.eCash) { + final prefix = "${coin.uriScheme}:"; + if (address.startsWith(prefix)) { + sanitizedAddress = address.replaceFirst(prefix, ""); + } + } + String uriString = "${coin.uriScheme}:$sanitizedAddress"; if (params.isNotEmpty) { uriString += Uri(queryParameters: params).toString(); } From bd5a0c163138b47085498162dd505b14d27aef0f Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 30 Jun 2023 15:30:33 -0600 Subject: [PATCH 06/10] actually use price interval --- lib/services/price.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/price.dart b/lib/services/price.dart index 22f0e79aa..24d929062 100644 --- a/lib/services/price.dart +++ b/lib/services/price.dart @@ -80,7 +80,7 @@ class PriceAPI { {required String baseCurrency}) async { final now = DateTime.now(); if (_lastUsedBaseCurrency != baseCurrency || - now.difference(_lastCalled).inSeconds > 0) { + now.difference(_lastCalled) > refreshIntervalDuration) { _lastCalled = now; _lastUsedBaseCurrency = baseCurrency; } else { From fa1dbdbe51fdd678376fd5c3b7476a51ee87469f Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 1 Jul 2023 13:49:10 -0600 Subject: [PATCH 07/10] extra logging and exit properly instead of rethrowing what is isn't really a true exception but rather an expected result if not transactions are found. Thanks API designers --- lib/services/ethereum/ethereum_token_service.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/services/ethereum/ethereum_token_service.dart b/lib/services/ethereum/ethereum_token_service.dart index ebe55c73e..a42867485 100644 --- a/lib/services/ethereum/ethereum_token_service.dart +++ b/lib/services/ethereum/ethereum_token_service.dart @@ -449,6 +449,15 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache { ); if (response.value == null) { + if (response.exception != null && + response.exception!.message + .contains("response is empty but status code is 200")) { + Logging.instance.log( + "No ${tokenContract.name} transfers found for $addressString", + level: LogLevel.Info, + ); + return; + } throw response.exception ?? Exception("Failed to fetch token transaction data"); } From 26bddae248f4ebad5081501bc89e2108185a66d9 Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 1 Jul 2023 14:09:38 -0600 Subject: [PATCH 08/10] token loading screen navigation fix --- lib/widgets/wallet_card.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/widgets/wallet_card.dart b/lib/widgets/wallet_card.dart index 831b2077e..63b3a4a0e 100644 --- a/lib/widgets/wallet_card.dart +++ b/lib/widgets/wallet_card.dart @@ -26,6 +26,7 @@ import 'package:stackwallet/services/ethereum/ethereum_token_service.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/show_loading.dart'; import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; @@ -136,17 +137,18 @@ class SimpleWalletCard extends ConsumerWidget { context: desktopNavigatorState?.context ?? context, opaqueBG: true, message: "Loading ${contract.name}", + isDesktop: Util.isDesktop, ); if (!success) { + // TODO: show error dialog here? + Logging.instance.log( + "Failed to load token wallet for $contract", + level: LogLevel.Error, + ); return; } - if (desktopNavigatorState == null) { - // pop loading - nav.pop(); - } - if (desktopNavigatorState != null) { await desktopNavigatorState!.pushNamed( DesktopTokenView.routeName, From 011ba6bf61d658c392979a360cd343d08fd8a3f6 Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 1 Jul 2023 15:06:49 -0600 Subject: [PATCH 09/10] use theme brightness for simplex logo --- lib/pages/buy_view/buy_order_details.dart | 13 +++++++++---- lib/pages/buy_view/buy_quote_preview.dart | 13 +++++++++---- .../buy_view/sub_widgets/buy_warning_popup.dart | 16 +++++++++++----- lib/utilities/assets.dart | 4 ++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/pages/buy_view/buy_order_details.dart b/lib/pages/buy_view/buy_order_details.dart index 250cba77b..04a556850 100644 --- a/lib/pages/buy_view/buy_order_details.dart +++ b/lib/pages/buy_view/buy_order_details.dart @@ -9,9 +9,11 @@ */ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/models/buy/response_objects/order.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/themes/theme_providers.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; @@ -21,7 +23,7 @@ import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; -class BuyOrderDetailsView extends StatefulWidget { +class BuyOrderDetailsView extends ConsumerStatefulWidget { const BuyOrderDetailsView({ Key? key, required this.order, @@ -32,10 +34,11 @@ class BuyOrderDetailsView extends StatefulWidget { static const String routeName = "/buyOrderDetails"; @override - State createState() => _BuyOrderDetailsViewState(); + ConsumerState createState() => + _BuyOrderDetailsViewState(); } -class _BuyOrderDetailsViewState extends State { +class _BuyOrderDetailsViewState extends ConsumerState { final isDesktop = Util.isDesktop; @override @@ -245,7 +248,9 @@ class _BuyOrderDetailsViewState extends State { width: 64, height: 32, child: SvgPicture.asset( - Assets.buy.simplexLogo(context), + Assets.buy.simplexLogo( + ref.watch(themeProvider).brightness, + ), ), ), ], diff --git a/lib/pages/buy_view/buy_quote_preview.dart b/lib/pages/buy_view/buy_quote_preview.dart index 3f4f96006..66b9af812 100644 --- a/lib/pages/buy_view/buy_quote_preview.dart +++ b/lib/pages/buy_view/buy_quote_preview.dart @@ -11,11 +11,13 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:intl/intl.dart'; import 'package:stackwallet/models/buy/response_objects/quote.dart'; import 'package:stackwallet/pages/buy_view/sub_widgets/buy_warning_popup.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/themes/theme_providers.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; @@ -25,7 +27,7 @@ import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; -class BuyQuotePreviewView extends StatefulWidget { +class BuyQuotePreviewView extends ConsumerStatefulWidget { const BuyQuotePreviewView({ Key? key, required this.quote, @@ -36,10 +38,11 @@ class BuyQuotePreviewView extends StatefulWidget { static const String routeName = "/buyQuotePreview"; @override - State createState() => _BuyQuotePreviewViewState(); + ConsumerState createState() => + _BuyQuotePreviewViewState(); } -class _BuyQuotePreviewViewState extends State { +class _BuyQuotePreviewViewState extends ConsumerState { final isDesktop = Util.isDesktop; Future _buyWarning() async { @@ -222,7 +225,9 @@ class _BuyQuotePreviewViewState extends State { width: 64, height: 32, child: SvgPicture.asset( - Assets.buy.simplexLogo(context), + Assets.buy.simplexLogo( + ref.watch(themeProvider).brightness, + ), ), ), ], diff --git a/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart b/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart index f5d61e3f4..fa651e7df 100644 --- a/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart +++ b/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart @@ -11,6 +11,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/models/buy/response_objects/order.dart'; import 'package:stackwallet/models/buy/response_objects/quote.dart'; @@ -18,6 +19,7 @@ import 'package:stackwallet/pages/buy_view/buy_order_details.dart'; import 'package:stackwallet/services/buy/buy_response.dart'; import 'package:stackwallet/services/buy/simplex/simplex_api.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/themes/theme_providers.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; @@ -28,7 +30,7 @@ import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; -class BuyWarningPopup extends StatefulWidget { +class BuyWarningPopup extends ConsumerStatefulWidget { const BuyWarningPopup({ Key? key, required this.quote, @@ -37,10 +39,10 @@ class BuyWarningPopup extends StatefulWidget { final SimplexQuote quote; final SimplexOrder? order; @override - State createState() => _BuyWarningPopupState(); + ConsumerState createState() => _BuyWarningPopupState(); } -class _BuyWarningPopupState extends State { +class _BuyWarningPopupState extends ConsumerState { late final bool isDesktop; SimplexOrder? order; @@ -236,7 +238,9 @@ class _BuyWarningPopupState extends State { width: 64, height: 32, child: SvgPicture.asset( - Assets.buy.simplexLogo(context), + Assets.buy.simplexLogo( + ref.watch(themeProvider).brightness, + ), ), ), ], @@ -291,7 +295,9 @@ class _BuyWarningPopupState extends State { width: 64, height: 32, child: SvgPicture.asset( - Assets.buy.simplexLogo(context), + Assets.buy.simplexLogo( + ref.watch(themeProvider).brightness, + ), ), ), ); diff --git a/lib/utilities/assets.dart b/lib/utilities/assets.dart index 7f92a9d1d..b8ec501e8 100644 --- a/lib/utilities/assets.dart +++ b/lib/utilities/assets.dart @@ -65,8 +65,8 @@ class _EXCHANGE { class _BUY { const _BUY(); - String simplexLogo(BuildContext context) { - switch (MediaQuery.of(context).platformBrightness) { + String simplexLogo(Brightness themeBrightness) { + switch (themeBrightness) { case Brightness.dark: return "assets/svg/buy/Simplex-Nuvei-Logo-light.svg"; From 1b66cc23c381bd89979573fbd536190ac41a8701 Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 1 Jul 2023 15:15:22 -0600 Subject: [PATCH 10/10] temporarily force update dark theme (banano coin icon fix) --- lib/themes/theme_service.dart | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/themes/theme_service.dart b/lib/themes/theme_service.dart index c72d778b6..fef185c5b 100644 --- a/lib/themes/theme_service.dart +++ b/lib/themes/theme_service.dart @@ -157,20 +157,22 @@ class ThemeService { ); } else { // check installed version - final theme = ThemeService.instance.getTheme(themeId: "dark"); - if ((theme?.version ?? 1) < _currentDefaultThemeVersion) { - Logging.instance.log( - "Updating default dark theme...", - level: LogLevel.Info, - ); - final darkZip = await rootBundle.load("assets/default_themes/dark.zip"); - await ThemeService.instance - .install(themeArchiveData: darkZip.buffer.asUint8List()); - Logging.instance.log( - "Updating default dark theme... finished", - level: LogLevel.Info, - ); - } + // final theme = ThemeService.instance.getTheme(themeId: "dark"); + // Force update theme to add missing icons for now + // TODO: uncomment if statement in future when themes are version 4 or above + // if ((theme?.version ?? 1) < _currentDefaultThemeVersion) { + Logging.instance.log( + "Updating default dark theme...", + level: LogLevel.Info, + ); + final darkZip = await rootBundle.load("assets/default_themes/dark.zip"); + await ThemeService.instance + .install(themeArchiveData: darkZip.buffer.asUint8List()); + Logging.instance.log( + "Updating default dark theme... finished", + level: LogLevel.Info, + ); + // } } }