Skip to content

Commit

Permalink
Add max button for token transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbqds committed Jan 2, 2024
1 parent e02278a commit f941152
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/components/Multisig/BuildMultisigTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,26 @@ function BuildMultisigTx() {
}
}, [form])

const setMaxToken = useCallback(() => {
const tokenId = form.values.destinations[0].tokenId
const tokenInfo = tokenInfos.find((t) => t.id === tokenId)
if (balance !== undefined && tokenId !== '' && tokenInfo !== undefined) {
const rawAmount = balance.tokenBalances?.find((t) => t.id === tokenId)?.amount ?? 0n
const amount = number256ToNumber(rawAmount, tokenInfo.decimals)
form.setValues({
sweep: false,
destinations: [
{
address: form.values.destinations[0].address,
alphAmount: form.values.destinations[0].alphAmount,
tokenId: form.values.destinations[0].tokenId,
tokenAmount: amount
},
]
})
}
}, [form, balance, tokenInfos])

const buildTxCallback = useCallback(async () => {
try {
// Sweep tx has been built, go to the next step directly
Expand Down Expand Up @@ -453,6 +473,17 @@ function BuildMultisigTx() {
label={
<Group position="apart" w="95%" mx="auto">
<Text>Balance: {showTokenBalance(balance, getTokenInfo())}</Text>
<Button
size={rem(13)}
m={2}
p={3}
variant="light"
color="indigo"
compact
onClick={setMaxToken}
>
Max
</Button>
</Group>
}
ta="left"
Expand Down

0 comments on commit f941152

Please sign in to comment.