From de3801da24111f0ad42ed7eb513459edeb64d36e Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 23 Sep 2020 09:09:23 -0700 Subject: [PATCH] introduce additional token instructions (#12381) * introduce additional token instructions * change instruction display names to 'Checked' * display checked instruction amounts and labels nicely --- .../instruction/token/TokenDetailsCard.tsx | 23 ++++-- .../src/components/instruction/token/types.ts | 79 +++++++++++++++++++ 2 files changed, 97 insertions(+), 5 deletions(-) diff --git a/explorer/src/components/instruction/token/TokenDetailsCard.tsx b/explorer/src/components/instruction/token/TokenDetailsCard.tsx index 487f95d16..e96974b84 100644 --- a/explorer/src/components/instruction/token/TokenDetailsCard.tsx +++ b/explorer/src/components/instruction/token/TokenDetailsCard.tsx @@ -10,7 +10,12 @@ import { import { UnknownDetailsCard } from "../UnknownDetailsCard"; import { InstructionCard } from "../InstructionCard"; import { Address } from "components/common/Address"; -import { IX_STRUCTS, TokenInstructionType, IX_TITLES } from "./types"; +import { + IX_STRUCTS, + TokenInstructionType, + IX_TITLES, + TokenAmountUi, +} from "./types"; import { ParsedInfo } from "validators"; import { useTokenAccountInfo, @@ -98,11 +103,14 @@ function TokenInstruction(props: InfoProps) { } }, [fetchAccountInfo, mintAddress]); // eslint-disable-line react-hooks/exhaustive-deps - const decimals = mintInfo?.decimals; - const attributes = []; - + const attributes: JSX.Element[] = []; + let decimals = mintInfo?.decimals; let tokenSymbol = ""; + if ("tokenAmount" in props.info) { + decimals = props.info.tokenAmount.decimals; + } + if (mintAddress) { const tokenDetails = TokenRegistry.get(mintAddress, cluster); @@ -121,9 +129,14 @@ function TokenInstruction(props: InfoProps) { } for (let key in props.info) { - const value = props.info[key]; + let value = props.info[key]; if (value === undefined) continue; + if (key === "tokenAmount") { + key = "amount"; + value = (value as TokenAmountUi).amount; + } + let tag; let labelSuffix = ""; if (value instanceof PublicKey) { diff --git a/explorer/src/components/instruction/token/types.ts b/explorer/src/components/instruction/token/types.ts index 7019410b1..16f9b3bbc 100644 --- a/explorer/src/components/instruction/token/types.ts +++ b/explorer/src/components/instruction/token/types.ts @@ -12,6 +12,13 @@ import { } from "superstruct"; import { Pubkey } from "validators/pubkey"; +export type TokenAmountUi = StructType; +export const TokenAmountUi = object({ + amount: string(), + decimals: number(), + uiAmount: number(), +}); + const InitializeMint = pick({ mint: Pubkey, decimals: number(), @@ -102,6 +109,60 @@ const CloseAccount = object({ signers: optional(array(Pubkey)), }); +const FreezeAccount = object({ + account: Pubkey, + mint: Pubkey, + freezeAuthority: optional(Pubkey), + multisigFreezeAuthority: optional(Pubkey), + signers: optional(array(Pubkey)), +}); + +const ThawAccount = object({ + account: Pubkey, + mint: Pubkey, + freezeAuthority: optional(Pubkey), + multisigFreezeAuthority: optional(Pubkey), + signers: optional(array(Pubkey)), +}); + +const TransferChecked = object({ + source: Pubkey, + mint: Pubkey, + destination: Pubkey, + authority: optional(Pubkey), + multisigAuthority: optional(Pubkey), + signers: optional(array(Pubkey)), + tokenAmount: TokenAmountUi, +}); + +const ApproveChecked = object({ + source: Pubkey, + mint: Pubkey, + delegate: Pubkey, + owner: optional(Pubkey), + multisigOwner: optional(Pubkey), + signers: optional(array(Pubkey)), + tokenAmount: TokenAmountUi, +}); + +const MintToChecked = object({ + account: Pubkey, + mint: Pubkey, + mintAuthority: Pubkey, + multisigMintAuthority: optional(Pubkey), + signers: optional(array(Pubkey)), + tokenAmount: TokenAmountUi, +}); + +const BurnChecked = object({ + account: Pubkey, + mint: Pubkey, + authority: optional(Pubkey), + multisigAuthority: optional(Pubkey), + signers: optional(array(Pubkey)), + tokenAmount: TokenAmountUi, +}); + export type TokenInstructionType = StructType; export const TokenInstructionType = enums([ "initializeMint", @@ -114,6 +175,12 @@ export const TokenInstructionType = enums([ "mintTo", "burn", "closeAccount", + "freezeAccount", + "thawAccount", + "transfer2", + "approve2", + "mintTo2", + "burn2", ]); export const IX_STRUCTS = { @@ -127,6 +194,12 @@ export const IX_STRUCTS = { mintTo: MintTo, burn: Burn, closeAccount: CloseAccount, + freezeAccount: FreezeAccount, + thawAccount: ThawAccount, + transfer2: TransferChecked, + approve2: ApproveChecked, + mintTo2: MintToChecked, + burn2: BurnChecked, }; export const IX_TITLES = { @@ -140,4 +213,10 @@ export const IX_TITLES = { mintTo: "Mint To", burn: "Burn", closeAccount: "Close Account", + freezeAccount: "Freeze Account", + thawAccount: "Thaw Account", + transfer2: "Transfer (Checked)", + approve2: "Approve (Checked)", + mintTo2: "Mint To (Checked)", + burn2: "Burn (Checked)", };