Skip to content

Commit

Permalink
catch invalid bigint on quantity input change
Browse files Browse the repository at this point in the history
  • Loading branch information
NickJ202 committed Jul 17, 2024
1 parent aa06d19 commit e007717
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
3 changes: 1 addition & 2 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ import { SelectOptionType, WalletEnum } from './types';
export const AO = {
module: 'Pq2Zftrqut0hdisH_MC2pDOT6S4eQFoxGsFUzR6r350',
scheduler: '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA',
ucm: 'U3TjJAZWJjlWBB4KAXSHKzuky81jtyh0zqH8rUL4Wd0', // Prod
// ucm: 'fToLfaxMZzjmPIiJd7cNlRlzryhSMnU04SELFyJ06j4', // Test
ucm: 'U3TjJAZWJjlWBB4KAXSHKzuky81jtyh0zqH8rUL4Wd0',
defaultToken: 'xU9zFkq3X2ZQ6olwNVvr1vUWIjc3kXTWr7xKQD6dh10',
pixl: 'DM3FoZUq_yebASPhgd8pEIRIzDW6muXEhxz5-JwbZwo',
collectionsRegistry: 'TFWDmf8a3_nw43GCm_CuYlYoylHAjCcFGbgHfDaGcsg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default function AssetActionMarketOrders(props: IProps) {
} else {
let orderAmount = getTotalOrderAmount();
if (denomination) {
orderAmount = orderAmount / denomination;
orderAmount = BigInt(orderAmount) / BigInt(denomination);
}
setInsufficientBalance(Number(getTotalTokenBalance(arProvider.tokenBalances[AO.defaultToken])) < orderAmount);
}
Expand Down Expand Up @@ -208,16 +208,16 @@ export default function AssetActionMarketOrders(props: IProps) {
let transferQuantity: string | number = currentOrderQuantity;

switch (props.type) {
case 'sell':
case 'transfer':
case 'buy':
transferQuantity = getTotalOrderAmount().toString();
if (denomination) {
transferQuantity = Number(currentOrderQuantity) * denomination;
transferQuantity = (BigInt(transferQuantity) / BigInt(denomination)).toString();
}
break;
case 'buy':
transferQuantity = getTotalOrderAmount();
case 'sell':
case 'transfer':
if (denomination) {
transferQuantity = transferQuantity / denomination;
transferQuantity = Number(currentOrderQuantity) * denomination;
}
break;
}
Expand Down Expand Up @@ -446,28 +446,33 @@ export default function AssetActionMarketOrders(props: IProps) {
(a: AssetOrderType, b: AssetOrderType) => Number(a.price) - Number(b.price)
);

let totalQuantity = 0;
let totalPrice = 0;
let totalQuantity: bigint = BigInt(0);
let totalPrice: bigint = BigInt(0);

for (let i = 0; i < sortedOrders.length; i++) {
const quantity = Number(sortedOrders[i].quantity);
const price = Number(sortedOrders[i].price);
const quantity = BigInt(sortedOrders[i].quantity);
const price = BigInt(sortedOrders[i].price);

let inputQuantity = Number(currentOrderQuantity);
if (denomination) inputQuantity = Number(currentOrderQuantity) * denomination;
let inputQuantity;
try {
inputQuantity = BigInt(currentOrderQuantity);
if (denomination) inputQuantity = BigInt(currentOrderQuantity) * BigInt(denomination);

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;
totalQuantity += remainingQty;
totalPrice += remainingQty * price;
break;
} else {
totalQuantity += quantity;
totalPrice += quantity * price;
}
} catch (e: any) {
console.error(e);
inputQuantity = BigInt(0);
}
}

return totalPrice;
} else return 0;
} else {
Expand Down Expand Up @@ -575,10 +580,10 @@ export default function AssetActionMarketOrders(props: IProps) {

function getTotalPriceDisplay() {
let amount = getTotalOrderAmount();
if (props.type === 'buy' && denomination) amount = amount / denomination;
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;
return <CurrencyLine amount={amount || '0'} currency={orderCurrency} />;
return <CurrencyLine amount={amount ? amount.toString() : '0'} currency={orderCurrency} />;
}

function getOrderDetails() {
Expand Down

0 comments on commit e007717

Please sign in to comment.