From 5d6f94ef4254e53d4f423dee987768591fd74768 Mon Sep 17 00:00:00 2001 From: Noah Gundotra Date: Wed, 14 Dec 2022 13:27:47 -0500 Subject: [PATCH] Explorer: add alert notice to Project Serum deployments (#28913) * explorer: add scam notice to serum deployments * explorer: prettier fix * explorer: generalize account-incident alerting * explorer: format:fix * explorer: remove github registry link * explorer: remove unused fetch * Change flagged accounts from context to flat record --- explorer/src/pages/AccountDetailsPage.tsx | 10 +-- .../providers/accounts/flagged-accounts.tsx | 85 ++++++++++--------- explorer/src/providers/accounts/index.tsx | 5 +- 3 files changed, 48 insertions(+), 52 deletions(-) diff --git a/explorer/src/pages/AccountDetailsPage.tsx b/explorer/src/pages/AccountDetailsPage.tsx index a37ee60be1..1428124d16 100644 --- a/explorer/src/pages/AccountDetailsPage.tsx +++ b/explorer/src/pages/AccountDetailsPage.tsx @@ -35,7 +35,7 @@ import { useFetchAccountInfo, useMintAccountInfo, } from "providers/accounts"; -import { useFlaggedAccounts } from "providers/accounts/flagged-accounts"; +import FLAGGED_ACCOUNTS_WARNING from "providers/accounts/flagged-accounts"; import isMetaplexNFT from "providers/accounts/utils/isMetaplexNFT"; import { useAnchorProgram } from "providers/anchor"; import { CacheEntry, FetchStatus } from "providers/cache"; @@ -295,7 +295,6 @@ function DetailsSections({ const fetchAccount = useFetchAccountInfo(); const address = pubkey.toBase58(); const location = useLocation(); - const { flaggedAccounts } = useFlaggedAccounts(); if (!info || info.status === FetchStatus.Fetching) { return ; @@ -329,12 +328,7 @@ function DetailsSections({ return ( <> - {flaggedAccounts.has(address) && ( -
- Warning! This account has been flagged by the community as a scam - account. Please be cautious sending SOL to this account. -
- )} + {FLAGGED_ACCOUNTS_WARNING[address] ?? null} ; -type FlaggedMap = Map; -type ProviderProps = { children: React.ReactNode }; +type IncidentId = "ftx-hack-november-2022" | "known-scam"; +type IncidentDescription = React.ReactElement; -const FlaggedContext = React.createContext(new Map()); +const FLAGGED_ACCOUNTS: Record = { + GACpXND1SSfTSQMmqGuFvGwXB3jGEYBDRGNzmLfTYwSP: "known-scam", + "9tAViia54YAaL9gv92hBu8K4QGRBKbytCQ9TYsJ6F6or": "known-scam", + // Serum Swap + "22Y43yTVxuUkoRKdm9thyRhQ3SdgQS7c7kB6UNCiaczD": "ftx-hack-november-2022", + // Serum Dex V3 + "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin": "ftx-hack-november-2022", + // Serum Dex V2 + EUqojwWA2rd19FZrzeBncJsm38Jm1hEhE3zsmX3bRc2o: "ftx-hack-november-2022", + // Serum Dex V1 + BJ3jrUzddfuSrZHXSCxMUUQsjKEyLmuuyZebkcaFp2fg: "ftx-hack-november-2022", +}; -export function FlaggedAccountsProvider({ children }: ProviderProps) { - const [flaggedAccounts, setFlaggedAccounts] = React.useState( - new Map() - ); +const INCIDENTS: Record = { + "known-scam": ( + <> +
+ Warning! This account has been flagged by the community as a scam + account. Please be cautious sending SOL to this account. +
+ + ), + "ftx-hack-november-2022": ( + <> +
+ Warning! This program's upgrade key may have been compromised by the FTX + hack. Please migrate to the community fork:{" "} + + https://github.com/openbook-dex/program + +
+ + ), +} as const; - React.useEffect(() => { - fetch(FLAGGED_REGISTRY) - .then((res) => { - return res.text(); - }) - .then((body: string) => { - const flaggedAccounts = new Map(); - body - .split("\n") - .forEach((account) => flaggedAccounts.set(account, true)); - setFlaggedAccounts(flaggedAccounts); - }); - }, []); - - return ( - - {children} - - ); -} - -export function useFlaggedAccounts() { - const flaggedAccounts = React.useContext(FlaggedContext); - if (!flaggedAccounts) { - throw new Error( - `useFlaggedAccounts must be used within a AccountsProvider` - ); - } - - return { flaggedAccounts }; +const FLAGGED_ACCOUNTS_WARNING: FlaggedMap = {}; +for (const [account, incidentId] of Object.entries(FLAGGED_ACCOUNTS)) { + FLAGGED_ACCOUNTS_WARNING[account] = INCIDENTS[incidentId]; } +export default FLAGGED_ACCOUNTS_WARNING; diff --git a/explorer/src/providers/accounts/index.tsx b/explorer/src/providers/accounts/index.tsx index c616f6e4f8..2dead415a7 100644 --- a/explorer/src/providers/accounts/index.tsx +++ b/explorer/src/providers/accounts/index.tsx @@ -28,7 +28,6 @@ import { NonceAccount } from "validators/accounts/nonce"; import { SysvarAccount } from "validators/accounts/sysvar"; import { ConfigAccount } from "validators/accounts/config"; import { ParsedAddressLookupTableAccount } from "validators/accounts/address-lookup-table"; -import { FlaggedAccountsProvider } from "./flagged-accounts"; import { ProgramDataAccount, ProgramDataAccountInfo, @@ -177,9 +176,7 @@ export function AccountsProvider({ children }: AccountsProviderProps) { - - {children} - + {children}