From d2d48cba6a6c09a9e68998eaaa87c0a32b88d764 Mon Sep 17 00:00:00 2001 From: gregs Date: Wed, 6 Nov 2024 14:52:24 -0300 Subject: [PATCH] add isHardwareWallet to swap analytics event (#1748) Co-authored-by: Christopher Howard Co-authored-by: Daniel Sinclair Co-authored-by: brdy <41711440+BrodyHughes@users.noreply.github.com> --- src/analytics/event.ts | 8 ++++++++ src/entries/popup/pages/swap/onSwap.tsx | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/analytics/event.ts b/src/analytics/event.ts index a14b86f457..07be2def47 100644 --- a/src/analytics/event.ts +++ b/src/analytics/event.ts @@ -299,6 +299,10 @@ export type EventProperties = { * Whether Degen Mode was used for the swap. */ degenMode: boolean; + /** + * Whether a hardware wallet was used for the swap. + */ + hardwareWallet: boolean; }; [event.commandKActionExecuted]: { id?: string; @@ -838,6 +842,10 @@ export type EventProperties = { * Whether Degen Mode was used for the swap. */ degenMode: boolean; + /** + * Whether a hardware wallet was used for the swap. + */ + hardwareWallet: boolean; }; [event.walletViewed]: undefined; [event.toggledDegenMode]: { enabled: boolean }; diff --git a/src/entries/popup/pages/swap/onSwap.tsx b/src/entries/popup/pages/swap/onSwap.tsx index 88e3b955a0..ae75d8e499 100644 --- a/src/entries/popup/pages/swap/onSwap.tsx +++ b/src/entries/popup/pages/swap/onSwap.tsx @@ -1,4 +1,5 @@ import { CrosschainQuote, Quote, QuoteError } from '@rainbow-me/swaps'; +import { Address } from 'viem'; import { analytics } from '~/analytics'; import { event } from '~/analytics/event'; @@ -10,12 +11,13 @@ import { usePopupInstanceStore } from '~/core/state/popupInstances'; import { useSwapAssetsToRefreshStore } from '~/core/state/swapAssetsToRefresh'; import { ParsedSearchAsset } from '~/core/types/assets'; import { ChainId } from '~/core/types/chains'; +import { KeychainType } from '~/core/types/keychainTypes'; import { isSameAssetInDiffChains } from '~/core/utils/assets'; import { triggerAlert } from '~/design-system/components/Alert/Alert'; import playSound from '~/entries/popup/utils/playSound'; import { RainbowError, logger } from '~/logger'; -import * as wallet from '../../handlers/wallet'; +import { executeRap, getWallet } from '../../handlers/wallet'; export const onSwap = async ({ assetToSell, @@ -45,7 +47,9 @@ export const onSwap = async ({ const chainId = isConnectedToHardhat ? ChainId.hardhat : assetToSell.chainId; const isBridge = isSameAssetInDiffChains(assetToSell, assetToBuy); - const { errorMessage, nonce } = await wallet.executeRap({ + const wallet = getWallet(q.from as Address); + + const { errorMessage, nonce } = await executeRap({ rapActionParameters: { sellAmount: q.sellAmount?.toString(), buyAmount: q.buyAmount?.toString(), @@ -94,6 +98,7 @@ export const onSwap = async ({ tradeAmountUSD: q.tradeAmountUSD, crosschain: assetToSell.chainId !== assetToBuy.chainId, degenMode, + hardwareWallet: (await wallet).type === KeychainType.HardwareWalletKeychain, }); playSound('SendSound');