forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorResponse.tsx
More file actions
132 lines (123 loc) · 3.38 KB
/
Copy pathErrorResponse.tsx
File metadata and controls
132 lines (123 loc) · 3.38 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import {
AccountRequiresMemoError,
BadResponseError,
} from "@stellar/stellar-sdk";
import { Box } from "../../components/layout/Box";
import { TxResponse } from "./TxResponse";
import { ValidationResponseCard } from "./ValidationResponseCard";
import { PrettyJson } from "./PrettyJson";
import {
SubmitHorizonError,
SubmitRpcError,
SubmitRpcErrorStatus,
} from "../types/types";
import { Alert } from "@stellar/design-system";
export const HorizonErrorResponse = ({
error,
}: {
error: SubmitHorizonError;
}) => {
let message = "",
extras = null;
if (error instanceof AccountRequiresMemoError) {
message = "This destination requires a memo.";
extras = (
<Box gap="xs" data-testid="submit-tx-horizon-error-memo">
<TxResponse label="Destination account:" value={error.accountId} />
<TxResponse label="Operation index:" value={error.operationIndex} />
</Box>
);
} else if (
error?.response &&
error.response.data?.extras?.result_codes &&
error.response.data?.extras.result_xdr
) {
const { result_codes, result_xdr } = error.response.data.extras;
message = error.message;
extras = (
<Box gap="xs" data-testid="submit-tx-horizon-error-extras">
<TxResponse
label="extras.result_codes:"
value={JSON.stringify(result_codes)}
/>
<TxResponse label="Result XDR:" value={result_xdr} />
</Box>
);
} else {
message =
error instanceof BadResponseError
? "Received a bad response when submitting."
: "An unknown error occurred.";
extras = (
<Box gap="xs" data-testid="submit-tx-horizon-error">
<TxResponse
label="original error:"
value={JSON.stringify(error, null, 2)}
/>
</Box>
);
}
return (
<ValidationResponseCard
variant="error"
title="Error!"
summary={
<Alert variant="error" placement="inline" title="Failed Execution">
{message}
</Alert>
}
detailedResponse={extras}
/>
);
};
export const RpcErrorResponse = ({ error }: { error: SubmitRpcError }) => {
const getSubtitle = (status: SubmitRpcErrorStatus) => {
switch (status) {
case "DUPLICATE":
return "Duplicate transaction";
case "TIMEOUT":
return "Transaction timed out";
case "TRY_AGAIN_LATER":
case "ERROR":
case "FAILED":
default:
return "Transaction failed";
}
};
const errorFields = () => {
const { hash, errorResult, diagnosticEvents } = error.result;
return (
<>
{hash ? (
<Box gap="xs">
<TxResponse label="Transaction hash:" value={hash} />
</Box>
) : null}
{errorResult ? (
<Box gap="xs" data-testid="submit-tx-rpc-error">
<TxResponse
label="Error result:"
item={<PrettyJson json={errorResult} />}
/>
</Box>
) : null}
{diagnosticEvents ? (
<Box gap="xs">
<TxResponse
label="Diagnostic events:"
item={<PrettyJson json={diagnosticEvents} />}
/>
</Box>
) : null}
</>
);
};
return (
<ValidationResponseCard
variant="error"
title="Transaction Submission Error!"
subtitle={getSubtitle(error.status)}
detailedResponse={errorFields()}
/>
);
};