-
Notifications
You must be signed in to change notification settings - Fork 212
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
feat(wallet): keplr connection #4430
Conversation
@@ -62,6 +64,13 @@ const AppBar = () => { | |||
</a> | |||
</div> | |||
<div className={classes.appBarSection}> | |||
<div className={classes.connector}> | |||
{useChainBackend ? ( | |||
<ChainConnector></ChainConnector> |
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.
I looked into code-splitting, but it seemed to be more complexity than it's worth for now. Using the async import would only save the app from loading a couple hundred lines of code.
const cosmJS = await suggestChain(networkConfig[0]); | ||
if (!networkChanged) { | ||
setConnectionInProgress(false); | ||
window.cosmJS = cosmJS; |
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.
Setting this on the window so it can be tested through the console, but eventually the cosmJS ref should be stored in the application context.
const offlineSigner = window.getOfflineSigner(chainId); | ||
const accounts = await offlineSigner.getAccounts(); | ||
const cosmJS = new SigningCosmosClient( | ||
'https://node-cosmoshub-3.keplr.app/rest', // TODO: Provide correct rest API |
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.
This is where I get stuck. This endpoint did not work when I tried to do cosmJS.sendTokens(...)
. I'm not sure if the endpoint can be derived from the network config somehow. Maybe we should be using the agoric start local-chain
one (127.0.0.1:26657), but that might not work for all networks.
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.
Sorry, I thought the Keplr docs were up-to-date, but they weren't wrt CosmJS.
You'll have to blend the offlineSigner
into a Stargate chain client call like the ones in https://gist.github.com/webmaster128/8444d42a7eceeda2544c8a59fbd7e1d9#send-your-first-stargate-transaction-from-javascript
The key part is:
const rpcEndpoint = [one of network-config.rpcAddrs];
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, offlineSigner);
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.
So yes, the network config contains some suggested RPC addresses.
f5fb151
to
bee282a
Compare
@@ -67,12 +67,34 @@ export async function suggestChain(networkConfig, caption = undefined) { | |||
await window.keplr.enable(chainId); | |||
|
|||
const offlineSigner = window.getOfflineSigner(chainId); | |||
const cosmJS = await SigningStargateClient.connectWithSigner( |
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.
@michaelfig This worked, thanks! Looks like the docs were missing the fee part but I got something working below. Unit tests incoming
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.
Well done! It's a great start.
ce56090
to
280d46b
Compare
refs: #4421
Adds a "Connect Wallet" button to the appbar which opens a dialog for selecting the network.
Currently it works similar to https://wallet.agoric.app/ where you can choose mainnet/devnet/stage/testnet and add the network and approve the site.
Screenshots:
Initial:
Select Network:
Approval:
Success:
Error: