Skip to content

Commit

Permalink
fix: handle withdraw all (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
trkhoi authored Nov 29, 2023
1 parent e74f065 commit 2bad7a1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/commands/withdraw/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { formatView } from "commands/balances/index/processor"
import CacheManager from "cache/node-cache"
import { BigNumber, utils } from "ethers"
import { getSlashCommand } from "utils/commands"
import { parseUnits } from "ethers/lib/utils"
import { formatEther, parseEther, parseUnits } from "ethers/lib/utils"

type Params = {
amount?: string
Expand Down Expand Up @@ -568,6 +568,12 @@ export async function executeWithdraw(
call: () => Promise.resolve(null),
})

if (payload.amount === "all") {
const balances = await getBalances({ msgOrInteraction: interaction })
const balObj = balances.find((b: any) => b.token.id === payload.tokenId)
payload.amount = formatEther(balObj.amount)
}

// withdraw
const amount = parseUnits(
payload.amount.toLocaleString().replaceAll(",", ""),
Expand Down

0 comments on commit 2bad7a1

Please sign in to comment.