Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue serial number picker #89

Merged
merged 9 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rair-front/src/axios.responseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type TTokenData = {
export type TNftItemResponse = {
success: boolean;
result: TNftItemResult;
tokens?: any;
};

export type TFavotiteTokenData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,22 @@ const NftDataCommonLinkComponent: React.FC<INftDataCommonLinkComponent> = ({

const getAllProduct = useCallback(
async (fromToken: string, toToken: string, attributes: any) => {

setIsLoading(true);
const responseAllProduct = await axios.get<TNftItemResponse>(
`/api/nft/network/${blockchain}/${contract}/${product}?fromToken=${fromToken}&toToken=${toToken}${
attributes ? `&metadataFilters=${JSON.stringify(attributes)}` : ''
}`
);
let responseAllProduct;
if(!window.location.href.includes('/tokens')) {
responseAllProduct = await axios.get<TNftItemResponse>(
`/api/nft/network/${blockchain}/${contract}/${product}?fromToken=${fromToken}&toToken=${toToken}${
attributes ? `&metadataFilters=${JSON.stringify(attributes)}` : ''
}`
);
} else {
responseAllProduct = await axios.get<TNftItemResponse>(
`/api/nft/network/${blockchain}/${contract}/${product}?fromToken=${tokenId}&toToken=${tokenId}${
attributes ? `&metadataFilters=${JSON.stringify(attributes)}` : ''
}`
);
}
const resaleData = await rFetch(
`/api/resales/open?contract=${contract}&blockchain=${blockchain}`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { BreadcrumbsView } from '../Breadcrumbs/Breadcrumbs';
import { changeIPFSLink } from '../utils/changeIPFSLink';

import TitleCollection from './TitleCollection/TitleCollection';
import { useParams } from 'react-router';

const NftDataPageMain: React.FC<INftDataPageMain> = ({
blockchain,
Expand All @@ -52,12 +53,15 @@ const NftDataPageMain: React.FC<INftDataPageMain> = ({
const { tokenData } = useSelector<RootState, InitialNftDataStateType>(
(state) => state.nftDataStore
);
const {tokenId} = useParams();

const [selectVideo, setSelectVideo] = useState<TFileType | undefined>();
const [openVideoplayer, setOpenVideoPlayer] = useState<boolean>(false);
const [verticalImage, setVerticalImage] = useState(false);
const [isFileUrl, setIsFileUrl] = useState<string | undefined>();
const myRef = useRef(null);
const hotdropsVar = import.meta.env.VITE_TESTNET === 'true';
const [serialNumberData, setSerialNumberData] = useState<any>([]);
const [playing, setPlaying] = useState<boolean>(false);
const [tokenDataForResale, setTokenDataForResale] = useState<any>(undefined);
const [, /*offersIndexesData*/ setOffersIndexesData] =
Expand All @@ -74,9 +78,9 @@ const NftDataPageMain: React.FC<INftDataPageMain> = ({
const dispatch = useDispatch();

const getTokenData = useCallback(async () => {
if (tokenData && selectedToken && tokenData[selectedToken]) {
if (tokenData && tokenId) {
const response = await rFetch(
`/api/tokens/id/${tokenData[selectedToken]._id}`,
`/api/tokens/id/${tokenData[0]._id}`,
undefined,
undefined,
undefined
Expand Down Expand Up @@ -151,24 +155,55 @@ const NftDataPageMain: React.FC<INftDataPageMain> = ({
setOpenVideoPlayer(true);
};

const fetchSerialNumberData = useCallback( async() => {
if(tokenId) {
const { data } = await axios.get<TNftItemResponse>(
`/api/nft/network/${blockchain}/${contract}/${product}/numbers`
);

if(data.success && data?.tokens) {
setSerialNumberData(data.tokens);
}

}
}, [])

useEffect(() => {
fetchSerialNumberData();
}, [fetchSerialNumberData])

const fetchTokenOneData = useCallback( async() => {
if(tokenId) {
const { data } = await axios.get<TNftItemResponse>(
`/api/nft/network/${blockchain}/${contract}/${product}?fromToken=${tokenId}&toToken=${tokenId}`
);
}
}, [tokenId])

useEffect(() => {
fetchTokenOneData();
}, [fetchTokenOneData])

const fetchTokenFullData = useCallback(async () => {
const { data } = await axios.get<TNftItemResponse>(
`/api/nft/network/${blockchain}/${contract}/${product}?fromToken=0&toToken=1`
`/api/nft/network/${blockchain}/${contract}/${product}?fromToken=${tokenId}&toToken=${tokenId}`
);

if (data.success) {
if (data.success && tokenId) {
const response = await axios.get<TNftItemResponse>(
`/api/nft/network/${blockchain}/${contract}/${product}?fromToken=0&toToken=${data.result.totalCount}`
`/api/nft/network/${blockchain}/${contract}/${product}?fromToken=${tokenId}&toToken=${tokenId}`
);

const mapping = {};
response.data.result.tokens.forEach((token) => {
mapping[token.token] = token;
});

setTokenFullData(mapping);
getProductsFromOffer();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [blockchain, contract, product, setTokenFullData]);
}, [blockchain, contract, product, setTokenFullData, tokenId]);

useEffect(() => {
fetchTokenFullData();
Expand Down Expand Up @@ -293,7 +328,7 @@ const NftDataPageMain: React.FC<INftDataPageMain> = ({
blockchain={blockchain}
contract={contract}
currentTokenId={
tokenData && selectedToken && tokenData[selectedToken]?._id
tokenDataForResale && tokenDataForResale?._id
}
selectedToken={selectedToken}
classTitle={
Expand All @@ -313,7 +348,7 @@ const NftDataPageMain: React.FC<INftDataPageMain> = ({
contract={contract}
selectedToken={selectedToken}
currentTokenId={
tokenData && selectedToken && tokenData[selectedToken]?._id
tokenDataForResale && tokenDataForResale?._id
}
classTitle={
selectedData?.animation_url && isFileUrl !== 'gif'
Expand Down Expand Up @@ -384,7 +419,7 @@ const NftDataPageMain: React.FC<INftDataPageMain> = ({
tokenData={tokenFullData}
handleClickToken={handleClickToken}
setSelectedToken={setSelectedToken}
totalCount={totalCount}
totalCount={serialNumberData}
blockchain={blockchain as BlockchainType}
offerData={offerData}
product={product}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
const getInfoFromUser = useCallback(async () => {
// find user
if (
selectedToken &&
tokenData?.[selectedToken]?.ownerAddress &&
utils.isAddress(tokenData?.[selectedToken]?.ownerAddress) &&
tokenData?.[selectedToken]?.ownerAddress !== constants.AddressZero
params.tokenId && tokenData &&
Object.values(tokenData)[0]?.ownerAddress &&
utils.isAddress(Object.values(tokenData)[0]?.ownerAddress) &&
Object.values(tokenData)[0]?.ownerAddress !== constants.AddressZero
) {
try {
const result = await axios
.get<TUserResponse>(
`/api/users/${tokenData?.[selectedToken]?.ownerAddress}`
`/api/users/${Object.values(tokenData)[0]?.ownerAddress}`
)
.then((res) => res.data);
if (result.success) {
Expand All @@ -85,7 +85,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
setAccountData(null);
}
}
}, [selectedToken, setAccountData, tokenData]);
}, [params.tokenId, setAccountData, tokenData]);

const buyContract = useCallback(async () => {
if (!contractData || !offerData) {
Expand Down Expand Up @@ -180,7 +180,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
if (
!diamondMarketplaceInstance ||
!selectedToken ||
!tokenData?.[selectedToken]
tokenData && !Object.values(tokenData)[0].uniqueIndexInContract
) {
return;
}
Expand All @@ -196,7 +196,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
}
setResaleData(undefined);
const resaleResponse = await rFetch(
`/api/resales/open?contract=${params.contract}&blockchain=${params.blockchain}&index=${tokenData[selectedToken].uniqueIndexInContract}`
`/api/resales/open?contract=${params.contract}&blockchain=${params.blockchain}&index=${tokenData && Object.values(tokenData)[0].uniqueIndexInContract}`
);
if (!resaleResponse.success) {
return;
Expand All @@ -217,7 +217,8 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
params.contract,
params.blockchain,
tokenData,
selectedToken
selectedToken,
params.tokenId
]);

useEffect(() => {
Expand Down Expand Up @@ -250,7 +251,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
}
*/
const { isConfirmed } = await reactSwal.fire({
imageUrl: tokenData[params.tokenId].metadata.image,
imageUrl: Object.values(tokenData)[0].metadata.image,
imageHeight: '25vh',
title: 'Purchase token',
html: <>Currently owned by: {resaleData.seller}</>,
Expand All @@ -277,7 +278,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
[
params.contract, // address erc721,
currentUserAddress, // address buyer,
tokenData?.[selectedToken]?.ownerAddress, // address seller,
Object.values(tokenData)[0]?.ownerAddress, // address seller,
resaleData.tokenIndex, // uint token,
resaleData.price, // uint tokenPrice,
import.meta.env.VITE_NODE_ADDRESS, // address nodeAddress,
Expand Down Expand Up @@ -331,7 +332,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
if (
selectedToken &&
tokenData &&
tokenData?.[selectedToken]?.isMinted === true
Object.values(tokenData)[0]?.isMinted === true
) {
return (
<div className="container-sell-button-user">
Expand All @@ -342,7 +343,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
alt="User Avatar"
/>
{selectedToken && (
<NavLink to={`/${tokenData?.[selectedToken]?.ownerAddress}`}>
<NavLink to={`/${Object.values(tokenData)[0]?.ownerAddress}`}>
<h5>
{(accountData &&
accountData.nickName &&
Expand All @@ -351,10 +352,10 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
'....' +
accountData.nickName.slice(length - 4)
: accountData && accountData.nickName) ||
(tokenData?.[selectedToken]?.ownerAddress &&
tokenData?.[selectedToken]?.ownerAddress.slice(0, 4) +
(Object.values(tokenData)[0]?.ownerAddress &&
Object.values(tokenData)[0]?.ownerAddress.slice(0, 4) +
'....' +
tokenData?.[selectedToken]?.ownerAddress.slice(
Object.values(tokenData)[0]?.ownerAddress.slice(
length - 4
))}
</h5>
Expand Down Expand Up @@ -389,7 +390,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
}

// Blockchain is correct and offer exists
if (selectedToken && !tokenData?.[selectedToken]?.isMinted && offerData) {
if (tokenData && !Object.values(tokenData)[0]?.isMinted && offerData) {
const rawPrice = BigNumber.from(offerData?.price ? offerData?.price : 0);
const price = numberTooBigThreshold.gte(rawPrice)
? '0.000+'
Expand Down Expand Up @@ -427,7 +428,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
</>
);
// Token is minted
} else if (selectedToken && tokenData?.[selectedToken]?.isMinted) {
} else if (tokenData && Object.values(tokenData)[0]?.isMinted) {
if (resaleData) {
const price = numberTooBigThreshold.gte(resaleData.price)
? '0.000+'
Expand Down Expand Up @@ -456,7 +457,7 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
}
// Current user is owner of the token
if (
tokenData[selectedToken].ownerAddress ===
Object.values(tokenData)[0].ownerAddress ===
currentUserAddress?.toLowerCase()
) {
return (
Expand All @@ -476,8 +477,8 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
src={accountData?.avatar ? accountData.avatar : defaultImage}
alt="User Avatar"
/>
{selectedToken && (
<NavLink to={`/${tokenData?.[selectedToken]?.ownerAddress}`}>
{Object.values(tokenData)[0] && (
<NavLink to={`/${Object.values(tokenData)[0]?.ownerAddress}`}>
<h5>
{(accountData &&
accountData.nickName &&
Expand All @@ -486,10 +487,10 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
'....' +
accountData.nickName.slice(length - 4)
: accountData && accountData.nickName) ||
(tokenData?.[selectedToken]?.ownerAddress &&
tokenData?.[selectedToken]?.ownerAddress.slice(0, 4) +
(Object.values(tokenData)[0]?.ownerAddress &&
Object.values(tokenData)[0]?.ownerAddress.slice(0, 4) +
'....' +
tokenData?.[selectedToken]?.ownerAddress.slice(
Object.values(tokenData)[0]?.ownerAddress.slice(
length - 4
))}
</h5>
Expand Down Expand Up @@ -548,8 +549,8 @@ const SerialNumberBuySell: React.FC<ISerialNumberBuySell> = ({
{tokenData &&
selectedToken &&
tokenDataForResale &&
tokenData?.[selectedToken]?.isMinted &&
currentUserAddress === tokenData[selectedToken].ownerAddress && (
Object.values(tokenData)[0]?.isMinted &&
currentUserAddress === Object.values(tokenData)[0].ownerAddress && (
<button
onClick={() => {
reactSwal.fire({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { memo } from 'react';
import React, { memo, useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { useParams } from 'react-router';

import { RootState } from '../../../../../ducks';
import { ColorStoreType } from '../../../../../ducks/colors/colorStore.types';
Expand All @@ -17,7 +18,8 @@ const CurrentTokensComponent: React.FC<ICurrentTokensComponent> = ({
selectedToken,
handleIsOpen,
onClickItem,
numberRef
numberRef,
totalCount
}) => {
const { primaryButtonColor, textColor, iconColor } = useSelector<
RootState,
Expand All @@ -26,6 +28,8 @@ const CurrentTokensComponent: React.FC<ICurrentTokensComponent> = ({

const { customSecondaryColor } = useServerSettings();

const {tokenId} = useParams();

return (
<>
<div ref={numberRef} className="select-number-container">
Expand Down Expand Up @@ -97,12 +101,13 @@ const CurrentTokensComponent: React.FC<ICurrentTokensComponent> = ({
&#10007;
</div>
</div>
{items &&
items.map((el, index) => {
{totalCount && totalCount.length > 0 &&
totalCount.map((el,index) => {
return (
<div
// className={`select-number-box ${tokenId && Number(tokenId) === el.token ? "selected-box" : ''}`}
className={`select-number-box ${
selectedToken === el.token ? 'selected-box' : ''
tokenId === el.token ? 'selected-box' : ''
} ${el.sold ? 'sold-token' : ''}`}
data-title={` #${el.token}`}
style={{
Expand All @@ -118,9 +123,10 @@ const CurrentTokensComponent: React.FC<ICurrentTokensComponent> = ({
: primaryButtonColor
: primaryButtonColor
}`,
color: `${primaryColor === 'rhyno' ? '#fff' : 'A7A6A6'}`
color: `${primaryColor === 'rhyno' ? '#fff' : 'A7A6A6'}`,
fontWeight: "bold"
}}
key={el.id + index}
key={index}
onClick={() => onClickItem(el.token)}>
{el.sold ? 'Sold' : el.token}
</div>
Expand Down
Loading