From 4269b51ea6303be34d00f8291770ce4c38089e8e Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 19 Jul 2021 14:44:09 +0200 Subject: [PATCH] feat(@desktop/wallet): display confirmation block count fixes #2715 --- src/app/wallet/view.nim | 3 +++ src/app/wallet/views/transaction_list.nim | 5 ++++- src/status/wallet.nim | 21 ++++++++++++------- .../Wallet/components/TransactionModal.qml | 8 +++---- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index 41c53d9331..f6f4b3df56 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -102,6 +102,9 @@ QtObject: self.balanceView.getAccountBalanceSuccess(jsonResponse) self.updateView() + proc getLatestBlockNumber*(self: WalletView): int {.slot.} = + return self.status.wallet.getLatestBlockNumber() + proc getDefaultAddress*(self: WalletView): string {.slot.} = result = $self.status.wallet.getWalletAccounts()[0].address diff --git a/src/app/wallet/views/transaction_list.nim b/src/app/wallet/views/transaction_list.nim index 38b98cd50a..24904b1c54 100644 --- a/src/app/wallet/views/transaction_list.nim +++ b/src/app/wallet/views/transaction_list.nim @@ -17,6 +17,7 @@ type From = UserRole + 12, To = UserRole + 13 Contract = UserRole + 14 + Id = UserRole + 15 QtObject: type TransactionList* = ref object of QAbstractListModel @@ -79,6 +80,7 @@ QtObject: of TransactionRoles.From: result = newQVariant(transaction.fromAddress) of TransactionRoles.To: result = newQVariant(transaction.to) of TransactionRoles.Contract: result = newQVariant(transaction.contract) + of TransactionRoles.Id: result = newQVariant(transaction.id) method roleNames(self: TransactionList): Table[int, string] = { TransactionRoles.Type.int:"typeValue", @@ -94,7 +96,8 @@ QtObject: TransactionRoles.Value.int:"value", TransactionRoles.From.int:"fromAddress", TransactionRoles.To.int:"to", - TransactionRoles.Contract.int:"contract"}.toTable + TransactionRoles.Contract.int:"contract", + TransactionRoles.Id.int:"id",}.toTable proc addTransactionToList*(self: TransactionList, transaction: Transaction) = self.beginInsertRows(newQModelIndex(), self.transactions.len, self.transactions.len) diff --git a/src/status/wallet.nim b/src/status/wallet.nim index bb673e9e07..cafa6a00ad 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -98,14 +98,21 @@ proc confirmTransactionStatus(self: WalletModel, pendingTransactions: JsonNode, ) self.events.emit(parseEnum[PendingTransactionType](trx["type"].getStr).confirmed, ev) -proc checkPendingTransactions*(self: WalletModel) = +proc getLatestBlockNumber*(self: WalletModel): int = let response = getBlockByNumber("latest").parseJson() - if response.hasKey("result"): - let latestBlock = parseInt($fromHex(Stuint[256], response["result"]["number"].getStr)) - let pendingTransactions = status_wallet.getPendingTransactions() - if (pendingTransactions != ""): - self.confirmTransactionStatus(pendingTransactions.parseJson{"result"}, latestBlock) - + if not response.hasKey("result"): + return -1 + + return parseInt($fromHex(Stuint[256], response["result"]["number"].getStr)) + +proc checkPendingTransactions*(self: WalletModel) = + let latestBlockNumber = self.getLatestBlockNumber() + if latestBlockNumber == -1: + return + + let pendingTransactions = status_wallet.getPendingTransactions() + if (pendingTransactions != ""): + self.confirmTransactionStatus(pendingTransactions.parseJson{"result"}, latestBlockNumber) proc checkPendingTransactions*(self: WalletModel, address: string, blockNumber: int) = self.confirmTransactionStatus(status_wallet.getPendingOutboundTransactionsByAddress(address).parseJson["result"], blockNumber) diff --git a/ui/app/AppLayouts/Wallet/components/TransactionModal.qml b/ui/app/AppLayouts/Wallet/components/TransactionModal.qml index bf6a454831..fee418d4c2 100644 --- a/ui/app/AppLayouts/Wallet/components/TransactionModal.qml +++ b/ui/app/AppLayouts/Wallet/components/TransactionModal.qml @@ -20,9 +20,9 @@ ModalPopup { StyledText { id: confirmationsCount - // TODO get the right value - //% "9999 Confirmations" - text: qsTrId("9999-confirmations") + text: { + return walletModel.getLatestBlockNumber() - utilsModel.hex2Dec(blockNumber) + qsTrId(" confirmation(s)") + } font.pixelSize: 14 } @@ -97,7 +97,7 @@ ModalPopup { Address { id: valueHash - text: blockHash + text: id width: 160 maxWidth: parent.width - labelHash.width - Style.current.padding color: Style.current.textColor