Skip to content

Commit

Permalink
SERVICES-1085 BigNumber.toFixed() and check for duplicates before cre…
Browse files Browse the repository at this point in the history
…ating auction/offer (for hybrid reindexing states)
  • Loading branch information
johnykes authored and danielailie committed Nov 8, 2023
1 parent cc4ee60 commit 2d8ac95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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),
Expand Down

0 comments on commit 2d8ac95

Please sign in to comment.