From e8118dcf05b0ea7069d55b011b1c6d4739f833fb Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Mon, 28 Oct 2024 13:34:21 +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 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 +++++------------- vendor/status-go | 2 +- 6 files changed, 46 insertions(+), 101 deletions(-) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index ba961a1aa2..135ca40ee0 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -459,17 +459,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 fc1b9d19b8..c2209aeb49 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -340,9 +340,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 06a6256b3e..45cf4adc21 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.getEtherscanLink(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.getEtherscanLink(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.getEtherscanLink(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.getEtherscanLink(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.getEtherscanLink(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) { diff --git a/vendor/status-go b/vendor/status-go index 132ea05fc8..bc6754192b 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 132ea05fc8735b91922a440009efdbc7f1b8b8ce +Subproject commit bc6754192bfb82871aee3c6e96ba2eeac49e4ec2