From cd96a390902bf09748c03a6510b373a12f74900d Mon Sep 17 00:00:00 2001 From: Lantt Date: Wed, 15 Jun 2022 01:10:01 +0800 Subject: [PATCH] fix: should clear asset state in nft wall when change plugin id --- .../plugin-infra/src/web3/useNonFungibleAssets.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/plugin-infra/src/web3/useNonFungibleAssets.ts b/packages/plugin-infra/src/web3/useNonFungibleAssets.ts index ae2bd59ce5ba..550ff8fafd20 100644 --- a/packages/plugin-infra/src/web3/useNonFungibleAssets.ts +++ b/packages/plugin-infra/src/web3/useNonFungibleAssets.ts @@ -22,7 +22,8 @@ export function useNonFungibleAssets { if ((!account && !options?.account) || !hub?.getNonFungibleTokens || !networks) return - + setAssets(EMPTY_LIST) + setDone(false) return flattenAsyncIterator( networks .filter((x) => x.isMainnet) @@ -39,13 +40,14 @@ export function useNonFungibleAssets { if (!iterator || done) return + const batchResult: Array> = [] try { - for (const v of Array.from({ length: 48 })) { + for (const v of Array.from({ length: 36 })) { const { value, done: iteratorDone } = await iterator.next() if (value instanceof Error) { // Controlled error @@ -57,7 +59,7 @@ export function useNonFungibleAssets [...pred, value]) + batchResult.push(value) } } } @@ -66,6 +68,7 @@ export function useNonFungibleAssets [...pred, ...batchResult]) }, [iterator, done]) // Execute once after next update @@ -74,12 +77,10 @@ export function useNonFungibleAssets { - setAssets([]) + setAssets(EMPTY_LIST) setDone(false) }, []) - useEffect(() => retry(), [options?.account ?? account, retry, options?.chainId]) - return { value: assets.filter((x) => (options?.chainId ? x.chainId === options?.chainId : true)), next,