Skip to content

Commit

Permalink
feat: add transaction json download to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Dec 5, 2023
1 parent 0f07b81 commit 1fd5f50
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions applications/tari_dan_wallet_web_ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions applications/tari_dan_wallet_web_ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@tanstack/react-query": "^4.33.0",
"@tanstack/react-query-devtools": "^4.33.0",
"async-mutex": "^0.4.0",
"file-saver": "^2.0.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.9.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function RowData({ info, state }: any, index: number) {
const theme = useTheme();
const itemKey = Object.keys(info[0])[0];
const itemValue = Object.values(info[0])[0];
console.log(info);
return (
<>
<TableRow key={`${index}-1`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useTransactionDetails } from "../../api/hooks/useTransactions";
import { Accordion, AccordionDetails, AccordionSummary } from "../../Components/Accordion";
import { Grid, Table, TableContainer, TableBody, TableRow, TableCell, Button, Fade, Alert } from "@mui/material";
import Typography from "@mui/material/Typography";
import { saveAs } from 'file-saver';
import { DataTableCell, StyledPaper } from "../../Components/StyledComponents";
import PageHeading from "../../Components/PageHeading";
import Events from "./Events";
Expand Down Expand Up @@ -66,21 +67,21 @@ export default function TransactionDetails() {
if (result) {
if (result.result.Accept) {
return (
<span>Accepted</span>);
<span>Accepted</span>);
}
if (result.result.AcceptFeeRejectRest) {
return (
<span>{result.result.AcceptFeeRejectRest[1].ExecutionFailure}</span>
<span>{result.result.AcceptFeeRejectRest[1].ExecutionFailure}</span>
);
}
if (result.result.Reject) {
return (
<span>{Object.keys(result.result.Reject)[0]} - {result.result.Reject[Object.keys(result.result.Reject)[0]]}</span>
<span>{Object.keys(result.result.Reject)[0]} - {result.result.Reject[Object.keys(result.result.Reject)[0]]}</span>
)
}
} else {
return (
<span>In progress</span>
<span>In progress</span>
);
}
}
Expand All @@ -107,6 +108,14 @@ export default function TransactionDetails() {
</>
);
}
console.log(data);
const handleDownload = () => {
const json = JSON.stringify(data, null, 2);
const blob = new Blob([json], { type: 'application/json' });
const filename = `tx-${data?.transaction?.id}.json` || 'tx-unknown_id.json';
saveAs(blob, filename);
}


if (data.status === "Rejected" || data.status === "InvalidTransaction") {
return (
Expand All @@ -128,6 +137,10 @@ export default function TransactionDetails() {
<StatusChip status={data.status} />
</DataTableCell>
</TableRow>
<TableRow>
<TableCell>JSON</TableCell>
<DataTableCell><Button variant="outlined" onClick={handleDownload}>Download</Button></DataTableCell>
</TableRow>
<TableRow>
<TableCell>Reason</TableCell>
<DataTableCell>
Expand Down Expand Up @@ -172,6 +185,10 @@ export default function TransactionDetails() {
<TableCell>Result</TableCell>
<DataTableCell>{renderResult(data?.result)}</DataTableCell>
</TableRow>
<TableRow>
<TableCell>JSON</TableCell>
<DataTableCell><Button variant="outlined" onClick={handleDownload}>Download</Button></DataTableCell>
</TableRow>
{data?.transaction_failure ? (
<TableRow>
<TableCell>Reason</TableCell>
Expand All @@ -190,7 +207,7 @@ export default function TransactionDetails() {
alignItems: "center",
padding: "2rem 1rem 0.5rem 1rem",
}}
// className="flex-container"
// className="flex-container"
>
<Typography variant="h5">More Info</Typography>
<div
Expand Down

0 comments on commit 1fd5f50

Please sign in to comment.