Skip to content

Commit

Permalink
check for scams on erc721
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkNerdi committed Apr 30, 2024
1 parent 66c07d0 commit 198e2a5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { DEFAULT_NFT_NAME, MimeType } from '@core/nfts'
import { IErc721Nft, IPersistedErc721Nft } from '../interfaces'
import { isScamErc721Nft } from './isScamErc721Nft'

export function buildNftFromPersistedErc721Nft(nft: IPersistedErc721Nft, accountAddress: string): IErc721Nft {
const isSpendable = nft.ownerAddress === accountAddress
const isScam = nft?.isScam ?? (nft.metadata ? isScamErc721Nft(nft.metadata) : false)

return {
...nft,
isSpendable,
isScam,
name: nft.metadata?.name ?? nft.contractMetadata.name ?? DEFAULT_NFT_NAME,
description: nft.metadata?.description,
type: MimeType.ImagePng,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/lib/core/nfts/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './getSpendableStatusFromUnspentNftOutput'
export * from './isIrc27Nft'
export * from './isNftLocked'
export * from './isNftOwnedByAnyAccount'
export * from './isScamErc721Nft'
export * from './isScamIrc27Nft'
export * from './isValidNftUri'
export * from './isVisibleCollection'
Expand Down
28 changes: 28 additions & 0 deletions packages/shared/src/lib/core/nfts/utils/isScamErc721Nft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { appParameters } from '@core/app/stores'
import { IErc721TokenMetadata } from '../interfaces'
import { get } from 'svelte/store'

export function isScamErc721Nft(metadata: IErc721TokenMetadata): boolean {
const { urls, keywords } = get(appParameters).denylists

if (
urls.some(
(url) =>
metadata?.name?.toLocaleLowerCase()?.includes(url) ||
metadata?.description?.toLocaleLowerCase()?.includes(url) ||
metadata?.image?.toLocaleLowerCase()?.includes(url)
)
) {
return true
} else if (
keywords.some(
(phrase) =>
metadata?.name?.toLocaleLowerCase()?.includes(phrase) ||
metadata?.description?.toLocaleLowerCase()?.includes(phrase)
)
) {
return true
} else {
return false
}
}

0 comments on commit 198e2a5

Please sign in to comment.