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

Support multiple ICS channels #512

Draft
wants to merge 1 commit into
base: is-sprint-25
Choose a base branch
from
Draft
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
26 changes: 22 additions & 4 deletions src/data/queries/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,26 @@ export function useIBCChannels() {
const isCW20 = AccAddress.validate(tokenAddress)

if (isCW20) {
return networks[from]?.icsChannels?.[to]?.channel
const availableChannels = networks[from]?.ics20Channels?.[to]

if (!availableChannels) return

return (
availableChannels.find(
({ tokens }) => !!tokens && tokens.includes(tokenAddress)
) || availableChannels.find(({ tokens }) => !tokens)
)?.channel
}

if (
icsChannel &&
networks[to]?.icsChannels?.[from]?.channel === icsChannel
!!networks[to]?.ics20Channels?.[from]?.find(
({ channel }) => channel === icsChannel
)
) {
return networks[to]?.icsChannels?.[from]?.otherChannel
return networks[to]?.ics20Channels?.[from]?.find(
({ channel }) => channel === icsChannel
)?.otherChannel
}

return networks[from]?.channels?.[to]
Expand All @@ -122,11 +134,17 @@ export function useIBCChannels() {
getICSContract: ({
from,
to,
tokenAddress,
}: {
from: string
to: string
tokenAddress: AccAddress
}): string | undefined => {
return networks[from]?.icsChannels?.[to]?.contract
const channels = networks[from]?.ics20Channels?.[to]
return (
channels?.find(({ tokens }) => tokens?.includes(tokenAddress))
?.contract || channels?.find(({ tokens }) => !tokens)?.contract
)
},
}
}
1 change: 1 addition & 0 deletions src/pages/wallet/SendPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ const SendPage = () => {
contract: getICSContract({
from: chain,
to: destinationChain,
tokenAddress: token.denom,
}),
amount: amount,
msg: Buffer.from(
Expand Down
1 change: 1 addition & 0 deletions src/pages/wallet/TransferPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ const TransferPage = () => {
contract: getICSContract({
from: chain,
to: destinationChain,
tokenAddress: token.denom,
}),
amount: amount,
msg: Buffer.from(
Expand Down
5 changes: 3 additions & 2 deletions src/types/network.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ interface InterchainNetwork {
}
}
channels?: Record<ChainID, IBCChannel>
icsChannels?: Record<
ics20Channels?: Record<
ChainID,
{
contract: AccAddress
channel: IBCChannel
otherChannel: IBCChannel
}
tokens?: AccAddress[]
}[]
>
version?: string
isClassic?: boolean
Expand Down