From 5de541878cfd4102baa049a0d84ce9911746ac6c Mon Sep 17 00:00:00 2001 From: gregfromstl Date: Fri, 8 Nov 2024 01:44:33 +0000 Subject: [PATCH] [SDK] Feature: Include chain ID in analytics events (#5343) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CNCT-2138 --- ## PR-Codex overview This PR focuses on adding the `chainId` to various components and functions within the `thirdweb` package, enhancing analytics tracking and wallet creation processes by including chain-specific information. ### Detailed summary - Added `chainId` to `TransactionModal.tsx` for analytics. - Updated `ConfirmationScreen.tsx` to use `fromToken.chainId`. - Included `chainId` in wallet creation functions across multiple wallet types. - Modified `trackConnect` to accept `chainId` in its arguments. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .changeset/slimy-pots-camp.md | 5 +++++ packages/thirdweb/src/analytics/track/connect.ts | 4 +++- .../ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx | 2 +- .../src/react/web/ui/TransactionButton/TransactionModal.tsx | 1 + packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts | 2 ++ packages/thirdweb/src/wallets/create-wallet.ts | 4 ++++ .../thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts | 2 ++ packages/thirdweb/src/wallets/native/create-wallet.ts | 2 ++ packages/thirdweb/src/wallets/smart/smart-wallet.ts | 2 ++ 9 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .changeset/slimy-pots-camp.md diff --git a/.changeset/slimy-pots-camp.md b/.changeset/slimy-pots-camp.md new file mode 100644 index 00000000000..e21f13f62e1 --- /dev/null +++ b/.changeset/slimy-pots-camp.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Adds chain ID to tracked analytics diff --git a/packages/thirdweb/src/analytics/track/connect.ts b/packages/thirdweb/src/analytics/track/connect.ts index 089a1e390a3..8ba786d3d69 100644 --- a/packages/thirdweb/src/analytics/track/connect.ts +++ b/packages/thirdweb/src/analytics/track/connect.ts @@ -10,8 +10,9 @@ export async function trackConnect(args: { ecosystem?: Ecosystem; walletType: string; walletAddress: string; + chainId?: number; }) { - const { client, ecosystem, walletType, walletAddress } = args; + const { client, ecosystem, walletType, walletAddress, chainId } = args; return track({ client, ecosystem, @@ -20,6 +21,7 @@ export async function trackConnect(args: { action: "connect", walletType, walletAddress, + chainId, }, }); } diff --git a/packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx b/packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx index 26943ab09f1..ab388368c5e 100644 --- a/packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx +++ b/packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx @@ -279,7 +279,7 @@ export function SwapConfirmationScreen(props: { fromAmount: props.quote.swapDetails.fromAmountWei, toToken: props.quote.swapDetails.toToken.tokenAddress, toAmount: props.quote.swapDetails.toAmountWei, - chainId: props.quote.swapDetails.toToken.chainId, + chainId: props.quote.swapDetails.fromToken.chainId, dstChainId: props.quote.swapDetails.toToken.chainId, }); diff --git a/packages/thirdweb/src/react/web/ui/TransactionButton/TransactionModal.tsx b/packages/thirdweb/src/react/web/ui/TransactionButton/TransactionModal.tsx index 44a8a6a1b23..f8f952c1eb9 100644 --- a/packages/thirdweb/src/react/web/ui/TransactionButton/TransactionModal.tsx +++ b/packages/thirdweb/src/react/web/ui/TransactionButton/TransactionModal.tsx @@ -42,6 +42,7 @@ export function TransactionModal(props: ModalProps) { client: props.client, walletAddress: account.address, walletType: wallet.id, + dstChainId: props.tx.chain.id, event: "open_pay_transaction_modal", }); }, diff --git a/packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts b/packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts index 9b587b4765b..a7ccd26f456 100644 --- a/packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts +++ b/packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts @@ -81,6 +81,7 @@ export function coinbaseWalletSDK(args: { client: options.client, walletType: COINBASE, walletAddress: account.address, + chainId: chain.id, }); // return account return account; @@ -100,6 +101,7 @@ export function coinbaseWalletSDK(args: { client: options.client, walletType: COINBASE, walletAddress: account.address, + chainId: chain.id, }); // return account return account; diff --git a/packages/thirdweb/src/wallets/create-wallet.ts b/packages/thirdweb/src/wallets/create-wallet.ts index bf3e0ac19f4..229eded757e 100644 --- a/packages/thirdweb/src/wallets/create-wallet.ts +++ b/packages/thirdweb/src/wallets/create-wallet.ts @@ -250,6 +250,7 @@ export function createWallet( client: options.client, walletType: id, walletAddress: account.address, + chainId: chain.id, }); // return account return account; @@ -281,6 +282,7 @@ export function createWallet( client: options.client, walletType: id, walletAddress: account.address, + chainId: chain.id, }); // return account return account; @@ -314,6 +316,7 @@ export function createWallet( client: wcOptions.client, walletType: id, walletAddress: account.address, + chainId: chain.id, }); return account; } @@ -359,6 +362,7 @@ export function createWallet( client: options.client, walletType: id, walletAddress: account.address, + chainId: chain.id, }); // return account return account; diff --git a/packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts b/packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts index 6a820bdbf62..0c7f5235f76 100644 --- a/packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts +++ b/packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts @@ -106,6 +106,7 @@ export function createInAppWallet(args: { ecosystem, walletType: walletId, walletAddress: account.address, + chainId: chain.id, }); // return only the account return account; @@ -153,6 +154,7 @@ export function createInAppWallet(args: { ecosystem, walletType: walletId, walletAddress: account.address, + chainId: chain.id, }); // return only the account return account; diff --git a/packages/thirdweb/src/wallets/native/create-wallet.ts b/packages/thirdweb/src/wallets/native/create-wallet.ts index 49129496f34..03050417b10 100644 --- a/packages/thirdweb/src/wallets/native/create-wallet.ts +++ b/packages/thirdweb/src/wallets/native/create-wallet.ts @@ -169,6 +169,7 @@ export function createWallet( client: options.client, walletType: id, walletAddress: account.address, + chainId: chain.id, }); // return account return account; @@ -202,6 +203,7 @@ export function createWallet( client: wcOptions.client, walletType: id, walletAddress: account.address, + chainId: chain.id, }); return account; } diff --git a/packages/thirdweb/src/wallets/smart/smart-wallet.ts b/packages/thirdweb/src/wallets/smart/smart-wallet.ts index df070bb7a6b..d747e3602df 100644 --- a/packages/thirdweb/src/wallets/smart/smart-wallet.ts +++ b/packages/thirdweb/src/wallets/smart/smart-wallet.ts @@ -167,6 +167,7 @@ export function smartWallet( client: options.client, walletType: "smart", walletAddress: account.address, + chainId: chain.id, }); // return account return account; @@ -187,6 +188,7 @@ export function smartWallet( client: options.client, walletType: "smart", walletAddress: account.address, + chainId: chain.id, }); // return account emitter.emit("accountChanged", account);