Skip to content

Commit

Permalink
Display transaction hash with XDR input
Browse files Browse the repository at this point in the history
  • Loading branch information
quietbits committed Oct 29, 2024
1 parent 6e77686 commit 05f3b1f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/(sidebar)/transaction/submit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ValidationResponseCard } from "@/components/ValidationResponseCard";
import { TxResponse } from "@/components/TxResponse";
import { SaveTransactionModal } from "@/components/SaveTransactionModal";
import { SdsLink } from "@/components/SdsLink";
import { TransactionHashReadOnlyField } from "@/components/TransactionHashReadOnlyField";

import {
HorizonErrorResponse,
Expand Down Expand Up @@ -482,6 +483,11 @@ export default function SubmitTransaction() {
hasCopyButton
/>

<TransactionHashReadOnlyField
xdr={xdr.blob}
networkPassphrase={network.passphrase}
/>

<Box
gap="lg"
direction="row"
Expand Down
6 changes: 6 additions & 0 deletions src/app/(sidebar)/xdr/view/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { SdsLink } from "@/components/SdsLink";
import { XdrPicker } from "@/components/FormElements/XdrPicker";
import { XdrTypeSelect } from "@/components/XdrTypeSelect";
import { PrettyJsonTransaction } from "@/components/PrettyJsonTransaction";
import { TransactionHashReadOnlyField } from "@/components/TransactionHashReadOnlyField";

import { parseToLosslessJson } from "@/helpers/parseToLosslessJson";
import { useIsXdrInit } from "@/hooks/useIsXdrInit";
Expand Down Expand Up @@ -136,6 +137,11 @@ export default function ViewXdr() {
disabled={isFetchingLatestTxn}
/>

<TransactionHashReadOnlyField
xdr={xdr.blob}
networkPassphrase={network.passphrase}
/>

<XdrTypeSelect error={xdrJsonDecoded?.error} />

<>
Expand Down
25 changes: 25 additions & 0 deletions src/components/TransactionHashReadOnlyField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Input } from "@stellar/design-system";
import { transactionHashFromXdr } from "@/helpers/transactionHashFromXdr";

export const TransactionHashReadOnlyField = ({
xdr,
networkPassphrase,
}: {
xdr: string;
networkPassphrase: string;
}) => {
if (!xdr) {
return null;
}

return (
<Input
id="tx-hash"
fieldSize="md"
label="Transaction hash"
value={transactionHashFromXdr(xdr, networkPassphrase)}
copyButton={{ position: "right" }}
disabled
/>
);
};
6 changes: 6 additions & 0 deletions src/helpers/transactionHashFromXdr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TransactionBuilder } from "@stellar/stellar-sdk";

export const transactionHashFromXdr = (
xdr: string,
networkPassphrase: string,
) => TransactionBuilder.fromXDR(xdr, networkPassphrase).hash().toString("hex");

0 comments on commit 05f3b1f

Please sign in to comment.