fix: fiat amount when sending all (#1516)

* fix: fiat amount when sending all

* possible fix for pending txs
workaroudn update

* also for wow
This commit is contained in:
cyan 2024-07-06 15:01:42 +02:00 committed by GitHub
parent c5d3cbf66c
commit 0335702aa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 14 deletions

View file

@ -18,7 +18,7 @@ String getTxKey(String txId) {
monero.TransactionHistory? txhistory; monero.TransactionHistory? txhistory;
void refreshTransactions() { void refreshTransactions() {
txhistory = monero.Wallet_history(wptr!); txhistory ??= monero.Wallet_history(wptr!);
monero.TransactionHistory_refresh(txhistory!); monero.TransactionHistory_refresh(txhistory!);
} }
@ -27,17 +27,17 @@ int countOfTransactions() => monero.TransactionHistory_count(txhistory!);
List<Transaction> getAllTransactions() { List<Transaction> getAllTransactions() {
List<Transaction> dummyTxs = []; List<Transaction> dummyTxs = [];
txhistory = monero.Wallet_history(wptr!); txhistory ??= monero.Wallet_history(wptr!);
monero.TransactionHistory_refresh(txhistory!); monero.TransactionHistory_refresh(txhistory!);
int size = countOfTransactions(); 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!); final accts = monero.Wallet_numSubaddressAccounts(wptr!);
for (var i = 0; i < accts; i++) { for (var i = 0; i < accts; i++) {
final fullBalance = monero.Wallet_balance(wptr!, accountIndex: i); final fullBalance = monero.Wallet_balance(wptr!, accountIndex: i);
final availBalance = monero.Wallet_unlockedBalance(wptr!, accountIndex: i); final availBalance = monero.Wallet_unlockedBalance(wptr!, accountIndex: i);
if (fullBalance > availBalance) { 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( dummyTxs.add(
Transaction.dummy( Transaction.dummy(
displayLabel: "", displayLabel: "",
@ -50,7 +50,7 @@ List<Transaction> getAllTransactions() {
amount: fullBalance - availBalance, amount: fullBalance - availBalance,
isSpend: false, isSpend: false,
hash: "pending", hash: "pending",
key: "pending", key: "",
txInfo: Pointer.fromAddress(0), txInfo: Pointer.fromAddress(0),
)..timeStamp = DateTime.now() )..timeStamp = DateTime.now()
); );

View file

@ -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_opening_exception.dart';
import 'package:cw_monero/api/exceptions/wallet_restore_from_keys_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/exceptions/wallet_restore_from_seed_exception.dart';
import 'package:cw_monero/api/transaction_history.dart';
import 'package:cw_monero/api/wallet.dart'; import 'package:cw_monero/api/wallet.dart';
import 'package:monero/monero.dart' as monero; import 'package:monero/monero.dart' as monero;
@ -29,6 +30,7 @@ void createWalletSync(
required String password, required String password,
required String language, required String language,
int nettype = 0}) { int nettype = 0}) {
txhistory = null;
wptr = monero.WalletManager_createWallet(wmPtr, wptr = monero.WalletManager_createWallet(wmPtr,
path: path, password: password, language: language, networkType: 0); path: path, password: password, language: language, networkType: 0);
@ -53,6 +55,7 @@ void restoreWalletFromSeedSync(
required String seed, required String seed,
int nettype = 0, int nettype = 0,
int restoreHeight = 0}) { int restoreHeight = 0}) {
txhistory = null;
wptr = monero.WalletManager_recoveryWallet( wptr = monero.WalletManager_recoveryWallet(
wmPtr, wmPtr,
path: path, path: path,
@ -82,6 +85,7 @@ void restoreWalletFromKeysSync(
required String spendKey, required String spendKey,
int nettype = 0, int nettype = 0,
int restoreHeight = 0}) { int restoreHeight = 0}) {
txhistory = null;
wptr = monero.WalletManager_createWalletFromKeys( wptr = monero.WalletManager_createWalletFromKeys(
wmPtr, wmPtr,
path: path, path: path,
@ -110,6 +114,7 @@ void restoreWalletFromSpendKeySync(
required String spendKey, required String spendKey,
int nettype = 0, int nettype = 0,
int restoreHeight = 0}) { int restoreHeight = 0}) {
// txhistory = null;
// wptr = monero.WalletManager_createWalletFromKeys( // wptr = monero.WalletManager_createWalletFromKeys(
// wmPtr, // wmPtr,
// path: path, // path: path,
@ -121,6 +126,7 @@ void restoreWalletFromSpendKeySync(
// nettype: 0, // nettype: 0,
// ); // );
txhistory = null;
wptr = monero.WalletManager_createDeterministicWalletFromSpendKey( wptr = monero.WalletManager_createDeterministicWalletFromSpendKey(
wmPtr, wmPtr,
path: path, path: path,
@ -184,6 +190,7 @@ Map<String, monero.wallet> openedWalletsByPath = {};
void loadWallet( void loadWallet(
{required String path, required String password, int nettype = 0}) { {required String path, required String password, int nettype = 0}) {
if (openedWalletsByPath[path] != null) { if (openedWalletsByPath[path] != null) {
txhistory = null;
wptr = openedWalletsByPath[path]!; wptr = openedWalletsByPath[path]!;
return; return;
} }
@ -195,6 +202,7 @@ void loadWallet(
monero.Wallet_store(Pointer.fromAddress(addr)); monero.Wallet_store(Pointer.fromAddress(addr));
}); });
} }
txhistory = null;
wptr = monero.WalletManager_openWallet(wmPtr, wptr = monero.WalletManager_openWallet(wmPtr,
path: path, password: password); path: path, password: password);
openedWalletsByPath[path] = wptr!; openedWalletsByPath[path] = wptr!;

View file

@ -17,7 +17,7 @@ String getTxKey(String txId) {
wownero.TransactionHistory? txhistory; wownero.TransactionHistory? txhistory;
void refreshTransactions() { void refreshTransactions() {
txhistory = wownero.Wallet_history(wptr!); txhistory ??= wownero.Wallet_history(wptr!);
wownero.TransactionHistory_refresh(txhistory!); wownero.TransactionHistory_refresh(txhistory!);
} }
@ -26,17 +26,17 @@ int countOfTransactions() => wownero.TransactionHistory_count(txhistory!);
List<Transaction> getAllTransactions() { List<Transaction> getAllTransactions() {
List<Transaction> dummyTxs = []; List<Transaction> dummyTxs = [];
txhistory = wownero.Wallet_history(wptr!); txhistory ??= wownero.Wallet_history(wptr!);
wownero.TransactionHistory_refresh(txhistory!); wownero.TransactionHistory_refresh(txhistory!);
int size = countOfTransactions(); 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!); final accts = wownero.Wallet_numSubaddressAccounts(wptr!);
for (var i = 0; i < accts; i++) { for (var i = 0; i < accts; i++) {
final fullBalance = wownero.Wallet_balance(wptr!, accountIndex: i); final fullBalance = wownero.Wallet_balance(wptr!, accountIndex: i);
final availBalance = wownero.Wallet_unlockedBalance(wptr!, accountIndex: i); final availBalance = wownero.Wallet_unlockedBalance(wptr!, accountIndex: i);
if (fullBalance > availBalance) { 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( dummyTxs.add(
Transaction.dummy( Transaction.dummy(
displayLabel: "", displayLabel: "",

View file

@ -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_opening_exception.dart';
import 'package:cw_wownero/api/exceptions/wallet_restore_from_keys_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/exceptions/wallet_restore_from_seed_exception.dart';
import 'package:cw_wownero/api/transaction_history.dart';
import 'package:cw_wownero/api/wallet.dart'; import 'package:cw_wownero/api/wallet.dart';
import 'package:monero/wownero.dart' as wownero; import 'package:monero/wownero.dart' as wownero;
@ -29,6 +30,7 @@ void createWalletSync(
required String password, required String password,
required String language, required String language,
int nettype = 0}) { int nettype = 0}) {
txhistory = null;
wptr = wownero.WalletManager_createWallet(wmPtr, wptr = wownero.WalletManager_createWallet(wmPtr,
path: path, password: password, language: language, networkType: 0); path: path, password: password, language: language, networkType: 0);
@ -54,6 +56,7 @@ void restoreWalletFromSeedSync(
int nettype = 0, int nettype = 0,
int restoreHeight = 0}) { int restoreHeight = 0}) {
if (seed.split(" ").length == 14) { if (seed.split(" ").length == 14) {
txhistory = null;
wptr = wownero.WOWNERO_deprecated_restore14WordSeed( wptr = wownero.WOWNERO_deprecated_restore14WordSeed(
path: path, path: path,
password: password, password: password,
@ -65,6 +68,7 @@ void restoreWalletFromSeedSync(
height: wownero.WOWNERO_deprecated_14WordSeedHeight(seed: seed), height: wownero.WOWNERO_deprecated_14WordSeedHeight(seed: seed),
); );
} else { } else {
txhistory = null;
wptr = wownero.WalletManager_recoveryWallet( wptr = wownero.WalletManager_recoveryWallet(
wmPtr, wmPtr,
path: path, path: path,
@ -95,6 +99,7 @@ void restoreWalletFromKeysSync(
required String spendKey, required String spendKey,
int nettype = 0, int nettype = 0,
int restoreHeight = 0}) { int restoreHeight = 0}) {
txhistory = null;
wptr = wownero.WalletManager_createWalletFromKeys( wptr = wownero.WalletManager_createWalletFromKeys(
wmPtr, wmPtr,
path: path, path: path,
@ -123,6 +128,7 @@ void restoreWalletFromSpendKeySync(
required String spendKey, required String spendKey,
int nettype = 0, int nettype = 0,
int restoreHeight = 0}) { int restoreHeight = 0}) {
// txhistory = null;
// wptr = wownero.WalletManager_createWalletFromKeys( // wptr = wownero.WalletManager_createWalletFromKeys(
// wmPtr, // wmPtr,
// path: path, // path: path,
@ -134,6 +140,7 @@ void restoreWalletFromSpendKeySync(
// nettype: 0, // nettype: 0,
// ); // );
txhistory = null;
wptr = wownero.WalletManager_createDeterministicWalletFromSpendKey( wptr = wownero.WalletManager_createDeterministicWalletFromSpendKey(
wmPtr, wmPtr,
path: path, path: path,
@ -197,6 +204,7 @@ Map<String, wownero.wallet> openedWalletsByPath = {};
void loadWallet( void loadWallet(
{required String path, required String password, int nettype = 0}) { {required String path, required String password, int nettype = 0}) {
if (openedWalletsByPath[path] != null) { if (openedWalletsByPath[path] != null) {
txhistory = null;
wptr = openedWalletsByPath[path]!; wptr = openedWalletsByPath[path]!;
return; return;
} }
@ -208,6 +216,7 @@ void loadWallet(
wownero.Wallet_store(Pointer.fromAddress(addr)); wownero.Wallet_store(Pointer.fromAddress(addr));
}); });
} }
txhistory = null;
wptr = wownero.WalletManager_openWallet(wmPtr, wptr = wownero.WalletManager_openWallet(wmPtr,
path: path, password: password); path: path, password: password);
openedWalletsByPath[path] = wptr!; openedWalletsByPath[path] = wptr!;

View file

@ -332,7 +332,9 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
width: prefixIconWidth, width: prefixIconWidth,
height: prefixIconHeight, height: prefixIconHeight,
child: InkWell( child: InkWell(
onTap: () async => output.setSendAll(), onTap: () async {
output.setSendAll(sendViewModel.balance);
},
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context) color: Theme.of(context)

View file

@ -38,6 +38,7 @@ abstract class OutputBase with Store {
key = UniqueKey(), key = UniqueKey(),
sendAll = false, sendAll = false,
cryptoAmount = '', cryptoAmount = '',
cryptoFullBalance = '',
fiatAmount = '', fiatAmount = '',
address = '', address = '',
note = '', note = '',
@ -54,6 +55,9 @@ abstract class OutputBase with Store {
@observable @observable
String cryptoAmount; String cryptoAmount;
@observable
String cryptoFullBalance;
@observable @observable
String address; String address;
@ -202,9 +206,11 @@ abstract class OutputBase with Store {
final SettingsStore _settingsStore; final SettingsStore _settingsStore;
final FiatConversionStore _fiatConversationStore; final FiatConversionStore _fiatConversationStore;
final NumberFormat _cryptoNumberFormat; final NumberFormat _cryptoNumberFormat;
@action @action
void setSendAll() => sendAll = true; void setSendAll(String fullBalance) {
cryptoFullBalance = fullBalance;
sendAll = true;
}
@action @action
void reset() { void reset() {
@ -243,7 +249,7 @@ abstract class OutputBase with Store {
try { try {
final fiat = calculateFiatAmount( final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[cryptoCurrencyHandler()]!, price: _fiatConversationStore.prices[cryptoCurrencyHandler()]!,
cryptoAmount: cryptoAmount.replaceAll(',', '.')); cryptoAmount: sendAll ? cryptoFullBalance.replaceAll(",", ".") : cryptoAmount.replaceAll(',', '.'));
if (fiatAmount != fiat) { if (fiatAmount != fiat) {
fiatAmount = fiat; fiatAmount = fiat;
} }