Skip to content

Commit

Permalink
fix: get debank history by page (#8824)
Browse files Browse the repository at this point in the history
* fix: get debank history by page

* refactor: change max page size to 99

---------

Co-authored-by: guanbinrui <guanbinrui@dimension.im>
  • Loading branch information
lelenei and guanbinrui committed Mar 1, 2023
1 parent f597344 commit 9acf08d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/mask/src/plugins/Tips/hooks/useProvedWallets.ts
@@ -1,11 +1,11 @@
import { useEffect } from 'react'
import { useAsyncRetry } from 'react-use'
import { head } from 'lodash-es'
import type { AsyncStateRetry } from 'react-use/lib/useAsyncRetry.js'
import { BindingProof, ECKeyIdentifier, EMPTY_LIST, NextIDPlatform } from '@masknet/shared-base'
import { useValueRef } from '@masknet/shared-base-ui'
import Services from '../../../extension/service.js'
import { currentPersonaIdentifier } from '../../../../shared/legacy-settings/settings.js'
import type { AsyncStateRetry } from 'react-use/lib/useAsyncRetry.js'
import { MaskMessages } from '../../../utils/messages.js'
import { usePersonaProofs } from '@masknet/shared'

Expand Down
9 changes: 8 additions & 1 deletion packages/shared/src/hooks/useIterator.ts
@@ -1,4 +1,5 @@
import { useCallback, useState } from 'react'
import { useUpdateEffect } from 'react-use'
import type { AsyncStateRetry } from 'react-use/lib/useAsyncRetry.js'
import { EMPTY_LIST } from '@masknet/shared-base'

Expand Down Expand Up @@ -37,7 +38,6 @@ export function useIterator<T>(
}
setDone(true)
}

setData((pred) => [...pred, ...batchFollowers])
setLoading(false)
}, [iterator, done])
Expand All @@ -48,6 +48,13 @@ export function useIterator<T>(
setDone(false)
}, [])

useUpdateEffect(() => {
if (!iterator) return
setData([])
setDone(false)
setLoading(false)
}, [iterator])

if (loading) {
return {
retry,
Expand Down
17 changes: 10 additions & 7 deletions packages/web3-hooks/base/src/useTransactions.ts
@@ -1,9 +1,9 @@
import { useMemo } from 'react'
import type { NetworkPluginID } from '@masknet/shared-base'
import type { Web3Helper } from '@masknet/web3-helpers'
import { useChainContext } from './useContext.js'
import { useWeb3Hub } from './useWeb3Hub.js'
import { pageableToIterator } from '@masknet/web3-shared-base'
import { useMemo } from 'react'

export function useTransactions<S extends 'all' | void = void, T extends NetworkPluginID = NetworkPluginID>(
pluginID?: NetworkPluginID,
Expand All @@ -12,10 +12,13 @@ export function useTransactions<S extends 'all' | void = void, T extends Network
const { account, chainId } = useChainContext()
const hub = useWeb3Hub(pluginID, options)
return useMemo(() => {
return pageableToIterator(async (indicator) => {
return hub?.getTransactions(options?.chainId ?? chainId, options?.account ?? account, {
indicator,
})
})
}, [account, chainId, hub])
return pageableToIterator(
async (indicator) => {
return hub?.getTransactions(options?.chainId ?? chainId, options?.account ?? account, {
indicator,
})
},
{ maxSize: 99 },
)
}, [account, chainId, hub, options?.chainId, options?.account])
}

0 comments on commit 9acf08d

Please sign in to comment.