From 83d7c03585f86f98ac7a23dc9e983276ba7f3440 Mon Sep 17 00:00:00 2001 From: Cuteivist Date: Mon, 30 Sep 2024 10:34:28 +0200 Subject: [PATCH] feat(wallet): Add metrics for Send / Bridge / Swap (#16400) --- src/app_service/service/transaction/service.nim | 7 +++++++ .../AppLayouts/Wallet/popups/swap/SwapModal.qml | 15 ++++++++++++++- ui/imports/shared/popups/send/Helpers.qml | 15 +++++++++++++++ ui/imports/shared/popups/send/SendModal.qml | 10 ++++++++++ .../shared/popups/send/views/NetworkSelector.qml | 2 ++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/app_service/service/transaction/service.nim b/src/app_service/service/transaction/service.nim index e2b9757569..60107a7ac3 100644 --- a/src/app_service/service/transaction/service.nim +++ b/src/app_service/service/transaction/service.nim @@ -369,6 +369,8 @@ QtObject: self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(uuid: uuid, error: err, txType: txType, fromAddress: fromAddr, toAddress: toAddr, fromTokenKey: fromTokenKey, fromAmount: fromAmount, toTokenKey: toTokenKey, toAmount: toAmount)) + if txType == SendType.Swap: + singletonInstance.globalEvents.addCentralizedMetricIfEnabled("swap", $(%*{"subEvent": "tx error"})) elif response.result{"hashes"} != nil: for route in routes: for hash in response.result["hashes"][$route.fromNetwork.chainID]: @@ -382,6 +384,9 @@ QtObject: let metadata = TokenTransferMetadata(tokenName: tokenName, isOwnerToken: isOwnerToken) self.watchTransaction(hash.getStr, fromAddr, toAddr, $PendingTransactionTypeDto.WalletTransfer, $(%metadata), route.fromNetwork.chainID, fromTokenKey, fromAmount, toTokenKey, toAmount, txType) + + if txType == SendType.Swap: + singletonInstance.globalEvents.addCentralizedMetricIfEnabled("swap", $(%*{"subEvent": "tx success"})) proc isCollectiblesTransfer(self: Service, sendType: SendType): bool = return sendType == ERC721Transfer or sendType == ERC1155Transfer @@ -446,6 +451,7 @@ QtObject: if sendType == SendType.Swap: mtCommand.toAmount = "0x" & totalAmountToReceive.toHex + singletonInstance.globalEvents.addCentralizedMetricIfEnabled("swap", $(%*{"subEvent": "send tx"})) let response = transactions.createMultiTransaction( mtCommand, @@ -562,6 +568,7 @@ QtObject: mtCommand.fromAmount = "0x" & totalAmountToSend.toHex if sendType == SendType.Swap: mtCommand.toAmount = "0x" & totalAmountToReceive.toHex + singletonInstance.globalEvents.addCentralizedMetricIfEnabled("swap", $(%*{"subEvent": "send tx"})) let response = transactions.createMultiTransaction(mtCommand, paths, password) diff --git a/ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml b/ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml index 9d46100aa1..cab54f7dc7 100644 --- a/ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml +++ b/ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml @@ -68,6 +68,10 @@ StatusDialog { selectedNetworkChainId: root.swapInputParamsForm.selectedNetworkChainId selectedTokenKey: root.swapInputParamsForm.fromTokensKey } + + function addMetricsEvent(subEventName) { + Global.addCentralizedMetricIfEnabled("swap", {subEvent: subEventName}) + } } Connections { @@ -111,10 +115,14 @@ StatusDialog { NumberAnimation { duration: 1000; easing.type: Easing.OutExpo; alwaysRunToEnd: true} } - onOpened: payPanel.forceActiveFocus() + onOpened: { + payPanel.forceActiveFocus() + d.addMetricsEvent("popup opened") + } onClosed: { root.swapAdaptor.stopUpdatesForSuggestedRoute() root.swapAdaptor.reset() + d.addMetricsEvent("popup closed") } header: Item { @@ -431,6 +439,7 @@ StatusDialog { !root.swapAdaptor.approvalPending onClicked: { if (root.swapAdaptor.validSwapProposalReceived) { + d.addMetricsEvent("next button pressed") if (root.swapAdaptor.swapOutputData.approvalNeeded) Global.openPopup(swapApproveModalComponent) else @@ -485,7 +494,9 @@ StatusDialog { serviceProviderContractAddress: root.swapAdaptor.swapOutputData.approvalContractAddress serviceProviderHostname: Constants.swap.paraswapHostname + onRejected: d.addMetricsEvent("rejected approve") onAccepted: { + d.addMetricsEvent("send approve tx") root.swapAdaptor.sendApproveTx() } } @@ -535,7 +546,9 @@ StatusDialog { serviceProviderURL: Constants.swap.paraswapUrl // TODO https://github.com/status-im/status-desktop/issues/15329 serviceProviderTandCUrl: Constants.swap.paraswapTermsAndConditionUrl // TODO https://github.com/status-im/status-desktop/issues/15329 + onRejected: d.addMetricsEvent("rejected sign") onAccepted: { + d.addMetricsEvent("send swap tx") root.swapAdaptor.sendSwapTx() root.close() } diff --git a/ui/imports/shared/popups/send/Helpers.qml b/ui/imports/shared/popups/send/Helpers.qml index 33c6c13c19..f1af28b8cf 100644 --- a/ui/imports/shared/popups/send/Helpers.qml +++ b/ui/imports/shared/popups/send/Helpers.qml @@ -23,6 +23,21 @@ QtObject { RecentsAddress // Recent addresses object got from transactions history } + function recipientAddressObjectTypeToString(type) { + switch (type) { + case RecipientAddressObjectType.Address: + return "Address" + case RecipientAddressObjectType.Account: + return "Account" + case RecipientAddressObjectType.SavedAddress: + return "SavedAddress" + case RecipientAddressObjectType.RecentsAddress: + return "RecentsAddress" + default: + return "Unknown" + } + } + function createSendModalRequirements() { return { preSelectedAccount: null, diff --git a/ui/imports/shared/popups/send/SendModal.qml b/ui/imports/shared/popups/send/SendModal.qml index dd3a071387..63da2ec428 100644 --- a/ui/imports/shared/popups/send/SendModal.qml +++ b/ui/imports/shared/popups/send/SendModal.qml @@ -173,6 +173,10 @@ StatusDialog { recalculateRoutesAndFees() } + + function addMetricsEvent(subEventName) { + Global.addCentralizedMetricIfEnabled(d.isBridgeTx ? "bridge" : "send", {subEvent: subEventName}) + } } LeftJoinModel { @@ -276,11 +280,14 @@ StatusDialog { .arg(Constants.suggestedRoutesExtraParamsProperties.publicKey) .arg(popup.publicKey) } + + d.addMetricsEvent("popup opened") } onClosed: { popup.store.stopUpdatesForSuggestedRoute() popup.store.resetStoredProperties() + d.addMetricsEvent("popup closed") } header: Item { @@ -751,6 +758,7 @@ StatusDialog { onNextButtonClicked: { d.sendError = "" popup.sendTransaction() + d.addMetricsEvent("next button clicked") } } @@ -788,8 +796,10 @@ StatusDialog { return } d.sendError = error + d.addMetricsEvent("tx send error") return } + d.addMetricsEvent("tx send successful") popup.close() } } diff --git a/ui/imports/shared/popups/send/views/NetworkSelector.qml b/ui/imports/shared/popups/send/views/NetworkSelector.qml index f5910a4bed..692fa729b6 100644 --- a/ui/imports/shared/popups/send/views/NetworkSelector.qml +++ b/ui/imports/shared/popups/send/views/NetworkSelector.qml @@ -39,6 +39,8 @@ Item { property double totalFeesInFiat property bool showCustomRoutingMode + readonly property int currentIndex: tabBar.currentIndex + property string routerError: "" property string routerErrorDetails: ""