Skip to content

Commit

Permalink
Support multiple ICS channels
Browse files Browse the repository at this point in the history
  • Loading branch information
alecande11 committed Aug 31, 2023
1 parent ed27d74 commit e7b2eb1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
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

0 comments on commit e7b2eb1

Please sign in to comment.