Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add transaction json download to ui #815

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 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.

2 changes: 2 additions & 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 All @@ -26,6 +27,7 @@
"zustand-persist": "^0.1.6"
},
"devDependencies": {
"@types/file-saver": "^2.0.7",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react-swc": "^3.0.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
Loading