From 02a7f57f394bf1c402a01207941f2a0adb01dc25 Mon Sep 17 00:00:00 2001 From: NickJ202 Date: Thu, 18 Jul 2024 19:05:36 -0400 Subject: [PATCH] fix big int order amount issue --- .../AssetActionMarketOrders.tsx | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/views/Asset/AssetAction/AssetActionMarket/AssetActionMarketOrders/AssetActionMarketOrders.tsx b/src/views/Asset/AssetAction/AssetActionMarket/AssetActionMarketOrders/AssetActionMarketOrders.tsx index ca240cc..40e0c86 100644 --- a/src/views/Asset/AssetAction/AssetActionMarket/AssetActionMarketOrders/AssetActionMarketOrders.tsx +++ b/src/views/Asset/AssetAction/AssetActionMarket/AssetActionMarketOrders/AssetActionMarketOrders.tsx @@ -160,7 +160,7 @@ export default function AssetActionMarketOrders(props: IProps) { if (!arProvider.tokenBalances || !arProvider.tokenBalances[AO.defaultToken]) { setInsufficientBalance(true); } else { - let orderAmount = getTotalOrderAmount(); + let orderAmount = BigInt(getTotalOrderAmount()); if (denomination) { orderAmount = BigInt(orderAmount) / BigInt(denomination); } @@ -453,24 +453,20 @@ export default function AssetActionMarketOrders(props: IProps) { const quantity = BigInt(sortedOrders[i].quantity); const price = BigInt(sortedOrders[i].price); - let inputQuantity; - try { - inputQuantity = BigInt(currentOrderQuantity); - if (denomination) inputQuantity = BigInt(currentOrderQuantity) * BigInt(denomination); + let inputQuantity: any; + inputQuantity = denomination + ? BigInt((currentOrderQuantity as number) * denomination) + : BigInt(Math.floor(currentOrderQuantity as any)); - if (quantity >= inputQuantity - totalQuantity) { - const remainingQty = inputQuantity - totalQuantity; + if (quantity >= inputQuantity - totalQuantity) { + const remainingQty = inputQuantity - totalQuantity; - totalQuantity += remainingQty; - totalPrice += remainingQty * price; - break; - } else { - totalQuantity += quantity; - totalPrice += quantity * price; - } - } catch (e: any) { - console.error(e); - inputQuantity = BigInt(0); + totalQuantity += remainingQty; + totalPrice += remainingQty * price; + break; + } else { + totalQuantity += quantity; + totalPrice += quantity * price; } } return totalPrice; @@ -579,7 +575,7 @@ export default function AssetActionMarketOrders(props: IProps) { }, [props.asset, props.type, totalAssetBalance, totalSalesQuantity, connectedBalance, ucmReducer]); function getTotalPriceDisplay() { - let amount = getTotalOrderAmount(); + let amount = BigInt(getTotalOrderAmount()); if (props.type === 'buy' && denomination) amount = BigInt(amount) / BigInt(denomination); const orderCurrency = props.asset.orders && props.asset.orders.length ? props.asset.orders[0].currency : AO.defaultToken;