Skip to content

Commit b965e07

Browse files
authored
feat: Namadillo - Improve gasLimit error (#1977)
1 parent 2996391 commit b965e07

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

apps/namadillo/src/lib/query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
TransactionEventsClasses,
1919
TransactionEventsStatus,
2020
} from "types/events";
21+
import { toErrorDetail } from "utils";
2122
import { getSdkInstance } from "utils/sdk";
2223

2324
export type TransactionPair<T> = {
@@ -234,7 +235,7 @@ export const broadcastTxWithEvents = async <T>(
234235
if (result.status === "fulfilled") {
235236
return result.value.commitments;
236237
} else {
237-
throw new Error(result.reason.toString());
238+
throw new Error(toErrorDetail(encodedTx.txs, result.reason));
238239
}
239240
});
240241

apps/namadillo/src/utils/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { Asset, AssetDenomUnit } from "@chain-registry/types";
22
import namadaAssets from "@namada/chain-registry/namada/assetlist.json";
3-
import { ProposalStatus, ProposalTypeString } from "@namada/types";
3+
import {
4+
BroadcastTxError,
5+
ProposalStatus,
6+
ProposalTypeString,
7+
ResultCode,
8+
TxMsgValue,
9+
} from "@namada/types";
410
import { localnetConfigAtom } from "atoms/integrations/atoms";
511
import BigNumber from "bignumber.js";
612
import { getDefaultStore } from "jotai";
@@ -114,3 +120,22 @@ export const toBaseAmount = (
114120
}
115121
return displayAmount.shiftedBy(displayUnit.exponent);
116122
};
123+
124+
/**
125+
* Returns formatted error message based on tx props and error code
126+
*/
127+
export const toErrorDetail = (
128+
tx: TxMsgValue[],
129+
error: BroadcastTxError
130+
): string => {
131+
const { gasLimit } = tx[0].args;
132+
const { code } = error.toProps();
133+
134+
// TODO: Over time we may expand this to format errors for more result codes
135+
switch (code) {
136+
case ResultCode.TxGasLimit:
137+
return `${error.toString()} Please raise the Gas Amount above the previously provided ${gasLimit} in the fee options for your transaction.`;
138+
default:
139+
return error.toString();
140+
}
141+
};

packages/types/src/tx/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const ResultCodes: Record<ResultCode, string> = {
108108
[ResultCode.ReplayTx]: "Replayed tx",
109109
[ResultCode.InvalidChainId]: "Invalid chain ID",
110110
[ResultCode.ExpiredTx]: "Expired tx",
111-
[ResultCode.TxGasLimit]: "Exceeded gas limit",
111+
[ResultCode.TxGasLimit]: "Transaction gas required exceeds the gas limit.",
112112
[ResultCode.FeeError]: "Error in paying tx fee",
113113
[ResultCode.InvalidVoteExtension]: "Invalid vote extension",
114114
[ResultCode.TooLarge]: "Tx is too large",

0 commit comments

Comments
 (0)