From 9ae95f62b27ffd1804670769835d43d655b0d758 Mon Sep 17 00:00:00 2001 From: Juan Miguel Sanchez Mola Date: Tue, 25 Jun 2024 11:07:29 -0400 Subject: [PATCH 1/3] Remove user data query call --- .../components/MockUpPage/NftList/NftItem.tsx | 50 ++++----------- .../components/MockUpPage/NftList/NftList.tsx | 7 +-- .../MockUpPage/NftList/nftList.types.ts | 1 + .../src/components/ResalePage/ListOffers.tsx | 46 -------------- .../UserProfilePage/UserProfilePage.tsx | 2 +- rair-front/src/ducks/nftData/action.ts | 18 +++--- rair-front/src/ducks/nftData/saga.ts | 2 +- rair-front/src/images/index.tsx | 2 +- .../bin/api/contracts/contracts.Service.js | 61 +++++++++---------- .../integrations/ethers/importContractData.js | 14 +---- 10 files changed, 56 insertions(+), 147 deletions(-) delete mode 100644 rair-front/src/components/ResalePage/ListOffers.tsx diff --git a/rair-front/src/components/MockUpPage/NftList/NftItem.tsx b/rair-front/src/components/MockUpPage/NftList/NftItem.tsx index b91ba10a7..9bb570b2a 100644 --- a/rair-front/src/components/MockUpPage/NftList/NftItem.tsx +++ b/rair-front/src/components/MockUpPage/NftList/NftItem.tsx @@ -8,17 +8,11 @@ import React, { import ReactPlayer from 'react-player'; import { useNavigate } from 'react-router-dom'; import axios from 'axios'; -import { constants, utils } from 'ethers'; import { useStateIfMounted } from 'use-state-if-mounted'; import { INftItemComponent } from './nftList.types'; -import { - TNftItemResponse, - TTokenData, - TUserResponse -} from '../../../axios.responseTypes'; -import { UserType } from '../../../ducks/users/users.types'; +import { TNftItemResponse, TTokenData } from '../../../axios.responseTypes'; import useIPFSImageLink from '../../../hooks/useIPFSImageLink'; import useWindowDimensions from '../../../hooks/useWindowDimensions'; import { defaultHotDrops } from '../../../images'; @@ -44,15 +38,13 @@ const NftItemComponent: React.FC = ({ index, playing, setPlaying, - className + className, + userData }) => { const navigate = useNavigate(); const [metaDataProducts, setMetaDataProducts] = useStateIfMounted< TTokenData | undefined >(undefined); - const [accountData, setAccountData] = useStateIfMounted( - null - ); const [isFileUrl, setIsFileUrl] = useState(); const { width } = useWindowDimensions(); @@ -79,20 +71,6 @@ const NftItemComponent: React.FC = ({ } }, [metaDataProducts, setIsFileUrl]); - const getInfoFromUser = useCallback(async () => { - // find user - if ( - ownerCollectionUser && - utils.isAddress(ownerCollectionUser) && - ownerCollectionUser !== constants.AddressZero - ) { - const result = await axios - .get(`/api/users/${ownerCollectionUser}`) - .then((res) => res.data); - setAccountData(result.user); - } - }, [ownerCollectionUser, setAccountData]); - const handlePlaying = (el?: unknown) => { if (el === null) { setPlaying(null); @@ -223,10 +201,6 @@ const NftItemComponent: React.FC = ({ getProductAsync(); }, [getProductAsync]); - useEffect(() => { - getInfoFromUser(); - }, [getInfoFromUser]); - const displayImage = metaDataProducts?.metadata?.image_thumbnail ? metaDataProducts.metadata.image_thumbnail : ipfsLink @@ -366,25 +340,23 @@ const NftItemComponent: React.FC = ({ {collectionName.length > 12 ? '...' : ''}
- {accountData ? ( + {userData ? (
User Avatar
- {accountData.nickName - ? accountData.nickName.length > 16 - ? accountData.nickName.slice(0, 5) + + {userData.nickName + ? userData.nickName.length > 16 + ? userData.nickName.slice(0, 5) + '...' + - accountData.nickName.slice( - accountData.nickName.length - 4 + userData.nickName.slice( + userData.nickName.length - 4 ) - : accountData.nickName + : userData.nickName : ownerCollectionUser.slice(0, 5) + '...' + ownerCollectionUser.slice( diff --git a/rair-front/src/components/MockUpPage/NftList/NftList.tsx b/rair-front/src/components/MockUpPage/NftList/NftList.tsx index 316c4809b..26d550cf7 100644 --- a/rair-front/src/components/MockUpPage/NftList/NftList.tsx +++ b/rair-front/src/components/MockUpPage/NftList/NftList.tsx @@ -42,7 +42,7 @@ const NftListComponent: React.FC = ({ ? defaultHotDrops : `${ import.meta.env.VITE_IPFS_GATEWAY - }/QmNtfjBAPYEFxXiHmY5kcPh9huzkwquHBcn9ZJHGe7hfaW`; + }QmcV94NurwfWVGpXTST1we8uDbYiVQamKe87WEHK6DRzqa`; const filteredData = data && @@ -79,15 +79,14 @@ const NftListComponent: React.FC = ({ if (contractData.cover !== 'none') { return ( String(p.price))} blockchain={contractData.blockchain} collectionName={contractData.name} ownerCollectionUser={contractData.user} + userData={contractData.userData} index={index} playing={playing} setPlaying={setPlaying} diff --git a/rair-front/src/components/MockUpPage/NftList/nftList.types.ts b/rair-front/src/components/MockUpPage/NftList/nftList.types.ts index 871640922..d048cf399 100644 --- a/rair-front/src/components/MockUpPage/NftList/nftList.types.ts +++ b/rair-front/src/components/MockUpPage/NftList/nftList.types.ts @@ -30,6 +30,7 @@ export interface INftItemComponent { playing: number | null; setPlaying: (arg: null | number) => void; className?: string; + userData: UserType; } export type TSortChoice = 'down' | 'up'; diff --git a/rair-front/src/components/ResalePage/ListOffers.tsx b/rair-front/src/components/ResalePage/ListOffers.tsx deleted file mode 100644 index 3b960f1cb..000000000 --- a/rair-front/src/components/ResalePage/ListOffers.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { useSelector } from 'react-redux'; - -import { NftItem } from './ItemOffer'; -import { IListOffersComponent } from './listOffers.types'; - -import { RootState } from '../../ducks'; -import LoadingComponent from '../common/LoadingComponent'; - -const ListOffers: React.FC = ({ data }) => { - const loading = useSelector( - (store) => store.nftDataStore.loading - ); - - if (loading) { - return ; - } - return ( -
- {data && data.length > 0 ? ( - data - .filter((resaleOffer) => resaleOffer.status === '0') - .map((resaleOffer, index) => { - return ( - - ); - }) - ) : ( -
-

No items to display

-
- )} -
- ); -}; - -export default ListOffers; diff --git a/rair-front/src/components/UserProfilePage/UserProfilePage.tsx b/rair-front/src/components/UserProfilePage/UserProfilePage.tsx index 232cd6b85..2f2a13bd4 100644 --- a/rair-front/src/components/UserProfilePage/UserProfilePage.tsx +++ b/rair-front/src/components/UserProfilePage/UserProfilePage.tsx @@ -143,7 +143,7 @@ const UserProfilePage: React.FC = () => { const covers = contractsFiltered.map((item: TContract) => ({ id: item._id, - productId: item.products?._id ?? 'wut', + productId: item.products?._id, blockchain: item.blockchain, collectionIndexInContract: item.products.collectionIndexInContract, contract: item.contractAddress, diff --git a/rair-front/src/ducks/nftData/action.ts b/rair-front/src/ducks/nftData/action.ts index 27eb96704..a2067ac6b 100644 --- a/rair-front/src/ducks/nftData/action.ts +++ b/rair-front/src/ducks/nftData/action.ts @@ -6,47 +6,47 @@ import { TTokenData } from '../../axios.responseTypes'; const getNftDataStart = () => ({ type: types.GET_NFTLIST_START - } as const); + }) as const; const getNftDataStartWithParams = (params: object) => ({ type: types.GET_NFTLIST_START, params - } as const); + }) as const; const setNftData = (nftList: Array) => ({ type: types.GET_NFTLIST_COMPLETE, nftList - } as const); + }) as const; const getNftListTotal = (nftListTotal: number) => ({ type: types.GET_NFT_LIST_TOTAL, nftListTotal - } as const); + }) as const; const getNftListTotalClear = () => ({ type: types.GET_NFT_TOTAL_CLEAR - } as const); + }) as const; const getNftDataError = (errorMessage: string) => ({ type: types.GET_NFT_DATA_ERROR, errorMessage - } as const); + }) as const; const setTokenDataStart = () => ({ type: types.SET_TOKEN_DATA_START - } as const); + }) as const; const setTokenData = (tokenData: { [index: string]: TTokenData }) => - ({ type: types.SET_TOKEN_DATA, tokenData } as const); + ({ type: types.SET_TOKEN_DATA, tokenData }) as const; const setTokenDataTotalCount = (tokenDataListTotal) => - ({ type: types.SET_TOKEN_DATA_TOTAL_COUNT, tokenDataListTotal } as const); + ({ type: types.SET_TOKEN_DATA_TOTAL_COUNT, tokenDataListTotal }) as const; export { getNftDataError, diff --git a/rair-front/src/ducks/nftData/saga.ts b/rair-front/src/ducks/nftData/saga.ts index f0d18c9e8..46795be14 100644 --- a/rair-front/src/ducks/nftData/saga.ts +++ b/rair-front/src/ducks/nftData/saga.ts @@ -28,7 +28,7 @@ export function* setNftDataContract({ params }: TParamsNftDataProps) { if (data.success) { const covers = data.contracts.map((item: TContract) => ({ id: item._id, - productId: item.products?._id ?? 'wut', + productId: item.products?._id, blockchain: item.blockchain, collectionIndexInContract: item.products.collectionIndexInContract, contract: item.contractAddress, diff --git a/rair-front/src/images/index.tsx b/rair-front/src/images/index.tsx index b4352b24a..aa5f45588 100644 --- a/rair-front/src/images/index.tsx +++ b/rair-front/src/images/index.tsx @@ -11,6 +11,7 @@ import avatar from './defaultAvatarProfile.webp'; import discordIconWhiteNoBorder from './discord-white-no-border.webp'; import documentIcon from './documentIcon.svg'; import ethereum from './ethereum-logo.svg'; +import tokenLogoRair from './favicon2.png'; import grandpaGif from './grandpa.gif'; import hotdropsDefaultBanner from './hotDrops_defaultBanner.png'; import defaultHotDropsImg from './hotdrops-default.png'; @@ -35,7 +36,6 @@ import rairTechLogoWhite from './rairTechLogoWhite.webp'; import rarible from './rarible-logo.webp'; import verifiedIcon from './verify-icon.png'; import yotiLogo from './yoti-logo.png'; -import tokenLogoRair from './favicon2.png'; // images export const bgLogoBlack = blackBg; diff --git a/rair-node/bin/api/contracts/contracts.Service.js b/rair-node/bin/api/contracts/contracts.Service.js index 56868be39..9367bf883 100644 --- a/rair-node/bin/api/contracts/contracts.Service.js +++ b/rair-node/bin/api/contracts/contracts.Service.js @@ -220,6 +220,34 @@ module.exports = { }, }; options.push(lookupProduct, { $unwind: '$products' }); + const lookupUser = { + $lookup: { + from: 'User', + let: { + usr: '$user', + }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { + $eq: ['$publicAddress', '$$usr'], + }, + ], + }, + }, + }, + ], + as: 'userData', + }, + }; + options.push(lookupUser, { + $unwind: { + path: '$userData', + preserveNullAndEmptyArrays: true, + }, + }); if (category.length > 0) { const categoryIds = category.map((cat) => new ObjectId(cat)); @@ -262,38 +290,6 @@ module.exports = { } options.push( - { - $lookup: { - from: 'OfferPool', - let: { - contr: '$_id', - prod: '$products.collectionIndexInContract', - }, - pipeline: [ - { - $match: { - $expr: { - $and: [ - { - $eq: ['$contract', '$$contr'], - }, - { - $eq: ['$product', '$$prod'], - }, - ], - }, - }, - }, - ], - as: 'offerPool', - }, - }, - { - $unwind: { - path: '$offerPool', - preserveNullAndEmptyArrays: true, - }, - }, { $lookup: { from: 'Offer', @@ -326,7 +322,6 @@ module.exports = { { diamond: true, 'products.offers': { $not: { $size: 0 } } }, { diamond: { $in: [false, undefined] }, - offerPool: { $ne: null }, 'products.offers': { $not: { $size: 0 } }, }, ], diff --git a/rair-node/bin/integrations/ethers/importContractData.js b/rair-node/bin/integrations/ethers/importContractData.js index 22fa1e029..94b58f3b1 100644 --- a/rair-node/bin/integrations/ethers/importContractData.js +++ b/rair-node/bin/integrations/ethers/importContractData.js @@ -2,7 +2,7 @@ const { Alchemy } = require('alchemy-sdk'); const fetch = require('node-fetch'); const log = require('../../utils/logger')(module); -const { Contract, Product, Offer, OfferPool, MintedToken } = require('../../models'); +const { Contract, Product, Offer, MintedToken } = require('../../models'); const { alchemy } = require('../../config'); const { processMetadata } = require('../../utils/metadataClassify'); const { emitEvent } = require('../socket.io'); @@ -77,7 +77,6 @@ const insertToken = async (token, contractId) => { uniqueIndexInContract: token.tokenId, isMinted: true, offer: 0, - offerPool: 0, product: 0, }, { upsert: true, @@ -101,7 +100,6 @@ module.exports = { let contract; let product; let offer; - let offerPool; // Optional Config object, but defaults to demo api-key and eth-mainnet. const settings = { @@ -185,7 +183,6 @@ module.exports = { offerIndex: 0, contract: contract._id, product: 0, - offerPool: 0, copies: contractMetadata.totalSupply, soldCopies: contractMetadata.totalSupply - 1, sold: true, @@ -195,18 +192,10 @@ module.exports = { diamondRangeIndex: 0, transactionHash: 'UNKNOWN - External Import', }); - offerPool = new OfferPool({ - marketplaceCatalogIndex: 0, - contract: contract._id, - product: 0, - rangeNumber: 0, - transactionHash: 'UNKNOWN - External Import', - }); } else { update = true; product = await Product.findOne({ contract: contract._id }); offer = await Offer.findOne({ contract: contract._id }); - offerPool = await OfferPool.findOne({ contract: contract._id }); } // Can't be used, it doesn't say which NFT they own @@ -253,7 +242,6 @@ module.exports = { await contract.save(); await product.save(); await offer.save(); - await offerPool.save(); await processMetadata(contract._id, product.collectionIndexInContract); emitEvent(socket)( From 0313b31230bc446bccf37c5c4402408ff1dcb6eb Mon Sep 17 00:00:00 2001 From: Juan Miguel Sanchez Mola Date: Tue, 25 Jun 2024 12:16:36 -0400 Subject: [PATCH 2/3] Optional user data --- rair-front/src/components/MockUpPage/NftList/nftList.types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rair-front/src/components/MockUpPage/NftList/nftList.types.ts b/rair-front/src/components/MockUpPage/NftList/nftList.types.ts index d048cf399..9fbab49f0 100644 --- a/rair-front/src/components/MockUpPage/NftList/nftList.types.ts +++ b/rair-front/src/components/MockUpPage/NftList/nftList.types.ts @@ -30,7 +30,7 @@ export interface INftItemComponent { playing: number | null; setPlaying: (arg: null | number) => void; className?: string; - userData: UserType; + userData?: UserType; } export type TSortChoice = 'down' | 'up'; From 7c777158a01db16703be0f7d47b343a9c6c6d51d Mon Sep 17 00:00:00 2001 From: Juan Miguel Sanchez Mola Date: Tue, 25 Jun 2024 21:12:52 -0400 Subject: [PATCH 3/3] Update import logic --- .../integrations/ethers/importContractData.js | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/rair-node/bin/integrations/ethers/importContractData.js b/rair-node/bin/integrations/ethers/importContractData.js index 94b58f3b1..c5ef97398 100644 --- a/rair-node/bin/integrations/ethers/importContractData.js +++ b/rair-node/bin/integrations/ethers/importContractData.js @@ -117,7 +117,7 @@ module.exports = { } const alchemySDK = new Alchemy(settings); - let update = false; + let update = true; contract = await Contract.findOne({ contractAddress, @@ -166,20 +166,32 @@ module.exports = { contractAddress, blockchain: networkId, importedBy: importerAddress, - diamond: false, + diamond: true, external: true, }); + update = false; + } + + product = await Product.findOne({ contract: contract._id }); + if (!product) { product = new Product({ name: contractMetadata.name, collectionIndexInContract: 0, contract: contract._id, copies: contractMetadata.totalSupply, soldCopies: contractMetadata.totalSupply, + diamond: true, sold: true, firstTokenIndex: 0, transactionHash: 'UNKNOWN - External Import', }); + update = false; + } + + offer = await Offer.findOne({ contract: contract._id }); + if (!offer) { offer = new Offer({ + diamond: true, offerIndex: 0, contract: contract._id, product: 0, @@ -192,10 +204,7 @@ module.exports = { diamondRangeIndex: 0, transactionHash: 'UNKNOWN - External Import', }); - } else { - update = true; - product = await Product.findOne({ contract: contract._id }); - offer = await Offer.findOne({ contract: contract._id }); + update = false; } // Can't be used, it doesn't say which NFT they own @@ -239,6 +248,9 @@ module.exports = { } try { + if (!contract || !product || !offer) { + throw Error('Missing information for database'); + } await contract.save(); await product.save(); await offer.save();