From aef84d56dc871efa8c3d29422d5387c26788d740 Mon Sep 17 00:00:00 2001 From: "saeta.eth" Date: Tue, 8 Feb 2022 13:29:42 -0300 Subject: [PATCH 1/3] wip --- packages/dapp/components/Gallery/Cell/Cell.js | 8 ++++---- .../dapp/components/Gallery/Cell/Cell.module.scss | 2 +- packages/dapp/components/Gallery/Grid/Grid.js | 11 ++++++----- packages/dapp/hooks/useGallery.js | 8 +++++++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/dapp/components/Gallery/Cell/Cell.js b/packages/dapp/components/Gallery/Cell/Cell.js index 84bebfb..f8ef692 100644 --- a/packages/dapp/components/Gallery/Cell/Cell.js +++ b/packages/dapp/components/Gallery/Cell/Cell.js @@ -13,7 +13,7 @@ import styles from './Cell.module.scss'; const MAX_PRIORITY_ITEMS = 24; -const Cell = ({ assetId, isRevealed, kind, isMiddleCell }) => { +const Cell = ({ assetId, tokenId, isRevealed, kind, isMiddleCell }) => { const { breakpoint } = useBreakpoint(BREAKPOINTS, 'desktop'); const isMobile = breakpoint === 'mobile'; @@ -37,7 +37,7 @@ const Cell = ({ assetId, isRevealed, kind, isMiddleCell }) => { return (
{ {...imageSize} {...imageSize} className={styles.image} - priority={hasPriority} + priority={hasPriority.toString()} /> - #{assetId} + #{tokenId}
); }; diff --git a/packages/dapp/components/Gallery/Cell/Cell.module.scss b/packages/dapp/components/Gallery/Cell/Cell.module.scss index a914094..3ebabed 100644 --- a/packages/dapp/components/Gallery/Cell/Cell.module.scss +++ b/packages/dapp/components/Gallery/Cell/Cell.module.scss @@ -11,7 +11,7 @@ width: 360px; } - .assetId { + .tokenId { top: -22px; position: relative; left: 6px; diff --git a/packages/dapp/components/Gallery/Grid/Grid.js b/packages/dapp/components/Gallery/Grid/Grid.js index 6efcf6f..7532635 100644 --- a/packages/dapp/components/Gallery/Grid/Grid.js +++ b/packages/dapp/components/Gallery/Grid/Grid.js @@ -22,11 +22,11 @@ const Grid = ({ items, kind }) => { const chunks = useMemo(() => chunk(items, columns), [items, columns]); - const isMiddleCell = (assetId) => { + const isMiddleCell = (tokenId) => { if (kind === ME) return false; return chunks.some((item) => { - return item[1]?.assetId === assetId; + return item[1]?.tokenId === tokenId; }); }; @@ -39,11 +39,12 @@ const Grid = ({ items, kind }) => { [styles.mobileGrid]: isMobile, })} > - {items?.map(({ assetId, isRevealed }) => { - const isMiddle = isMiddleCell(assetId); + {items?.map(({ assetId, tokenId, isRevealed }) => { + const isMiddle = isMiddleCell(tokenId); return ( { Ethernauts.totalSupply().then(Number), ]); + const batchNumber = Math.floor(tokenId / batchSize); + const maxTokenIdRevealed = totalSupply - (totalSupply % batchSize) - 1; const logs = await provider.getLogs(filter); + const randomNumber = await Ethernauts.getRandomNumberForBatch(batchNumber); + const offset = Number(randomNumber.mod(batchSize)); + const galleryItems = await logs.reduce(async (pGalleryItems, curr) => { const galleryItems = await pGalleryItems; @@ -59,12 +64,13 @@ const useGallery = () => { const to = parsedLog.args.to.toLowerCase(); const tokenId = parsedLog.args.tokenId.toNumber(); - const assetId = await Ethernauts.getAssetIdForTokenId(tokenId); + // const assetId = await Ethernauts.getAssetIdForTokenId(tokenId); // getAssetIdForTokenId returns "assetId,boolean" so it takes the first position; const [formattedAssetId] = assetId.toString().split(','); const item = { + tokenId, assetId: formattedAssetId, owner: to, isRevealed: tokenId <= maxTokenIdRevealed, From 8a1a754bc253988dfbce0a11e0d9f9da207804f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mati=CC=81as?= Date: Tue, 8 Feb 2022 17:38:54 +0100 Subject: [PATCH 2/3] update gallery update sync --- packages/dapp/hooks/useGallery.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/dapp/hooks/useGallery.js b/packages/dapp/hooks/useGallery.js index 109f394..f9205b1 100644 --- a/packages/dapp/hooks/useGallery.js +++ b/packages/dapp/hooks/useGallery.js @@ -43,14 +43,18 @@ const useGallery = () => { Ethernauts.totalSupply().then(Number), ]); - const batchNumber = Math.floor(tokenId / batchSize); - + const maxBatchRevealed = Math.floor(totalSupply / batchSize - 1); const maxTokenIdRevealed = totalSupply - (totalSupply % batchSize) - 1; - const logs = await provider.getLogs(filter); + const offsets = []; - const randomNumber = await Ethernauts.getRandomNumberForBatch(batchNumber); - const offset = Number(randomNumber.mod(batchSize)); + for (let batchId = 0; batchId <= maxBatchRevealed; batchId++) { + const randomNumber = await Ethernauts.getRandomNumberForBatch(batchId); + const offset = Number(randomNumber.mod(batchSize)); + offsets.push(offset); + } + + const logs = await provider.getLogs(filter); const galleryItems = await logs.reduce(async (pGalleryItems, curr) => { const galleryItems = await pGalleryItems; @@ -63,17 +67,19 @@ const useGallery = () => { const to = parsedLog.args.to.toLowerCase(); const tokenId = parsedLog.args.tokenId.toNumber(); + const isRevealed = tokenId <= maxTokenIdRevealed; + const batchNumber = Math.floor(tokenId / batchSize); + const maxTokenIdInBatch = batchSize * (batchNumber + 1) - 1; + const offset = offsets[batchNumber]; - // const assetId = await Ethernauts.getAssetIdForTokenId(tokenId); - - // getAssetIdForTokenId returns "assetId,boolean" so it takes the first position; - const [formattedAssetId] = assetId.toString().split(','); + let assetId = tokenId + offset; + if (assetId > maxTokenIdInBatch) assetId -= batchSize; const item = { tokenId, - assetId: formattedAssetId, + assetId, owner: to, - isRevealed: tokenId <= maxTokenIdRevealed, + isRevealed, }; // Push all nfts From 693b4d09694bf86e50ddba78922951226927ec41 Mon Sep 17 00:00:00 2001 From: "saeta.eth" Date: Fri, 1 Apr 2022 14:28:15 -0300 Subject: [PATCH 3/3] fix fleek issue --- packages/dapp/components/Gallery/Cell/Cell.js | 2 +- packages/dapp/next.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dapp/components/Gallery/Cell/Cell.js b/packages/dapp/components/Gallery/Cell/Cell.js index f8ef692..f311407 100644 --- a/packages/dapp/components/Gallery/Cell/Cell.js +++ b/packages/dapp/components/Gallery/Cell/Cell.js @@ -22,7 +22,7 @@ const Cell = ({ assetId, tokenId, isRevealed, kind, isMiddleCell }) => { const imageSrc = useMemo(() => { if (isRevealed && !isDev) - return `https://storageapi.fleek.co/${FLEEK_BUCKET_ID}/assets/${assetId}.png`; + return `https://storageapi2.fleek.co/${FLEEK_BUCKET_ID}/assets/${assetId}.png`; if (isRevealed && isDev) return '/assets/revealed-token.png'; diff --git a/packages/dapp/next.config.js b/packages/dapp/next.config.js index b9d4417..2fa8ed7 100644 --- a/packages/dapp/next.config.js +++ b/packages/dapp/next.config.js @@ -9,7 +9,7 @@ module.exports = { }; }, images: { - domains: ['https://storageapi.fleek.co/'], + domains: ['https://storageapi.fleek.co/', 'https://storageapi2.fleek.co/'], }, // Fix fast refresh for Windows users webpackDevMiddleware: (config) => {