forked from solana-foundation/explorer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInstructionCard.tsx
More file actions
71 lines (64 loc) · 2.22 KB
/
InstructionCard.tsx
File metadata and controls
71 lines (64 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { BaseInstructionCard } from '@components/common/BaseInstructionCard';
import { useFetchRawTransaction, useRawTransactionDetails } from '@providers/transactions/raw';
import { ParsedInstruction, SignatureResult, TransactionInstruction } from '@solana/web3.js';
import React, { useCallback, useContext } from 'react';
import { SignatureContext } from './SignatureContext';
type InstructionProps = {
title: string;
children?: React.ReactNode;
result: SignatureResult;
index: number;
ix: TransactionInstruction | ParsedInstruction;
defaultRaw?: boolean;
innerCards?: JSX.Element[];
eventCards?: JSX.Element[];
childIndex?: number;
// Raw instruction for displaying accounts and hex data in raw mode (used by inspector)
raw?: TransactionInstruction;
headerButtons?: React.ReactNode;
collapsible?: boolean;
};
export function InstructionCard({
title,
children,
result,
index,
ix,
defaultRaw,
innerCards,
eventCards,
childIndex,
raw: rawProp,
headerButtons,
collapsible,
}: InstructionProps) {
const signature = useContext(SignatureContext);
const rawDetails = useRawTransactionDetails(signature);
// Use provided raw prop, or fetch from transaction details
let raw: TransactionInstruction | undefined = rawProp;
if (!raw && rawDetails && childIndex === undefined) {
raw = rawDetails?.data?.raw?.transaction.instructions[index];
}
const fetchRaw = useFetchRawTransaction();
const fetchRawTrigger = useCallback(() => fetchRaw(signature), [signature, fetchRaw]);
// Only allow fetching raw data if we have a valid signature (not in inspector mode)
const canFetchRaw = signature && !raw;
return (
<BaseInstructionCard
title={title}
result={result}
index={index}
ix={ix}
defaultRaw={defaultRaw}
innerCards={innerCards}
eventCards={eventCards}
childIndex={childIndex}
raw={raw}
onRequestRaw={canFetchRaw ? fetchRawTrigger : undefined}
headerButtons={headerButtons}
collapsible={collapsible}
>
{children}
</BaseInstructionCard>
);
}