Skip to content

Commit

Permalink
display 'transaction hash' component only if the xdr type is tx (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesunikim authored Nov 4, 2024
1 parent 5a28a76 commit e648d73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/(sidebar)/xdr/view/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function ViewXdr() {
} catch (e) {
return {
jsonString: "",
error: `Unable to decode input as ${xdr.type}: ${e}`,
error: `Unable to decode input as ${xdr.type}: ${e}. Select another XDR type.`,
};
}
};
Expand Down
8 changes: 7 additions & 1 deletion src/components/TransactionHashReadOnlyField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ export const TransactionHashReadOnlyField = ({
return null;
}

const hashValue = transactionHashFromXdr(xdr, networkPassphrase);

if (!hashValue) {
return null;
}

return (
<Input
id="tx-hash"
fieldSize="md"
label="Transaction hash"
value={transactionHashFromXdr(xdr, networkPassphrase)}
value={hashValue}
copyButton={{ position: "right" }}
disabled
/>
Expand Down
13 changes: 12 additions & 1 deletion src/helpers/transactionHashFromXdr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@ import { TransactionBuilder } from "@stellar/stellar-sdk";
export const transactionHashFromXdr = (
xdr: string,
networkPassphrase: string,
) => TransactionBuilder.fromXDR(xdr, networkPassphrase).hash().toString("hex");
) => {
try {
// Code to read XDR data
return TransactionBuilder?.fromXDR(xdr, networkPassphrase)
.hash()
.toString("hex");
} catch (e) {
// @TODO Do nothing for now
// add amplitude error tracking
return;
}
};

0 comments on commit e648d73

Please sign in to comment.