This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
FailedNotification.tsx
131 lines (120 loc) · 5.4 KB
/
FailedNotification.tsx
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
import React, { FC } from "react";
import { TxInfo } from "@terra-money/terra.js";
import { Text } from "@chakra-ui/react";
import { TERRA_ERROR_MAP, CosmosError, WasmError } from "constants/terra";
type Props = {
txInfo: TxInfo;
};
const friendlyMessages = {
[CosmosError.TxParseError]:
"We're sorry, we were unable to parse your transaction. Please try again.",
[CosmosError.InvalidSequence]:
"We're sorry, your signature sequence was invalid. Please try again.",
[CosmosError.Unauthorized]:
"We're sorry, you don't have the authorization to carry out this request. Verify your permissions and try again.",
[CosmosError.InsufficientFunds]:
"We're sorry, you don't have enough funds to complete this request. Please try again when you have more funds available.",
[CosmosError.UnknownRequest]:
"We're sorry, we couldn't identify the request you made.",
[CosmosError.InvalidAddress]:
"We're sorry, that address is not valid. Please try again with a valid address.",
[CosmosError.InvalidPubkey]:
"We're sorry, that public key is not valid. Please try again with a valid public key.",
[CosmosError.UnknownAddress]:
"We're sorry, we couldn't find the address you specified. Please try again.",
[CosmosError.InvalidCoins]: "Sorry, the coins you specified are not valid.",
[CosmosError.OutOfGas]:
"Sorry, your request ran out of gas. Please try again with a higher gas limit.",
[CosmosError.MemoTooLarge]:
"Sorry, the amount of text you included in your memo was too large. Please try again with a smaller amount of text.",
[CosmosError.InsufficientFee]:
"Sorry, the specified fee was not enough to cover the cost of this transaction. Please try again.",
[CosmosError.MaxSignaturesExceeded]:
"Sorry, the maximum number of signatures has been reached. Please try again with fewer signatures.",
[CosmosError.NoSignatures]:
"Sorry, we didn't receive any signatures for this transaction. Please try again with at least one signature.",
[CosmosError.FailedToMarshalJSON]:
"Sorry, Cosmos was unable to encode your JSON bytes. Please try again with valid JSON data.",
[CosmosError.FailedToUnmarshalJSON]:
"Sorry, Cosmos was not able to decode your JSON bytes. Please try again with valid JSON data.",
[CosmosError.InvalidRequest]:
"Sorry, that request was not valid. Please try again with a valid request.",
[CosmosError.TxAlreadyInMempool]:
"Sorry, that transaction was already being processed in the mempool. Please try again later.",
[CosmosError.MempoolFull]:
"Sorry, the mempool is full and cannot accept any more transactions. Please try again later.",
[CosmosError.TxTooLarge]:
"Sorry, the transaction size is too large. Please try again with a smaller transaction.",
[CosmosError.KeyNotFound]:
"Sorry, that key was not found in our system. Please try again with a different key.",
[CosmosError.InvalidAccountPassword]:
"Sorry, the key password you entered is not valid. Please try again with a valid key password.",
// TODO
// [CosmosError.TxSignerMismatch]: "",
// [CosmosError.InvalidGasAdjustment]: "",
// [CosmosError.InvalidHeight]: "",
// [CosmosError.InvalidVersion]: "",
// [CosmosError.InvalidChainID]: "",
// [CosmosError.InvalidType]: "",
// [CosmosError.TxTimeoutHeight]: "",
// [CosmosError.UnknownExtensionOptions]: "",
// [CosmosError.IncorrectAccountSequence]: "",
// [CosmosError.ProtobufPackingFailed]: "",
// [CosmosError.ProtobufUnpackingFailed]: "",
// [CosmosError.InternalLogicError]: "",
// [CosmosError.Conflict]: "",
// [CosmosError.FeatureNotSupported]: "",
// [CosmosError.NotFound]: "",
// [CosmosError.InternalIOError]: "",
// [CosmosError.ErrorInAppToml]: "",
// [WasmError.ContractAccountExists]: "",
// [WasmError.InstantiateFailed]: "",
[WasmError.ExecuteFailed]:
"Execution failed: we're sorry, we were unable to realize your transaction. Please try again.",
// [WasmError.InsufficientGas]: "",
// [WasmError.InvalidGenesis]: "",
// [WasmError.NotFound]: "",
// [WasmError.InvalidMsg]: "",
// [WasmError.NoRegisteredQuerier]: "",
// [WasmError.NoRegisteredParser]: "",
// [WasmError.MigrationFailed]: "",
// [WasmError.NotMigratable]: "",
// [WasmError.StoreCodeFailed]: "",
// [WasmError.ContractQueryFailed]: "",
// [WasmError.ExceedMaxContractSize]: "",
// [WasmError.ExceedMaxContractMsgSize]: "",
// [WasmError.ExceedMaxContractDataSize]: "",
// [WasmError.ReplyFailed]: "",
// [WasmError.ExceedMaxQueryDepth]: "",
};
const executeFailedMessages = [
{
keySearch: "minimum receive amount",
message:
"Execution failed: slippage tolerance exceeded for the current swap.",
},
{
keySearch: "Error parsing into type",
message: "Execution failed: parsing error. Please try again.",
},
];
const FailedNotification: FC<Props> = ({ txInfo }) => {
const { codespace, code, raw_log } = txInfo;
let message;
if (codespace && code) {
// @ts-ignore
const terraError = TERRA_ERROR_MAP[codespace]?.[code];
// @ts-ignore
message = friendlyMessages[terraError];
// Replace generic WasmError.ExecuteFailed message
if (codespace === "wasm" && code === 4) {
executeFailedMessages.forEach((efm) => {
if (txInfo.raw_log.includes(efm.keySearch)) {
message = efm.message;
}
});
}
}
return <Text textStyle={["small", "medium"]}>{message ?? raw_log}</Text>;
};
export default FailedNotification;