diff --git a/src/pages/Stc/Batch/BatchTransfer.tsx b/src/pages/Stc/Batch/BatchTransfer.tsx index bd89ac4..075d2df 100644 --- a/src/pages/Stc/Batch/BatchTransfer.tsx +++ b/src/pages/Stc/Batch/BatchTransfer.tsx @@ -15,24 +15,27 @@ import {visuallyHidden} from '@mui/utils'; import Button from "@mui/material/Button"; import {NANO_STC} from "../../../utils/consts"; -import {batchTransfer_v2} from "../../../utils/stcWalletSdk"; +import {batchTransfer_v2, getTokenList} from "../../../utils/stcWalletSdk"; import {useTranslation} from "react-i18next"; +import {useMemo, useState} from "react"; +import {FormControl, InputLabel, MenuItem, Select, SelectChangeEvent} from "@mui/material"; +import {useAppSelector} from "../../../store/hooks"; interface Data { - stc: number; + tokenAmount: number; address: string; - nanoSTC: number; + nanoToken: number; } function createData( address: string, - stc: number, - nanoSTC: number, + tokenAmount: number, + nanoToken: number, ): Data { return { address, - stc, - nanoSTC + tokenAmount, + nanoToken }; } @@ -90,16 +93,16 @@ const headCells: readonly HeadCell[] = [ label: 'address', }, { - id: 'stc', + id: 'tokenAmount', numeric: true, disablePadding: false, - label: 'STC', + label: 'Token amount', }, { - id: 'nanoSTC', + id: 'nanoToken', numeric: true, disablePadding: false, - label: 'nanoSTC', + label: 'nano Token', }, ]; @@ -127,7 +130,7 @@ function EnhancedTableHead(props: EnhancedTableProps) { {headCells.map((headCell) => ( @@ -178,7 +181,7 @@ const EnhancedTableToolbar = (props: EnhancedTableToolbarProps) => { variant="subtitle1" component="div" > - total address: {numSelected} total STC:{totalStc} + total address: {numSelected} total Token Amount: {totalStc} @@ -198,16 +201,38 @@ interface Props { export default function BatchTransfer(props: Props) { - - const {addressArray} = props; - const [order, setOrder] = React.useState('asc'); - const [orderBy, setOrderBy] = React.useState('nanoSTC'); + const [orderBy, setOrderBy] = React.useState('nanoToken'); const [selected, setSelected] = React.useState([]); const [page] = React.useState(0); const [dense] = React.useState(true); const [rowsPerPage] = React.useState(5); + const [token, setToken] = useState("0x00000000000000000000000000000001::STC::STC") + const [tokenList, setTokenList] = useState(["0x00000000000000000000000000000001::STC::STC"]) + const accountAddresses = useAppSelector((state:any) => state.wallet.accountAddress) + useMemo(async ()=>{ + const fetch = async ()=>{ + + const tokenObj = await getTokenList(accountAddresses[0]) + let tokens :string[]; + if (tokenObj){ + tokens = Object.keys(tokenObj).map((item)=>{ + return item + }) + }else { + tokens = ["0x00000000000000000000000000000001::STC::STC"] + } + setTokenList(tokens) + } + if (accountAddresses[0]){ + await fetch() + } + + },[accountAddresses]) + + + const rows: Data[] = []; @@ -217,16 +242,16 @@ export default function BatchTransfer(props: Props) { }) - let totalStc = 0; - const computeTotalStc = () => { + let totalToken; + const computeTotalToken = () => { window.console.info(rows) - let totalStc = 0; + let totalToken = 0; rows.forEach(v => { - totalStc += v.stc + totalToken += v.tokenAmount }) - return totalStc; + return totalToken; } - totalStc = computeTotalStc(); + totalToken = computeTotalToken(); const handleRequestSort = ( @@ -279,9 +304,9 @@ export default function BatchTransfer(props: Props) { await batchTransfer_v2(rows.map(v => { return { account: v.address, - amount: v.stc + amount: v.tokenAmount } - })) + }),token) } catch (e: any) { if (e.toString().includes("UNSUPPORTED_OPERATION")) { @@ -296,6 +321,11 @@ export default function BatchTransfer(props: Props) { } + const handleChangeToken = (event: SelectChangeEvent) => { + setToken(event.target.value as string); + }; + + const isSelected = (name: string) => selected.indexOf(name) !== -1; // Avoid a layout jump when reaching the last page with empty rows. @@ -305,7 +335,26 @@ export default function BatchTransfer(props: Props) { return ( - + + Token + + + + + {row.address} - {row.stc} - {row.nanoSTC} + {row.tokenAmount} + {row.nanoToken} ); })} diff --git a/src/utils/stcWalletSdk.ts b/src/utils/stcWalletSdk.ts index 190a9be..ec2f16c 100644 --- a/src/utils/stcWalletSdk.ts +++ b/src/utils/stcWalletSdk.ts @@ -68,7 +68,7 @@ export async function transfer(account: string, stcAmount: number, content: stri } -export async function batchTransfer_v2(input: BatchTransferInput[]) { +export async function batchTransfer_v2(input: BatchTransferInput[],token:string) { const toAddress: string[] = [] @@ -80,7 +80,7 @@ export async function batchTransfer_v2(input: BatchTransferInput[]) { try { const functionId = '0x1::TransferScripts::batch_peer_to_peer_v2' - const tyArgs = ['0x1::STC::STC'] + const tyArgs = [token] const args = [ toAddress, toAmount @@ -122,6 +122,12 @@ export async function batchTransfer_v2(input: BatchTransferInput[]) { } +export async function getTokenList(address:string){ + const starcoinProvider = await getProvder(); + return await starcoinProvider.getBalances(address) +} + + export interface BatchTransferInput { account: string amount: number