From 0335702aa925bd6477cea4db77fe954e835e84e0 Mon Sep 17 00:00:00 2001 From: cyan Date: Sat, 6 Jul 2024 15:01:42 +0200 Subject: [PATCH] fix: fiat amount when sending all (#1516) * fix: fiat amount when sending all * possible fix for pending txs workaroudn update * also for wow --- cw_monero/lib/api/transaction_history.dart | 10 +++++----- cw_monero/lib/api/wallet_manager.dart | 10 +++++++++- cw_wownero/lib/api/transaction_history.dart | 8 ++++---- cw_wownero/lib/api/wallet_manager.dart | 9 +++++++++ lib/src/screens/send/widgets/send_card.dart | 4 +++- lib/view_model/send/output.dart | 12 +++++++++--- 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/cw_monero/lib/api/transaction_history.dart b/cw_monero/lib/api/transaction_history.dart index 187921ff4..5e33c6c56 100644 --- a/cw_monero/lib/api/transaction_history.dart +++ b/cw_monero/lib/api/transaction_history.dart @@ -18,7 +18,7 @@ String getTxKey(String txId) { monero.TransactionHistory? txhistory; void refreshTransactions() { - txhistory = monero.Wallet_history(wptr!); + txhistory ??= monero.Wallet_history(wptr!); monero.TransactionHistory_refresh(txhistory!); } @@ -27,17 +27,17 @@ int countOfTransactions() => monero.TransactionHistory_count(txhistory!); List getAllTransactions() { List dummyTxs = []; - txhistory = monero.Wallet_history(wptr!); + txhistory ??= monero.Wallet_history(wptr!); monero.TransactionHistory_refresh(txhistory!); int size = countOfTransactions(); - final list = List.generate(size, (index) => Transaction(txInfo: monero.TransactionHistory_transaction(txhistory!, index: index)))..addAll(dummyTxs); + final list = List.generate(size, (index) => Transaction(txInfo: monero.TransactionHistory_transaction(txhistory!, index: index))); final accts = monero.Wallet_numSubaddressAccounts(wptr!); for (var i = 0; i < accts; i++) { final fullBalance = monero.Wallet_balance(wptr!, accountIndex: i); final availBalance = monero.Wallet_unlockedBalance(wptr!, accountIndex: i); if (fullBalance > availBalance) { - if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isNotEmpty) { + if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isEmpty) { dummyTxs.add( Transaction.dummy( displayLabel: "", @@ -50,7 +50,7 @@ List getAllTransactions() { amount: fullBalance - availBalance, isSpend: false, hash: "pending", - key: "pending", + key: "", txInfo: Pointer.fromAddress(0), )..timeStamp = DateTime.now() ); diff --git a/cw_monero/lib/api/wallet_manager.dart b/cw_monero/lib/api/wallet_manager.dart index 1873f734e..8a1eee3f7 100644 --- a/cw_monero/lib/api/wallet_manager.dart +++ b/cw_monero/lib/api/wallet_manager.dart @@ -6,6 +6,7 @@ import 'package:cw_monero/api/exceptions/wallet_creation_exception.dart'; import 'package:cw_monero/api/exceptions/wallet_opening_exception.dart'; import 'package:cw_monero/api/exceptions/wallet_restore_from_keys_exception.dart'; import 'package:cw_monero/api/exceptions/wallet_restore_from_seed_exception.dart'; +import 'package:cw_monero/api/transaction_history.dart'; import 'package:cw_monero/api/wallet.dart'; import 'package:monero/monero.dart' as monero; @@ -29,6 +30,7 @@ void createWalletSync( required String password, required String language, int nettype = 0}) { + txhistory = null; wptr = monero.WalletManager_createWallet(wmPtr, path: path, password: password, language: language, networkType: 0); @@ -53,6 +55,7 @@ void restoreWalletFromSeedSync( required String seed, int nettype = 0, int restoreHeight = 0}) { + txhistory = null; wptr = monero.WalletManager_recoveryWallet( wmPtr, path: path, @@ -82,6 +85,7 @@ void restoreWalletFromKeysSync( required String spendKey, int nettype = 0, int restoreHeight = 0}) { + txhistory = null; wptr = monero.WalletManager_createWalletFromKeys( wmPtr, path: path, @@ -110,6 +114,7 @@ void restoreWalletFromSpendKeySync( required String spendKey, int nettype = 0, int restoreHeight = 0}) { + // txhistory = null; // wptr = monero.WalletManager_createWalletFromKeys( // wmPtr, // path: path, @@ -120,7 +125,8 @@ void restoreWalletFromSpendKeySync( // viewKeyString: '', // nettype: 0, // ); - + + txhistory = null; wptr = monero.WalletManager_createDeterministicWalletFromSpendKey( wmPtr, path: path, @@ -184,6 +190,7 @@ Map openedWalletsByPath = {}; void loadWallet( {required String path, required String password, int nettype = 0}) { if (openedWalletsByPath[path] != null) { + txhistory = null; wptr = openedWalletsByPath[path]!; return; } @@ -195,6 +202,7 @@ void loadWallet( monero.Wallet_store(Pointer.fromAddress(addr)); }); } + txhistory = null; wptr = monero.WalletManager_openWallet(wmPtr, path: path, password: password); openedWalletsByPath[path] = wptr!; diff --git a/cw_wownero/lib/api/transaction_history.dart b/cw_wownero/lib/api/transaction_history.dart index 42b2ef6f3..3ccd0b3c6 100644 --- a/cw_wownero/lib/api/transaction_history.dart +++ b/cw_wownero/lib/api/transaction_history.dart @@ -17,7 +17,7 @@ String getTxKey(String txId) { wownero.TransactionHistory? txhistory; void refreshTransactions() { - txhistory = wownero.Wallet_history(wptr!); + txhistory ??= wownero.Wallet_history(wptr!); wownero.TransactionHistory_refresh(txhistory!); } @@ -26,17 +26,17 @@ int countOfTransactions() => wownero.TransactionHistory_count(txhistory!); List getAllTransactions() { List dummyTxs = []; - txhistory = wownero.Wallet_history(wptr!); + txhistory ??= wownero.Wallet_history(wptr!); wownero.TransactionHistory_refresh(txhistory!); int size = countOfTransactions(); - final list = List.generate(size, (index) => Transaction(txInfo: wownero.TransactionHistory_transaction(txhistory!, index: index)))..addAll(dummyTxs); + final list = List.generate(size, (index) => Transaction(txInfo: wownero.TransactionHistory_transaction(txhistory!, index: index))); final accts = wownero.Wallet_numSubaddressAccounts(wptr!); for (var i = 0; i < accts; i++) { final fullBalance = wownero.Wallet_balance(wptr!, accountIndex: i); final availBalance = wownero.Wallet_unlockedBalance(wptr!, accountIndex: i); if (fullBalance > availBalance) { - if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isNotEmpty) { + if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isEmpty) { dummyTxs.add( Transaction.dummy( displayLabel: "", diff --git a/cw_wownero/lib/api/wallet_manager.dart b/cw_wownero/lib/api/wallet_manager.dart index 53d62f1cf..2f92bb080 100644 --- a/cw_wownero/lib/api/wallet_manager.dart +++ b/cw_wownero/lib/api/wallet_manager.dart @@ -6,6 +6,7 @@ import 'package:cw_wownero/api/exceptions/wallet_creation_exception.dart'; import 'package:cw_wownero/api/exceptions/wallet_opening_exception.dart'; import 'package:cw_wownero/api/exceptions/wallet_restore_from_keys_exception.dart'; import 'package:cw_wownero/api/exceptions/wallet_restore_from_seed_exception.dart'; +import 'package:cw_wownero/api/transaction_history.dart'; import 'package:cw_wownero/api/wallet.dart'; import 'package:monero/wownero.dart' as wownero; @@ -29,6 +30,7 @@ void createWalletSync( required String password, required String language, int nettype = 0}) { + txhistory = null; wptr = wownero.WalletManager_createWallet(wmPtr, path: path, password: password, language: language, networkType: 0); @@ -54,6 +56,7 @@ void restoreWalletFromSeedSync( int nettype = 0, int restoreHeight = 0}) { if (seed.split(" ").length == 14) { + txhistory = null; wptr = wownero.WOWNERO_deprecated_restore14WordSeed( path: path, password: password, @@ -65,6 +68,7 @@ void restoreWalletFromSeedSync( height: wownero.WOWNERO_deprecated_14WordSeedHeight(seed: seed), ); } else { + txhistory = null; wptr = wownero.WalletManager_recoveryWallet( wmPtr, path: path, @@ -95,6 +99,7 @@ void restoreWalletFromKeysSync( required String spendKey, int nettype = 0, int restoreHeight = 0}) { + txhistory = null; wptr = wownero.WalletManager_createWalletFromKeys( wmPtr, path: path, @@ -123,6 +128,7 @@ void restoreWalletFromSpendKeySync( required String spendKey, int nettype = 0, int restoreHeight = 0}) { + // txhistory = null; // wptr = wownero.WalletManager_createWalletFromKeys( // wmPtr, // path: path, @@ -134,6 +140,7 @@ void restoreWalletFromSpendKeySync( // nettype: 0, // ); + txhistory = null; wptr = wownero.WalletManager_createDeterministicWalletFromSpendKey( wmPtr, path: path, @@ -197,6 +204,7 @@ Map openedWalletsByPath = {}; void loadWallet( {required String path, required String password, int nettype = 0}) { if (openedWalletsByPath[path] != null) { + txhistory = null; wptr = openedWalletsByPath[path]!; return; } @@ -208,6 +216,7 @@ void loadWallet( wownero.Wallet_store(Pointer.fromAddress(addr)); }); } + txhistory = null; wptr = wownero.WalletManager_openWallet(wmPtr, path: path, password: password); openedWalletsByPath[path] = wptr!; diff --git a/lib/src/screens/send/widgets/send_card.dart b/lib/src/screens/send/widgets/send_card.dart index c9ae5182a..ec833159f 100644 --- a/lib/src/screens/send/widgets/send_card.dart +++ b/lib/src/screens/send/widgets/send_card.dart @@ -332,7 +332,9 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin output.setSendAll(), + onTap: () async { + output.setSendAll(sendViewModel.balance); + }, child: Container( decoration: BoxDecoration( color: Theme.of(context) diff --git a/lib/view_model/send/output.dart b/lib/view_model/send/output.dart index 892841a60..94854df31 100644 --- a/lib/view_model/send/output.dart +++ b/lib/view_model/send/output.dart @@ -38,6 +38,7 @@ abstract class OutputBase with Store { key = UniqueKey(), sendAll = false, cryptoAmount = '', + cryptoFullBalance = '', fiatAmount = '', address = '', note = '', @@ -54,6 +55,9 @@ abstract class OutputBase with Store { @observable String cryptoAmount; + @observable + String cryptoFullBalance; + @observable String address; @@ -202,9 +206,11 @@ abstract class OutputBase with Store { final SettingsStore _settingsStore; final FiatConversionStore _fiatConversationStore; final NumberFormat _cryptoNumberFormat; - @action - void setSendAll() => sendAll = true; + void setSendAll(String fullBalance) { + cryptoFullBalance = fullBalance; + sendAll = true; + } @action void reset() { @@ -243,7 +249,7 @@ abstract class OutputBase with Store { try { final fiat = calculateFiatAmount( price: _fiatConversationStore.prices[cryptoCurrencyHandler()]!, - cryptoAmount: cryptoAmount.replaceAll(',', '.')); + cryptoAmount: sendAll ? cryptoFullBalance.replaceAll(",", ".") : cryptoAmount.replaceAll(',', '.')); if (fiatAmount != fiat) { fiatAmount = fiat; }