Skip to content

fix(checkout): Correctly handle adding a new network#2625

Merged
keithbro-imx merged 2 commits into
mainfrom
bug/GFI-389-handle-add-network
May 5, 2025
Merged

fix(checkout): Correctly handle adding a new network#2625
keithbro-imx merged 2 commits into
mainfrom
bug/GFI-389-handle-add-network

Conversation

@keithbro-imx
Copy link
Copy Markdown
Contributor

@keithbro-imx keithbro-imx commented May 5, 2025

Hi👋, please ensure the PR title follows the below standards:

  • PR is titled with conventional commit style naming: type(scope): message. For example: feat(passport): my new feature
  • If you have introduced modification that necessitates immediate adjustments by this SDK's users to their applications, clients, or integrations to avert disruptions to existing features or functionalities, add a ! after the type(scope), for example feat(passport)!: my new breaking feature

Summary

This was a regression in v2 of the SDK, due to the changes in the way Ethers does error handling.

Detail and impact of the change

Added

Changed

Deprecated

Removed

Fixed

Security

Anything else worth calling out?

@keithbro-imx keithbro-imx changed the title GFI-389: Correctly handle adding a new network bug(checkout): Correctly handle adding a new network May 5, 2025
@keithbro-imx keithbro-imx changed the title bug(checkout): Correctly handle adding a new network fix(checkout): Correctly handle adding a new network May 5, 2025
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 5, 2025

View your CI Pipeline Execution ↗ for commit a9481b4.

Command Status Duration Result
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 1m 10s View ↗
nx affected -t build,lint,test ✅ Succeeded 2m 24s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-05 09:58:23 UTC

export async function switchWalletNetwork(
config: CheckoutConfiguration,
provider: JsonRpcProvider | WrappedBrowserProvider,
provider: WrappedBrowserProvider,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never pass in a JsonRpcProvider so we can simplify the contents of this function


if (
!allowedNetworks.networks.some((network) => Number(network.chainId) === chainId)
!allowedNetworks.networks.some((network) => network.chainId === chainId)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chainId is already a number no need to cast it

}

if ('ethereumProvider' in provider && provider.ethereumProvider?.isPassport) {
if (provider.ethereumProvider?.isPassport) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a WrappedBrowserProvider will always have ethereumProvider so no need to check

const currentChainId = await provider.send('eth_chainId', []);
// eslint-disable-next-line radix
const parsedChainId = Number(currentChainId.toString());
const currentChainId = await provider.send('eth_chainId', []) as `0x${string}`;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eth_chainId returns a hexidecimal string so capture that in types

let walletName = '';
if (isWalletConnectProvider(provider)) {
walletName = (provider.provider as any)?.session?.peer?.metadata?.name.toLowerCase();
walletName = (provider.ethereumProvider as any)?.session?.peer?.metadata?.name.toLowerCase();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated bug also introduced in v2

@keithbro-imx keithbro-imx marked this pull request as ready for review May 5, 2025 23:11
@keithbro-imx keithbro-imx requested a review from a team as a code owner May 5, 2025 23:11
@keithbro-imx keithbro-imx added this pull request to the merge queue May 5, 2025
Merged via the queue into main with commit ae356ba May 5, 2025
9 checks passed
@keithbro-imx keithbro-imx deleted the bug/GFI-389-handle-add-network branch May 5, 2025 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants