diff --git a/package.json b/package.json
index 80d49e4..b2b3947 100644
--- a/package.json
+++ b/package.json
@@ -76,7 +76,8 @@
"web3": "^1.7.0",
"@metamask/detect-provider": "^1.2.0",
"@walletconnect/client": "^1.7.1",
- "@walletconnect/qrcode-modal": "^1.7.1"
+ "@walletconnect/qrcode-modal": "^1.7.1",
+ "bignumber.js": "^9.0.0"
},
"devDependencies": {
"@ant-design/pro-cli": "^2.0.2",
diff --git a/src/pages/All/Address/Edit/index.tsx b/src/pages/All/Address/Edit/index.tsx
index 4946e4f..2300ac8 100644
--- a/src/pages/All/Address/Edit/index.tsx
+++ b/src/pages/All/Address/Edit/index.tsx
@@ -27,8 +27,7 @@ const WorkEdit = () => {
val.sign = signInfo.sign;
val.coinType = 'eth';
val.num = parseInt(val.num);
- const params = { ...val };
- await AddAddress(params);
+ await AddAddress(val);
message.success('操作成功');
setLoading(false);
history.back();
diff --git a/src/pages/All/Address/Edit/AddAddressModal.tsx b/src/pages/All/Address/List/components/AddAddressModal.tsx
similarity index 100%
rename from src/pages/All/Address/Edit/AddAddressModal.tsx
rename to src/pages/All/Address/List/components/AddAddressModal.tsx
diff --git a/src/pages/All/Address/List/index.tsx b/src/pages/All/Address/List/index.tsx
index 48fe575..4380990 100644
--- a/src/pages/All/Address/List/index.tsx
+++ b/src/pages/All/Address/List/index.tsx
@@ -3,9 +3,9 @@ import Table, { ProColumns, ActionType } from '@/components/Table';
import { queryAddressList } from '@/services/eth';
import { fetchTableData } from '@/utils/table';
import CoinType from '@/constants/enum/coinType';
-import AddAddressModal from '../Edit/AddAddressModal';
+import AddAddressModal from './components/AddAddressModal';
import { AddAddress } from '@/services/eth';
-import { initWeb3, walletSign } from '../../../../utils/web3';
+import { initWeb3, walletSign } from '@/utils/web3';
import { message, Select } from 'antd';
const AddressList = () => {
@@ -63,14 +63,12 @@ const AddressList = () => {
{
- // history.push(RoutePath.ETH_ADDRESS.EDIT);
setIsModalVisible(true);
},
},
diff --git a/src/pages/All/Record/List/index.tsx b/src/pages/All/Record/List/index.tsx
index 141ea1f..f8f1318 100644
--- a/src/pages/All/Record/List/index.tsx
+++ b/src/pages/All/Record/List/index.tsx
@@ -3,8 +3,9 @@ import Table, { ProColumns, ActionType } from '@/components/Table';
import { queryRecordList } from '@/services/eth';
import { fetchTableData } from '@/utils/table';
import CoinType from '@/constants/enum/coinType';
-import { web3 } from '@/utils/web3';
import { Select } from 'antd';
+import { getBalanceAmount } from '@/utils/formatBalance';
+import BigNumber from 'bignumber.js';
const AddressList = () => {
const tableRef = useRef();
@@ -36,7 +37,6 @@ const AddressList = () => {
dataIndex: 'txHash',
hideInSearch: true,
ellipsis: true,
- // search: { transform: (value: any) => ({ startTime: value[0], endTime: value[1] }) },
},
{
title: '金额',
@@ -73,28 +73,17 @@ const AddressList = () => {
{
- // history.push(RoutePath.ETH_ADDRESS.EDIT);
- // setIsModalVisible(true);
- // },
- // },
- // ]}
request={async (params) => {
- // params.coinType = CoinType.ETH;
const res = await fetchTableData(queryRecordList, params);
for (const key in res.data) {
if (Object.prototype.hasOwnProperty.call(res.data, key)) {
const element = res.data[key];
- element.amount = web3.utils
- .toBN(element.amount)
- .div(web3.utils.toBN(Math.pow(10, Number(element.decimals))))
- .toNumber();
+ element.amount = getBalanceAmount(
+ new BigNumber(element.amount),
+ element.decimals,
+ ).toNumber();
}
}
return res;
diff --git a/src/pages/Eth/Address/Edit/AddAddressModal.tsx b/src/pages/Eth/Address/List/components/AddAddressModal.tsx
similarity index 100%
rename from src/pages/Eth/Address/Edit/AddAddressModal.tsx
rename to src/pages/Eth/Address/List/components/AddAddressModal.tsx
diff --git a/src/pages/Eth/Address/List/index.tsx b/src/pages/Eth/Address/List/index.tsx
index 0d6de07..221b14f 100644
--- a/src/pages/Eth/Address/List/index.tsx
+++ b/src/pages/Eth/Address/List/index.tsx
@@ -3,9 +3,9 @@ import Table, { ProColumns, ActionType } from '@/components/Table';
import { queryAddressList } from '@/services/eth';
import { fetchTableData } from '@/utils/table';
import CoinType from '@/constants/enum/coinType';
-import AddAddressModal from '../Edit/AddAddressModal';
+import AddAddressModal from './components/AddAddressModal';
import { AddAddress } from '@/services/eth';
-import { initWeb3, walletSign } from '../../../../utils/web3';
+import { initWeb3, walletSign } from '@/utils/web3';
import { message } from 'antd';
const AddressList = () => {
@@ -43,7 +43,6 @@ const AddressList = () => {
{
type: 'add',
onConfirm: () => {
- // history.push(RoutePath.ETH_ADDRESS.EDIT);
setIsModalVisible(true);
},
},
@@ -65,8 +64,7 @@ const AddressList = () => {
val.key = signInfo.raw;
val.sign = signInfo.sign;
val.coinType = CoinType.ETH;
- const params = { ...val };
- await AddAddress(params);
+ await AddAddress(val);
message.success('操作成功');
} catch (e) {}
setIsModalVisible(false);
diff --git a/src/pages/Eth/Record/List/index.tsx b/src/pages/Eth/Record/List/index.tsx
index 4668c0c..593279e 100644
--- a/src/pages/Eth/Record/List/index.tsx
+++ b/src/pages/Eth/Record/List/index.tsx
@@ -3,7 +3,8 @@ import Table, { ProColumns, ActionType } from '@/components/Table';
import { queryRecordList } from '@/services/eth';
import { fetchTableData } from '@/utils/table';
import CoinType from '@/constants/enum/coinType';
-import { web3 } from '@/utils/web3';
+import { getBalanceAmount } from '@/utils/formatBalance';
+import BigNumber from 'bignumber.js';
const AddressList = () => {
const tableRef = useRef();
@@ -13,7 +14,6 @@ const AddressList = () => {
dataIndex: 'txHash',
hideInSearch: true,
ellipsis: true,
- // search: { transform: (value: any) => ({ startTime: value[0], endTime: value[1] }) },
},
{
title: '金额',
@@ -50,28 +50,18 @@ const AddressList = () => {
{
- // history.push(RoutePath.ETH_ADDRESS.EDIT);
- // setIsModalVisible(true);
- // },
- // },
- // ]}
request={async (params) => {
params.coinType = CoinType.ETH;
const res = await fetchTableData(queryRecordList, params);
for (const key in res.data) {
if (Object.prototype.hasOwnProperty.call(res.data, key)) {
const element = res.data[key];
- element.amount = web3.utils
- .toBN(element.amount)
- .div(web3.utils.toBN(Math.pow(10, Number(element.decimals))))
- .toNumber();
+ element.amount = getBalanceAmount(
+ new BigNumber(element.amount),
+ element.decimals,
+ ).toNumber();
}
}
return res;
diff --git a/src/utils/bigNumber.ts b/src/utils/bigNumber.ts
new file mode 100644
index 0000000..2c96fcf
--- /dev/null
+++ b/src/utils/bigNumber.ts
@@ -0,0 +1,6 @@
+import BigNumber from 'bignumber.js';
+
+export const BIG_ZERO = new BigNumber(0);
+export const BIG_ONE = new BigNumber(1);
+export const BIG_NINE = new BigNumber(9);
+export const BIG_TEN = new BigNumber(10);
diff --git a/src/utils/formatBalance.ts b/src/utils/formatBalance.ts
new file mode 100644
index 0000000..8cbe1b5
--- /dev/null
+++ b/src/utils/formatBalance.ts
@@ -0,0 +1,6 @@
+import BigNumber from 'bignumber.js';
+import { BIG_TEN } from './bigNumber';
+
+export const getBalanceAmount = (amount: BigNumber, decimals = 18) => {
+ return new BigNumber(amount).dividedBy(BIG_TEN.pow(decimals));
+};