From 2d8ac951f4e5d410d5772c3e00e9a7d176a3d24e Mon Sep 17 00:00:00 2001 From: johnykes Date: Thu, 23 Mar 2023 17:51:19 +0200 Subject: [PATCH] SERVICES-1085 BigNumber.toFixed() and check for duplicates before creating auction/offer (for hybrid reindexing states) --- .../reindex-auction-started.handler.ts | 9 ++++++--- .../reindex-offer-created.hander.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/marketplaces/marketplaces-reindex-handlers/reindex-auction-started.handler.ts b/src/modules/marketplaces/marketplaces-reindex-handlers/reindex-auction-started.handler.ts index a93351c5f..3f58fb6eb 100644 --- a/src/modules/marketplaces/marketplaces-reindex-handlers/reindex-auction-started.handler.ts +++ b/src/modules/marketplaces/marketplaces-reindex-handlers/reindex-auction-started.handler.ts @@ -1,5 +1,6 @@ import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; import { Injectable } from '@nestjs/common'; +import BigNumber from 'bignumber.js'; import { constants } from 'src/config'; import { AuctionEntity } from 'src/db/auctions'; import { AuctionStatusEnum } from 'src/modules/auctions/models'; @@ -22,10 +23,12 @@ export class ReindexAuctionStartedHandler { const minBidDenominated = BigNumberUtils.denominateAmount(input.minBid, paymentToken.decimals); const maxBidDenominated = BigNumberUtils.denominateAmount(input.maxBid !== 'NaN' ? input.maxBid : '0', paymentToken.decimals); + marketplaceReindexState.deleteAuctionIfDuplicates(input.auctionId); + const auction = new AuctionEntity({ creationDate: modifiedDate, modifiedDate, - id: marketplaceReindexState.auctions.length, + id: marketplaceReindexState.getNewAuctionId(), marketplaceAuctionId: input.auctionId !== 0 ? input.auctionId : marketplaceReindexState.auctions.length + 1, identifier: input.identifier, collection: input.collection, @@ -36,8 +39,8 @@ export class ReindexAuctionStartedHandler { paymentToken: paymentToken.identifier, paymentNonce, ownerAddress: input.sender, - minBid: input.minBid, - maxBid: input.maxBid !== 'NaN' ? input.maxBid : '0', + minBid: new BigNumber(input.minBid).toFixed(), + maxBid: new BigNumber(input.maxBid !== 'NaN' ? input.maxBid : '0').toFixed(), minBidDenominated: Math.min(minBidDenominated, constants.dbMaxDenominatedValue), maxBidDenominated: Math.min(maxBidDenominated, constants.dbMaxDenominatedValue), minBidDiff: input.minBidDiff ?? '0', diff --git a/src/modules/marketplaces/marketplaces-reindex-handlers/reindex-offer-created.hander.ts b/src/modules/marketplaces/marketplaces-reindex-handlers/reindex-offer-created.hander.ts index 7e45e29c6..d0faa5b76 100644 --- a/src/modules/marketplaces/marketplaces-reindex-handlers/reindex-offer-created.hander.ts +++ b/src/modules/marketplaces/marketplaces-reindex-handlers/reindex-offer-created.hander.ts @@ -1,4 +1,5 @@ import { Injectable } from '@nestjs/common'; +import BigNumber from 'bignumber.js'; import { constants } from 'src/config'; import { OfferEntity } from 'src/db/offers'; import { OfferStatusEnum } from 'src/modules/offers/models'; @@ -14,8 +15,11 @@ export class ReindexOfferCreatedHandler { handle(marketplaceReindexState: MarketplaceReindexState, input: OfferCreatedSummary, decimals: number): void { const modifiedDate = DateUtils.getUtcDateFromTimestamp(input.timestamp); const priceAmountDenominated = BigNumberUtils.denominateAmount(input.price, decimals); + + marketplaceReindexState.deleteOfferIfDuplicates(input.offerId); + const offer = new OfferEntity({ - id: marketplaceReindexState.offers.length, + id: marketplaceReindexState.getNewOfferId(), creationDate: modifiedDate, modifiedDate, marketplaceOfferId: input.offerId, @@ -24,7 +28,7 @@ export class ReindexOfferCreatedHandler { identifier: input.identifier, priceToken: input.paymentToken, priceNonce: input.paymentNonce, - priceAmount: input.price, + priceAmount: new BigNumber(input.price).toFixed(), priceAmountDenominated: Math.min(priceAmountDenominated, constants.dbMaxDenominatedValue), ownerAddress: input.address, endDate: Math.min(input.endTime, constants.dbMaxTimestamp),