Skip to content

Commit

Permalink
fix big int order amount issue
Browse files Browse the repository at this point in the history
  • Loading branch information
NickJ202 committed Jul 18, 2024
1 parent ae7fc64 commit 02a7f57
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 02a7f57

Please sign in to comment.