Skip to content

Commit

Permalink
Merge pull request rairprotocol#101 from rairprotocol/58-collection-p…
Browse files Browse the repository at this point in the history
…age-user-data

Collection page user data
  • Loading branch information
sarora180673 authored Jul 10, 2024
2 parents e5beb92 + 5e86cf9 commit 3460441
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import ReactPlayer from 'react-player';
import { Provider, useSelector, useStore } from 'react-redux';
import { useNavigate, useParams } from 'react-router-dom';
import axios, { AxiosError } from 'axios';
import { BigNumber, constants, utils } from 'ethers';
import { BigNumber } from 'ethers';
import { formatEther } from 'ethers/lib/utils';

import {
IOffersResponseType,
TUserResponse
} from '../../../axios.responseTypes';
import { IOffersResponseType } from '../../../axios.responseTypes';
import { RootState } from '../../../ducks';
import { ColorStoreType } from '../../../ducks/colors/colorStore.types';
import { ContractsInitialType } from '../../../ducks/contracts/contracts.types';
import { UserType } from '../../../ducks/users/users.types';
import useIPFSImageLink from '../../../hooks/useIPFSImageLink';
import useSwal from '../../../hooks/useSwal';
import useWindowDimensions from '../../../hooks/useWindowDimensions';
Expand Down Expand Up @@ -61,7 +57,6 @@ const NftItemForCollectionViewComponent: React.FC<
const navigate = useNavigate();
const store = useStore();

const [userInfoMinted, setUserInfoMinted] = useState<UserType | null>(null);
const [isFileUrl, setIsFileUrl] = useState<string | undefined>();
const ipfsLink = useIPFSImageLink(metadata?.image);
const [tokenInfo, setTokenInfo] = useState<any>(null);
Expand Down Expand Up @@ -199,20 +194,6 @@ const NftItemForCollectionViewComponent: React.FC<
}
}, [navigate, tokenInfo, contract, blockchain, product, index, item]);

const getInfoFromUser = useCallback(async () => {
// find user
if (
item &&
utils.isAddress(item.ownerAddress) &&
item.ownerAddress !== constants.AddressZero
) {
const result = await axios
.get<TUserResponse>(`/api/users/${item.ownerAddress}`)
.then((res) => res.data);
setUserInfoMinted(result.user);
}
}, [item]);

const initialTokenData = useCallback(() => {
if (item && resaleFlag) {
if (item.contract?.diamond) {
Expand Down Expand Up @@ -313,10 +294,6 @@ const NftItemForCollectionViewComponent: React.FC<
getParticularOffer();
}, [getParticularOffer]);

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

useEffect(() => {
checkUrl();
}, [checkUrl]);
Expand Down Expand Up @@ -517,25 +494,25 @@ const NftItemForCollectionViewComponent: React.FC<
maxHeight: '40px'
}}>
<div>
{item?.isMinted && userInfoMinted ? (
{item?.isMinted && item.ownerData ? (
<div className="collection-block-user-creator">
<img
src={
userInfoMinted.avatar
? userInfoMinted.avatar
item.ownerData?.avatar
? item.ownerData?.avatar
: defaultImage
}
alt="User Avatar"
/>
<h5 style={{ wordBreak: 'break-all' }}>
{userInfoMinted.nickName
? userInfoMinted.nickName.length > 16
? userInfoMinted.nickName.slice(0, 5) +
{item.ownerData?.nickName
? item.ownerData?.nickName.length > 16
? item.ownerData?.nickName.slice(0, 5) +
'...' +
userInfoMinted.nickName.slice(
userInfoMinted.nickName.length - 4
item.ownerData?.nickName.slice(
item.ownerData?.nickName.length - 4
)
: userInfoMinted.nickName
: item.ownerData?.nickName
: userName?.slice(0, 5) +
'....' +
userName?.slice(userName.length - 4)}
Expand Down Expand Up @@ -578,10 +555,10 @@ const NftItemForCollectionViewComponent: React.FC<
)}
</div>
{item && !resaleFlag && item.isMinted && !resalePrice && (
<div className="nft-item-collection-sold-out">
<div className="sold-out-box">Sold out</div>
</div>
)}
<div className="nft-item-collection-sold-out">
<div className="sold-out-box">Sold out</div>
</div>
)}
<div
className="collection-block-price"
style={{ alignItems: 'flex-end' }}>
Expand Down
40 changes: 27 additions & 13 deletions rair-node/bin/api/nft/nft.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,20 +568,34 @@ module.exports = {
},
},
{
$lookup: {
from: 'Offer',
let: populateOptions.let,
pipeline: [
{
$match: {
$expr: {
$and: populateOptions.and,
},
},
},
],
as: 'offer',
$lookup: {
from: 'Offer',
let: populateOptions.let,
pipeline: [
{
$match: {
$expr: {
$and: populateOptions.and,
},
},
},
],
as: 'offer',
},
},
{
$lookup: {
from: 'User',
localField: 'ownerAddress',
foreignField: 'publicAddress',
as: 'ownerData',
},
},
{
$unwind: {
path: '$ownerData',
preserveNullAndEmptyArrays: true,
},
},
{ $unwind: '$offer' },
{ $match: filterOptions },
Expand Down

0 comments on commit 3460441

Please sign in to comment.