From d793b036b52cdcc023db2d16c85c7716403dae72 Mon Sep 17 00:00:00 2001 From: Juan Miguel Sanchez Mola Date: Tue, 1 Oct 2024 22:37:49 -0400 Subject: [PATCH] Check user balance --- .../NftList/NftData/SerialNumberBuySell.tsx | 16 ++++++++++++---- .../src/components/common/PurchaseToken.tsx | 17 +++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/rair-front/src/components/MockUpPage/NftList/NftData/SerialNumberBuySell.tsx b/rair-front/src/components/MockUpPage/NftList/NftData/SerialNumberBuySell.tsx index c020f4c8..87363558 100644 --- a/rair-front/src/components/MockUpPage/NftList/NftData/SerialNumberBuySell.tsx +++ b/rair-front/src/components/MockUpPage/NftList/NftData/SerialNumberBuySell.tsx @@ -43,7 +43,9 @@ const SerialNumberBuySell: React.FC = ({ ); const { primaryColor } = useAppSelector((store) => store.colors); const { databaseResales } = useAppSelector((store) => store.settings); - const { currentCollection } = useAppSelector((store) => store.tokens); + const { currentCollection, currentCollectionMetadata } = useAppSelector( + (store) => store.tokens + ); const dispatch = useAppDispatch(); @@ -62,15 +64,20 @@ const SerialNumberBuySell: React.FC = ({ !offerData || !contractData.diamond || !diamondMarketplaceInstance || - !selectedToken + !selectedToken || + !currentCollectionMetadata.product ) { return; } + const realNumber = ( + BigInt(selectedToken) - + BigInt(currentCollectionMetadata.product?.firstTokenIndex) + ).toString(); const marketplaceContract = diamondMarketplaceInstance; const marketplaceMethod = 'buyMintingOffer'; const marketplaceArguments: any[] = [ offerData.offerIndex, // Offer Index - selectedToken // Token Index + realNumber // Token Index ]; marketplaceArguments.push({ value: offerData.price @@ -123,7 +130,8 @@ const SerialNumberBuySell: React.FC = ({ web3TxHandler, blockchain, dispatch, - currentCollection + currentCollection, + currentCollectionMetadata ]); const { getBlockchainData } = useServerSettings(); diff --git a/rair-front/src/components/common/PurchaseToken.tsx b/rair-front/src/components/common/PurchaseToken.tsx index 932e5fc5..8aafc40c 100644 --- a/rair-front/src/components/common/PurchaseToken.tsx +++ b/rair-front/src/components/common/PurchaseToken.tsx @@ -475,12 +475,17 @@ const Agreements: React.FC = ({ currentUserAddress ); - if ( - userBalance && - contractInstance?.runner?.provider?.getBalance && - BigInt(userBalance?.toString()) < - BigInt(price) * BigInt(amountOfTokensToPurchase) - ) { + const tokenPrice = BigInt(price) + BigInt(amountOfTokensToPurchase); + + if (!userBalance) { + if (setPurchaseStatus) { + setPurchaseStatus(false); + } + reactSwal.fire('Error', "Couldn't load user balance", 'error'); + return; + } + + if (BigInt(userBalance.toString()) < tokenPrice) { if (setPurchaseStatus) { setPurchaseStatus(false); }