Skip to content

Commit

Permalink
[SDK] Feature: Include chain ID in analytics events (#5343)
Browse files Browse the repository at this point in the history
CNCT-2138

<!-- start pr-codex -->

---

## 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}`

<!-- end pr-codex -->
  • Loading branch information
gregfromstl committed Nov 8, 2024
1 parent 46d0b4b commit 5de5418
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-pots-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Adds chain ID to tracked analytics
4 changes: 3 additions & 1 deletion packages/thirdweb/src/analytics/track/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,6 +21,7 @@ export async function trackConnect(args: {
action: "connect",
walletType,
walletAddress,
chainId,
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 282 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx#L282

Added line #L282 was not covered by tests
dstChainId: props.quote.swapDetails.toToken.chainId,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function TransactionModal(props: ModalProps) {
client: props.client,
walletAddress: account.address,
walletType: wallet.id,
dstChainId: props.tx.chain.id,

Check warning on line 45 in packages/thirdweb/src/react/web/ui/TransactionButton/TransactionModal.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/TransactionButton/TransactionModal.tsx#L45

Added line #L45 was not covered by tests
event: "open_pay_transaction_modal",
});
},
Expand Down
2 changes: 2 additions & 0 deletions packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function coinbaseWalletSDK(args: {
client: options.client,
walletType: COINBASE,
walletAddress: account.address,
chainId: chain.id,

Check warning on line 84 in packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts#L84

Added line #L84 was not covered by tests
});
// return account
return account;
Expand All @@ -100,6 +101,7 @@ export function coinbaseWalletSDK(args: {
client: options.client,
walletType: COINBASE,
walletAddress: account.address,
chainId: chain.id,

Check warning on line 104 in packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts#L104

Added line #L104 was not covered by tests
});
// return account
return account;
Expand Down
4 changes: 4 additions & 0 deletions packages/thirdweb/src/wallets/create-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export function createWallet<const ID extends WalletId>(
client: options.client,
walletType: id,
walletAddress: account.address,
chainId: chain.id,

Check warning on line 253 in packages/thirdweb/src/wallets/create-wallet.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/create-wallet.ts#L253

Added line #L253 was not covered by tests
});
// return account
return account;
Expand Down Expand Up @@ -281,6 +282,7 @@ export function createWallet<const ID extends WalletId>(
client: options.client,
walletType: id,
walletAddress: account.address,
chainId: chain.id,

Check warning on line 285 in packages/thirdweb/src/wallets/create-wallet.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/create-wallet.ts#L285

Added line #L285 was not covered by tests
});
// return account
return account;
Expand Down Expand Up @@ -314,6 +316,7 @@ export function createWallet<const ID extends WalletId>(
client: wcOptions.client,
walletType: id,
walletAddress: account.address,
chainId: chain.id,

Check warning on line 319 in packages/thirdweb/src/wallets/create-wallet.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/create-wallet.ts#L319

Added line #L319 was not covered by tests
});
return account;
}
Expand Down Expand Up @@ -359,6 +362,7 @@ export function createWallet<const ID extends WalletId>(
client: options.client,
walletType: id,
walletAddress: account.address,
chainId: chain.id,

Check warning on line 365 in packages/thirdweb/src/wallets/create-wallet.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/create-wallet.ts#L365

Added line #L365 was not covered by tests
});
// return account
return account;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function createInAppWallet(args: {
ecosystem,
walletType: walletId,
walletAddress: account.address,
chainId: chain.id,

Check warning on line 109 in packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts#L109

Added line #L109 was not covered by tests
});
// return only the account
return account;
Expand Down Expand Up @@ -153,6 +154,7 @@ export function createInAppWallet(args: {
ecosystem,
walletType: walletId,
walletAddress: account.address,
chainId: chain.id,

Check warning on line 157 in packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts#L157

Added line #L157 was not covered by tests
});
// return only the account
return account;
Expand Down
2 changes: 2 additions & 0 deletions packages/thirdweb/src/wallets/native/create-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export function createWallet<const ID extends WalletId>(
client: options.client,
walletType: id,
walletAddress: account.address,
chainId: chain.id,
});
// return account
return account;
Expand Down Expand Up @@ -202,6 +203,7 @@ export function createWallet<const ID extends WalletId>(
client: wcOptions.client,
walletType: id,
walletAddress: account.address,
chainId: chain.id,
});
return account;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/thirdweb/src/wallets/smart/smart-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export function smartWallet(
client: options.client,
walletType: "smart",
walletAddress: account.address,
chainId: chain.id,

Check warning on line 170 in packages/thirdweb/src/wallets/smart/smart-wallet.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/smart/smart-wallet.ts#L170

Added line #L170 was not covered by tests
});
// return account
return account;
Expand All @@ -187,6 +188,7 @@ export function smartWallet(
client: options.client,
walletType: "smart",
walletAddress: account.address,
chainId: chain.id,
});
// return account
emitter.emit("accountChanged", account);
Expand Down

0 comments on commit 5de5418

Please sign in to comment.