introduce additional token instructions (#12381)
* introduce additional token instructions * change instruction display names to 'Checked' * display checked instruction amounts and labels nicely
This commit is contained in:
parent
54775ffedf
commit
de3801da24
|
@ -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) {
|
||||
|
|
|
@ -12,6 +12,13 @@ import {
|
|||
} from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
|
||||
export type TokenAmountUi = StructType<typeof TokenAmountUi>;
|
||||
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<typeof TokenInstructionType>;
|
||||
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)",
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue