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

fix: use network-config for ibc transfer rpc #123

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions wallet/src/util/chainInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ export const bech32Config: Bech32Config = {
bech32PrefixConsAddr: 'agoricvalcons',
bech32PrefixConsPub: 'agoricvalconspub',
};

export const fetchChainInfo = async (netconfigURL: string) => {
const response = await fetch(netconfigURL, {
headers: { accept: 'application/json' },
});
const { rpcAddrs, chainName } = await response.json();

return {
rpc: rpcAddrs[Math.floor(Math.random() * rpcAddrs.length)],
chainName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a need for chainName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not currently, I just copied it from https:/Agoric/dapp-inter/blob/main/src/utils/rpc.ts

I thought about using it instead of https:/Agoric/wallet-app/pull/123/files#diff-abea311c6054fa50321c5819ce3d8747cea8edd05cbb6a8e2bc2f5afefb9a515R12, but that const is exported for this check, and I didn't want to refactor that part to make an rpc request yet.

};
};
14 changes: 4 additions & 10 deletions wallet/src/util/ibcTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { OfflineSigner } from '@cosmjs/proto-signing';
import { SigningStargateClient } from '@cosmjs/stargate';
import { AssetInfo } from './ibc-assets';
import { KnownNetworkConfigUrls } from './connections';
import { fetchChainInfo } from './chainInfo';

const secondsUntilTimeout = 300;

const timeoutTimestampSeconds = () =>
Math.round(Date.now() / 1000) + secondsUntilTimeout;

export const agoricChainId = 'agoric-3';
const agoricRpc = 'https://agoric-rpc.polkachu.com:443';
const agoricGas = '500000';

export const sendIbcTokens = async (
Expand Down Expand Up @@ -50,15 +51,8 @@ export const withdrawIbcTokens = async (
) => {
// @ts-expect-error window keys
const { keplr } = window;
const { rpc } = await fetchChainInfo(KnownNetworkConfigUrls.main);
const signer = await keplr.getOfflineSignerOnlyAmino(agoricChainId);

return sendIbcTokens(
assetInfo,
agoricRpc,
signer,
amount,
from,
to,
agoricGas,
);
return sendIbcTokens(assetInfo, rpc, signer, amount, from, to, agoricGas);
};