import { useEffect, useMemo, useState } from "react"; import useCopyLink from "~/hooks/useCopy"; import { getTime, splitAddress, toThousands } from "~/utils"; import store from "~/store"; import { observer } from "mobx-react"; import { useRouter } from "~/hooks/useRouter"; import BackBar from "~/components/BackBar"; import { Cell, Empty, List, Tabs } from "react-vant"; import { debounce } from 'lodash'; import '~/styles/personal.scss'; import { history_record } from "~/api"; const Record = () => { const { token } = store.state; const { push, location } = useRouter() console.log(location); const recordTabs = useMemo(() => ['充值', '提现', '收益'], []); const [recordIndex, setRecordIndex] = useState(location.state ? location.state.index : 0); const { copyVal } = useCopyLink(); const [query, setQuery] = useState([ { page: 1, page_size: 20 }, { page: 1, page_size: 20 }, { page: 1, page_size: 20 }, ]); const [finished, setFinished] = useState([true, true, true]); const [assetsRecord, setAssetsRecord] = useState([ [] as any[], [] as any[], [] as any[], ]); const getAssetsRecord = debounce(async () => { let res: any = await history_record({ type: recordIndex + 1, ...query[recordIndex] }); if (res.code === 0) { if (res.data.length < 20) { if (assetsRecord[recordIndex].length <= 0) { assetsRecord[recordIndex] = res.data } else { assetsRecord[recordIndex] = [...assetsRecord[recordIndex], ...res.data] } finished[recordIndex] = true setFinished([...finished]); setAssetsRecord([...assetsRecord]); return } query[recordIndex].page = query[recordIndex].page + 1 if (assetsRecord[recordIndex].length <= 0) { assetsRecord[recordIndex] = res.data } else { assetsRecord[recordIndex] = [...assetsRecord[recordIndex], ...res.data] }; finished[recordIndex] = false; setFinished([...finished]); setAssetsRecord([...assetsRecord]); setQuery([...query]); }; }, 200); const renderItem = (index: number) => { let el = [ , , , ]; return el[index]; }; useEffect(() => { token && assetsRecord[recordIndex].length <= 0 && getAssetsRecord(); !token && push('/', null, true); !token && setFinished([true, true, true, true, true, true]); }, [recordIndex, token]); return (
setRecordIndex(index)} align="start" className="tabs" lazyRender > { recordTabs.map((item, index) => ( {renderItem(index)} )) }
) } interface ChildProps { list: any[], copy?: Function, finished: boolean, getData: Function } const RechargeRecord = ( { list, copy, finished, getData }: ChildProps ) => { if (list.length <= 0 || Object.keys(list).length <= 0) return ; return ( getData()} errorText="请求失败,点击重新加载" offset={10}> { list.map((item) => (
{item.name}
{getTime(item.time * 1000)}
交易哈希:{splitAddress(item.tx_hash, 10)} { item.tx_hash && ( copy && copy(item.tx_hash)}> ) }
+{toThousands(item.amount)} {item.symbol}
{item.status === 1 ? '完成' : '確認中'}
)) }
) } const WithdrawRecord = ({ list, finished, getData, copy }: ChildProps) => { if (list.length <= 0 || Object.keys(list).length <= 0) return ; return ( getData()} errorText="请求失败,点击重新加载" offset={10}> { list.map((item, index) => (
提现
{getTime(item.time * 1000)}
交易哈希:{item.tx_hash && splitAddress(item.tx_hash, 8)} {item.tx_hash && { copy && copy(item.tx_hash) }}>}
-{toThousands(item.amount)} {item.symbol}
手續費:{item.withdraw_fee} {item.withdraw_fee_symbol}
{item.status === 4 ? '完成' : '確認中'}
)) }
) } const TransferRecord = ({ list, finished, getData }: ChildProps) => { if (list.length <= 0 || Object.keys(list).length <= 0) return ; return ( getData()} errorText="请求失败,点击重新加载" offset={10}> { list.map((item, index) => (
{item.name}
{getTime(item.time * 1000)}
+{toThousands(item.amount)} {item.symbol}
+{toThousands(item.amount_usdt)} USDT(價值)
)) }
) } export default observer(Record);