Skip to content

Commit

Permalink
Merge pull request #223 from cosmos/feat/ibc-dropdown
Browse files Browse the repository at this point in the history
Autofill IBC MsgTransfer channel
  • Loading branch information
abefernan authored Jun 19, 2024
2 parents 1201522 + fa1a780 commit 9679f9a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ const MsgTransferForm = ({ senderAddress, setMsgGetter, deleteMsg }: MsgTransfer
setMsgGetter({ isMsgValid, msg });
}, [chain.chainId, senderAddress, setMsgGetter, trimmedInputs]);

useEffect(() => {
if (!denom || !denom.startsWith("ibc/")) {
return;
}

const foundDenom = chain.assets.find((asset) => asset.base === denom);
if (!foundDenom) {
return;
}

const trace = foundDenom.traces?.[0];
if (!trace) {
return;
}

setSourcePort(trace.chain?.path?.split("/")?.[0] || "transfer");
setSourceChannel(trace.chain?.channel_id || "");
}, [chain.assets, denom]);

return (
<StackableContainer lessPadding lessMargin>
<button className="remove" onClick={() => deleteMsg()}>
Expand Down
14 changes: 14 additions & 0 deletions types/chainRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ export interface RegistryAssetDenomUnit {
readonly aliases?: readonly string[];
}

export interface AssetTrace {
readonly type?: "string";
readonly chain?: {
readonly channel_id?: string;
readonly path?: string;
};
readonly counterparty?: {
readonly chain_name?: string;
readonly base_denom?: string;
readonly channel_id?: string;
};
}

/**
* See https://github.com/cosmos/chain-registry/blob/1e9ecde770951cab90f0853a624411d79af90b83/provenance/assetlist.json#L5-L28
*/
Expand All @@ -94,4 +107,5 @@ export interface RegistryAsset {
readonly svg: string;
};
readonly coingecko_id?: string;
readonly traces?: readonly AssetTrace[];
}

0 comments on commit 9679f9a

Please sign in to comment.