Skip to content

Commit

Permalink
add isHardwareWallet to swap analytics event (#1748)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Howard <[email protected]>
Co-authored-by: Daniel Sinclair <[email protected]>
Co-authored-by: brdy <[email protected]>
  • Loading branch information
4 people authored Nov 6, 2024
1 parent 488460d commit d2d48cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/analytics/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 };
Expand Down
9 changes: 7 additions & 2 deletions src/entries/popup/pages/swap/onSwap.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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<typeof type>({
const wallet = getWallet(q.from as Address);

const { errorMessage, nonce } = await executeRap<typeof type>({
rapActionParameters: {
sellAmount: q.sellAmount?.toString(),
buyAmount: q.buyAmount?.toString(),
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit d2d48cb

Please sign in to comment.