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

refactor: token balance error handling #3096

Merged
merged 12 commits into from
Oct 16, 2024
Merged

Conversation

magiziz
Copy link
Contributor

@magiziz magiziz commented Oct 16, 2024

Description

Refactored token balance error message and ensured that token balances are only fetched again after 5 seconds if the token balance API fails.

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Showcase (Optional)

image

Checklist

  • Code in this PR is covered by automated tests (Unit tests, E2E tests)
  • My changes generate no new warnings
  • I have reviewed my own code
  • I have filled out all required sections
  • I have tested my changes on the preview link
  • Approver of this PR confirms that the changes are tested on the preview link

Copy link

vercel bot commented Oct 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
appkit-laboratory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 16, 2024 11:40am
appkit-wagmi-cdn-example ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 16, 2024 11:40am
web3modal-gallery ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 16, 2024 11:40am

Copy link

changeset-bot bot commented Oct 16, 2024

🦋 Changeset detected

Latest commit: 3324bbc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@apps/laboratory Patch
@reown/appkit-core Patch
@apps/demo Patch
@apps/gallery Patch
@reown/appkit-adapter-ethers Patch
@reown/appkit-adapter-ethers5 Patch
@reown/appkit-adapter-polkadot Patch
@reown/appkit-adapter-solana Patch
@reown/appkit-adapter-wagmi Patch
@reown/appkit Patch
@reown/appkit-utils Patch
@reown/appkit-cdn Patch
@reown/appkit-common Patch
@reown/appkit-experimental Patch
@reown/appkit-polyfills Patch
@reown/appkit-scaffold-ui Patch
@reown/appkit-siwe Patch
@reown/appkit-ui Patch
@reown/appkit-wallet Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@magiziz magiziz requested a review from tomiir October 16, 2024 10:27
Copy link
Contributor

github-actions bot commented Oct 16, 2024

Coverage Report for Coverage

Status Category Percentage Covered / Total
🔵 Lines 307.94000000000005% 4457 / 19401
🔵 Statements 307.94000000000005% 4457 / 19401
🔵 Functions 330.94% 348 / 1036
🔵 Branches 376.68999999999994% 638 / 1334
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/core/src/controllers/AccountController.ts 45.78% 83.33% 38.46% 45.78% 62-63, 69-72, 74-76, 79-83, 85-98, 101-102, 105-106, 109-112, 154-155, 166-167, 170-171, 174-177, 180-183, 186-190, 200-206, 209-215, 218-224, 227-230, 232-237, 239-241, 243-245, 247-252, 254-256, 263-264
packages/core/src/utils/CoreHelperUtil.ts 42.16% 71.42% 35.29% 42.16% 11-16, 18-19, 22-23, 26, 28-29, 32, 34-35, 38-39, 42-43, 46-47, 50-51, 58-59, 73, 75-78, 80-85, 88-89, 92-102, 104, 106-108, 110-114, 117-124, 126-130, 133-135, 137-138, 140-141, 144-149, 155, 157, 159, 164-170, 172-173, 192, 194-201, 203-208, 223-225, 227-229, 231-233, 240-243, 245, 264, 266, 268-269, 279-282, 284-285, 288-289, 291-292, 301, 306, 311, 321-322, 330-337, 339-340
Generated in workflow #6867 for commit 3324bbc by the Vitest Coverage Report Action

@@ -100,9 +100,18 @@ emailTest('it should show names feature only for EVM networks', async ({ library
emailTest('it should show loading on page refresh', async () => {
await page.page.reload()
await validator.expectConnectButtonLoading()
await page.page.waitForTimeout(5000)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it'd need to finish loading before i can open the modal again

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we don't know when the loading will finish right? Cannot be wait for an element to be visible instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think best way here is to add a validator.expectConnectButtonReady or similar that does

    const connectButton = this.page.getByTestId('connect-button')
    await expect(connectButton).toContainText('Connect', {
      timeout: MAX_WAIT
    }))
``` 
That way you do not use arbitrary timeouts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, let me add that 🙏

@@ -239,7 +248,10 @@ export const AccountController = {
SwapController.setBalances(SwapApiUtil.mapBalancesToSwapTokens(response.balances))
}
} catch (error) {
SnackController.showError('Failed to fetch token balance')
if (chainId && state.tokenFetchFailureChainIds) {
state.tokenFetchFailureChainIds.add(chainId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we not clearing this? What happens if there's a true flake in the request?
I think we should silently retry after some time

@magiziz magiziz merged commit 3bb4660 into main Oct 16, 2024
18 checks passed
@magiziz magiziz deleted the refactor/fetch-token-balance-error branch October 16, 2024 11:56
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.

3 participants