From 3a455be34387e0faa3135b731ef199319de2335f Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Thu, 24 Aug 2023 22:14:37 +0000 Subject: [PATCH] fix: check UTL verifiedness of tokens before showing spoof warning banner # Summary The UTL provides a `verfied` property. Let's not show a token name/icon spoof warning banner unless that property is `false`. # Test Plan --- app/address/[address]/layout.tsx | 12 +++++++----- app/utils/token-info.ts | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/address/[address]/layout.tsx b/app/address/[address]/layout.tsx index 07acde11..8d8814fe 100644 --- a/app/address/[address]/layout.tsx +++ b/app/address/[address]/layout.tsx @@ -42,7 +42,7 @@ import { redirect, useSelectedLayoutSegment } from 'next/navigation'; import React, { PropsWithChildren } from 'react'; import useSWRImmutable from 'swr/immutable'; -import { FullLegacyTokenInfo, getFullTokenInfo } from '@/app/utils/token-info'; +import { FullTokenInfo, getFullTokenInfo } from '@/app/utils/token-info'; const IDENTICON_WIDTH = 64; @@ -203,7 +203,7 @@ export default function AddressLayout({ children, params }: Props) { ); } -function AccountHeader({ address, account, tokenInfo, isTokenInfoLoading }: { address: string; account?: Account, tokenInfo?: FullLegacyTokenInfo, isTokenInfoLoading: boolean }) { +function AccountHeader({ address, account, tokenInfo, isTokenInfoLoading }: { address: string; account?: Account, tokenInfo?: FullTokenInfo, isTokenInfoLoading: boolean }) { const mintInfo = useMintAccountInfo(address); const parsedData = account?.data.parsed; @@ -230,7 +230,9 @@ function AccountHeader({ address, account, tokenInfo, isTokenInfoLoading }: { ad logoURI: parsedData?.nftData?.json?.image, name: parsedData?.nftData?.json?.name ?? parsedData?.nftData.metadata.data.name, }; - unverified = true; + if (!tokenInfo?.verified) { + unverified = true; + } } else if (tokenInfo) { token = tokenInfo; } @@ -292,7 +294,7 @@ function DetailsSections({ pubkey: PublicKey; tab?: string; info?: CacheEntry; - tokenInfo?: FullLegacyTokenInfo; + tokenInfo?: FullTokenInfo; isTokenInfoLoading: boolean; }) { const fetchAccount = useFetchAccountInfo(); @@ -320,7 +322,7 @@ function DetailsSections({ ); } -function InfoSection({ account, tokenInfo }: { account: Account, tokenInfo?: FullLegacyTokenInfo }) { +function InfoSection({ account, tokenInfo }: { account: Account, tokenInfo?: FullTokenInfo }) { const parsedData = account.data.parsed; const rawData = account.data.raw; diff --git a/app/utils/token-info.ts b/app/utils/token-info.ts index 8b3c2a1d..0908122f 100644 --- a/app/utils/token-info.ts +++ b/app/utils/token-info.ts @@ -31,6 +31,9 @@ export type FullLegacyTokenInfo = { readonly tags?: string[], readonly extensions?: TokenExtensions, } +export type FullTokenInfo = FullLegacyTokenInfo & { + readonly verified: boolean; +}; type FullLegacyTokenInfoList = { tokens: FullLegacyTokenInfo[] @@ -97,7 +100,7 @@ export async function getFullTokenInfo( address: PublicKey, cluster: Cluster, connectionString: string -): Promise { +): Promise { const chainId = getChainId(cluster); if (!chainId) return undefined; @@ -107,7 +110,12 @@ export async function getFullTokenInfo( ]); if (!sdkTokenInfo) { - return legacyCdnTokenInfo; + return legacyCdnTokenInfo + ? { + ...legacyCdnTokenInfo, + verified: true, + } + : undefined; } // Merge the fields, prioritising the sdk ones which are more up to date @@ -123,8 +131,9 @@ export async function getFullTokenInfo( logoURI: sdkTokenInfo.logoURI ?? undefined, name: sdkTokenInfo.name, symbol: sdkTokenInfo.symbol, - tags - } + tags, + verified: !!(legacyCdnTokenInfo || sdkTokenInfo.verified), + }; } export async function getTokenInfos(