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

feat(wallet): keplr connection #4430

Merged
merged 4 commits into from
Feb 3, 2022
Merged

feat(wallet): keplr connection #4430

merged 4 commits into from
Feb 3, 2022

Conversation

samsiegart
Copy link
Contributor

@samsiegart samsiegart commented Feb 1, 2022

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:

image

Select Network:

image

Approval:

image

Success:

image

Error:

image

@@ -62,6 +64,13 @@ const AppBar = () => {
</a>
</div>
<div className={classes.appBarSection}>
<div className={classes.connector}>
{useChainBackend ? (
<ChainConnector></ChainConnector>
Copy link
Contributor Author

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;
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Copy link
Member

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);

Copy link
Member

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.

@@ -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(
Copy link
Contributor Author

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

@samsiegart samsiegart requested a review from michaelfig February 2, 2022 03:35
Copy link
Member

@michaelfig michaelfig left a 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.

@samsiegart samsiegart added automerge:rebase Automatically rebase updates, then merge automerge:squash Automatically squash merge labels Feb 3, 2022
@mergify mergify bot merged commit dbc22b7 into master Feb 3, 2022
@mergify mergify bot deleted the wallet-keplr branch February 3, 2022 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge automerge:squash Automatically squash merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants