From 97f8961e0bf2f998be22ee9074eb2bb89deadc97 Mon Sep 17 00:00:00 2001 From: zzy <> Date: Fri, 17 Jun 2022 22:55:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E3=80=81=E5=85=85=E5=80=BC=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/enum/coinType.ts | 5 ++ .../Eth/Address/Edit/AddAddressModal.tsx | 67 +++++++++++++++ .../Address/Edit/components/AddAddress.tsx | 0 src/pages/Eth/Address/Edit/index.tsx | 70 ++++++++++++++++ src/pages/Eth/Address/List/index.tsx | 76 +++++++++++++++++ src/pages/Eth/Record/List/index.tsx | 81 +++++++++++++++++++ src/pages/Login/index.tsx | 3 +- src/pages/Work/List/index.tsx | 38 +++++---- src/routes/index.ts | 26 +++--- src/routes/routePath.ts | 7 +- src/services/eth.ts | 25 ++++++ src/utils/table.ts | 3 +- 12 files changed, 361 insertions(+), 40 deletions(-) create mode 100644 src/constants/enum/coinType.ts create mode 100644 src/pages/Eth/Address/Edit/AddAddressModal.tsx delete mode 100644 src/pages/Eth/Address/Edit/components/AddAddress.tsx create mode 100644 src/pages/Eth/Address/Edit/index.tsx create mode 100644 src/services/eth.ts diff --git a/src/constants/enum/coinType.ts b/src/constants/enum/coinType.ts new file mode 100644 index 0000000..58343a1 --- /dev/null +++ b/src/constants/enum/coinType.ts @@ -0,0 +1,5 @@ +export enum CoinType { + ETH = 'eth', + TRON = 'tron', +} +export default CoinType; diff --git a/src/pages/Eth/Address/Edit/AddAddressModal.tsx b/src/pages/Eth/Address/Edit/AddAddressModal.tsx new file mode 100644 index 0000000..4476c3b --- /dev/null +++ b/src/pages/Eth/Address/Edit/AddAddressModal.tsx @@ -0,0 +1,67 @@ +import React, { useState } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { message } from 'antd'; + +import { Form, FormItem, Input, Submit } from '@formily/antd'; +import { AddAddress } from '@/services/eth'; +import { initWeb3, walletSign } from '../../../../utils/web3'; +import { values } from 'lodash'; + +interface AddAddressModalPropsType extends ModalProps { + onOk: (val: any) => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Submit, + }, +}); + +const form = createForm({}); + +const AddAddressModal = (onOk, { ...rest }: AddAddressModalPropsType) => { + const handleOk = () => { + const val = form.getState(); + console.log('val = ', val); + onOk && onOk(val); + // try { + // await initWeb3(); + // const signInfo = await walletSign(); + // val.key = signInfo.raw; + // val.sign = signInfo.sign; + // val.coinType = 'eth'; + // val.num = parseInt(val.num); + // const params = { ...val }; + // await AddAddress(params); + // message.success('操作成功'); + // } catch (e) {} + }; + return ( + +
+ + + + +
+
+ ); +}; + +export default AddAddressModal; diff --git a/src/pages/Eth/Address/Edit/components/AddAddress.tsx b/src/pages/Eth/Address/Edit/components/AddAddress.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/src/pages/Eth/Address/Edit/index.tsx b/src/pages/Eth/Address/Edit/index.tsx new file mode 100644 index 0000000..4946e4f --- /dev/null +++ b/src/pages/Eth/Address/Edit/index.tsx @@ -0,0 +1,70 @@ +import React, { useState } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import { message, Spin } from 'antd'; +import DetailPageContainer from '@/components/DetailPageContainer'; +import { AddAddress } from '@/services/eth'; +import { initWeb3, walletSign } from '../../../../utils/web3'; +import { Form, FormItem, Input, FormButtonGroup, Submit } from '@formily/antd'; + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Submit, + }, +}); +const form = createForm({}); +const WorkEdit = () => { + const [loading, setLoading] = useState(false); + + const handleSubmit = async (val) => { + setLoading(true); + try { + await initWeb3(); + const signInfo = await walletSign(); + val.key = signInfo.raw; + val.sign = signInfo.sign; + val.coinType = 'eth'; + val.num = parseInt(val.num); + const params = { ...val }; + await AddAddress(params); + message.success('操作成功'); + setLoading(false); + history.back(); + } catch (e) { + setLoading(false); + } + }; + return ( + + +
+ + + + + + + 提交 + + +
+
+
+ ); +}; + +export default WorkEdit; diff --git a/src/pages/Eth/Address/List/index.tsx b/src/pages/Eth/Address/List/index.tsx index e69de29..805362f 100644 --- a/src/pages/Eth/Address/List/index.tsx +++ b/src/pages/Eth/Address/List/index.tsx @@ -0,0 +1,76 @@ +import React, { useRef, useState } from 'react'; +import Table, { ProColumns, ActionType } from '@/components/Table'; +import { history } from 'umi'; +import RoutePath from '@/routes/routePath'; +import { queryAddressList } from '@/services/eth'; +import { fetchTableData } from '@/utils/table'; +import CoinType from '@/constants/enum/coinType'; +// import WorkSelectModal from '@/widget/Work/WorkSelectModal'; +// import AddAddressModal from '../Edit/AddAddressModal'; + +const AddressList = () => { + // const [isModalVisible, setIsModalVisible] = useState(false); + const tableRef = useRef(); + const columns: ProColumns[] = [ + { + title: '备注', + dataIndex: 'remarks', + width: '20%', + // hideInSearch: true, + }, + { + title: '地址', + dataIndex: 'address', + hideInSearch: true, + ellipsis: true, + }, + // { + // title: '余额', + // dataIndex: 'series', + // hideInSearch: true, + // }, + { + title: 'key', + dataIndex: 'key', + hideInSearch: true, + }, + ]; + return ( +
+ { + history.push(RoutePath.ETH_ADDRESS.EDIT); + // setIsModalVisible(true); + }, + }, + ]} + request={async (params) => { + params.coinType = CoinType.ETH; + return fetchTableData(queryAddressList, params); + }} + /> + {/* */} + {/* */} + + ); +}; + +export default AddressList; diff --git a/src/pages/Eth/Record/List/index.tsx b/src/pages/Eth/Record/List/index.tsx index e69de29..6d791d8 100644 --- a/src/pages/Eth/Record/List/index.tsx +++ b/src/pages/Eth/Record/List/index.tsx @@ -0,0 +1,81 @@ +import React, { useRef } from 'react'; +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'; + +const AddressList = () => { + const tableRef = useRef(); + const columns: ProColumns[] = [ + { + title: '交易哈希', + dataIndex: 'txHash', + // width: '20%', + // hideInSearch: true, + }, + { + title: '金额', + dataIndex: 'amount', + // hideInSearch: true, + // ellipsis: true, + }, + { + title: '位数', + dataIndex: 'decimals', + // hideInSearch: true, + // ellipsis: true, + }, + { + title: '区块', + dataIndex: 'blockNumber', + // hideInSearch: true, + }, + { + title: '发送地址', + dataIndex: 'from', + // hideInSearch: true, + // ellipsis: true, + }, + { + title: '接受地址', + dataIndex: 'to', + // hideInSearch: true, + }, + ]; + return ( +
+
{ + // 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(); + } + } + return res; + }} + /> + + ); +}; + +export default AddressList; diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index 47cded9..45404eb 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -16,7 +16,7 @@ const Login: React.FC = () => { await initWeb3(); const signInfo = await walletSign(); const res: any = await login({ data: signInfo.raw, sign: signInfo.sign }); - localStorage.setItem(CACHE_TOKEN, res.token); + localStorage.setItem(CACHE_TOKEN, res); // const res: any = await login({ ...values }); // localStorage.setItem(CACHE_TOKEN, res.token); /** 此方法会跳转到 redirect 参数所在的位置 */ @@ -25,7 +25,6 @@ const Login: React.FC = () => { const { redirect } = query as { redirect: string }; history.push(redirect || '/'); }; - return (
diff --git a/src/pages/Work/List/index.tsx b/src/pages/Work/List/index.tsx index 0ad4609..9b0df54 100644 --- a/src/pages/Work/List/index.tsx +++ b/src/pages/Work/List/index.tsx @@ -7,6 +7,7 @@ import RoutePath from '@/routes/routePath'; import { queryWorkList, deleteWork } from '@/services/work'; import { fetchTableData } from '@/utils/table'; import TimeText from '@/components/Typography/TimeText'; +import WorkSelectModal from '@/widget/Work/WorkSelectModal'; const WorkList = () => { const tableRef = useRef(); @@ -74,23 +75,28 @@ const WorkList = () => { }, ]; return ( -
{ - history.push(RoutePath.WORK.EDIT); +
+
{ + history.push(RoutePath.WORK.EDIT); + }, }, - }, - ]} - request={async (params) => { - return fetchTableData(queryWorkList, params); - }} - /> + ]} + request={async (params) => { + return fetchTableData(queryWorkList, params); + }} + /> + + ); }; diff --git a/src/routes/index.ts b/src/routes/index.ts index 81dd357..986575d 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -16,39 +16,33 @@ export default [ routes: [ { path: RoutePath.ETH, - redirect: RoutePath.ADDRESS.LIST, + redirect: RoutePath.ETH_ADDRESS.LIST, hideInMenu: true, }, { name: 'ETH地址管理', - path: RoutePath.ADDRESS.LIST, - component: './Work/List', + path: RoutePath.ETH_ADDRESS.LIST, + component: './Eth/Address/List', }, { name: 'ETH地址详情', - path: RoutePath.ADDRESS.EDIT, + path: RoutePath.ETH_ADDRESS.EDIT, hideInMenu: true, - component: './Work/Edit', + component: './Eth/Address/Edit', }, { name: 'ETH充值记录', - path: RoutePath.RECORD.LIST, - component: './Work/List', - }, - { - name: 'ETH充值详情', - path: RoutePath.RECORD.EDIT, - hideInMenu: true, - component: './Work/Edit', + path: RoutePath.ETH_RECORD.LIST, + component: './Eth/Record/List', }, { name: 'ETH币种管理', - path: RoutePath.CURRENCY.LIST, + path: RoutePath.ETH_CURRENCY.LIST, component: './Work/List', }, { name: 'ETH币种详情', - path: RoutePath.CURRENCY.EDIT, + path: RoutePath.ETH_CURRENCY.EDIT, hideInMenu: true, component: './Work/Edit', }, @@ -79,7 +73,7 @@ export default [ }, { path: '/', - redirect: RoutePath.WORK.LIST, + redirect: RoutePath.ETH_ADDRESS.LIST, }, { diff --git a/src/routes/routePath.ts b/src/routes/routePath.ts index 6a53c47..1594520 100644 --- a/src/routes/routePath.ts +++ b/src/routes/routePath.ts @@ -3,15 +3,14 @@ const ETH = '/eth'; const RoutePath = { LOGIN: '/login', ETH: ETH, - ADDRESS: { + ETH_ADDRESS: { LIST: `${ETH}/address`, EDIT: `${ETH}/address/edit`, }, - RECORD: { + ETH_RECORD: { LIST: `${ETH}/record`, - EDIT: `${ETH}/record/edit`, }, - CURRENCY: { + ETH_CURRENCY: { LIST: `${ETH}/currency`, EDIT: `${ETH}/currency/edit`, }, diff --git a/src/services/eth.ts b/src/services/eth.ts new file mode 100644 index 0000000..d794879 --- /dev/null +++ b/src/services/eth.ts @@ -0,0 +1,25 @@ +import request from '@/utils/request'; + +export const queryAddressList = (data) => { + return request.request({ + url: '/admin/api/v1/address/get', + method: 'post', + data, + }); +}; + +export const AddAddress = (data) => { + return request.request({ + url: '/admin/api/v1/address/mask', + method: 'post', + data, + }); +}; + +export const queryRecordList = (data) => { + return request.request({ + url: '/admin/api/v1/records/get', + method: 'post', + data, + }); +}; diff --git a/src/utils/table.ts b/src/utils/table.ts index d02e49a..47bb6fc 100644 --- a/src/utils/table.ts +++ b/src/utils/table.ts @@ -9,8 +9,7 @@ export const fetchTableData = async ( delete params.current; delete params.pageSize; const res = (await fetch(params)) || {}; - const data = res.data; - + const data = res; data?.forEach((n: any) => { for (const key in formatObj) { n[key] = n[formatObj[key]]; -- 2.40.1 From 10614bdb9b1904bd136e7db35cb82f56d7934526 Mon Sep 17 00:00:00 2001 From: zzy <> Date: Mon, 20 Jun 2022 16:27:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=B8=BA=E5=BC=B9=E7=AA=97=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Eth/Address/Edit/AddAddressModal.tsx | 37 +++++++------------ src/pages/Eth/Address/List/index.tsx | 37 +++++++++++-------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/pages/Eth/Address/Edit/AddAddressModal.tsx b/src/pages/Eth/Address/Edit/AddAddressModal.tsx index 4476c3b..219d053 100644 --- a/src/pages/Eth/Address/Edit/AddAddressModal.tsx +++ b/src/pages/Eth/Address/Edit/AddAddressModal.tsx @@ -1,47 +1,36 @@ -import React, { useState } from 'react'; +// 选择作品弹窗 +import React, { useRef } from 'react'; import { createForm } from '@formily/core'; import { createSchemaField } from '@formily/react'; import Modal, { ModalProps } from '@/components/Modal'; -import { message } from 'antd'; - -import { Form, FormItem, Input, Submit } from '@formily/antd'; -import { AddAddress } from '@/services/eth'; -import { initWeb3, walletSign } from '../../../../utils/web3'; -import { values } from 'lodash'; +import { Form, FormItem, Input } from '@formily/antd'; interface AddAddressModalPropsType extends ModalProps { onOk: (val: any) => void; + onCancel: () => void; } const SchemaField = createSchemaField({ components: { FormItem, Input, - Submit, }, }); const form = createForm({}); -const AddAddressModal = (onOk, { ...rest }: AddAddressModalPropsType) => { +const AddAddressModal = ({ onOk, onCancel, ...rest }: AddAddressModalPropsType) => { const handleOk = () => { - const val = form.getState(); - console.log('val = ', val); - onOk && onOk(val); - // try { - // await initWeb3(); - // const signInfo = await walletSign(); - // val.key = signInfo.raw; - // val.sign = signInfo.sign; - // val.coinType = 'eth'; - // val.num = parseInt(val.num); - // const params = { ...val }; - // await AddAddress(params); - // message.success('操作成功'); - // } catch (e) {} + const formState = form.getFormState(); + onOk(formState.values); }; + + const handleCancel = () => { + onCancel(); + }; + return ( - +
{ - // const [isModalVisible, setIsModalVisible] = useState(false); + const [isModalVisible, setIsModalVisible] = useState(false); const tableRef = useRef(); const columns: ProColumns[] = [ { @@ -46,8 +46,8 @@ const AddressList = () => { { type: 'add', onConfirm: () => { - history.push(RoutePath.ETH_ADDRESS.EDIT); - // setIsModalVisible(true); + // history.push(RoutePath.ETH_ADDRESS.EDIT); + setIsModalVisible(true); }, }, ]} @@ -56,19 +56,26 @@ const AddressList = () => { return fetchTableData(queryAddressList, params); }} /> - {/* */} - {/* { + try { + await initWeb3(); + const signInfo = await walletSign(); + val.key = signInfo.raw; + val.sign = signInfo.sign; + val.coinType = CoinType.ETH; + val.num = parseInt(val.num); + const params = { ...val }; + await AddAddress(params); + message.success('操作成功'); + } catch (e) {} setIsModalVisible(false); }} - /> */} + /> ); }; -- 2.40.1 From 4688ee966733a1b5c72afd3daf1aeda7875a9f99 Mon Sep 17 00:00:00 2001 From: zzy <> Date: Tue, 28 Jun 2022 13:49:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../All/Address/Edit/AddAddressModal.tsx | 57 ++++++++++ src/pages/All/Address/Edit/index.tsx | 70 ++++++++++++ src/pages/All/Address/List/index.tsx | 105 +++++++++++++++++ .../Currency/Edit/components/AddCurrency.tsx | 0 src/pages/All/Currency/List/index.tsx | 0 src/pages/All/Record/List/index.tsx | 107 ++++++++++++++++++ .../Eth/Address/Edit/AddAddressModal.tsx | 7 +- src/pages/Eth/Address/List/index.tsx | 8 +- src/pages/Eth/Record/List/index.tsx | 23 ++-- src/pages/Login/index.less | 8 +- src/pages/Login/index.tsx | 20 +++- src/routes/index.ts | 38 +++++++ src/routes/routePath.ts | 13 +++ src/utils/web3.ts | 7 +- 14 files changed, 437 insertions(+), 26 deletions(-) create mode 100644 src/pages/All/Address/Edit/AddAddressModal.tsx create mode 100644 src/pages/All/Address/Edit/index.tsx create mode 100644 src/pages/All/Address/List/index.tsx create mode 100644 src/pages/All/Currency/Edit/components/AddCurrency.tsx create mode 100644 src/pages/All/Currency/List/index.tsx create mode 100644 src/pages/All/Record/List/index.tsx diff --git a/src/pages/All/Address/Edit/AddAddressModal.tsx b/src/pages/All/Address/Edit/AddAddressModal.tsx new file mode 100644 index 0000000..835286f --- /dev/null +++ b/src/pages/All/Address/Edit/AddAddressModal.tsx @@ -0,0 +1,57 @@ +// 选择作品弹窗 +import React, { useRef } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, NumberPicker } from '@formily/antd'; + +interface AddAddressModalPropsType extends ModalProps { + onOk: (val: any) => void; + onCancel: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + NumberPicker, + }, +}); + +const form = createForm({}); + +const AddAddressModal = ({ onOk, onCancel, ...rest }: AddAddressModalPropsType) => { + const handleOk = () => { + const formState = form.getFormState(); + onOk(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + + + + + + + + + ); +}; + +export default AddAddressModal; diff --git a/src/pages/All/Address/Edit/index.tsx b/src/pages/All/Address/Edit/index.tsx new file mode 100644 index 0000000..4946e4f --- /dev/null +++ b/src/pages/All/Address/Edit/index.tsx @@ -0,0 +1,70 @@ +import React, { useState } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import { message, Spin } from 'antd'; +import DetailPageContainer from '@/components/DetailPageContainer'; +import { AddAddress } from '@/services/eth'; +import { initWeb3, walletSign } from '../../../../utils/web3'; +import { Form, FormItem, Input, FormButtonGroup, Submit } from '@formily/antd'; + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Submit, + }, +}); +const form = createForm({}); +const WorkEdit = () => { + const [loading, setLoading] = useState(false); + + const handleSubmit = async (val) => { + setLoading(true); + try { + await initWeb3(); + const signInfo = await walletSign(); + val.key = signInfo.raw; + val.sign = signInfo.sign; + val.coinType = 'eth'; + val.num = parseInt(val.num); + const params = { ...val }; + await AddAddress(params); + message.success('操作成功'); + setLoading(false); + history.back(); + } catch (e) { + setLoading(false); + } + }; + return ( + + +
+ + + + + + + 提交 + + + +
+
+ ); +}; + +export default WorkEdit; diff --git a/src/pages/All/Address/List/index.tsx b/src/pages/All/Address/List/index.tsx new file mode 100644 index 0000000..48fe575 --- /dev/null +++ b/src/pages/All/Address/List/index.tsx @@ -0,0 +1,105 @@ +import React, { useRef, useState } from 'react'; +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 { AddAddress } from '@/services/eth'; +import { initWeb3, walletSign } from '../../../../utils/web3'; +import { message, Select } from 'antd'; + +const AddressList = () => { + const [isModalVisible, setIsModalVisible] = useState(false); + const [selectValue, setSelectValue] = useState(CoinType.ETH); + + const tableRef = useRef(); + const columns: ProColumns[] = [ + { + title: '类型', + dataIndex: 'coinType', + hideInTable: true, + initialValue: CoinType.ETH, + renderFormItem: (item, { type, defaultRender, ...rest }, form) => { + return ( +
{ + // history.push(RoutePath.ETH_ADDRESS.EDIT); + setIsModalVisible(true); + }, + }, + ]} + request={async (params) => { + return fetchTableData(queryAddressList, params); + }} + /> + { + try { + await initWeb3(); + const signInfo = await walletSign(); + val.key = signInfo.raw; + val.sign = signInfo.sign; + val.coinType = selectValue; + const params = { ...val }; + await AddAddress(params); + message.success('操作成功'); + } catch (e) {} + setIsModalVisible(false); + }} + /> + + ); +}; + +export default AddressList; diff --git a/src/pages/All/Currency/Edit/components/AddCurrency.tsx b/src/pages/All/Currency/Edit/components/AddCurrency.tsx new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/All/Currency/List/index.tsx b/src/pages/All/Currency/List/index.tsx new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/All/Record/List/index.tsx b/src/pages/All/Record/List/index.tsx new file mode 100644 index 0000000..141ea1f --- /dev/null +++ b/src/pages/All/Record/List/index.tsx @@ -0,0 +1,107 @@ +import React, { useRef } from 'react'; +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'; + +const AddressList = () => { + const tableRef = useRef(); + const columns: ProColumns[] = [ + { + title: '类型', + dataIndex: 'coinType', + hideInTable: true, + initialValue: CoinType.ETH, + renderFormItem: (item, { type, defaultRender, ...rest }, form) => { + return ( +
{ + // 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(); + } + } + return res; + }} + /> + + ); +}; + +export default AddressList; diff --git a/src/pages/Eth/Address/Edit/AddAddressModal.tsx b/src/pages/Eth/Address/Edit/AddAddressModal.tsx index 219d053..835286f 100644 --- a/src/pages/Eth/Address/Edit/AddAddressModal.tsx +++ b/src/pages/Eth/Address/Edit/AddAddressModal.tsx @@ -3,7 +3,7 @@ import React, { useRef } from 'react'; import { createForm } from '@formily/core'; import { createSchemaField } from '@formily/react'; import Modal, { ModalProps } from '@/components/Modal'; -import { Form, FormItem, Input } from '@formily/antd'; +import { Form, FormItem, Input, NumberPicker } from '@formily/antd'; interface AddAddressModalPropsType extends ModalProps { onOk: (val: any) => void; @@ -14,6 +14,7 @@ const SchemaField = createSchemaField({ components: { FormItem, Input, + NumberPicker, }, }); @@ -30,7 +31,7 @@ const AddAddressModal = ({ onOk, onCancel, ...rest }: AddAddressModalPropsType) }; return ( - +
diff --git a/src/pages/Eth/Address/List/index.tsx b/src/pages/Eth/Address/List/index.tsx index ff1d5d6..0d6de07 100644 --- a/src/pages/Eth/Address/List/index.tsx +++ b/src/pages/Eth/Address/List/index.tsx @@ -15,6 +15,7 @@ const AddressList = () => { { title: '备注', dataIndex: 'remarks', + hideInSearch: true, width: '20%', // hideInSearch: true, }, @@ -24,11 +25,7 @@ const AddressList = () => { hideInSearch: true, ellipsis: true, }, - // { - // title: '余额', - // dataIndex: 'series', - // hideInSearch: true, - // }, + { title: 'key', dataIndex: 'key', @@ -68,7 +65,6 @@ const AddressList = () => { val.key = signInfo.raw; val.sign = signInfo.sign; val.coinType = CoinType.ETH; - val.num = parseInt(val.num); const params = { ...val }; await AddAddress(params); message.success('操作成功'); diff --git a/src/pages/Eth/Record/List/index.tsx b/src/pages/Eth/Record/List/index.tsx index 6d791d8..4668c0c 100644 --- a/src/pages/Eth/Record/List/index.tsx +++ b/src/pages/Eth/Record/List/index.tsx @@ -11,36 +11,39 @@ const AddressList = () => { { title: '交易哈希', dataIndex: 'txHash', - // width: '20%', - // hideInSearch: true, + hideInSearch: true, + ellipsis: true, + // search: { transform: (value: any) => ({ startTime: value[0], endTime: value[1] }) }, }, { title: '金额', dataIndex: 'amount', - // hideInSearch: true, - // ellipsis: true, + width: '10%', + hideInSearch: true, }, { title: '位数', dataIndex: 'decimals', - // hideInSearch: true, - // ellipsis: true, + width: '5%', + hideInSearch: true, }, { title: '区块', dataIndex: 'blockNumber', - // hideInSearch: true, + width: '10%', + hideInSearch: true, }, { title: '发送地址', dataIndex: 'from', - // hideInSearch: true, - // ellipsis: true, + hideInSearch: true, + ellipsis: true, }, { title: '接受地址', dataIndex: 'to', - // hideInSearch: true, + hideInSearch: true, + ellipsis: true, }, ]; return ( diff --git a/src/pages/Login/index.less b/src/pages/Login/index.less index 88b73ab..a44d4be 100644 --- a/src/pages/Login/index.less +++ b/src/pages/Login/index.less @@ -3,6 +3,7 @@ .container { display: flex; flex-direction: column; + align-items: center; height: 100vh; overflow: auto; background: @layout-body-background; @@ -23,6 +24,10 @@ } } +.button { + margin-top: 24px; +} + .content { flex: 1; padding: 32px 0; @@ -37,7 +42,8 @@ } .content { - padding: 100px 0 24px; + width: 40%; + padding: 300px 0 24px; } } diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index 45404eb..b26c785 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -8,10 +8,11 @@ import styles from './index.less'; import { CACHE_TOKEN } from '@/constants/cacheKey'; import { initWeb3, walletSign } from '../../utils/web3'; +import { Button } from 'antd'; const Login: React.FC = () => { const intl = useIntl(); - const handleSubmit = async (values: API.LoginParams) => { + const handleSubmit = async () => { // 登录 await initWeb3(); const signInfo = await walletSign(); @@ -25,10 +26,23 @@ const Login: React.FC = () => { const { redirect } = query as { redirect: string }; history.push(redirect || '/'); }; + const handleQRCodeSubmit = async () => {}; return (
- + 登录 + + + {/* } title={defaultSettings.title as string} initialValues={{ @@ -82,7 +96,7 @@ const Login: React.FC = () => { }, ]} /> - + */}
); diff --git a/src/routes/index.ts b/src/routes/index.ts index 986575d..4581854 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -10,6 +10,44 @@ export default [ layout: false, component: './Login', }, + { + name: 'ALL', + path: RoutePath.ALL, + routes: [ + { + path: RoutePath.ALL, + redirect: RoutePath.ALL_ADDRESS.LIST, + hideInMenu: true, + }, + { + name: '地址管理', + path: RoutePath.ALL_ADDRESS.LIST, + component: './All/Address/List', + }, + { + name: '地址详情', + path: RoutePath.ALL_ADDRESS.EDIT, + hideInMenu: true, + component: './All/Address/Edit', + }, + { + name: '充值记录', + path: RoutePath.ALL_RECORD.LIST, + component: './All/Record/List', + }, + { + name: '币种管理', + path: RoutePath.ALL_CURRENCY.LIST, + component: './Work/List', + }, + { + name: '币种详情', + path: RoutePath.ALL_CURRENCY.EDIT, + hideInMenu: true, + component: './Work/Edit', + }, + ], + }, { name: 'ETH', path: RoutePath.ETH, diff --git a/src/routes/routePath.ts b/src/routes/routePath.ts index 1594520..a82c4b9 100644 --- a/src/routes/routePath.ts +++ b/src/routes/routePath.ts @@ -1,7 +1,20 @@ const SETTING = '/setting'; const ETH = '/eth'; +const ALL = '/all'; const RoutePath = { LOGIN: '/login', + ALL: ALL, + ALL_ADDRESS: { + LIST: `${ALL}/address`, + EDIT: `${ALL}/address/edit`, + }, + ALL_RECORD: { + LIST: `${ALL}/record`, + }, + ALL_CURRENCY: { + LIST: `${ALL}/currency`, + EDIT: `${ALL}/currency/edit`, + }, ETH: ETH, ETH_ADDRESS: { LIST: `${ETH}/address`, diff --git a/src/utils/web3.ts b/src/utils/web3.ts index b64adcb..d5f47a7 100644 --- a/src/utils/web3.ts +++ b/src/utils/web3.ts @@ -1,6 +1,7 @@ import Web3 from 'web3'; import detectEthereumProvider from '@metamask/detect-provider'; import { getData } from '@/services/login'; +import { message } from 'antd'; let provider: any; @@ -28,14 +29,14 @@ export async function initWeb3() { } catch (reason) { switch (reason) { case 'Already processing eth_requestAccounts. Please wait.': // 已有请求存在 - console.log('请打开MetaMask完成授权'); + message.warning('请打开MetaMask完成授权'); break; case 'User rejected provider access': //如果用户拒绝了登录请求 - console.log('请同意登录请求'); + message.warning('请同意登录请求'); break; default: // 本不该执行到这里,但是真到这里了,说明发生了意外 - console.log('登录出错!err:' + reason); + message.warning('登录出错!err:' + reason); break; } } -- 2.40.1 From 07380301b237608e84f593d808676be93ebfc313 Mon Sep 17 00:00:00 2001 From: zzy <> Date: Fri, 8 Jul 2022 17:09:21 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/pages/All/Address/Edit/index.tsx | 3 +-- .../components}/AddAddressModal.tsx | 0 src/pages/All/Address/List/index.tsx | 6 ++--- src/pages/All/Record/List/index.tsx | 23 +++++-------------- .../components}/AddAddressModal.tsx | 0 src/pages/Eth/Address/List/index.tsx | 8 +++---- src/pages/Eth/Record/List/index.tsx | 22 +++++------------- src/utils/bigNumber.ts | 6 +++++ src/utils/formatBalance.ts | 6 +++++ 10 files changed, 32 insertions(+), 45 deletions(-) rename src/pages/All/Address/{Edit => List/components}/AddAddressModal.tsx (100%) rename src/pages/Eth/Address/{Edit => List/components}/AddAddressModal.tsx (100%) create mode 100644 src/utils/bigNumber.ts create mode 100644 src/utils/formatBalance.ts 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)); +}; -- 2.40.1