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

Improve LUNC/LUNA IBC detection #456

Merged
merged 5 commits into from
Jul 6, 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
59 changes: 28 additions & 31 deletions src/data/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const WithTokenItem = ({ token, chainID, children }: Props) => {
export const getIcon = (path: string) => `${ASSETS}/icon/svg/${path}`

export const useNativeDenoms = () => {
const { whitelist, ibcDenoms, legacyWhitelist } = useWhitelist()
const { whitelist, ibcDenoms } = useWhitelist()
const { list: cw20 } = useCustomTokensCW20()
const networkName = useNetworkName()
const networks = useNetwork()
Expand Down Expand Up @@ -158,46 +158,43 @@ export const useNativeDenoms = () => {

// ibc token
let ibcToken = ibcDenoms[networkName]?.[denom]?.token
const chainOrigin = ibcDenoms[networkName]?.[denom]?.chainID
const ibcLunc =
chainOrigin &&
["phoenix-1:uluna", "pisco-1:uluna"].includes(ibcToken) &&
networkName !== "classic" &&
ibcDenoms["classic"]?.[denom]
if (ibcLunc) {
ibcToken = ibcDenoms["classic"]?.[denom]?.token
return {
...whitelist["classic"][ibcToken],
// @ts-expect-error
chains: [ibcDenoms["classic"]?.[denom]?.chainID],
}
} else if (ibcToken && whitelist[networkName][ibcToken]) {

if (
ibcToken &&
whitelist[networkName][ibcToken] &&
(!chainID || ibcDenoms[networkName][denom].chainID === chainID)
) {
return {
...whitelist[networkName][ibcToken],
// @ts-expect-error
chains: [ibcDenoms[networkName][denom].chain],
chains: [ibcDenoms[networkName][denom].chainID],
}
}

// Assuming terra-utils returns "Luna" for LUNC.
if (fixedDenom === "Luna" && networkName !== "classic") {
return {
token: denom,
symbol: "LUNC",
name: "Luna Classic",
icon: "https://assets.terra.money/icon/svg/LUNC.svg",
decimals: 6,
isNonWhitelisted: false,
if (denom === "uluna") {
if (chainID === "columbus-5" || (!chainID && networkName === "classic")) {
return {
token: denom,
symbol: "LUNC",
name: "Luna Classic",
icon: "https://assets.terra.money/icon/svg/LUNC.svg",
decimals: 6,
isNonWhitelisted: false,
}
} else if (chainID === "phoenix-1" || chainID === "pisco-1") {
return {
token: denom,
symbol: "LUNA",
name: "Luna",
icon: "https://assets.terra.money/icon/svg/Luna.svg",
decimals: 6,
isNonWhitelisted: false,
}
}
}

return (
legacyWhitelist[denom] ??
cw20.find(({ token }) => denom === token) ??
// that's needed for axl tokens
Object.values(whitelist[networkName] ?? {}).find(
(t) => t.token === denom
) ?? {
cw20.find(({ token }) => denom === token) ?? {
// default token icon
token: denom,
symbol: fixedDenom,
Expand Down
27 changes: 17 additions & 10 deletions src/pages/wallet/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const AssetList = () => {
const unknownIBCDenomsData = useIBCBaseDenoms(
coins
.map(({ denom, chain }) => ({ denom, chainID: chain }))
.filter(({ denom }) => {
const data = readNativeDenom(denom)
.filter(({ denom, chainID }) => {
const data = readNativeDenom(denom, chainID)
return denom.startsWith("ibc/") && data.symbol.endsWith("...")
})
)
Expand All @@ -52,7 +52,9 @@ const AssetList = () => {
data
? {
...acc,
[data.ibcDenom]: {
[[data.ibcDenom, data.chainIDs[data.chainIDs.length - 1]].join(
"*"
)]: {
baseDenom: data.baseDenom,
chainID: data?.chainIDs[0],
chainIDs: data?.chainIDs,
Expand All @@ -71,13 +73,15 @@ const AssetList = () => {
...Object.values(
coins.reduce((acc, { denom, amount, chain }) => {
const data = readNativeDenom(
unknownIBCDenoms[denom]?.baseDenom ?? denom,
unknownIBCDenoms[denom]?.chainID ?? chain
unknownIBCDenoms[[denom, chain].join("*")]?.baseDenom ?? denom,
unknownIBCDenoms[[denom, chain].join("*")]?.chainIDs[0] ?? chain
)

const key = [
// @ts-expect-error
unknownIBCDenoms[denom]?.chainID ?? data?.chainID ?? chain,
unknownIBCDenoms[[denom, chain].join("*")]?.chainIDs[0] ??
// @ts-expect-error
data?.chainID ??
chain,
data.token,
].join("*")

Expand Down Expand Up @@ -119,7 +123,9 @@ const AssetList = () => {
id: key,
whitelisted: !(
data.isNonWhitelisted ||
unknownIBCDenoms[denom]?.chainIDs.find((c) => !networks[c])
unknownIBCDenoms[[denom, chain].join("*")]?.chainIDs.find(
(c) => !networks[c]
)
),
},
}
Expand Down Expand Up @@ -168,8 +174,9 @@ const AssetList = () => {
<Asset
denom={denom}
{...readNativeDenom(
unknownIBCDenoms[denom]?.baseDenom ?? denom,
unknownIBCDenoms[denom]?.chainID ?? chainID
unknownIBCDenoms[[denom, chainID].join("*")]?.baseDenom ??
denom,
unknownIBCDenoms[[denom, chainID].join("*")]?.chainID ?? chainID
)}
id={id}
{...item}
Expand Down
22 changes: 13 additions & 9 deletions src/pages/wallet/AssetPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const AssetPage = () => {
const unknownIBCDenomsData = useIBCBaseDenoms(
balances
.map(({ denom, chain }) => ({ denom, chainID: chain }))
.filter(({ denom }) => {
const data = readNativeDenom(denom)
.filter(({ denom, chainID }) => {
const data = readNativeDenom(denom, chainID)
return denom.startsWith("ibc/") && data.symbol.endsWith("...")
})
)
Expand All @@ -53,7 +53,9 @@ const AssetPage = () => {
data
? {
...acc,
[data.ibcDenom]: {
[[data.ibcDenom, data.chainIDs[data.chainIDs.length - 1]].join(
"*"
)]: {
baseDenom: data.baseDenom,
chains: data?.chainIDs,
},
Expand All @@ -64,21 +66,21 @@ const AssetPage = () => {

const filteredBalances = balances.filter((b) => {
return (
readNativeDenom(b.denom).token === token &&
readNativeDenom(b.denom).symbol === symbol
readNativeDenom(b.denom, b.chain).token === token &&
readNativeDenom(b.denom, b.chain).symbol === symbol
)
})

const filteredUnsupportedBalances = balances.filter((b) => {
// only return unsupported token if the current chain is found in the ibc path
if (chain) {
return (
unknownIBCDenoms[b.denom]?.baseDenom === token &&
unknownIBCDenoms[b.denom]?.chains?.includes(chain)
unknownIBCDenoms[[b.denom, b.chain].join("*")]?.baseDenom === token &&
unknownIBCDenoms[[b.denom, b.chain].join("*")]?.chains?.[0] === chain
)
}

return unknownIBCDenoms[b.denom]?.baseDenom === token
return unknownIBCDenoms[[b.denom, b.chain].join("*")]?.baseDenom === token
})

const totalBalance = [
Expand Down Expand Up @@ -146,7 +148,9 @@ const AssetPage = () => {
token={token}
denom={b.denom}
decimals={decimals}
path={unknownIBCDenoms[b.denom]?.chains}
path={
unknownIBCDenoms[[b.denom, b.chain].join("*")]?.chains
}
ibcDenom={b.denom}
/>
</div>
Expand Down