From 74d3175d879555d92054f03151a856fc3fe38a3d Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 25 May 2023 09:24:07 -0600 Subject: [PATCH 1/3] fix: Handle sent to self transactions when sent to a change address --- lib/services/mixins/electrum_x_parsing.dart | 36 ++++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/services/mixins/electrum_x_parsing.dart b/lib/services/mixins/electrum_x_parsing.dart index c313a91eb..92cf86305 100644 --- a/lib/services/mixins/electrum_x_parsing.dart +++ b/lib/services/mixins/electrum_x_parsing.dart @@ -148,19 +148,31 @@ mixin ElectrumXParsing { type = TransactionType.outgoing; amount = amountSentFromWallet - changeAmount - fee; - final possible = - outputAddresses.difference(myChangeReceivedOnAddresses).first; + // non wallet addresses found in tx outputs + final nonWalletOutAddresses = outputAddresses.difference( + myChangeReceivedOnAddresses, + ); - if (transactionAddress.value != possible) { - transactionAddress = Address( - walletId: walletId, - value: possible, - derivationIndex: -1, - derivationPath: null, - subType: AddressSubType.nonWallet, - type: AddressType.nonWallet, - publicKey: [], - ); + if (nonWalletOutAddresses.isNotEmpty) { + final possible = nonWalletOutAddresses.first; + + if (transactionAddress.value != possible) { + transactionAddress = Address( + walletId: walletId, + value: possible, + derivationIndex: -1, + derivationPath: null, + subType: AddressSubType.nonWallet, + type: AddressType.nonWallet, + publicKey: [], + ); + } + } else { + // some other type of tx where the receiving address is + // one of my change addresses + + type = TransactionType.sentToSelf; + amount = changeAmount; } } else { // incoming tx From 3189203419632b2f712a608708343f432a9cc952 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 25 May 2023 10:05:20 -0600 Subject: [PATCH 2/3] fix: Firo total displayed on favourite card --- .../sub_widgets/favorite_card.dart | 111 +++++++++++------- .../sub_widgets/favorite_wallets.dart | 2 - .../desktop_favorite_wallets.dart | 1 - 3 files changed, 66 insertions(+), 48 deletions(-) diff --git a/lib/pages/wallets_view/sub_widgets/favorite_card.dart b/lib/pages/wallets_view/sub_widgets/favorite_card.dart index 87ffbccd1..8daf05a5d 100644 --- a/lib/pages/wallets_view/sub_widgets/favorite_card.dart +++ b/lib/pages/wallets_view/sub_widgets/favorite_card.dart @@ -6,7 +6,7 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/providers/providers.dart'; -import 'package:stackwallet/services/coins/manager.dart'; +import 'package:stackwallet/services/coins/firo/firo_wallet.dart'; import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; @@ -24,13 +24,11 @@ class FavoriteCard extends ConsumerStatefulWidget { required this.walletId, required this.width, required this.height, - required this.managerProvider, }) : super(key: key); final String walletId; final double width; final double height; - final ChangeNotifierProvider managerProvider; @override ConsumerState createState() => _FavoriteCardState(); @@ -38,15 +36,10 @@ class FavoriteCard extends ConsumerStatefulWidget { class _FavoriteCardState extends ConsumerState { late final String walletId; - late final ChangeNotifierProvider managerProvider; - - Amount _cachedBalance = Amount.zero; - Amount _cachedFiatValue = Amount.zero; @override void initState() { walletId = widget.walletId; - managerProvider = widget.managerProvider; super.initState(); } @@ -55,9 +48,13 @@ class _FavoriteCardState extends ConsumerState { @override Widget build(BuildContext context) { - final coin = ref.watch(managerProvider.select((value) => value.coin)); + final coin = ref.watch( + walletsChangeNotifierProvider + .select((value) => value.getManager(walletId).coin), + ); final externalCalls = ref.watch( - prefsChangeNotifierProvider.select((value) => value.externalCalls)); + prefsChangeNotifierProvider.select((value) => value.externalCalls), + ); return ConditionalParent( condition: Util.isDesktop, @@ -109,7 +106,10 @@ class _FavoriteCardState extends ConsumerState { child: GestureDetector( onTap: () async { if (coin == Coin.monero || coin == Coin.wownero) { - await ref.read(managerProvider).initializeExisting(); + await ref + .read(walletsChangeNotifierProvider) + .getManager(walletId) + .initializeExisting(); } if (mounted) { if (Util.isDesktop) { @@ -122,7 +122,9 @@ class _FavoriteCardState extends ConsumerState { WalletView.routeName, arguments: Tuple2( walletId, - managerProvider, + ref + .read(walletsChangeNotifierProvider) + .getManagerProvider(walletId), ), ); } @@ -205,8 +207,12 @@ class _FavoriteCardState extends ConsumerState { children: [ Expanded( child: Text( - ref.watch(managerProvider - .select((value) => value.walletName)), + ref.watch( + walletsChangeNotifierProvider.select( + (value) => + value.getManager(walletId).walletName, + ), + ), style: STextStyles.itemSubtitle12(context).copyWith( color: Theme.of(context) .extension()! @@ -225,41 +231,54 @@ class _FavoriteCardState extends ConsumerState { ], ), ), - FutureBuilder( - future: Future(() => ref.watch(managerProvider - .select((value) => value.balance.total))), - builder: (builderContext, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - if (snapshot.data != null) { - _cachedBalance = snapshot.data!; - if (externalCalls && _cachedBalance > Amount.zero) { - _cachedFiatValue = (_cachedBalance.decimal * - ref - .watch( - priceAnd24hChangeNotifierProvider - .select( - (value) => value.getPrice(coin), - ), - ) - .item1) - .toAmount(fractionDigits: 2); - } - } + Builder( + builder: (context) { + final balance = ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManager(walletId).balance, + ), + ); + + Amount total = balance.total; + if (coin == Coin.firo || coin == Coin.firoTestNet) { + final balancePrivate = ref.watch( + walletsChangeNotifierProvider.select( + (value) => (value.getManager(walletId).wallet + as FiroWallet) + .balancePrivate, + ), + ); + + total += balancePrivate.total; } + + Amount fiatTotal = Amount.zero; + + if (externalCalls && total > Amount.zero) { + fiatTotal = (total.decimal * + ref + .watch( + priceAnd24hChangeNotifierProvider.select( + (value) => value.getPrice(coin), + ), + ) + .item1) + .toAmount(fractionDigits: 2); + } + return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ FittedBox( fit: BoxFit.scaleDown, child: Text( - "${_cachedBalance.localizedStringAsFixed( + "${total.localizedStringAsFixed( locale: ref.watch( - localeServiceChangeNotifierProvider - .select((value) => value.locale), + localeServiceChangeNotifierProvider.select( + (value) => value.locale, + ), ), - decimalPlaces: ref.watch(managerProvider - .select((value) => value.coin.decimals)), + decimalPlaces: coin.decimals, )} ${coin.ticker}", style: STextStyles.titleBold12(context).copyWith( fontSize: 16, @@ -275,15 +294,17 @@ class _FavoriteCardState extends ConsumerState { ), if (externalCalls) Text( - "${_cachedFiatValue.localizedStringAsFixed( + "${fiatTotal.localizedStringAsFixed( locale: ref.watch( - localeServiceChangeNotifierProvider - .select((value) => value.locale), + localeServiceChangeNotifierProvider.select( + (value) => value.locale, + ), ), decimalPlaces: 2, )} ${ref.watch( - prefsChangeNotifierProvider - .select((value) => value.currency), + prefsChangeNotifierProvider.select( + (value) => value.currency, + ), )}", style: STextStyles.itemSubtitle12(context).copyWith( diff --git a/lib/pages/wallets_view/sub_widgets/favorite_wallets.dart b/lib/pages/wallets_view/sub_widgets/favorite_wallets.dart index afbea4562..665c147e1 100644 --- a/lib/pages/wallets_view/sub_widgets/favorite_wallets.dart +++ b/lib/pages/wallets_view/sub_widgets/favorite_wallets.dart @@ -211,7 +211,6 @@ class _FavoriteWalletsState extends ConsumerState { child: FavoriteCard( key: Key("favCard_$walletId"), walletId: walletId!, - managerProvider: managerProvider!, width: cardWidth, height: cardHeight, ), @@ -219,7 +218,6 @@ class _FavoriteWalletsState extends ConsumerState { : FavoriteCard( key: Key("favCard_$walletId"), walletId: walletId!, - managerProvider: managerProvider!, width: cardWidth, height: cardHeight, ) diff --git a/lib/pages_desktop_specific/my_stack_view/desktop_favorite_wallets.dart b/lib/pages_desktop_specific/my_stack_view/desktop_favorite_wallets.dart index b9ce38eb4..03d0df2ca 100644 --- a/lib/pages_desktop_specific/my_stack_view/desktop_favorite_wallets.dart +++ b/lib/pages_desktop_specific/my_stack_view/desktop_favorite_wallets.dart @@ -74,7 +74,6 @@ class DesktopFavoriteWallets extends ConsumerWidget { key: Key(walletName), width: cardWidth, height: cardHeight, - managerProvider: managerProvider, ); }) ], From 6a92657f504405a7eb653f615fdb315e0b7ed1b2 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 25 May 2023 10:10:07 -0600 Subject: [PATCH 3/3] fix: Firo total displayed on managed favourite list card --- lib/widgets/managed_favorite.dart | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/widgets/managed_favorite.dart b/lib/widgets/managed_favorite.dart index 6383c8501..cd03e7f59 100644 --- a/lib/widgets/managed_favorite.dart +++ b/lib/widgets/managed_favorite.dart @@ -4,8 +4,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/providers/providers.dart'; +import 'package:stackwallet/services/coins/firo/firo_wallet.dart'; import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; @@ -34,6 +36,28 @@ class _ManagedFavoriteCardState extends ConsumerState { final isDesktop = Util.isDesktop; + final balance = ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManager(widget.walletId).balance, + ), + ); + + Amount total = balance.total; + if (manager.coin == Coin.firo || manager.coin == Coin.firoTestNet) { + final balancePrivate = ref.watch( + walletsChangeNotifierProvider.select( + (value) => (value + .getManager( + widget.walletId, + ) + .wallet as FiroWallet) + .balancePrivate, + ), + ); + + total += balancePrivate.total; + } + return RoundedWhiteContainer( padding: EdgeInsets.all(isDesktop ? 0 : 4.0), child: RawMaterialButton( @@ -107,7 +131,7 @@ class _ManagedFavoriteCardState extends ConsumerState { ), Expanded( child: Text( - "${manager.balance.total.localizedStringAsFixed( + "${total.localizedStringAsFixed( locale: ref.watch( localeServiceChangeNotifierProvider.select( (value) => value.locale, @@ -150,7 +174,7 @@ class _ManagedFavoriteCardState extends ConsumerState { height: 2, ), Text( - "${manager.balance.total.localizedStringAsFixed( + "${total.localizedStringAsFixed( locale: ref.watch( localeServiceChangeNotifierProvider.select( (value) => value.locale,