Skip to content

Commit d93fa62

Browse files
authored
Merge pull request #1389 from AmbireTech/add/insufficient-eth-error-humanization
Add/ Error humanization for "Insufficient ETH for transaction calls"
2 parents 12d6d82 + 69d4d36 commit d93fa62

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/libs/errorDecoder/errorDecoder.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ describe('Error decoders work', () => {
377377
expect(decodedError.reason).toBe(`Insufficient ${base.nativeAssetSymbol} for transaction calls`)
378378
const humanized = getHumanReadableEstimationError(decodedError)
379379
expect(humanized.message).toBe(
380-
`The transaction will fail because it will revert onchain. Error code: Insufficient ${base.nativeAssetSymbol} for transaction calls\n`
380+
"The transaction will fail because you don't have enough ETH to cover the gas costs for this transaction."
381381
)
382382

383383
const sameErrorOnAvax = new InnerCallFailureError(
@@ -392,7 +392,7 @@ describe('Error decoders work', () => {
392392
)
393393
const humanizedAvax = getHumanReadableEstimationError(decodedsameErrorOnAvax)
394394
expect(humanizedAvax.message).toBe(
395-
`The transaction will fail because it will revert onchain. Error code: Insufficient ${avalanche.nativeAssetSymbol} for transaction calls\n`
395+
"The transaction will fail because you don't have enough AVAX to cover the gas costs for this transaction."
396396
)
397397
})
398398
it('Should report transaction reverted with error unknown when error is 0x and the calls value is less or equal to the portfolio amount', async () => {

src/libs/errorHumanizer/errors.ts

+18
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ const BROADCAST_OR_ESTIMATION_ERRORS: ErrorHumanizerError[] = [
5656
reasons: ['Transaction underpriced'],
5757
message: 'it is underpriced. Please select a higher transaction speed and try again.'
5858
},
59+
// TODO: Figure out a more elegant way to handle errors with dynamic messages
60+
{
61+
reasons: ['Insufficient ETH for transaction calls'],
62+
message: "you don't have enough ETH to cover the gas costs for this transaction."
63+
},
64+
{
65+
reasons: ['Insufficient AVAX for transaction calls'],
66+
message: "you don't have enough AVAX to cover the gas costs for this transaction."
67+
},
68+
{
69+
reasons: ['Insufficient BNB for transaction calls'],
70+
message: "you don't have enough BNB to cover the gas costs for this transaction."
71+
},
72+
{
73+
reasons: ['Insufficient POL for transaction calls'],
74+
message: "you don't have enough POL to cover the gas costs for this transaction."
75+
},
76+
// End of TODO
5977
// Smart Accounts
6078
{
6179
reasons: ['Sponsorship failed.'],

src/libs/estimate/estimate.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ describe('estimate', () => {
932932

933933
expect(response instanceof Error).toBe(true)
934934
expect((response as Error).message).toBe(
935-
'The transaction will fail because it will revert onchain. Error code: Insufficient ETH for transaction calls\n'
935+
"The transaction will fail because you don't have enough ETH to cover the gas costs for this transaction."
936936
)
937937
})
938938

@@ -1117,7 +1117,7 @@ describe('estimate', () => {
11171117
)
11181118
expect(response instanceof Error).toBe(true)
11191119
expect((response as Error).message).toBe(
1120-
'The transaction will fail because it will revert onchain. Error code: Insufficient POL for transaction calls\n'
1120+
"The transaction will fail because you don't have enough POL to cover the gas costs for this transaction."
11211121
)
11221122
})
11231123

0 commit comments

Comments
 (0)