Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh - Coinbase dependency upgrade to 4.0 #2204

Merged
merged 10 commits into from
Jun 4, 2024
Merged

Conversation

Adamj1232
Copy link
Member

Description

Coinbase dependency upgrade to 4.0
This support the new Coinbase smartwallet usage

Checklist

  • Increment the version field in package.json of the package you have made changes in following semantic versioning and using alpha release tagging
  • Check the box that allows repo maintainers to update this PR
  • Test locally to make sure this feature/fix works
  • Run yarn check-all to confirm there are not any associated errors
  • Confirm this PR passes Circle CI checks
  • Add or update relevant information in the documentation

Tests with demo app (SDK)

  • send transaction
  • switch chains
  • sign message
  • sign typed message
  • disconnect

Copy link

socket-security bot commented May 28, 2024

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

Comment on lines 53 to 56
const appChainIds = chains.map(
// @ts-ignore - treating hex strings as numbers as they are expected to be hex numbers
({ id }) => id as number
)

Choose a reason for hiding this comment

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

CoinbaseWalletSDK is expecting appChainIds: number[], so this should be something like

const appChainIds = chains.map(({ id }) => convertChainIdToNumber(id))

Copy link
Member Author

Choose a reason for hiding this comment

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

@nateReiners the number type accepts hex numbers as does the coinbase SDK from my testing. Am I incorrect in this finding?
The SDK does work as expected when using hex IDs and W3O expects chainId in hex.

Copy link
Member Author

Choose a reason for hiding this comment

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

Using https://coinbase.github.io/coinbase-wallet-sdk/ on requestAccounts connect returns a hex so its unclear why I would pass in an int number instead of hex number

Copy link
Member Author

Choose a reason for hiding this comment

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

chainChanged also returns a hex number.
({ id }) => id as number the id here is a hex number not a string number

Copy link

@nateReiners nateReiners May 30, 2024

Choose a reason for hiding this comment

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

number type accepts hex numbers

If this were true we wouldn't need any typecasting / ts-ignore here right?

Am I incorrect in this finding

I think so. The CoinbaseWalletSDK uses the first chainId in appChainIds as the default chain for the next request you make after connecting, and a hex string won't be recognized by the Smart Wallet popup as a supported chain. Here's how you can test it:

  1. Run the demo project locally by running yarn dev from root and visiting localhost:8080
  2. Connect with Coinbase Wallet
  3. Click the 'Sign Message' button - this request will be made on whatever chainID is the first chain ID in the appChainIds array, in the case of the demo app it is "0x1".

What you'll see is an unsupported network error in the Smart Wallet Popup.

I opened a PR into your feature branch to save you some time :) #2212

Copy link
Member Author

Choose a reason for hiding this comment

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

@nateReiners can the SDK be updated to handle hex chainIds along with number values? Use of hex chain ID is pretty consistent throughout

Copy link

@nateReiners nateReiners May 30, 2024

Choose a reason for hiding this comment

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

W3O expects chain Ids returned from the sdk to be in hex format so passing in number values causes issues down the line in core and common

Understood. To clarify, you mean the chainId returned from an eth_chainId request should be a hex but is a number instead? Thank you for raising this -- this looks like a bug in our provider which we will address ASAP. In the meantime you'll have to convert the eth_chainId response to hex on your end, but you can expect 4.0.3 with that fix very soon. Are there any other spots you are expecting a hex but we're returning a number, or is it just eth_chainId requests?

Other libs that use @coinbase/wallet-sdk like Viem and Wagmi have chain models where the id is represented as a number, so I get what you're saying about converting to number only to get hex back again, but either way someone will have to do a hex/number conversion so we're going to leave it as appChainIds: number[] for now.

I am not able to catch a connect event to convert the value to for w3o

The provider does emit a 'connect' event with the chainID as a hex upon successful connection LOC.

You should be able to listen for it like this

const provider = sdk.makeWeb3Provider();

provider.on('connect', (info) => {
    setConnect(info);
});

If you can point me to the LOC I can help debug if that listener isn't working.

Copy link
Member Author

@Adamj1232 Adamj1232 May 30, 2024

Choose a reason for hiding this comment

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

Thanks for that @nateReiners !
Thats the only spot I have found issues.

I have a patched the provider for that request in the meantime and tagged you in it in the PR. Apologies for the lack of clarity above but I think we have this at a good spot for an alpha release. All other testing has yielded good results.
Thank you again for your help!

Choose a reason for hiding this comment

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

PR to fix eth_chainId result: coinbase/coinbase-wallet-sdk#1310

Choose a reason for hiding this comment

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

@Adamj1232 Yep agree the branch looks good to me!

@@ -62,9 +89,20 @@ function coinbaseWallet({

return coinbaseWalletProvider
}
const provider = createEIP1193Provider(coinbaseWalletProvider, {
Copy link
Member Author

Choose a reason for hiding this comment

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

@nateReiners patched provider to handle number value returned from eth_chainId - just flagging for visibility 😄

Choose a reason for hiding this comment

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

@Adamj1232 If you want to bump the sdk to 4.0.3 and get rid of this workaround, the version with the eth_chainId fix was just published https://www.npmjs.com/package/@coinbase/wallet-sdk/v/4.0.3

Copy link
Member Author

Choose a reason for hiding this comment

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

@nateReiners when I remove the patch and createEIP1193Provider function and just use the coinbaseWalletProvider I get the following error after bumping to 4.0.3 - I dont get this error on 4.0.2 without the method.
eth_chainId fix is working well!
Screenshot 2024-05-31 at 11 11 24

@Adamj1232 Adamj1232 marked this pull request as ready for review June 4, 2024 17:38
@Adamj1232 Adamj1232 merged commit 5b2b95f into develop Jun 4, 2024
3 checks passed
@Adamj1232 Adamj1232 deleted the enh/cb_4.0_upgrade branch June 4, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants