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 hiding unverified assets #3708

Merged
merged 5 commits into from
Dec 21, 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 background/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type AssetMetadata = {
* legitimate asset.
*/
verified?: boolean
removed?: boolean
}

/**
Expand Down
11 changes: 11 additions & 0 deletions background/services/indexing/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ export class IndexingDatabase extends Dexie {
).filter((asset) => asset?.metadata?.removed !== true)
}

async getRemovedCustomAssetsByNetworks(
networks: EVMNetwork[],
): Promise<CustomAsset[]> {
return (
await this.customAssets
.where("homeNetwork.chainID")
.anyOf(networks.map((network) => network.chainID))
.toArray()
).filter((asset) => asset?.metadata?.removed === true)
}

async getCustomAssetByAddressAndNetwork(
network: EVMNetwork,
contractAddress: string,
Expand Down
13 changes: 12 additions & 1 deletion background/services/indexing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
isBaselineTrustedAsset,
isUnverifiedAsset,
isTrustedAsset,
isSameAsset,
} from "../../redux-slices/utils/asset-utils"

// Transactions seen within this many blocks of the chain tip will schedule a
Expand Down Expand Up @@ -562,6 +563,10 @@ export default class IndexingService extends BaseService<Events> {
return acc
}, {})

const removedCustomAssets = await this.db.getRemovedCustomAssetsByNetworks([
addressNetwork.network,
])

// look up all assets and set balances
const unfilteredAccountBalances = await Promise.allSettled(
balances.map(async ({ smartContract: { contractAddress }, amount }) => {
Expand Down Expand Up @@ -603,7 +608,13 @@ export default class IndexingService extends BaseService<Events> {

const accountBalances = unfilteredAccountBalances.reduce<AccountBalance[]>(
(acc, current) => {
if (current.status === "fulfilled" && current.value) {
if (
current.status === "fulfilled" &&
current.value &&
!removedCustomAssets.some((asset) =>
isSameAsset(asset, current.value?.assetAmount.asset),
)
) {
return [...acc, current.value]
}
return acc
Expand Down