From faa3a4146518a606a1c302bf8bf6428be5dfc9af Mon Sep 17 00:00:00 2001 From: Khushboo-dev-cpp <60327365+Khushboo-dev-cpp@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:59:08 +0100 Subject: [PATCH] fix(@wallet/desktop): No feedback after token approval. Once the approval is confirmed the Swap dialog becomes editable again, with the Swap button enabled (#16666) fixes #16569 --- src/app/modules/main/module.nim | 9 +- src/app/modules/main/view.nim | 5 +- .../transaction/router_transactions_dto.nim | 5 +- .../service/transaction/service.nim | 4 +- ui/app/mainui/AppMain.qml | 122 +++++------------- 5 files changed, 45 insertions(+), 100 deletions(-) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 57aa559eb2..d199fc3fa2 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -467,17 +467,16 @@ proc connectForNotificationsOnly[T](self: Module[T]) = let args = TransactionSentArgs(e) self.view.showToastTransactionSent(args.chainId, args.txHash, args.uuid, args.error, ord(args.txType), args.fromAddress, args.toAddress, args.fromTokenKey, args.fromAmount, - args.toTokenKey, args.toAmount) + args.toTokenKey, args.toAmount, args.approvalTx) self.events.on(MARK_WALLET_ADDRESSES_AS_SHOWN) do(e:Args): let args = WalletAddressesArgs(e) for address in args.addresses: self.addressWasShown(address) - self.events.on(SIGNAL_TRANSACTION_SENDING_COMPLETE) do(e:Args): - let args = TransactionMinedArgs(e) - self.view.showToastTransactionSendingComplete(args.chainId, args.transactionHash, args.data, args.success, - ord(args.txType), args.fromAddress, args.toAddress, args.fromTokenKey, args.fromAmount, args.toTokenKey, args.toAmount) + self.events.on(SIGNAL_TRANSACTION_STATUS_CHANGED) do(e:Args): + let args = TransactionStatusArgs(e) + self.view.showToastTransactionSendingComplete(args.data.hash, args.data.status) self.events.on(SIGNAL_PAIRING_FALLBACK_COMPLETED) do(e:Args): self.view.showToastPairingFallbackCompleted() diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index 25dc778791..cf0a1b8ffc 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -341,9 +341,8 @@ QtObject: proc showToastKeypairRemoved*(self: View, keypairName: string) {.signal.} proc showToastKeypairsImported*(self: View, keypairName: string, keypairsCount: int, error: string) {.signal.} proc showToastTransactionSent*(self: View, chainId: int, txHash: string, uuid: string, error: string, - txType: int, fromAddr: string, toAddr: string, fromTokenKey: string, fromAmount: string, toTokenKey: string, toAmount: string) {.signal.} - proc showToastTransactionSendingComplete*(self: View, chainId: int, txHash: string, data: string, success: bool, - txType: int, fromAddr: string, toAddr: string, fromTokenKey: string, fromAmount: string, toTokenKey: string, toAmount: string) {.signal.} + txType: int, fromAddr: string, toAddr: string, fromTokenKey: string, fromAmount: string, toTokenKey: string, toAmount: string, approvalTx: bool) {.signal.} + proc showToastTransactionSendingComplete*(self: View, txHash: string, data: string) {.signal.} proc showToastPairingFallbackCompleted*(self: View) {.signal.} ## Used in test env only, for testing keycard flows diff --git a/src/app_service/service/transaction/router_transactions_dto.nim b/src/app_service/service/transaction/router_transactions_dto.nim index 75cdf45ce0..dccd802e47 100644 --- a/src/app_service/service/transaction/router_transactions_dto.nim +++ b/src/app_service/service/transaction/router_transactions_dto.nim @@ -55,6 +55,7 @@ type fromToken*: string toToken*: string amount*: UInt256 # amount of the transaction + amountOut*: UInt256 # amount of the transaction hash*: string approvalTx*: bool @@ -130,6 +131,8 @@ proc toRouterSentTransaction*(jsonObj: JsonNode): RouterSentTransaction = var tmpObj: JsonNode if jsonObj.getProp("amount", tmpObj): result.amount = stint.fromHex(UInt256, tmpObj.getStr) + if jsonObj.getProp("amountOut", tmpObj): + result.amountOut = stint.fromHex(UInt256, tmpObj.getStr) proc toRouterSentTransactionsDto*(jsonObj: JsonNode): RouterSentTransactionsDto = result = RouterSentTransactionsDto() @@ -138,4 +141,4 @@ proc toRouterSentTransactionsDto*(jsonObj: JsonNode): RouterSentTransactionsDto result.sendDetails = toSendDetailsDto(tmpObj) if jsonObj.getProp("sentTransactions", tmpObj) and tmpObj.kind == JArray: for tx in tmpObj: - result.sentTransactions.add(toRouterSentTransaction(tx)) \ No newline at end of file + result.sentTransactions.add(toRouterSentTransaction(tx)) diff --git a/src/app_service/service/transaction/service.nim b/src/app_service/service/transaction/service.nim index b15b403e98..a8c8637658 100644 --- a/src/app_service/service/transaction/service.nim +++ b/src/app_service/service/transaction/service.nim @@ -365,9 +365,9 @@ QtObject: fromAddress: tx.fromAddress, toAddress: tx.toAddress, fromTokenKey: tx.fromToken, - fromAmount: tx.amount.toString(10), + fromAmount: sendDetails.fromAmount.toString(10), toTokenKey: tx.toToken, - toAmount: tx.amount.toString(10), + toAmount: tx.amountOut.toString(10), approvalTx: tx.approvalTx, username: sendDetails.username, publicKey: sendDetails.publicKey, diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 955a3e156a..749b76f547 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -237,52 +237,46 @@ Item { function onShowToastTransactionSent(chainId: int, txHash: string, uuid: string, error: string, txType: int, fromAddr: string, toAddr: string, fromTokenKey: string, fromAmount: string, - toTokenKey: string, toAmount: string) { + toTokenKey: string, toAmount: string, approvalTx: bool) { switch(txType) { - case Constants.SendType.Approve: { - const fromToken = SQUtils.ModelUtils.getByKey(appMain.tokensStore.plainTokensBySymbolModel, "key", fromTokenKey) - const fromAccountName = SQUtils.ModelUtils.getByKey(appMain.transactionStore.accounts, "address", fromAddr, "name") - const networkName = SQUtils.ModelUtils.getByKey(WalletStores.RootStore.filteredFlatModel, "chainId", chainId, "chainName") - if(!!fromToken && !!fromAccountName && !!networkName) { - const approvalAmount = currencyStore.formatCurrencyAmountFromBigInt(fromAmount, fromToken.symbol, fromToken.decimals) - let toastTitle = qsTr("Setting spending cap: %1 in %2 for %3 on %4").arg(approvalAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) - let toastSubtitle = qsTr("View on %1").arg(networkName) - let urlLink = "%1/%2".arg(appMain.rootStore.getEtherscanTxLink(chainId)).arg(txHash) - let toastType = Constants.ephemeralNotificationType.normal - let icon = "" - if(error) { - toastTitle = qsTr("Failed to set spending cap: %1 in %2 for %3 on %4").arg(approvalAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) - toastSubtitle = "" - urlLink = "" - toastType = Constants.ephemeralNotificationType.danger - icon = "warning" - } - Global.displayToastMessage(toastTitle, toastSubtitle, icon, !error, toastType, urlLink) - } - break - } case Constants.SendType.Swap: { const fromToken = SQUtils.ModelUtils.getByKey(appMain.tokensStore.plainTokensBySymbolModel, "key", fromTokenKey) - const toToken = SQUtils.ModelUtils.getByKey(appMain.tokensStore.plainTokensBySymbolModel, "key", toTokenKey) const fromAccountName = SQUtils.ModelUtils.getByKey(appMain.transactionStore.accounts, "address", fromAddr, "name") const networkName = SQUtils.ModelUtils.getByKey(WalletStores.RootStore.filteredFlatModel, "chainId", chainId, "chainName") - if(!!fromToken && !!toToken && !!fromAccountName && !!networkName) { - const fromSwapAmount = currencyStore.formatCurrencyAmountFromBigInt(fromAmount, fromToken.symbol, fromToken.decimals) - const toSwapAmount = currencyStore.formatCurrencyAmountFromBigInt(toAmount, toToken.symbol, toToken.decimals) - let toastTitle = qsTr("Swapping %1 to %2 in %3 using %4 on %5").arg(fromSwapAmount).arg(toSwapAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) - let toastSubtitle = qsTr("View on %1").arg(networkName) - let urlLink = "%1/%2".arg(appMain.rootStore.getEtherscanTxLink(chainId)).arg(txHash) - let toastType = Constants.ephemeralNotificationType.normal - let icon = "" - if(error) { - toastTitle = qsTr("Failed to swap %1 to %2 in %3 using %4 on %5").arg(fromSwapAmount).arg(toSwapAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) - toastSubtitle = "" - urlLink = "" - toastType = Constants.ephemeralNotificationType.danger - icon = "warning" + let toastTitle = "" + let toastSubtitle = qsTr("View on %1").arg(networkName) + let urlLink = "%1/%2".arg(appMain.rootStore.getEtherscanTxLink(chainId)).arg(txHash) + let toastType = Constants.ephemeralNotificationType.normal + let icon = "" + if (approvalTx) { + if(!!fromToken && !!fromAccountName && !!networkName) { + const approvalAmount = currencyStore.formatCurrencyAmountFromBigInt(fromAmount, fromToken.symbol, fromToken.decimals) + toastTitle = qsTr("Setting spending cap: %1 in %2 for %3 on %4").arg(approvalAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) + if(error) { + toastTitle = qsTr("Failed to set spending cap: %1 in %2 for %3 on %4").arg(approvalAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) + toastSubtitle = "" + urlLink = "" + toastType = Constants.ephemeralNotificationType.danger + icon = "warning" + } } - Global.displayToastMessage(toastTitle, toastSubtitle, icon, !error, toastType, urlLink) } + else { + const toToken = SQUtils.ModelUtils.getByKey(appMain.tokensStore.plainTokensBySymbolModel, "key", toTokenKey) + if(!!fromToken && !!toToken && !!fromAccountName && !!networkName) { + const fromSwapAmount = currencyStore.formatCurrencyAmountFromBigInt(fromAmount, fromToken.symbol, fromToken.decimals) + const toSwapAmount = currencyStore.formatCurrencyAmountFromBigInt(toAmount, toToken.symbol, toToken.decimals) + toastTitle = qsTr("Swapping %1 to %2 in %3 using %4 on %5").arg(fromSwapAmount).arg(toSwapAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) + if(error) { + toastTitle = qsTr("Failed to swap %1 to %2 in %3 using %4 on %5").arg(fromSwapAmount).arg(toSwapAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) + toastSubtitle = "" + urlLink = "" + toastType = Constants.ephemeralNotificationType.danger + icon = "warning" + } + } + } + Global.displayToastMessage(toastTitle, toastSubtitle, icon, !error, toastType, urlLink) break } default: { @@ -302,56 +296,6 @@ Item { } } - function onShowToastTransactionSendingComplete(chainId: int, txHash: string, data: string, success: bool, - txType: int, fromAddr: string, toAddr: string, fromTokenKey: string, - fromAmount: string, toTokenKey: string, toAmount: string) { - switch(txType) { - case Constants.SendType.Approve: { - const fromToken = SQUtils.ModelUtils.getByKey(appMain.tokensStore.plainTokensBySymbolModel, "key", fromTokenKey) - const fromAccountName = SQUtils.ModelUtils.getByKey(appMain.transactionStore.accounts, "address", fromAddr, "name") - const networkName = SQUtils.ModelUtils.getByKey(WalletStores.RootStore.filteredFlatModel, "chainId", chainId, "chainName") - if(!!fromToken && !!fromAccountName && !!networkName) { - const approvalAmount = currencyStore.formatCurrencyAmountFromBigInt(fromAmount, fromToken.symbol, fromToken.decimals) - let toastTitle = qsTr("Spending cap set: %1 in %2 for %3 on %4").arg(approvalAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) - const toastSubtitle = qsTr("View on %1").arg(networkName) - const urlLink = "%1/%2".arg(appMain.rootStore.getEtherscanTxLink(chainId)).arg(txHash) - let toastType = Constants.ephemeralNotificationType.success - let icon = "checkmark-circle" - if(!success) { - toastTitle = qsTr("Failed to set spending cap: %1 in %2 for %3 on %4").arg(approvalAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) - toastType = Constants.ephemeralNotificationType.danger - icon = "warning" - } - Global.displayToastMessage(toastTitle, toastSubtitle, icon, false, toastType, urlLink) - } - break - } - case Constants.SendType.Swap: { - const fromToken = SQUtils.ModelUtils.getByKey(appMain.tokensStore.plainTokensBySymbolModel, "key", fromTokenKey) - const toToken = SQUtils.ModelUtils.getByKey(appMain.tokensStore.plainTokensBySymbolModel, "key", toTokenKey) - const fromAccountName = SQUtils.ModelUtils.getByKey(appMain.transactionStore.accounts, "address", fromAddr, "name") - const networkName = SQUtils.ModelUtils.getByKey(WalletStores.RootStore.filteredFlatModel, "chainId", chainId, "chainName") - if(!!fromToken && !!toToken && !!fromAccountName && !!networkName) { - const fromSwapAmount = currencyStore.formatCurrencyAmountFromBigInt(fromAmount, fromToken.symbol, fromToken.decimals) - const toSwapAmount = currencyStore.formatCurrencyAmountFromBigInt(toAmount, toToken.symbol, toToken.decimals) - let toastTitle = qsTr("Swapped %1 to %2 in %3 using %4 on %5").arg(fromSwapAmount).arg(toSwapAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) - const toastSubtitle = qsTr("View on %1").arg(networkName) - const urlLink = "%1/%2".arg(appMain.rootStore.getEtherscanTxLink(chainId)).arg(txHash) - let toastType = Constants.ephemeralNotificationType.success - let icon = "checkmark-circle" - if(!success) { - toastTitle = qsTr("Failed to swap %1 to %2 in %3 using %4 on %5").arg(fromSwapAmount).arg(toSwapAmount).arg(fromAccountName).arg(Constants.swap.paraswapHostname).arg(networkName) - toastType = Constants.ephemeralNotificationType.danger - icon = "warning" - } - Global.displayToastMessage(toastTitle, toastSubtitle, icon, false, toastType, urlLink) - } - break - } - default: break - } - } - function onCommunityMemberStatusEphemeralNotification(communityName: string, memberName: string, state: CommunityMembershipRequestState) { var text = "" switch (state) {