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

Make custom tokens visible in the asset list even if they have a balance of zero #3313

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions background/redux-slices/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
AssetMainCurrencyAmount,
AssetDecimalAmount,
isBuiltInNetworkBaseAsset,
isCustomAsset,
} from "./utils/asset-utils"
import { DomainName, HexString, URI } from "../types"
import { normalizeEVMAddress, sameEVMAddress } from "../lib/utils"
Expand Down Expand Up @@ -310,10 +311,15 @@ const accountSlice = createSlice({
if (existingAccountData !== "loading") {
if (
updatedAccountBalance.assetAmount.amount === 0n &&
existingAccountData.balances[updatedAssetSymbol] === undefined &&
!isBuiltInNetworkBaseAsset(asset, network) // add base asset even if balance is 0
existingAccountData.balances[updatedAssetSymbol] === undefined
) {
return
// add base asset even if balance is 0 or is a custom asset
if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine these two ifs?

!isCustomAsset(asset) &&
!isBuiltInNetworkBaseAsset(asset, network)
) {
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
return
}
}
existingAccountData.balances[updatedAssetSymbol] =
updatedAccountBalance
Expand Down
9 changes: 5 additions & 4 deletions background/redux-slices/selectors/accountsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
enrichAssetAmountWithMainCurrencyValues,
formatCurrencyAmount,
heuristicDesiredDecimalsForUnitPrice,
isCustomAsset,
isNetworkBaseAsset,
} from "../utils/asset-utils"
import {
Expand Down Expand Up @@ -163,17 +164,17 @@ const computeCombinedAssetAmountsData = (
? true
: assetAmount.mainCurrencyAmount > userValueDustThreshold
const isPresent = assetAmount.decimalAmount > 0
const isTrusted =
!!(assetAmount.asset?.metadata?.tokenLists?.length ?? 0) ||
assetAmount.asset.metadata?.trusted
const isCustom = isCustomAsset(assetAmount.asset)
const isTrusted = assetAmount.asset.metadata?.trusted

// Hide dust, untrusted assets and missing amounts.
if (
isForciblyDisplayed ||
(isCustom && !hideDust) ||
(isTrusted && (hideDust ? isNotDust && isPresent : isPresent))
) {
acc.combinedAssetAmounts.push(assetAmount)
} else if (isPresent) {
} else if (!isCustom ? isPresent : true) {
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
acc.hiddenAssetAmounts.push(assetAmount)
}
return acc
Expand Down
7 changes: 7 additions & 0 deletions background/redux-slices/utils/asset-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,10 @@ export function isUntrustedAsset(asset: AnyAsset | undefined): boolean {
}
return false
}

export function isCustomAsset(asset: AnyAsset | undefined): boolean {
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
if (asset) {
return (asset?.metadata?.tokenLists?.length ?? 0) < 1
}
return false
}