-
Notifications
You must be signed in to change notification settings - Fork 519
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
Conversation
No dependency changes detected. Learn more about Socket for GitHub ↗︎ 👍 No dependency changes detected in pull request |
packages/coinbase/src/index.ts
Outdated
const appChainIds = chains.map( | ||
// @ts-ignore - treating hex strings as numbers as they are expected to be hex numbers | ||
({ id }) => id as number | ||
) |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
- Run the demo project locally by running
yarn dev
from root and visiting localhost:8080 - Connect with Coinbase Wallet
- 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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
packages/coinbase/src/index.ts
Outdated
@@ -62,9 +89,20 @@ function coinbaseWallet({ | |||
|
|||
return coinbaseWalletProvider | |||
} | |||
const provider = createEIP1193Provider(coinbaseWalletProvider, { |
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
Description
Coinbase dependency upgrade to 4.0
This support the new Coinbase smartwallet usage
Checklist
package.json
of the package you have made changes in following semantic versioning and using alpha release taggingyarn check-all
to confirm there are not any associated errorsTests with demo app (SDK)