-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathSorobanTransactionXdr.tsx
More file actions
61 lines (52 loc) · 1.58 KB
/
SorobanTransactionXdr.tsx
File metadata and controls
61 lines (52 loc) · 1.58 KB
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
"use client";
import { useEffect } from "react";
import { useStore } from "@/store/useStore";
import { useBuildFlowStore } from "@/store/createTransactionFlowStore";
import { TransactionBuilder } from "@stellar/stellar-sdk";
import { ValidationResponseCard } from "@/components/ValidationResponseCard";
import { TransactionXdrDisplay } from "./TransactionXdrDisplay";
export const SorobanTransactionXdr = () => {
const { network } = useStore();
const { build, setBuildSorobanXdr } = useBuildFlowStore();
const { isValid } = build;
const { soroban } = build;
useEffect(() => {
// Reset transaction.xdr if the transaction is not valid
if (!(isValid.params && isValid.operations)) {
setBuildSorobanXdr("");
}
// Not including setBuildSorobanXdr
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isValid.params, isValid.operations]);
if (!(isValid.params && isValid.operations)) {
return null;
}
if (soroban.xdr) {
try {
const txnHash = TransactionBuilder.fromXDR(
soroban.xdr,
network.passphrase,
)
.hash()
.toString("hex");
return (
<TransactionXdrDisplay
xdr={soroban.xdr}
networkPassphrase={network.passphrase}
txnHash={txnHash}
dataTestId="build-soroban-transaction-envelope-xdr"
txType="smart-contract"
/>
);
} catch (e: any) {
return (
<ValidationResponseCard
variant="error"
title="Transaction Error:"
response={e.toString()}
/>
);
}
}
return null;
};