From be25aa82c861840f4e9b79129a109cc186f7c636 Mon Sep 17 00:00:00 2001 From: findolor Date: Mon, 21 Oct 2024 10:07:54 +0300 Subject: [PATCH] fix: handle negative values and division operation --- .../tables/OrderTradesListTable.svelte | 46 ++++++++----------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte b/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte index 29f131c33..aaedd77d1 100644 --- a/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte +++ b/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte @@ -83,41 +83,31 @@ {formatUnits( - BigInt(item.outputVaultBalanceChange.amount), + BigInt(item.outputVaultBalanceChange.amount) * BigInt(-1), Number(item.outputVaultBalanceChange.vault.token.decimals ?? 0), )} {item.outputVaultBalanceChange.vault.token.symbol} - {Math.abs( - Number( - formatUnits( - BigInt(item.inputVaultBalanceChange.amount), - Number(item.inputVaultBalanceChange.vault.token.decimals ?? 0), - ), - ) / - Number( - formatUnits( - BigInt(item.outputVaultBalanceChange.amount), - Number(item.outputVaultBalanceChange.vault.token.decimals ?? 0), - ), - ), + {formatUnits( + (BigInt(10 ** 18) * + BigInt(item.inputVaultBalanceChange.amount) * + BigInt(10 ** Number(item.outputVaultBalanceChange.vault.token.decimals ?? 0))) / + (BigInt(-1) * + BigInt(item.outputVaultBalanceChange.amount) * + BigInt(10 ** Number(item.inputVaultBalanceChange.vault.token.decimals ?? 0))), + 18, )} - ({Math.abs( - Number( - formatUnits( - BigInt(item.outputVaultBalanceChange.amount), - Number(item.outputVaultBalanceChange.vault.token.decimals ?? 0), - ), - ) / - Number( - formatUnits( - BigInt(item.inputVaultBalanceChange.amount), - Number(item.inputVaultBalanceChange.vault.token.decimals ?? 0), - ), - ), - )}) + {formatUnits( + (BigInt(10 ** 18) * + BigInt(-1) * + BigInt(item.outputVaultBalanceChange.amount) * + BigInt(10 ** Number(item.inputVaultBalanceChange.vault.token.decimals ?? 0))) / + (BigInt(item.inputVaultBalanceChange.amount) * + BigInt(10 ** Number(item.outputVaultBalanceChange.vault.token.decimals ?? 0))), + 18, + )}