Skip to content

Commit

Permalink
Check user balance
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsm412 committed Oct 2, 2024
1 parent 4d031fe commit d793b03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
);
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();

Expand All @@ -62,15 +64,20 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
!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
Expand Down Expand Up @@ -123,7 +130,8 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
web3TxHandler,
blockchain,
dispatch,
currentCollection
currentCollection,
currentCollectionMetadata
]);

const { getBlockchainData } = useServerSettings();
Expand Down
17 changes: 11 additions & 6 deletions rair-front/src/components/common/PurchaseToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,17 @@ const Agreements: React.FC<IAgreementsPropsType> = ({
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);
}
Expand Down

0 comments on commit d793b03

Please sign in to comment.