feat(wallet): Add metrics for Send / Bridge / Swap (#16400)

This commit is contained in:
Cuteivist 2024-09-30 10:34:28 +02:00 committed by GitHub
parent 2e249f9941
commit 83d7c03585
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 1 deletions

View File

@ -369,6 +369,8 @@ QtObject:
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(uuid: uuid, error: err, txType: txType, self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(uuid: uuid, error: err, txType: txType,
fromAddress: fromAddr, toAddress: toAddr, fromTokenKey: fromTokenKey, fromAmount: fromAmount, fromAddress: fromAddr, toAddress: toAddr, fromTokenKey: fromTokenKey, fromAmount: fromAmount,
toTokenKey: toTokenKey, toAmount: toAmount)) toTokenKey: toTokenKey, toAmount: toAmount))
if txType == SendType.Swap:
singletonInstance.globalEvents.addCentralizedMetricIfEnabled("swap", $(%*{"subEvent": "tx error"}))
elif response.result{"hashes"} != nil: elif response.result{"hashes"} != nil:
for route in routes: for route in routes:
for hash in response.result["hashes"][$route.fromNetwork.chainID]: for hash in response.result["hashes"][$route.fromNetwork.chainID]:
@ -383,6 +385,9 @@ QtObject:
self.watchTransaction(hash.getStr, fromAddr, toAddr, $PendingTransactionTypeDto.WalletTransfer, $(%metadata), route.fromNetwork.chainID, self.watchTransaction(hash.getStr, fromAddr, toAddr, $PendingTransactionTypeDto.WalletTransfer, $(%metadata), route.fromNetwork.chainID,
fromTokenKey, fromAmount, toTokenKey, toAmount, txType) fromTokenKey, fromAmount, toTokenKey, toAmount, txType)
if txType == SendType.Swap:
singletonInstance.globalEvents.addCentralizedMetricIfEnabled("swap", $(%*{"subEvent": "tx success"}))
proc isCollectiblesTransfer(self: Service, sendType: SendType): bool = proc isCollectiblesTransfer(self: Service, sendType: SendType): bool =
return sendType == ERC721Transfer or sendType == ERC1155Transfer return sendType == ERC721Transfer or sendType == ERC1155Transfer
@ -446,6 +451,7 @@ QtObject:
if sendType == SendType.Swap: if sendType == SendType.Swap:
mtCommand.toAmount = "0x" & totalAmountToReceive.toHex mtCommand.toAmount = "0x" & totalAmountToReceive.toHex
singletonInstance.globalEvents.addCentralizedMetricIfEnabled("swap", $(%*{"subEvent": "send tx"}))
let response = transactions.createMultiTransaction( let response = transactions.createMultiTransaction(
mtCommand, mtCommand,
@ -562,6 +568,7 @@ QtObject:
mtCommand.fromAmount = "0x" & totalAmountToSend.toHex mtCommand.fromAmount = "0x" & totalAmountToSend.toHex
if sendType == SendType.Swap: if sendType == SendType.Swap:
mtCommand.toAmount = "0x" & totalAmountToReceive.toHex mtCommand.toAmount = "0x" & totalAmountToReceive.toHex
singletonInstance.globalEvents.addCentralizedMetricIfEnabled("swap", $(%*{"subEvent": "send tx"}))
let response = transactions.createMultiTransaction(mtCommand, paths, password) let response = transactions.createMultiTransaction(mtCommand, paths, password)

View File

@ -68,6 +68,10 @@ StatusDialog {
selectedNetworkChainId: root.swapInputParamsForm.selectedNetworkChainId selectedNetworkChainId: root.swapInputParamsForm.selectedNetworkChainId
selectedTokenKey: root.swapInputParamsForm.fromTokensKey selectedTokenKey: root.swapInputParamsForm.fromTokensKey
} }
function addMetricsEvent(subEventName) {
Global.addCentralizedMetricIfEnabled("swap", {subEvent: subEventName})
}
} }
Connections { Connections {
@ -111,10 +115,14 @@ StatusDialog {
NumberAnimation { duration: 1000; easing.type: Easing.OutExpo; alwaysRunToEnd: true} NumberAnimation { duration: 1000; easing.type: Easing.OutExpo; alwaysRunToEnd: true}
} }
onOpened: payPanel.forceActiveFocus() onOpened: {
payPanel.forceActiveFocus()
d.addMetricsEvent("popup opened")
}
onClosed: { onClosed: {
root.swapAdaptor.stopUpdatesForSuggestedRoute() root.swapAdaptor.stopUpdatesForSuggestedRoute()
root.swapAdaptor.reset() root.swapAdaptor.reset()
d.addMetricsEvent("popup closed")
} }
header: Item { header: Item {
@ -431,6 +439,7 @@ StatusDialog {
!root.swapAdaptor.approvalPending !root.swapAdaptor.approvalPending
onClicked: { onClicked: {
if (root.swapAdaptor.validSwapProposalReceived) { if (root.swapAdaptor.validSwapProposalReceived) {
d.addMetricsEvent("next button pressed")
if (root.swapAdaptor.swapOutputData.approvalNeeded) if (root.swapAdaptor.swapOutputData.approvalNeeded)
Global.openPopup(swapApproveModalComponent) Global.openPopup(swapApproveModalComponent)
else else
@ -485,7 +494,9 @@ StatusDialog {
serviceProviderContractAddress: root.swapAdaptor.swapOutputData.approvalContractAddress serviceProviderContractAddress: root.swapAdaptor.swapOutputData.approvalContractAddress
serviceProviderHostname: Constants.swap.paraswapHostname serviceProviderHostname: Constants.swap.paraswapHostname
onRejected: d.addMetricsEvent("rejected approve")
onAccepted: { onAccepted: {
d.addMetricsEvent("send approve tx")
root.swapAdaptor.sendApproveTx() root.swapAdaptor.sendApproveTx()
} }
} }
@ -535,7 +546,9 @@ StatusDialog {
serviceProviderURL: Constants.swap.paraswapUrl // TODO https://github.com/status-im/status-desktop/issues/15329 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 serviceProviderTandCUrl: Constants.swap.paraswapTermsAndConditionUrl // TODO https://github.com/status-im/status-desktop/issues/15329
onRejected: d.addMetricsEvent("rejected sign")
onAccepted: { onAccepted: {
d.addMetricsEvent("send swap tx")
root.swapAdaptor.sendSwapTx() root.swapAdaptor.sendSwapTx()
root.close() root.close()
} }

View File

@ -23,6 +23,21 @@ QtObject {
RecentsAddress // Recent addresses object got from transactions history 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() { function createSendModalRequirements() {
return { return {
preSelectedAccount: null, preSelectedAccount: null,

View File

@ -173,6 +173,10 @@ StatusDialog {
recalculateRoutesAndFees() recalculateRoutesAndFees()
} }
function addMetricsEvent(subEventName) {
Global.addCentralizedMetricIfEnabled(d.isBridgeTx ? "bridge" : "send", {subEvent: subEventName})
}
} }
LeftJoinModel { LeftJoinModel {
@ -276,11 +280,14 @@ StatusDialog {
.arg(Constants.suggestedRoutesExtraParamsProperties.publicKey) .arg(Constants.suggestedRoutesExtraParamsProperties.publicKey)
.arg(popup.publicKey) .arg(popup.publicKey)
} }
d.addMetricsEvent("popup opened")
} }
onClosed: { onClosed: {
popup.store.stopUpdatesForSuggestedRoute() popup.store.stopUpdatesForSuggestedRoute()
popup.store.resetStoredProperties() popup.store.resetStoredProperties()
d.addMetricsEvent("popup closed")
} }
header: Item { header: Item {
@ -751,6 +758,7 @@ StatusDialog {
onNextButtonClicked: { onNextButtonClicked: {
d.sendError = "" d.sendError = ""
popup.sendTransaction() popup.sendTransaction()
d.addMetricsEvent("next button clicked")
} }
} }
@ -788,8 +796,10 @@ StatusDialog {
return return
} }
d.sendError = error d.sendError = error
d.addMetricsEvent("tx send error")
return return
} }
d.addMetricsEvent("tx send successful")
popup.close() popup.close()
} }
} }

View File

@ -39,6 +39,8 @@ Item {
property double totalFeesInFiat property double totalFeesInFiat
property bool showCustomRoutingMode property bool showCustomRoutingMode
readonly property int currentIndex: tabBar.currentIndex
property string routerError: "" property string routerError: ""
property string routerErrorDetails: "" property string routerErrorDetails: ""