Fix explorer token crash on unknown instruction (#12329)

This commit is contained in:
Justin Starry 2020-09-18 18:05:31 +08:00 committed by GitHub
parent fdbb22dc07
commit f03621d24a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -25,6 +25,7 @@ import {
TokenInstructionType,
IX_TITLES,
} from "components/instruction/token/types";
import { reportError } from "utils/sentry";
export function TokenHistoryCard({ pubkey }: { pubkey: PublicKey }) {
const address = pubkey.toBase58();
@ -194,6 +195,21 @@ function TokenHistoryTable({ tokens }: { tokens: TokenInfoWithPubkey[] }) {
);
}
function instructionTypeName(
ix: ParsedInstruction,
tx: ConfirmedSignatureInfo
): string {
try {
const parsed = coerce(ix.parsed, ParsedInfo);
const { type: rawType } = parsed;
const type = coerce(rawType, TokenInstructionType);
return IX_TITLES[type];
} catch (err) {
reportError(err, { signature: tx.signature });
return "Unknown";
}
}
function TokenTransactionRow({
mint,
tx,
@ -219,10 +235,7 @@ function TokenTransactionRow({
return (
<>
{tokenInstructions.map((ix, index) => {
const parsed = coerce(ix.parsed, ParsedInfo);
const { type: rawType } = parsed;
const type = coerce(rawType, TokenInstructionType);
const typeName = IX_TITLES[type];
const typeName = instructionTypeName(ix, tx);
let statusText;
let statusClass;