Skip to content

Commit

Permalink
fix: add a gas limit error msg format (#1480)
Browse files Browse the repository at this point in the history
- Closes #1357

---

| 📷  Demo |
| --- |
| <img width="322" alt="Screenshot 2024-09-17 at 12 17 26"
src="https://github.com/user-attachments/assets/40f5ee7a-87a1-43e2-9aae-05215dc954c5">
|
  • Loading branch information
helciofranco authored Sep 18, 2024
1 parent 14e6385 commit 65a987b
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 105 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-dragons-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

Improve gas error message by adding number formatting for better readability.
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"ts-jest-mock-import-meta": "1.1.0",
"tsconfig-paths-webpack-plugin": "4.1.0",
"typescript": "5.2.2",
"vite": "4.5.3",
"vite": "4.5.5",
"vite-plugin-clean": "1.0.0",
"vite-plugin-static-copy": "0.17.0",
"vite-tsconfig-paths": "4.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { BN } from 'fuels';
import type { ReactNode } from 'react';
import { FormProvider as Provider, useForm } from 'react-hook-form';
import * as yup from 'yup';
import { formatGasLimit } from '~/systems/Transaction';

export type TransactionRequestFormData = {
fees: {
Expand Down Expand Up @@ -58,7 +59,9 @@ const schema = yup

return ctx.createError({
path: 'fees.gasLimit',
message: `Gas limit must be greater than or equal to '${minGasLimit.toString()}'.`,
message: `Gas limit must be greater than or equal to ${formatGasLimit(
minGasLimit
)}.`,
});
},
})
Expand All @@ -74,7 +77,9 @@ const schema = yup

return ctx.createError({
path: 'fees.gasLimit',
message: `Gas limit must be lower than or equal to '${maxGasLimit.toString()}'.`,
message: `Gas limit must be lower than or equal to ${formatGasLimit(
maxGasLimit
)}.`,
});
},
})
Expand Down
11 changes: 8 additions & 3 deletions packages/app/src/systems/Send/hooks/useSend.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { yupResolver } from '@hookform/resolvers/yup';
import { useInterpret, useSelector } from '@xstate/react';
import type { BN, BNInput } from 'fuels';
import { DEFAULT_DECIMAL_UNITS, bn, isB256, isBech32 } from 'fuels';
import { bn, isB256, isBech32 } from 'fuels';
import { useCallback, useEffect, useMemo } from 'react';
import { useForm, useWatch } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
Expand All @@ -13,6 +13,7 @@ import { useTransactionRequest } from '~/systems/DApp';
import { TxRequestStatus } from '~/systems/DApp/machines/transactionRequestMachine';
import type { TxInputs } from '~/systems/Transaction/services';

import { formatGasLimit } from '~/systems/Transaction';
import { sendMachine } from '../machines/sendMachine';
import type { SendMachineState } from '../machines/sendMachine';

Expand Down Expand Up @@ -171,7 +172,9 @@ const schema = yup

return ctx.createError({
path: 'fees.gasLimit',
message: `Gas limit must be greater than or equal to '${minGasLimit.toString()}'.`,
message: `Gas limit must be greater than or equal to ${formatGasLimit(
minGasLimit
)}.`,
});
},
})
Expand All @@ -187,7 +190,9 @@ const schema = yup

return ctx.createError({
path: 'fees.gasLimit',
message: `Gas limit must be lower than or equal to '${maxGasLimit.toString()}'.`,
message: `Gas limit must be lower than or equal to ${formatGasLimit(
maxGasLimit
)}.`,
});
},
})
Expand Down
8 changes: 8 additions & 0 deletions packages/app/src/systems/Transaction/utils/gasLimit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { BN } from 'fuels';

export const formatGasLimit = (value: BN) => {
const hex = value.toHex();
const gasLimit = BigInt(hex);

return gasLimit.toLocaleString('en-US');
};
1 change: 1 addition & 0 deletions packages/app/src/systems/Transaction/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './abi';
export * from './color';
export * from './error';
export * from './gasLimit';
export * from './icon';
export * from './text';
export * from './date';
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
8 changes: 4 additions & 4 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@fuel-ui/react": "0.23.3",
"@fuels/connectors": "0.28.0",
"@fuels/react": "0.28.0",
"@mdx-js/react": "^2.3.0",
"@next/mdx": "14.2.3",
"@mdx-js/react": "2.3.0",
"@next/mdx": "14.2.12",
"@tanstack/react-query": "5.28.4",
"acorn": "^8.10.0",
"acorn-loose": "^8.3.0",
Expand All @@ -31,15 +31,15 @@
"gray-matter": "^4.0.3",
"hast-util-heading-rank": "^3.0.0",
"hast-util-to-string": "^3.0.0",
"next": "14.2.3",
"next": "14.2.12",
"next-mdx-remote": "4.4.1",
"plyr-react": "^5.3.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-syntax-highlighter": "^15.5.0",
"remark": "14.0.3",
"remark-gfm": "3.0.1",
"remark-slug": "^7.0.1",
"remark-slug": "7.0.1",
"sharp": "^0.32.6",
"strip-indent": "^4.0.0",
"unist-util-visit": "^5.0.0",
Expand Down
Loading

0 comments on commit 65a987b

Please sign in to comment.