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

Collection page user data #101

Merged
merged 3 commits into from
Jul 10, 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
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