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: check UTL verifiedness of tokens before showing spoof warning banner #288

Merged
merged 1 commit into from
Aug 24, 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
12 changes: 7 additions & 5 deletions app/address/[address]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -292,7 +294,7 @@ function DetailsSections({
pubkey: PublicKey;
tab?: string;
info?: CacheEntry<Account>;
tokenInfo?: FullLegacyTokenInfo;
tokenInfo?: FullTokenInfo;
isTokenInfoLoading: boolean;
}) {
const fetchAccount = useFetchAccountInfo();
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 13 additions & 4 deletions app/utils/token-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export type FullLegacyTokenInfo = {
readonly tags?: string[],
readonly extensions?: TokenExtensions,
}
export type FullTokenInfo = FullLegacyTokenInfo & {
readonly verified: boolean;
};

type FullLegacyTokenInfoList = {
tokens: FullLegacyTokenInfo[]
Expand Down Expand Up @@ -97,7 +100,7 @@ export async function getFullTokenInfo(
address: PublicKey,
cluster: Cluster,
connectionString: string
): Promise<FullLegacyTokenInfo | undefined> {
): Promise<FullTokenInfo | undefined> {
const chainId = getChainId(cluster);
if (!chainId) return undefined;

Expand All @@ -107,7 +110,12 @@ export async function getFullTokenInfo(
]);

if (!sdkTokenInfo) {
return legacyCdnTokenInfo;
return legacyCdnTokenInfo
? {
...legacyCdnTokenInfo,
verified: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mcintyre94, I'm presuming that everything that comes from the legacy token list CDN can be presumed to be ‘verified.’ Does that make sense?

}
: undefined;
}

// Merge the fields, prioritising the sdk ones which are more up to date
Expand All @@ -123,8 +131,9 @@ export async function getFullTokenInfo(
logoURI: sdkTokenInfo.logoURI ?? undefined,
name: sdkTokenInfo.name,
symbol: sdkTokenInfo.symbol,
tags
}
tags,
verified: !!(legacyCdnTokenInfo || sdkTokenInfo.verified),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This means ‘if you're on the legacy token list, or the UTL registry said you're verified, you're verified.’ Is that sound, @mcintyre94?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I missed this PR before! I think this is reasonable, but if the UTL registry contains the same token as unverified maybe that should take precedence?

So:

  • Not on the legacy token list at all, UTL verified determines it
  • On legacy token list and UTL, UTL verified determines it
  • On legacy token list and not UTL, verified

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So, if I understand correctly, that basically implies that we should do this?

Suggested change
verified: !!(legacyCdnTokenInfo || sdkTokenInfo.verified),
verified: sdkTokenInfo.verified ?? false,
  1. By this line, we know that sdkTokenInfo is non-null.
  2. The ‘not on UTL but on legacy list’ case is handled above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Building a Vercel preview for that now: #289.

};
}

export async function getTokenInfos(
Expand Down