Skip to content

Commit

Permalink
feat: suggest chain on wallet connection
Browse files Browse the repository at this point in the history
  • Loading branch information
samsiegart committed Apr 22, 2024
1 parent 81c7a6d commit 41c64da
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/ChainConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Oval } from 'react-loader-spinner';
import {
makeAgoricWalletConnection,
AgoricKeplrConnectionErrors as Errors,
suggestChain,
} from '@agoric/web-components';
import {
brandToInfoAtom,
Expand All @@ -17,6 +18,7 @@ import {
termsIndexAgreedUponAtom,
smartWalletProvisionedAtom,
networkConfigPAtom,
networkConfigAtom,
rpcNodeAtom,
apiNodeAtom,
chainConnectionErrorAtom,
Expand Down Expand Up @@ -59,6 +61,7 @@ const ChainConnection = () => {
const setChainConnectionError = useSetAtom(chainConnectionErrorAtom);
const savedApi = useAtomValue(savedApiNodeAtom);
const savedRpc = useAtomValue(savedRpcNodeAtom);
const networkConfigInfo = useAtomValue(networkConfigAtom);

const areLatestTermsAgreed = termsAgreed === currentTermsIndex;

Expand Down Expand Up @@ -123,6 +126,13 @@ const ChainConnection = () => {
if (!rpc || !api || !chainId) {
throw new Error(Errors.networkConfig);
}

try {
await suggestChain(networkConfigInfo.url);
} catch {
throw new Error(Errors.enableKeplr);
}

setRpcNode(rpc);
setApiNode(api);
const watcher = makeAgoricChainStorageWatcher(api, chainId, e => {
Expand Down Expand Up @@ -161,6 +171,7 @@ const ChainConnection = () => {
}, [
connectionInProgress,
networkConfig,
networkConfigInfo.url,
savedApi,
savedRpc,
setApiNode,
Expand Down

0 comments on commit 41c64da

Please sign in to comment.