From 30057f43edfb38b55b2c50ea7c04dc607018e740 Mon Sep 17 00:00:00 2001 From: Mentor Palokaj Date: Tue, 7 Dec 2021 15:24:40 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20ids=20to=20multiple=20rockete?= =?UTF-8?q?er=20endpoint=20and=20remove=20website=20link=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-website.yml | 4 ---- functions/nft-media/rocketeer.js | 7 ++++-- minter/src/modules/api.js | 33 +++++++++++++++++++--------- minter/src/modules/web3.js | 3 ++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 7819fa5..6fe53f9 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -49,10 +49,6 @@ jobs: run: npm i working-directory: website - - name: test if all links work - run: npm test - working-directory: website - - name: Build website files env: NODE_ENV: production diff --git a/functions/nft-media/rocketeer.js b/functions/nft-media/rocketeer.js index 35e3d42..bffe86e 100644 --- a/functions/nft-media/rocketeer.js +++ b/functions/nft-media/rocketeer.js @@ -155,8 +155,11 @@ async function safelyReturnMultipleRocketeers( ids=[], network='mainnet' ) { const invalidIds = await Promise.all( ids.map( id => isInvalidRocketeerId( id, network ) ) ) if( invalidIds.includes( true ) ) throw invalidIds - // Get old rocketeers - const rocketeers = await Promise.all( ids.map( id => getExistingRocketeer( id ) ) ) + // Get old rocketeers and append their ids + const rocketeers = await Promise.all( ids.map( async id => ( { + ...await getExistingRocketeer( id ), + id: id + } ) ) ) // Send back an array of rocketeers, but not any failed ones return rocketeers.filter( rocketeer => rocketeer ) diff --git a/minter/src/modules/api.js b/minter/src/modules/api.js index 067e6d0..5986e9f 100644 --- a/minter/src/modules/api.js +++ b/minter/src/modules/api.js @@ -42,21 +42,32 @@ export function useRocketeers( onlyGrabThisId ) { const ids = onlyGrabThisId ? [ onlyGrabThisId ] : tokenIds const [ rocketeers, setRocketeers ] = useState( [] ) - useEffect( f => { + useEffect( ( ) => { - ( async function() { + let cancelled = false; - const rocketeerMetas = await Promise.all( ids.map( async id => ( { - ...await callApi( `/rocketeer/${ id }` ), - id: id - } ) ) ) - log( 'Received rocketeers: ', rocketeerMetas ) - setRocketeers( rocketeerMetas ) + ( async () => { - } )( ) + try { + + if( !ids.length || cancelled ) return + const rocketeerMetas = await callApi( `/rocketeers/?ids=${ ids.join( ',' ) }` ) + log( 'Received rocketeers: ', rocketeerMetas ) + if( !cancelled ) setRocketeers( rocketeerMetas ) + + } catch( e ) { + + } finally { + + } + + } )( ) + + return () => cancelled = true }, [ tokenIds, onlyGrabThisId ] ) + return rocketeers } @@ -65,16 +76,18 @@ export function useRocketeerImages() { const ids = useTokenIds() const chainId = useChainId() + const rocketeers = useRocketeers() const [ images, setImages ] = useState( [] ) useEffect( f => { + if( rocketeers.length ) setImages( rocketeers.map( ( { image, id }, i ) => ( { src: image, id: id || i } ) ) ) setImages( ids.map( id => ( { id, src: getImage( id, 'jpg', chainId === '0x1' ? 'mainnet' : 'testnet' ) } ) ) ) - }, [ ids, chainId ] ) + }, [ ids, chainId, rocketeers ] ) return images diff --git a/minter/src/modules/web3.js b/minter/src/modules/web3.js index 4381c2e..1e52fc6 100644 --- a/minter/src/modules/web3.js +++ b/minter/src/modules/web3.js @@ -216,6 +216,7 @@ export function useChainId() { export function useTokenIds() { // Deps + const chain = useChainId() const address = useAddress() const contract = useContract() const balance = useBalanceOf() @@ -253,7 +254,7 @@ export function useTokenIds() { return () => cancelled = true - }, [ contract, address, balance ] ) + }, [ contract, address, balance, chain ] ) return tokens