From c8f919ce5aae68b0bfba4c9633cc060559f756ee Mon Sep 17 00:00:00 2001 From: saplf Date: Thu, 5 Sep 2019 23:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/locales/en-US.ts | 20 ++++ src/locales/zh-CN.ts | 20 ++++ src/models/user.ts | 3 +- src/pages/check/service.ts | 2 +- src/pages/draw/index.tsx | 166 ++++++++++++++++++++++++++++++++ src/pages/draw/model.ts | 169 +++++++++++++++++++++++++++++++++ src/pages/draw/service.ts | 55 +++++++++++ src/pages/draw/style.less | 117 +++++++++++++++++++++++ src/pages/home/fund/index.tsx | 13 +-- src/pages/home/fund/model.ts | 32 ++++++- src/pages/home/fund/service.ts | 16 +--- src/pages/home/fund/style.less | 2 + src/pages/mine/index.tsx | 1 + src/pages/mine/model.ts | 6 +- src/pages/mine/service.ts | 5 +- src/pages/mine/style.less | 2 +- src/services/common.ts | 24 ++++- src/types/common.ts | 20 +++- src/utils/storage.ts | 22 +++++ 19 files changed, 658 insertions(+), 37 deletions(-) create mode 100644 src/pages/draw/index.tsx create mode 100644 src/pages/draw/model.ts create mode 100644 src/pages/draw/service.ts create mode 100644 src/pages/draw/style.less diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index 92286fc..5e325ca 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -20,6 +20,7 @@ export default { 'common.ok': 'Ok', 'common.modify': 'Modify', 'common.copied': '复制成功', + 'common.prompt': 'Prompt', 'check.login': 'Sign In', 'check.register': 'Sign Up', @@ -69,6 +70,7 @@ export default { 'home.fund.type1': '挖矿收益', 'home.fund.type2': '社区奖励', 'home.fund.type3': '提币', + 'home.fund.prompt': '尚未设置资金密码,是否前往设置?', 'home.community.total': '累计社区奖励', 'home.community.totalInvited': '成功邀请:{num}人', @@ -96,6 +98,24 @@ export default { 'mine.addressTitle': '充值 {label} 到您的专属地址,即可获得矿晶。扫描二维码或点击地址复制:', 'mine.info': '当你完成充值后,必须回到上一页矿场,点击刷新矿晶列表,平台查账确认后,您才能获赠矿晶。', + 'draw.title': '提币转账', + 'draw.selection': '请选择提取币种', + 'draw.target': '输入目标地址', + 'draw.placeholder': '通常一到二行的随机字符串', + 'draw.amount': '输入提币金额', + 'draw.avaliable': '可用余额:{num} {coin}', + 'draw.fee': '转账费用 {num} {coin}', + 'draw.actual': '预计到账 {num} {coin}', + 'draw.drawHint': '提币金额最低1000起/提币每周仅限一次', + 'draw.draw': 'Draw', + 'draw.qrPrompt': '请安装 App 扫描二维码', + 'draw.targetPrompt': '请填写目标地址', + 'draw.amountLt': '提币金额最低1000起', + 'draw.amountGt': '提币金额超出余额', + 'draw.summary': '你正在提取 {num} {coin} 到 {address}', + 'draw.pwdPrompt': '请输入资金密码', + 'draw.success': '您的提币请求正在处理中!经过区块链网络确认后即可到账,请注意查收。', + 'profile.account': 'Account Settings', 'profile.system': 'System Settings', 'profile.identity': '实名认证', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index e5c89a1..ec7d080 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -20,6 +20,7 @@ export default { 'common.ok': '确定', 'common.modify': '修改', 'common.copied': '复制成功', + 'common.prompt': '提示', 'check.login': '登录', 'check.register': '注册', @@ -69,6 +70,7 @@ export default { 'home.fund.type1': '挖矿收益', 'home.fund.type2': '社区奖励', 'home.fund.type3': '提币', + 'home.fund.prompt': '尚未设置资金密码,是否前往设置?', 'home.community.total': '累计社区奖励', 'home.community.totalInvited': '成功邀请:{num}人', @@ -96,6 +98,24 @@ export default { 'mine.addressTitle': '充值 {label} 到您的专属地址,即可获得矿晶。扫描二维码或点击地址复制:', 'mine.info': '当你完成充值后,必须回到上一页矿场,点击刷新矿晶列表,平台查账确认后,您才能获赠矿晶。', + 'draw.title': '提币转账', + 'draw.selection': '请选择提取币种', + 'draw.target': '输入目标地址', + 'draw.placeholder': '通常一到二行的随机字符串', + 'draw.amount': '输入提币金额', + 'draw.avaliable': '可用余额:{num} {coin}', + 'draw.fee': '转账费用 {num} {coin}', + 'draw.actual': '预计到账 {num} {coin}', + 'draw.drawHint': '提币金额最低1000起/提币每周仅限一次', + 'draw.draw': '提币', + 'draw.qrPrompt': '请安装 App 扫描二维码', + 'draw.targetPrompt': '请填写目标地址', + 'draw.amountLt': '提币金额最低1000起', + 'draw.amountGt': '提币金额超出余额', + 'draw.summary': '你正在提取 {num} {coin} 到 {address}', + 'draw.pwdPrompt': '请输入资金密码', + 'draw.success': '您的提币请求正在处理中!经过区块链网络确认后即可到账,请注意查收。', + 'profile.account': '账户管理', 'profile.system': '系统设置', 'profile.identity': '实名认证', diff --git a/src/models/user.ts b/src/models/user.ts index 66ad1c1..12e2236 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -1,7 +1,7 @@ import { Model } from 'dva'; import _ from 'lodash'; import { getLocale, setLocale } from 'umi-plugin-locale' -import { loadUser, storeUser, clearUser, clearMineList, clearCoins } from '@/utils/storage'; +import { loadUser, storeUser, clearUser, clearMineList, clearCoins, clearDrawCoins } from '@/utils/storage'; import { User } from '@/types/common'; const initState = () => { @@ -47,6 +47,7 @@ const model: Model = { *logout(_, { put, all }) { clearMineList(); clearCoins(); + clearDrawCoins(); yield all([ put({ type: 'clearUser' }), put({ type: 'home/clear' }), diff --git a/src/pages/check/service.ts b/src/pages/check/service.ts index 49f3232..35a2f63 100644 --- a/src/pages/check/service.ts +++ b/src/pages/check/service.ts @@ -31,7 +31,7 @@ export async function signIn(areacode: AreaCode, phone: string, password: string export async function signUp(areacode: AreaCode, phone: string, password: string, code: string, inviter: string): Promise { const { ok, msg, data } = await http.post( - '/sign/up', + '/sign/upwi', { phone: encodePhone(areacode, phone), password, diff --git a/src/pages/draw/index.tsx b/src/pages/draw/index.tsx new file mode 100644 index 0000000..208aad6 --- /dev/null +++ b/src/pages/draw/index.tsx @@ -0,0 +1,166 @@ +/** + * Title: 获取矿晶 + * Routes: + * - ./src/pages/routes + */ +import React, { useEffect } from 'react'; +import { connect, DispatchProp } from 'dva'; +import { Spin, Input, Select, Icon, Button, message, Modal } from 'antd'; +import { formatMessage } from 'umi-plugin-locale'; +import { DrawModelState } from './model'; +import { PageState } from '@/types/common'; +import Header from '@/components/Header'; + +import styles from './style.less'; + +const Option = Select.Option; + +const DrawPage: React.FC = ({ + dispatch, + pageState, + coin, + coins, + balance, + address, + amount, + fee, + actual, + confirmVisible, + confirmLoading, + password, +}) => { + useEffect(() => { + dispatch({ type: 'draw/load' }); + }, []); + + let body; + if (pageState === PageState.Pending) { + body = ( + + ); + } else if (pageState === PageState.Failure) { + body = ( +
{formatMessage({ id: 'common.loadError' })}
+ ); + } else if (pageState === PageState.Success) { + const coinLabel = coin && coin.label.toUpperCase(); + const onScan = () => { + message.warn(formatMessage({ id: 'draw.qrPrompt' })); + } + const confirmContent = ( + dispatch({ type: 'draw/onUpdateState', confirmVisible: false })} + onOk={() => dispatch({ type: 'draw/draw' })} + okText={formatMessage({ id: 'common.ok' })} + cancelText={formatMessage({ id: 'common.cancel' })} + confirmLoading={confirmLoading} + title={formatMessage({ id: 'common.prompt' })} + maskClosable={false} + > + + {formatMessage( + { id: 'draw.summary' }, + { num: amount, coin: coinLabel, address }, + )} + +
+ {formatMessage({ id: 'draw.pwdPrompt' })} + dispatch({ type: 'draw/onUpdateState', password: e.target.value })} + type="password" + /> +
+
+ ); + body = ( + <> +
+
+ {formatMessage({ id: 'draw.selection' })} + +
+
+ +
+
{formatMessage({ id: 'draw.target' }, { label: coinLabel })}
+ } + onChange={e => dispatch({ type: 'draw/changeAddress', payload: e.target.value })} + /> +
+ +
+
+ {formatMessage({ id: 'draw.amount' })} + + {formatMessage( + { id: 'draw.avaliable' }, + { num: balance || 0, coin: coinLabel }, + )} + +
+ dispatch({ type: 'draw/changeAmount', payload: e.target.value })} + /> +
+ {formatMessage({ id: 'draw.fee' }, { num: fee || 0, coin: coinLabel })} +
+
+ {formatMessage({ id: 'draw.actual' }, { num: actual || 0, coin: coinLabel })} +
+
+ + + + {confirmContent} + + ); + } + + return ( +
+
+ +
+
{body}
+
+
+ ); +}; + +export default connect( + ({ draw }: any) => ({ ...draw }), +)(DrawPage); diff --git a/src/pages/draw/model.ts b/src/pages/draw/model.ts new file mode 100644 index 0000000..52beaa9 --- /dev/null +++ b/src/pages/draw/model.ts @@ -0,0 +1,169 @@ +import { Model, routerRedux } from "dva"; +import _ from 'lodash'; +import { PageState, CoinDrawn, FundBasic } from '@/types/common'; +import { getCoins, retrieveBalance, calcFee, withdraw } from './service'; +import { getFundBasic } from '@/services/common'; +import { message, Modal } from 'antd'; +import { formatMessage } from 'umi-plugin-locale'; +import BigNumber from 'bignumber.js'; +import { dispatch } from '@/utils/utils'; + +export interface DrawModelState { + coins: CoinDrawn[]; + pageState: PageState; + coin: CoinDrawn | null; + + basic: FundBasic | null, + balance: string; + address: string; + amount: string; + fee: string; // 转账费用 + actual: string; // 实际到账 + + confirmVisible: boolean; + password: string; + confirmLoading: boolean; +} + +const initState: DrawModelState = { + coins: [], + coin: null, + pageState: PageState.Pending, + + basic: null, + balance: '', + address: '', + amount: '', + fee: '', + actual: '', + + confirmVisible: false, + password: '', + confirmLoading: false, +}; + +const model: Model = { + namespace: 'draw', + + state: initState, + + effects: { + *load(_, { put, call, all }) { + yield put({ type: 'onUpdateState', pageState: PageState.Pending }); + try { + const [coins, basic]: [CoinDrawn[], FundBasic] = yield all([ + call(getCoins), + call(getFundBasic), + ]); + const coin = coins[0]; + yield put({ + type: 'onUpdateState', + pageState: PageState.Success, + coins, + coin, + basic, + balance: retrieveBalance(basic, coin), + }); + } catch (e) { + yield put({ + type: 'onUpdateState', + pageState: PageState.Failure, + }); + } + }, + + *selectCoin({ payload: id }, { put, select }) { + const { coins, basic } = yield select((state: any) => state.draw); + const coin = _.find(coins, ['id', id]); + yield put({ + type: 'onUpdateState', + coin, + balance: retrieveBalance(basic, coin), + }); + }, + + *changeAddress({ payload }, { put }) { + if (!/^[\da-zA-Z]*$/.test(payload)) return; + yield put({ + type: 'onUpdateState', + address: payload, + }) + }, + + *changeAmount({ payload }, { put, select }) { + if (isNaN(payload)) return; + const { coin } = (yield select((state: any) => state.draw)) as DrawModelState; + if (!coin) return; + const { fee, actual } = calcFee(coin, payload); + yield put({ + type: 'onUpdateState', + amount: payload, + fee, + actual, + }); + }, + + *performDraw(_, { put, select }) { + const { + coin, + amount, + address, + balance, + } = (yield select((state: any) => state.draw)) as DrawModelState; + if (!coin || !balance) return; + if (!address) return message.warn(formatMessage({ id: 'draw.targetPrompt' })); + const inputAmount = new BigNumber(amount || 0); + if (inputAmount.lt(1000)) return message.warn(formatMessage({ id: 'draw.amountLt' })); + if (inputAmount.gt(balance)) return message.warn(formatMessage({ id: 'draw.amountGt' })); + yield put({ + type: 'onUpdateState', + confirmVisible: true, + confirmLoading: false, + password: '', + }) + }, + + *draw(_, { put, select, call }) { + const { + coin, + amount, + address, + password, + } = (yield select((state: any) => state.draw)) as DrawModelState; + if (!coin) return; + if (!address) return message.warn(formatMessage({ id: 'draw.targetPrompt' })); + if (!password) return; + yield put({ type: 'onUpdateState', confirmLoading: true }); + try { + yield call(withdraw, coin, address, amount, password); + yield put({ + type: 'onUpdateState', + confirmVisible: false, + }); + Modal.info({ + title: formatMessage({ id: 'common.prompt' }), + content: formatMessage({ id: 'draw.success' }), + okText: formatMessage({ id: 'common.ok' }), + cancelText: formatMessage({ id: 'common.cancel' }), + maskClosable: false, + onOk: () => dispatch(routerRedux.goBack()), + }); + } catch (e) { + message.error(e.message); + } finally { + yield put({ type: 'onUpdateState', confirmLoading: false }); + } + } + }, + + reducers: { + onUpdateState(state, payload) { + return { + ...state, + ...payload, + }; + }, + }, +}; + +export default model; diff --git a/src/pages/draw/service.ts b/src/pages/draw/service.ts new file mode 100644 index 0000000..c559881 --- /dev/null +++ b/src/pages/draw/service.ts @@ -0,0 +1,55 @@ +import http from '@/utils/http'; +import _ from 'lodash'; +import BigNumber from 'bignumber.js'; +import { CoinDrawn, FundBasic } from '@/types/common'; +import { loadDrawCoins, storeDrawCoins } from '@/utils/storage'; + +export async function getCoins(): Promise { + const coinsCached = loadDrawCoins(); + if (coinsCached && coinsCached.length) { + return coinsCached; + } + + const { ok, msg, data } = await http.get('/fund/withdrawCoins'); + + if (!ok || !data) { + throw Error(msg); + } + storeDrawCoins(data); + + return data; +} + +export async function withdraw( + coin: CoinDrawn, + targetAddress: string, + amount: string, + password: string, +): Promise { + const { ok, msg } = await http.post('/fund/withdraw', { + coinId: coin.id, + targetAddress, + amount, + password, + }); + if (ok) return + throw Error(msg); +} + +export function retrieveBalance(basic?: FundBasic, coin?: CoinDrawn): string { + if (!basic || !coin) return ''; + return (basic as any)[coin.label.toLocaleLowerCase()] +} + +export function calcFee(coin: CoinDrawn, input: string): { fee: string, actual: string } { + const fail = { fee: '', actual: '' }; + if (!coin || !input) return fail; + const i = new BigNumber(input); + const f = new BigNumber(coin.fee); + if (i.isNaN() || f.isNaN()) return fail; + const fee = i.times(f); + return { + fee: fee.decimalPlaces(2).toString(), + actual: i.minus(fee).decimalPlaces(2).toString(), + }; +} diff --git a/src/pages/draw/style.less b/src/pages/draw/style.less new file mode 100644 index 0000000..71a1a4d --- /dev/null +++ b/src/pages/draw/style.less @@ -0,0 +1,117 @@ + +@import '../../global.less'; + +.container { + height: 100%; + background: linear-gradient(to bottom, @blue-one, @blue-two); + position: relative; + display: flex; + flex-direction: column; + + :global { + .header { + background-color: rgba(255,255,255,0); + color: white; + } + + .ant-btn-primary { + border-width: 0; + background-color: @blue-one; + } + } +} + +.body { + flex-grow: 1; + overflow: auto; +} + +.none { + text-align: center; + width: 100%; + padding-top: 40%; +} + +.card { + background-color: #fff; + margin: 10px; + padding-bottom: 20px; + box-shadow: 1px 1px 8px rgba(0, 0, 0, .2); + min-height: 60%; + display: flex; + flex-direction: column; + align-items: stretch; +} + +@pLeft: 48px; +@pRight: 30px; +@pTop: 20px; + +.btn { + margin-left: @pLeft; + margin-right: @pRight; + margin-top: 40px; +} + +.section { + padding-left: @pLeft; + padding-right: @pRight; + padding-top: @pTop; + position: relative; + + &::before { + content: ''; + display: block; + position: absolute; + @size: 10px; + width: @size; + height: @size; + background-color: @blue-two; + border-radius: @size / 2; + top: @pTop + @size / 2 + 2px; + left: @pLeft / 2 - @size / 2; + } + + :global { + .app-input { + margin: 8px 0; + } + + .with-postfix { + display: flex; + align-items: baseline; + justify-content: space-between; + } + + .small-info { + font-weight: lighter; + font-size: 0.8rem; + } + + .coin-selection { + display: flex; + align-items: baseline; + + .ant-select { + flex-grow: 1; + margin: 0 4px; + } + } + + .right { + text-align: right; + } + } +} + +.main { + display: flex; + flex-direction: column; + align-items: center; + + :global { + canvas { + margin: 10px 0; + } + } +} diff --git a/src/pages/home/fund/index.tsx b/src/pages/home/fund/index.tsx index e009895..50a9cee 100644 --- a/src/pages/home/fund/index.tsx +++ b/src/pages/home/fund/index.tsx @@ -6,7 +6,6 @@ import { HomeFundModelState } from './model'; import { Journal, JournalOp } from '@/types/common'; import Label from '@/components/Label'; import List from '@/components/List'; -import { dispatch } from '@/utils/utils'; import styles from './style.less'; @@ -19,6 +18,7 @@ const FundPage: React.FC = ({ data, refreshingBasic, errorBasic, + loadingDraw, info, }) => { @@ -42,25 +42,26 @@ const FundPage: React.FC = ({
{formatMessage({ id: 'home.fund.total' })} - {info ? info.balanceSum : 0} + {info ? info.sum : 0} VIC
{formatMessage({ id: 'home.fund.totalVIC' })} - +{info ? info.balanceVIC : 0} VIC + +{info ? info.vic : 0} VIC {formatMessage({ id: 'home.fund.totalUSDT' })} - +{info ? info.balanceUSDT : 0} USDT + +{info ? info.usdt : 0} USDT
dispatch({ type: 'homeFund/gotoDraw' })} > - {formatMessage({ id: 'home.fund.draw' })} + {loadingDraw ? : formatMessage({ id: 'home.fund.draw' })}
@@ -79,7 +80,7 @@ const FundPage: React.FC = ({
{it.detail}
-
{it.timestamp}
+
{it.createdAt}
); diff --git a/src/pages/home/fund/model.ts b/src/pages/home/fund/model.ts index 87754b0..b94aca4 100644 --- a/src/pages/home/fund/model.ts +++ b/src/pages/home/fund/model.ts @@ -1,7 +1,9 @@ import { Model, routerRedux } from 'dva'; -import { message } from 'antd'; +import { message, Modal } from 'antd'; import { Journal, FundBasic } from '@/types/common'; -import { getFundList, getFundBasic } from './service'; +import { getFundList } from './service'; +import { checkFundPwd, getFundBasic } from '@/services/common'; +import { formatMessage } from 'umi-plugin-locale'; export interface HomeFundModelState { refreshingList: boolean; @@ -15,6 +17,7 @@ export interface HomeFundModelState { info: FundBasic | null; pageIndex: number; + loadingDraw: boolean; } const FundModel: Model = { @@ -32,6 +35,7 @@ const FundModel: Model = { info: null, pageIndex: 1, + loadingDraw: false, } as HomeFundModelState, effects: { @@ -99,6 +103,30 @@ const FundModel: Model = { }); } }, + + *gotoDraw(_, { put, select, call }) { + const { loadingDraw } = yield select((state: any) => state.homeFund); + if (loadingDraw) return; + yield put({ type: 'onUpdateState', loadingDraw: true }); + try { + const settled = yield call(checkFundPwd); + if (settled) { + yield put(routerRedux.push('/draw')); + } else { + Modal.confirm({ + okText: formatMessage({ id: 'common.ok' }), + cancelText: formatMessage({ id: 'common.cancel' }), + title: formatMessage({ id: 'common.prompt' }), + content: formatMessage({ id: 'home.fund.prompt' }), + onOk: () => { message.warn('暂未完成,请再次点击'); }, + }); + } + } catch (e) { + message.error(e.message); + } finally { + yield put({ type: 'onUpdateState', loadingDraw: false }); + } + }, }, reducers: { diff --git a/src/pages/home/fund/service.ts b/src/pages/home/fund/service.ts index e5afec3..7a53311 100644 --- a/src/pages/home/fund/service.ts +++ b/src/pages/home/fund/service.ts @@ -1,24 +1,12 @@ import http from '@/utils/http'; -import { Journal, FundBasic } from '@/types/common'; - -export async function getFundBasic(): Promise { - const { - ok, - data, - msg, - } = await http.get('/fund/detail'); - if (ok && data) { - return data; - } - throw Error(msg); -} +import { Journal } from '@/types/common'; export async function getFundList(pageIndex: number, pageSize: number): Promise { const { ok, data, msg, - } = await http.get('/fund/journals', { + } = await http.get('/fund/actions', { pageIndex, pageSize, }); diff --git a/src/pages/home/fund/style.less b/src/pages/home/fund/style.less index bcdee2b..4fe7631 100644 --- a/src/pages/home/fund/style.less +++ b/src/pages/home/fund/style.less @@ -86,6 +86,8 @@ .app-btn { user-select: none; white-space: nowrap; + width: 80px; + text-align: center; background-color: @blue-one; @btn-height: 28px; height: @btn-height; diff --git a/src/pages/mine/index.tsx b/src/pages/mine/index.tsx index ec7f1c6..4589ed4 100644 --- a/src/pages/mine/index.tsx +++ b/src/pages/mine/index.tsx @@ -66,6 +66,7 @@ const MinePage: React.FC = ({ size="small" value={srcValue} onChange={e => dispatch({ type: 'mine/changeSrc', payload: e.target.value })} + type="number" /> {coin && coin.label.toUpperCase()} = {dstValue} {formatMessage({ id: 'mine.mine' })} diff --git a/src/pages/mine/model.ts b/src/pages/mine/model.ts index bd750e7..d739c56 100644 --- a/src/pages/mine/model.ts +++ b/src/pages/mine/model.ts @@ -1,9 +1,7 @@ import { Model, routerRedux } from "dva"; import _ from 'lodash'; -import { message } from 'antd'; -import { Estate, PageState, CoinUnion } from '@/types/common'; +import { PageState, CoinUnion } from '@/types/common'; import { getCoins, calcRate } from './service'; -import { isDev } from '@/utils/utils'; export interface MineModelState { coins: CoinUnion[]; @@ -36,7 +34,7 @@ const model: Model = { type: 'onUpdateState', pageState: PageState.Success, coins, - coin: coins[0], + coin, srcValue: '1', dstValue: calcRate('1', coin && coin.rate), }); diff --git a/src/pages/mine/service.ts b/src/pages/mine/service.ts index dda58d8..0b007f8 100644 --- a/src/pages/mine/service.ts +++ b/src/pages/mine/service.ts @@ -1,8 +1,7 @@ import http from '@/utils/http'; import _ from 'lodash'; import BigNumber from 'bignumber.js'; -import { Estate, EstateType, CoinUnion, CoinSupport, CoinAddress } from '@/types/common'; -import { calcEstate } from '@/utils/transform'; +import { CoinUnion, CoinSupport, CoinAddress } from '@/types/common'; import { loadCoins, storeCoins } from '@/utils/storage'; export async function getCoins(): Promise { @@ -15,7 +14,7 @@ export async function getCoins(): Promise { { ok: sOk, data: sData, msg: sMsg }, { ok: aOk, data: aData, msg: aMsg }, ] = await Promise.all([ - http.get('/fund/coins'), + http.get('/fund/depositCoins'), http.get('/fund/queryAddress'), ]); diff --git a/src/pages/mine/style.less b/src/pages/mine/style.less index 5f4f6a9..23cb7fa 100644 --- a/src/pages/mine/style.less +++ b/src/pages/mine/style.less @@ -24,7 +24,7 @@ .none { text-align: center; width: 100%; - margin-top: 40%; + padding-top: 40%; } .card { diff --git a/src/services/common.ts b/src/services/common.ts index 0626c88..df5af5a 100644 --- a/src/services/common.ts +++ b/src/services/common.ts @@ -1,4 +1,4 @@ -import { AreaCodes, User } from '@/types/common'; +import { AreaCodes, User, FundBasic } from '@/types/common'; import { loadAreaCode, storeAreaCode, loadUser, storeUser } from '@/utils/storage'; import http from '@/utils/http'; @@ -43,3 +43,25 @@ export async function getUserInfo(refresh = false): Promise { throw Error(msg); } + +export async function getFundBasic(): Promise { + const { + ok, + data, + msg, + } = await http.get('/fund/detail'); + if (ok && data) { + return data; + } + throw Error(msg); +} + +export async function checkFundPwd(): Promise { + const { ok, msg, data } = await http.get('/user/checkFundPwd'); + if (ok) { + // 0 未设置;1 已设置 + return data === 1; + } + + throw Error(msg); +} diff --git a/src/types/common.ts b/src/types/common.ts index 600b0e0..ae90670 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -141,6 +141,9 @@ export interface Mine { export type Mines = Mine[]; +/** + * 获取矿晶页面,支持的币种 + */ export interface CoinSupport { id: string; label: string; @@ -155,21 +158,30 @@ export interface CoinAddress { export interface CoinUnion extends CoinSupport, CoinAddress { }; +/** + * 提币页面,支持的币种 + */ +export interface CoinDrawn { + id: string; + label: string; + fee: string; +} + export interface FundBasic { /** * 总余额(以VIC计算) */ - balanceSum: string; + sum: string; /** * 当前VIC余额 */ - balanceVIC: string; + vic: string; /** * 当前USDT余额 */ - balanceUSDT: string; + usdt: string; } export enum JournalType { @@ -207,7 +219,7 @@ export interface Journal { op: JournalOp; - timestamp: string; + createdAt: string; } export interface CommunityBasic { diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 7b832e5..d62805e 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -3,6 +3,7 @@ const userKey = 'user-key'; const areaCodeKey = 'area-code-key'; const mineListKey = 'mine-list-key'; const coinsKey = 'coin-key'; +const drawCoinsKey = 'draw-coin-key'; // user info from now on function storeUser(user: any = undefined) { @@ -72,6 +73,23 @@ function clearCoins() { localStorage.removeItem(coinsKey); } +// coin list info of draw page from now on +function storeDrawCoins(coins: any) { + localStorage.setItem(drawCoinsKey, JSON.stringify(coins)); +} + +function loadDrawCoins() { + try { + return JSON.parse(localStorage.getItem(drawCoinsKey) || 'null'); + } catch (e) { + return null; + } +} + +function clearDrawCoins() { + localStorage.removeItem(drawCoinsKey); +} + export { storeUser, loadUser, @@ -87,4 +105,8 @@ export { storeCoins, loadCoins, clearCoins, + + storeDrawCoins, + loadDrawCoins, + clearDrawCoins, }