Fix token instruction parsing (#12065)
This commit is contained in:
parent
879c98efeb
commit
f90e56e6c7
|
@ -104,23 +104,30 @@ function TokenInstruction(props: InfoProps) {
|
||||||
if (value === undefined) continue;
|
if (value === undefined) continue;
|
||||||
|
|
||||||
let tag;
|
let tag;
|
||||||
|
let labelSuffix = "";
|
||||||
if (value instanceof PublicKey) {
|
if (value instanceof PublicKey) {
|
||||||
tag = <Address pubkey={value} alignRight link />;
|
tag = <Address pubkey={value} alignRight link />;
|
||||||
} else if (key === "amount") {
|
} else if (key === "amount") {
|
||||||
|
let amount;
|
||||||
if (decimals === undefined) {
|
if (decimals === undefined) {
|
||||||
tag = <>(raw) {value}</>;
|
labelSuffix = " (raw)";
|
||||||
|
amount = new Intl.NumberFormat("en-US").format(value);
|
||||||
} else {
|
} else {
|
||||||
tag = <>{normalizeTokenAmount(value, decimals).toFixed(decimals)}</>;
|
amount = new Intl.NumberFormat("en-US", {
|
||||||
|
minimumFractionDigits: decimals,
|
||||||
|
maximumFractionDigits: decimals,
|
||||||
|
}).format(normalizeTokenAmount(value, decimals));
|
||||||
}
|
}
|
||||||
|
tag = <>{amount}</>;
|
||||||
} else {
|
} else {
|
||||||
tag = <>{value}</>;
|
tag = <>{value}</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
key = key.charAt(0).toUpperCase() + key.slice(1);
|
let label = key.charAt(0).toUpperCase() + key.slice(1) + labelSuffix;
|
||||||
|
|
||||||
attributes.push(
|
attributes.push(
|
||||||
<tr key={key}>
|
<tr key={key}>
|
||||||
<td>{key}</td>
|
<td>{label}</td>
|
||||||
<td className="text-lg-right">{tag}</td>
|
<td className="text-lg-right">{tag}</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,10 +3,12 @@ import {
|
||||||
object,
|
object,
|
||||||
StructType,
|
StructType,
|
||||||
number,
|
number,
|
||||||
|
string,
|
||||||
optional,
|
optional,
|
||||||
array,
|
array,
|
||||||
pick,
|
pick,
|
||||||
nullable,
|
nullable,
|
||||||
|
union,
|
||||||
} from "superstruct";
|
} from "superstruct";
|
||||||
import { Pubkey } from "validators/pubkey";
|
import { Pubkey } from "validators/pubkey";
|
||||||
|
|
||||||
|
@ -35,7 +37,7 @@ const InitializeMultisig = pick({
|
||||||
const Transfer = object({
|
const Transfer = object({
|
||||||
source: Pubkey,
|
source: Pubkey,
|
||||||
destination: Pubkey,
|
destination: Pubkey,
|
||||||
amount: number(),
|
amount: union([string(), number()]),
|
||||||
authority: optional(Pubkey),
|
authority: optional(Pubkey),
|
||||||
multisigAuthority: optional(Pubkey),
|
multisigAuthority: optional(Pubkey),
|
||||||
signers: optional(array(Pubkey)),
|
signers: optional(array(Pubkey)),
|
||||||
|
@ -44,7 +46,7 @@ const Transfer = object({
|
||||||
const Approve = object({
|
const Approve = object({
|
||||||
source: Pubkey,
|
source: Pubkey,
|
||||||
delegate: Pubkey,
|
delegate: Pubkey,
|
||||||
amount: number(),
|
amount: union([string(), number()]),
|
||||||
owner: optional(Pubkey),
|
owner: optional(Pubkey),
|
||||||
multisigOwner: optional(Pubkey),
|
multisigOwner: optional(Pubkey),
|
||||||
signers: optional(array(Pubkey)),
|
signers: optional(array(Pubkey)),
|
||||||
|
@ -77,7 +79,7 @@ const SetAuthority = object({
|
||||||
const MintTo = object({
|
const MintTo = object({
|
||||||
mint: Pubkey,
|
mint: Pubkey,
|
||||||
account: Pubkey,
|
account: Pubkey,
|
||||||
amount: number(),
|
amount: union([string(), number()]),
|
||||||
mintAuthority: optional(Pubkey),
|
mintAuthority: optional(Pubkey),
|
||||||
multisigMintAuthority: optional(Pubkey),
|
multisigMintAuthority: optional(Pubkey),
|
||||||
signers: optional(array(Pubkey)),
|
signers: optional(array(Pubkey)),
|
||||||
|
@ -86,7 +88,7 @@ const MintTo = object({
|
||||||
const Burn = object({
|
const Burn = object({
|
||||||
account: Pubkey,
|
account: Pubkey,
|
||||||
mint: Pubkey,
|
mint: Pubkey,
|
||||||
amount: number(),
|
amount: union([string(), number()]),
|
||||||
authority: optional(Pubkey),
|
authority: optional(Pubkey),
|
||||||
multisigAuthority: optional(Pubkey),
|
multisigAuthority: optional(Pubkey),
|
||||||
signers: optional(array(Pubkey)),
|
signers: optional(array(Pubkey)),
|
||||||
|
|
Loading…
Reference in New Issue