From f5e19a13ab26fc6a6dddfd35fa5344561bd697db Mon Sep 17 00:00:00 2001 From: M Date: Wed, 11 Nov 2020 00:24:50 +0200 Subject: [PATCH] Fixes. --- cw_monero/lib/wallet.dart | 8 ++++---- lib/monero/monero_transaction_info.dart | 15 +++++++++++---- lib/monero/monero_wallet.dart | 10 ++++++---- .../transaction_details_page.dart | 5 ++++- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cw_monero/lib/wallet.dart b/cw_monero/lib/wallet.dart index c0cd7b6fc..156a19679 100644 --- a/cw_monero/lib/wallet.dart +++ b/cw_monero/lib/wallet.dart @@ -240,16 +240,16 @@ class SyncListener { _initialSyncHeight = 0; _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async { - final _isNeededToRefresh = isNeededToRefresh(); - print('isNeededToRefresh $_isNeededToRefresh'); + // final _isNeededToRefresh = isNeededToRefresh(); + // print('isNeededToRefresh $_isNeededToRefresh'); - if (isNewTransactionExist() || _isNeededToRefresh) { + if (isNewTransactionExist()) { onNewTransaction?.call(); } var syncHeight = getSyncingHeight(); - print('syncHeight $syncHeight'); + // print('syncHeight $syncHeight'); if (syncHeight <= 0) { syncHeight = getCurrentHeight(); diff --git a/lib/monero/monero_transaction_info.dart b/lib/monero/monero_transaction_info.dart index 2259d7fb2..71bc5957a 100644 --- a/lib/monero/monero_transaction_info.dart +++ b/lib/monero/monero_transaction_info.dart @@ -8,7 +8,7 @@ import 'package:cw_monero/transaction_history.dart'; class MoneroTransactionInfo extends TransactionInfo { MoneroTransactionInfo(this.id, this.height, this.direction, this.date, - this.isPending, this.amount, this.accountIndex); + this.isPending, this.amount, this.accountIndex, this.fee); MoneroTransactionInfo.fromMap(Map map) : id = (map['hash'] ?? '') as String, @@ -21,7 +21,8 @@ class MoneroTransactionInfo extends TransactionInfo { isPending = parseBoolFromString(map['isPending'] as String), amount = map['amount'] as int, accountIndex = int.parse(map['accountIndex'] as String), - key = getTxKey((map['hash'] ?? '') as String); + key = getTxKey((map['hash'] ?? '') as String), + fee = map['fee'] as int ?? 0; MoneroTransactionInfo.fromRow(TransactionInfoRow row) : id = row.getHash(), @@ -32,7 +33,8 @@ class MoneroTransactionInfo extends TransactionInfo { isPending = row.isPending != 0, amount = row.getAmount(), accountIndex = row.subaddrAccount, - key = getTxKey(row.getHash()); + key = getTxKey(row.getHash()), + fee = row.fee; final String id; final int height; @@ -41,17 +43,22 @@ class MoneroTransactionInfo extends TransactionInfo { final int accountIndex; final bool isPending; final int amount; + final int fee; String recipientAddress; String key; String _fiatAmount; @override - String amountFormatted() => '${formatAmount(moneroAmountToString(amount: amount))} XMR'; + String amountFormatted() => + '${formatAmount(moneroAmountToString(amount: amount))} XMR'; @override String fiatAmount() => _fiatAmount ?? ''; @override void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount); + + String feeFormatted() => + '${formatAmount(moneroAmountToString(amount: fee))} XMR'; } diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index f5e0f637f..780153319 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -101,7 +101,7 @@ abstract class MoneroWalletBase extends WalletBase with Store { balance = MoneroBalance( fullBalance: monero_wallet.getFullBalance(accountIndex: account.id), unlockedBalance: - monero_wallet.getFullBalance(accountIndex: account.id)); + monero_wallet.getUnlockedBalance(accountIndex: account.id)); address = subaddress.address; _setListeners(); await transactionHistory.update(); @@ -186,8 +186,10 @@ abstract class MoneroWalletBase extends WalletBase with Store { if ((amount != null && unlockedBalance < amount) || (amount == null && unlockedBalance <= 0)) { + final formattedBalance = moneroAmountToString(amount: unlockedBalance); + throw MoneroTransactionCreationException( - 'Incorrect unlocked balance. Unlocked: $unlockedBalance. Transaction amount: ${_credentials.amount}.'); + 'Incorrect unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${_credentials.amount}.'); } if (!(syncStatus is SyncedSyncStatus)) { @@ -363,11 +365,11 @@ abstract class MoneroWalletBase extends WalletBase with Store { print('_onNewBlock called'); if (walletInfo.isRecovery) { _askForUpdateTransactionHistory(); + _askForUpdateBalance(); } - _askForUpdateBalance(); - if (blocksLeft < 100) { + _askForUpdateBalance(); syncStatus = SyncedSyncStatus(); await _afterSyncSave(); diff --git a/lib/src/screens/transaction_details/transaction_details_page.dart b/lib/src/screens/transaction_details/transaction_details_page.dart index 46a93d5f2..6745e05a7 100644 --- a/lib/src/screens/transaction_details/transaction_details_page.dart +++ b/lib/src/screens/transaction_details/transaction_details_page.dart @@ -29,7 +29,10 @@ class TransactionDetailsPage extends BasePage { title: S.current.transaction_details_height, value: '${tx.height}'), StandartListItem( title: S.current.transaction_details_amount, - value: tx.amountFormatted()) + value: tx.amountFormatted()), + StandartListItem( + title: S.current.send_fee, + value: tx.feeFormatted()) ]; if (showRecipientAddress) {