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

fix: always show native assets regardless of denoms #348

Merged
merged 15 commits into from
May 11, 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
1 change: 1 addition & 0 deletions src/pages/wallet/AssetList.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
background-color: var(--card-bg-muted);
padding-inline: 10px;
grid-area: list;

display: grid;
grid-template-areas: "title" "list";
grid-template-rows: min-content auto;
Expand Down
26 changes: 3 additions & 23 deletions src/pages/wallet/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import Asset from "./Asset"
import styles from "./AssetList.module.scss"
import { useTokenFilters } from "utils/localStorage"
import { toInput } from "txs/utils"
import {
useCustomTokensCW20,
useCustomTokensNative,
} from "data/settings/CustomTokens"
import { isNativeToken } from "utils/chain"

const AssetList = () => {
const { t } = useTranslation()
Expand All @@ -23,16 +20,6 @@ const AssetList = () => {
const coins = useBankBalance()
const { data: prices } = useExchangeRates()
const readNativeDenom = useNativeDenoms()
const native = useCustomTokensNative()
const cw20 = useCustomTokensCW20()
const alwaysVisibleDenoms = useMemo(
() =>
new Set([
...cw20.list.map((a) => a.token),
...native.list.map((a) => a.denom),
]),
[cw20.list, native.list]
)

const list = useMemo(
() =>
Expand Down Expand Up @@ -68,22 +55,15 @@ const AssetList = () => {
(a) => (hideNoWhitelist ? !a.symbol.endsWith("...") : true) // TODO: update and implement whitelist check
)
.filter((a) => {
if (!hideLowBal || a.price === 0 || alwaysVisibleDenoms.has(a.denom))
if (!(hideLowBal && a.price === 0) || isNativeToken(a.denom))
return true
return a.price * toInput(a.balance) >= 1
})
.sort(
(a, b) =>
b.price * parseInt(b.balance) - a.price * parseInt(a.balance)
),
[
coins,
readNativeDenom,
prices,
hideNoWhitelist,
hideLowBal,
alwaysVisibleDenoms,
]
[coins, readNativeDenom, prices, hideNoWhitelist, hideLowBal]
)

const render = () => {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useNativeDenoms } from "data/token"
import { useExchangeRates } from "data/queries/coingecko"
import { useDisplayChains } from "./localStorage/hooks"
import { useNetworkName } from "data/wallet"
import { AccAddress } from "@terra-money/feather.js"

type ChainId = string
type ChainPrefix = string
Expand Down Expand Up @@ -55,3 +56,8 @@ export const useSortedDisplayChains = () => {

export const useTerraChainName = () =>
useNetworkName() === "mainnet" ? "phoenix-1" : "pisco-1"

export const isNativeToken = (denom: string) =>
!denom.startsWith("ibc/") &&
!denom.startsWith("factory/") &&
!AccAddress.validate(denom)