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:
@@ -10,7 +10,12 @@ import {
|
|||||||
import { UnknownDetailsCard } from "../UnknownDetailsCard";
|
import { UnknownDetailsCard } from "../UnknownDetailsCard";
|
||||||
import { InstructionCard } from "../InstructionCard";
|
import { InstructionCard } from "../InstructionCard";
|
||||||
import { Address } from "components/common/Address";
|
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 { ParsedInfo } from "validators";
|
||||||
import {
|
import {
|
||||||
useTokenAccountInfo,
|
useTokenAccountInfo,
|
||||||
@@ -98,11 +103,14 @@ function TokenInstruction(props: InfoProps) {
|
|||||||
}
|
}
|
||||||
}, [fetchAccountInfo, mintAddress]); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [fetchAccountInfo, mintAddress]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const decimals = mintInfo?.decimals;
|
const attributes: JSX.Element[] = [];
|
||||||
const attributes = [];
|
let decimals = mintInfo?.decimals;
|
||||||
|
|
||||||
let tokenSymbol = "";
|
let tokenSymbol = "";
|
||||||
|
|
||||||
|
if ("tokenAmount" in props.info) {
|
||||||
|
decimals = props.info.tokenAmount.decimals;
|
||||||
|
}
|
||||||
|
|
||||||
if (mintAddress) {
|
if (mintAddress) {
|
||||||
const tokenDetails = TokenRegistry.get(mintAddress, cluster);
|
const tokenDetails = TokenRegistry.get(mintAddress, cluster);
|
||||||
|
|
||||||
@@ -121,9 +129,14 @@ function TokenInstruction(props: InfoProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let key in props.info) {
|
for (let key in props.info) {
|
||||||
const value = props.info[key];
|
let value = props.info[key];
|
||||||
if (value === undefined) continue;
|
if (value === undefined) continue;
|
||||||
|
|
||||||
|
if (key === "tokenAmount") {
|
||||||
|
key = "amount";
|
||||||
|
value = (value as TokenAmountUi).amount;
|
||||||
|
}
|
||||||
|
|
||||||
let tag;
|
let tag;
|
||||||
let labelSuffix = "";
|
let labelSuffix = "";
|
||||||
if (value instanceof PublicKey) {
|
if (value instanceof PublicKey) {
|
||||||
|
@@ -12,6 +12,13 @@ import {
|
|||||||
} from "superstruct";
|
} from "superstruct";
|
||||||
import { Pubkey } from "validators/pubkey";
|
import { Pubkey } from "validators/pubkey";
|
||||||
|
|
||||||
|
export type TokenAmountUi = StructType<typeof TokenAmountUi>;
|
||||||
|
export const TokenAmountUi = object({
|
||||||
|
amount: string(),
|
||||||
|
decimals: number(),
|
||||||
|
uiAmount: number(),
|
||||||
|
});
|
||||||
|
|
||||||
const InitializeMint = pick({
|
const InitializeMint = pick({
|
||||||
mint: Pubkey,
|
mint: Pubkey,
|
||||||
decimals: number(),
|
decimals: number(),
|
||||||
@@ -102,6 +109,60 @@ const CloseAccount = object({
|
|||||||
signers: optional(array(Pubkey)),
|
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 type TokenInstructionType = StructType<typeof TokenInstructionType>;
|
||||||
export const TokenInstructionType = enums([
|
export const TokenInstructionType = enums([
|
||||||
"initializeMint",
|
"initializeMint",
|
||||||
@@ -114,6 +175,12 @@ export const TokenInstructionType = enums([
|
|||||||
"mintTo",
|
"mintTo",
|
||||||
"burn",
|
"burn",
|
||||||
"closeAccount",
|
"closeAccount",
|
||||||
|
"freezeAccount",
|
||||||
|
"thawAccount",
|
||||||
|
"transfer2",
|
||||||
|
"approve2",
|
||||||
|
"mintTo2",
|
||||||
|
"burn2",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const IX_STRUCTS = {
|
export const IX_STRUCTS = {
|
||||||
@@ -127,6 +194,12 @@ export const IX_STRUCTS = {
|
|||||||
mintTo: MintTo,
|
mintTo: MintTo,
|
||||||
burn: Burn,
|
burn: Burn,
|
||||||
closeAccount: CloseAccount,
|
closeAccount: CloseAccount,
|
||||||
|
freezeAccount: FreezeAccount,
|
||||||
|
thawAccount: ThawAccount,
|
||||||
|
transfer2: TransferChecked,
|
||||||
|
approve2: ApproveChecked,
|
||||||
|
mintTo2: MintToChecked,
|
||||||
|
burn2: BurnChecked,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const IX_TITLES = {
|
export const IX_TITLES = {
|
||||||
@@ -140,4 +213,10 @@ export const IX_TITLES = {
|
|||||||
mintTo: "Mint To",
|
mintTo: "Mint To",
|
||||||
burn: "Burn",
|
burn: "Burn",
|
||||||
closeAccount: "Close Account",
|
closeAccount: "Close Account",
|
||||||
|
freezeAccount: "Freeze Account",
|
||||||
|
thawAccount: "Thaw Account",
|
||||||
|
transfer2: "Transfer (Checked)",
|
||||||
|
approve2: "Approve (Checked)",
|
||||||
|
mintTo2: "Mint To (Checked)",
|
||||||
|
burn2: "Burn (Checked)",
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user