Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add balance & blocknumber notifier #6489

Merged
merged 4 commits into from
Jun 12, 2022
Merged

Conversation

guanbinrui
Copy link
Member

@guanbinrui guanbinrui commented Jun 12, 2022

Description

This PR introduces two notifier state: BlockNumberNotifierState and BalanceNotifierState. Here is a code snippet to reveal how to use a notifier.

// The sender could be transaction state listener
BalanceNotifier.emitter.emit('update', {
    account: '0x...',
    chainId: ChainId.Mainnet,
})

// The listener is the `useBalance` hook
function useBalance(address: string) {
    const { BalanceNotifier } = useWeb3State()
    const asyncResult = useAsyncRetry(async () => { /** get balance **/ })
    
    useEffect(() => {
        return BalanceNotifier.on(() => {
            asyncRetry.retry()
        })
    }, [BalanceNotifier])

    return asyncResult
}

Closes # (NO_ISSUE)

Type of change

  • Documentation
  • Code refactoring (Restructuring existing code w/o changing its observable behavior)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (a fix or feature that would make something no longer possible to do/require old user must upgrade their Mask Network to this new version)

@github-actions
Copy link
Contributor

github-actions bot commented Jun 12, 2022

@github-actions github-actions bot temporarily deployed to pull request June 12, 2022 06:02 Inactive
@guanbinrui guanbinrui force-pushed the fix/update-balance branch from 5d31864 to 4d51f92 Compare June 12, 2022 06:04
@github-actions github-actions bot temporarily deployed to pull request June 12, 2022 06:10 Inactive
@guanbinrui guanbinrui force-pushed the fix/update-balance branch from 253e558 to 0913be2 Compare June 12, 2022 06:17
@guanbinrui guanbinrui marked this pull request as ready for review June 12, 2022 06:18
@github-actions github-actions bot temporarily deployed to pull request June 12, 2022 06:23 Inactive
@github-actions github-actions bot temporarily deployed to pull request June 12, 2022 10:30 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant