Skip to content

Commit f2e8f31

Browse files
authored
fix: handle error in case calc parameters not present (#216)
1 parent 500724b commit f2e8f31

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

core/src/auctions.ts

+26-18
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,32 @@ export const enrichAuctionWithPriceDrop = async function (auction: Auction): Pro
7373
if (!auction.isActive || auction.isFinished) {
7474
return auction;
7575
}
76-
const params = await fetchCalcParametersByCollateralType(auction.network, auction.collateralType);
77-
const auctionWithParams = {
78-
...auction,
79-
secondsBetweenPriceDrops: params.secondsBetweenPriceDrops,
80-
priceDropRatio: params.priceDropRatio,
81-
};
82-
const currentDate = await getNetworkDate(auction.network);
83-
const secondsTillNextPriceDrop = calculateAuctionDropTime(auctionWithParams, currentDate);
84-
const approximateUnitPrice = calculateAuctionPrice(auctionWithParams, currentDate);
85-
const totalPrice = auction.collateralAmount.multipliedBy(approximateUnitPrice);
86-
const transactionGrossProfitDate = calculateTransactionGrossProfitDate(auctionWithParams, currentDate);
87-
return {
88-
...auctionWithParams,
89-
secondsTillNextPriceDrop,
90-
approximateUnitPrice,
91-
totalPrice,
92-
transactionGrossProfitDate,
93-
};
76+
try {
77+
const params = await fetchCalcParametersByCollateralType(auction.network, auction.collateralType);
78+
const auctionWithParams = {
79+
...auction,
80+
secondsBetweenPriceDrops: params.secondsBetweenPriceDrops,
81+
priceDropRatio: params.priceDropRatio,
82+
};
83+
const currentDate = await getNetworkDate(auction.network);
84+
const secondsTillNextPriceDrop = calculateAuctionDropTime(auctionWithParams, currentDate);
85+
const approximateUnitPrice = calculateAuctionPrice(auctionWithParams, currentDate);
86+
const totalPrice = auction.collateralAmount.multipliedBy(approximateUnitPrice);
87+
const transactionGrossProfitDate = calculateTransactionGrossProfitDate(auctionWithParams, currentDate);
88+
return {
89+
...auctionWithParams,
90+
secondsTillNextPriceDrop,
91+
approximateUnitPrice,
92+
totalPrice,
93+
transactionGrossProfitDate,
94+
};
95+
} catch (error) {
96+
console.warn(`auction price drop information is not available for auction "${auction.id}"`);
97+
return {
98+
...auction,
99+
totalPrice: auction.collateralAmount.multipliedBy(auction.unitPrice),
100+
};
101+
}
94102
};
95103

96104
export const enrichAuctionWithPriceDropAndMarketValue = async function (

0 commit comments

Comments
 (0)