Skip to content

Commit

Permalink
Fix readNativeDenom
Browse files Browse the repository at this point in the history
  • Loading branch information
alecande11 committed Aug 25, 2023
1 parent 0274c7c commit 8722378
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ const AssetSelector = ({
<ArrowDropDownIcon style={{ fontSize: 20 }} className={styles.caret} />
</button>
{open && (
<AssetList list={assetList} onChange={handleSelection} value={value} />
<AssetList
list={assetList.filter(({ balance }) => !!Number(balance))}
onChange={handleSelection}
value={value}
/>
)}
</div>
)
Expand Down
28 changes: 21 additions & 7 deletions src/data/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export enum TokenType {
IBC = "ibc",
GAMM = "gamm",
FACTORY = "factory",
STRIDE = "stride",
}

export const useNativeDenoms = () => {
Expand All @@ -110,6 +111,11 @@ export const useNativeDenoms = () => {
} else if (denom.startsWith("gamm/")) {
tokenType = TokenType.GAMM
decimals = GAMM_TOKEN_DECIMALS
} else if (
denom.startsWith("stu") &&
(!chainID || chainID === "stride-1")
) {
tokenType = TokenType.STRIDE
}

let fixedDenom = ""
Expand All @@ -122,18 +128,21 @@ export const useNativeDenoms = () => {
fixedDenom = gammTokens.get(denom) ?? readDenom(denom)
break

case TokenType.FACTORY: {
case TokenType.FACTORY:
const factoryParts = denom.split(/[/:]/)
let tokenAddress = ""
if (factoryParts.length >= 2) {
tokenAddress = factoryParts.slice(2).join(" ")
}
fixedDenom = tokenAddress
break
}

case TokenType.STRIDE:
fixedDenom = `st${denom.replace("stu", "").toUpperCase()}`
break

default:
fixedDenom = readDenom(denom)
fixedDenom = readDenom(denom) || denom
}

let factoryIcon
Expand Down Expand Up @@ -204,6 +213,10 @@ export const useNativeDenoms = () => {
}
}

const CHAIN_ICON =
networks[chainID ?? ""]?.icon ||
"https://assets.terra.dev/icon/svg/Terra.svg"

return (
cw20.find(({ token }) => denom === token) ?? {
// default token icon
Expand All @@ -212,11 +225,12 @@ export const useNativeDenoms = () => {
name: fixedDenom,
type: tokenType,
icon:
tokenType === TokenType.IBC
(tokenType === TokenType.IBC
? "https://assets.terra.dev/icon/svg/IBC.svg"
: tokenType === TokenType.FACTORY || TokenType.GAMM
? factoryIcon
: "https://assets.terra.dev/icon/svg/Terra.svg",
: tokenType === TokenType.STRIDE
? "https://station-assets.terra.dev/img/chains/Stride.png"
: (tokenType === TokenType.FACTORY || TokenType.GAMM) &&
factoryIcon) || CHAIN_ICON,
decimals,
isNonWhitelisted: true,
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/wallet/SendPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const SendPage = () => {
() =>
Object.values(
(balances ?? []).reduce((acc, { denom, amount, chain }) => {
const data = readNativeDenom(denom)
const data = readNativeDenom(denom, chain)
// TODO: resolve ibc lun(a|c) balances better at balance fetch
// then update max / balance / messaging to translate lun(a|c)
// for now, check if token is LUNC and network isn't classic, discard if so
Expand Down

0 comments on commit 8722378

Please sign in to comment.