-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction-history.tsx
206 lines (190 loc) · 6.74 KB
/
transaction-history.tsx
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React, { FC, useCallback } from 'react';
import { styled } from '@mui/material/styles';
import {
Dialog,
Button,
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Skeleton,
DialogTitle,
DialogContent,
} from '@mui/material';
import HelpIcon from '@mui/icons-material/Help';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';
import AccountBalanceIcon from '@mui/icons-material/AccountBalance';
function trimAddress(addr: string) {
if (!addr) return addr;
let start = addr.substring(0, 8);
let end = addr.substring(addr.length - 4);
return `${start}...${end}`;
}
const BootstrapDialog = styled(Dialog)(({ theme }) => ({
'& .MuDialogContent-root': {
padding: theme.spacing(2),
},
'& .MuDialogActions-root': {
padding: theme.spacing(1),
},
}));
export interface DialogTitleProps {
id: string;
children?: React.ReactNode;
onClose: () => void;
}
const BootstrapDialogTitle = (props: DialogTitleProps) => {
const { children, onClose, ...other } = props;
return (
<DialogTitle sx={{ m: 0, p: 2 }} {...other}>
{children}
{onClose ? (
<IconButton
aria-label="close"
onClick={onClose}
sx={{
position: 'absolute',
right: 8,
top: 8,
color: (theme) => theme.palette.grey[500],
}}
>
<CloseIcon />
</IconButton>
) : null}
</DialogTitle>
);
};
export default function TransactionHistory(props: any) {
const [open, setOpen] = React.useState(false);
const [publicKey, setPublicKey] = React.useState(props.publicKey);
const [transactionHistory, setTransactionHistory] = React.useState(null);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
const GetTransactionHistory = async () => {
const body = {
method: "getConfirmedSignaturesForAddress2",
jsonrpc: "2.0",
params: [
publicKey,
{"limit":25}
],
"id":3,
};
const response = await fetch("https://free.rpcpool.com", {
//const response = await fetch("https://solana-api.projectserum.com/", {
method: "POST",
body: JSON.stringify(body),
headers: { "Content-Type": "application/json" },
});
const json = await response.json();
const resultValues = json.result
return resultValues;
};
const fetchTransactionHistoryData = async () => {
let [transactionHistory] = await Promise.all([GetTransactionHistory()]);
setTransactionHistory(transactionHistory);
}
React.useEffect(() => {
if (!transactionHistory){
fetchTransactionHistoryData();
}
}, [publicKey]);
return (
<React.Fragment>
<Button
variant="outlined"
//aria-controls={menuId}
title={`Transaction History`}
onClick={handleClickOpen}
size="small"
>
<AccountBalanceIcon />
</Button>
<BootstrapDialog
onClose={handleClose}
aria-labelledby="customized-dialog-title"
open={open}
PaperProps={{
style: {
background: 'linear-gradient(to right, #251a3a, #000000)',
boxShadow: '3',
border: '1px solid rgba(255,255,255,0.15)',
borderTop: '1px solid rgba(255,255,255,0.3)',
borderRadius: '20px',
padding:'4'
},
}}
>
<BootstrapDialogTitle id="customized-dialog-title" onClose={handleClose}>
Transaction History
</BootstrapDialogTitle>
<DialogContent dividers>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 400 }} size="small" aria-label="a dense table">
<TableHead>
<TableRow>
<TableCell>Signature</TableCell>
<TableCell align="right">Slot</TableCell>
<TableCell align="right">Age</TableCell>
<TableCell align="right">Result</TableCell>
</TableRow>
</TableHead>
<TableBody>
{transactionHistory ? transactionHistory.map((item: any) => (
<TableRow
key={1}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
<TableCell component="th" scope="row">
{item.signature}
</TableCell>
<TableCell align="right">
{item.slot}
</TableCell>
<TableCell align="right">
{item.blockTime}
</TableCell>
<TableCell align="right">
{item.confirmationStatus}
</TableCell>
</TableRow>
))
:
<React.Fragment>
<TableRow>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
</TableRow>
<TableRow>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
</TableRow>
<TableRow>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
<TableCell><Skeleton/></TableCell>
</TableRow>
</React.Fragment>
}
</TableBody>
</Table>
</TableContainer>
</DialogContent>
</BootstrapDialog>
</React.Fragment>
);
}