Skip to content

Commit

Permalink
Minor simplification of logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Karolina Kosiorowska committed Jul 4, 2023
1 parent 546f8c5 commit c83cf0e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
8 changes: 4 additions & 4 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ export default class Main extends BaseService<never> {
amount: bigint
mainCurrencyAmount?: number
balance: number
exists?: boolean
shouldDisplay?: boolean
}> {
const { network } = addressOnNetwork

Expand Down Expand Up @@ -1895,17 +1895,17 @@ export default class Main extends BaseService<never> {
const mainCurrencyAmount = convertedAssetAmount
? assetAmountToDesiredDecimals(convertedAssetAmount, 2)
: undefined
// Existing assets are those that are verified by default or by the user.
// The asset should be displayed in the regular list when that is verified by default or by the user.
// This check allows the user to add an asset that is on the unverified list.
const exists = cachedAsset ? isVerifiedAsset(cachedAsset) : false
const shouldDisplay = cachedAsset && isVerifiedAsset(cachedAsset)

return {
...assetData,
balance: Number.parseFloat(
utils.formatUnits(assetData.amount, assetData.asset.decimals)
),
mainCurrencyAmount,
exists,
shouldDisplay,
}
}

Expand Down
22 changes: 7 additions & 15 deletions background/redux-slices/selectors/0xSwapSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,13 @@ export const selectSwapBuyAssets = createSelector(
): asset is SwappableAsset & {
recentPrices: SingleAssetState["recentPrices"]
} => {
if (!isVerifiedAsset(asset)) {
return false
}
if (isSmartContractFungibleAsset(asset)) {
if (sameNetwork(asset.homeNetwork, currentNetwork)) {
return true
}
}
if (
// Explicitly add a network's base asset.
isBuiltInNetworkBaseAsset(asset, currentNetwork)
) {
return true
}
return false
return (
isVerifiedAsset(asset) &&
// Only list assets for the current network.
(isBuiltInNetworkBaseAsset(asset, currentNetwork) ||
(isSmartContractFungibleAsset(asset) &&
sameNetwork(asset.homeNetwork, currentNetwork)))
)
}
)
}
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/Settings/SettingsAddCustomAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,15 @@ export default function SettingsAddCustomAsset(): ReactElement {
!assetData ||
isLoadingAssetDetails ||
hasAssetDetailLoadError ||
assetData.exists ||
assetData.shouldDisplay ||
isImportingToken
}
isLoading={isLoadingAssetDetails || isImportingToken}
>
{t("submit")}
</SharedButton>
</div>
{assetData?.exists ? (
{assetData?.shouldDisplay ? (
<div className="alert">
<SharedIcon
color="var(--success)"
Expand Down

0 comments on commit c83cf0e

Please sign in to comment.