From 2bad7a1b0696d9e5d5e68a588ef0dddfabe9849f Mon Sep 17 00:00:00 2001 From: Ngo Trong Khoi <39881166+trkhoi@users.noreply.github.com> Date: Wed, 29 Nov 2023 08:51:09 +0700 Subject: [PATCH] fix: handle withdraw all (#1535) --- src/commands/withdraw/index/processor.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/withdraw/index/processor.ts b/src/commands/withdraw/index/processor.ts index 9d984a9b8..3ea1e6477 100644 --- a/src/commands/withdraw/index/processor.ts +++ b/src/commands/withdraw/index/processor.ts @@ -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 @@ -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(",", ""),