Skip to content

refactor: handle balance call failure on ethers and ethers5 adapters#4595

Merged
tomiir merged 3 commits intomainfrom
enes/apkt-3158-balance-calls-blocking-the-appkit-initialization-if-fails
Jul 1, 2025
Merged

refactor: handle balance call failure on ethers and ethers5 adapters#4595
tomiir merged 3 commits intomainfrom
enes/apkt-3158-balance-calls-blocking-the-appkit-initialization-if-fails

Conversation

@enesozturk
Copy link
Copy Markdown
Contributor

@enesozturk enesozturk commented Jul 1, 2025

Description

Refactors Ethers and Ethers5 adapters to resolve the balance calls to not block the AppKit to be initialized. When there is an error thrown in the JsonRpcProvider's calls, it's blocking AppKit to proceed.

Example track trace:

Uncaught (in promise) Error: server response 400  (request={  }, response={  }, error=null, info={ "requestUrl": "https://rpc.walletconnect.org/v1/?chainId=eip155%3A10&projectId=PROJ_ID", "responseBody": "{\"id\":\"\",\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"invalid request: json: cannot unmarshal array into Go value of type jsonrpc.Request\",\"data\":{\"error\":\"json: cannot unmarshal array into Go value of type jsonrpc.Request\",\"retryable\":\"false\"}}}", "responseStatus": "400 " }, code=SERVER_ERROR, version=6.14.0)
    at makeError (errors.js:137:21)
    at assert (errors.js:156:15)
    at FetchResponse.assertOk (fetch.js:846:59)
    at JsonRpcProvider._send (provider-jsonrpc.js:935:18)
    at async eval (provider-jsonrpc.js:301:40)

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)

Associated Issues

For Linear issues: Closes APKT-xxx
For GH issues: closes #...

Showcase (Optional)

If there is a UI change include the screenshots with before and after state.
If new feature is being introduced, include the link to demo recording.

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

@linear
Copy link
Copy Markdown

linear bot commented Jul 1, 2025

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jul 1, 2025

🦋 Changeset detected

Latest commit: bf1d188

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

This PR includes changesets to release 23 packages
Name Type
@reown/appkit-adapter-ethers5 Patch
@reown/appkit-adapter-ethers Patch
@reown/appkit-adapter-bitcoin Patch
@reown/appkit-adapter-solana Patch
@reown/appkit-adapter-wagmi Patch
@reown/appkit Patch
@reown/appkit-utils Patch
@reown/appkit-cdn Patch
@reown/appkit-cli Patch
@reown/appkit-codemod Patch
@reown/appkit-common Patch
@reown/appkit-controllers Patch
@reown/appkit-core Patch
@reown/appkit-experimental Patch
@reown/appkit-pay Patch
@reown/appkit-polyfills Patch
@reown/appkit-scaffold-ui Patch
@reown/appkit-siwe Patch
@reown/appkit-siwx Patch
@reown/appkit-testing Patch
@reown/appkit-ui Patch
@reown/appkit-wallet Patch
@reown/appkit-wallet-button 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

@vercel
Copy link
Copy Markdown

vercel bot commented Jul 1, 2025

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

Name Status Preview Comments Updated (UTC)
appkit-basic-html ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2025 10:54am
appkit-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2025 10:54am
appkit-laboratory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2025 10:54am
10 Skipped Deployments
Name Status Preview Comments Updated (UTC)
appkit-basic-example ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am
appkit-basic-sign-client-example ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am
appkit-basic-up-example ⬜️ Ignored (Inspect) Visit Preview Jul 1, 2025 10:54am
appkit-ethers5-bera ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am
appkit-nansen-demo ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am
appkit-vue-solana ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am
appkit-wagmi-cdn-example ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am
ethereum-provider-wagmi-example ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am
next-wagmi-solana-bitcoin-example ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am
vue-wagmi-example ⬜️ Ignored (Inspect) Jul 1, 2025 10:54am

cursor[bot]

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 1, 2025

Warnings
⚠️

🔑 Potential UUID detected in packages/adapters/ethers/src/tests/client.test.ts (line 966): ba0ba0cd-17c6-4806-a...

Generated by 🚫 dangerJS against bf1d188

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 1, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 77.84% 30835 / 39612
🔵 Statements 77.84% 30835 / 39612
🔵 Functions 68.74% 2538 / 3692
🔵 Branches 84.42% 6400 / 7581
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/adapters/ethers/src/client.ts 63.95% 71.66% 68.57% 63.95% 51-52, 55-56, 63-65, 87-88, 102-105, 147-148, 179-180, 194-217, 230-266, 272-273, 280-297, 369-391, 394-399, 411-412, 422-443, 448-449, 472, 499-500, 509-510, 555-601, 608-609, 631, 660-661, 672-673, 707-708, 712, 739-744, 753-771, 777-778, 782-787, 796-797, 808-809, 815-827
packages/adapters/ethers5/src/client.ts 54.8% 70.4% 60% 54.8% 48-134, 150-151, 182-183, 197-220, 233-269, 275-276, 283-300, 372-394, 397-402, 414-415, 425-446, 451-452, 475, 502-503, 512-513, 543-589, 611-612, 634, 663-664, 676-677, 714-715, 719, 738-752, 760-778, 784-785, 789-794, 803-804, 815-816, 822-834
Generated in workflow #13082 for commit bf1d188 by the Vitest Coverage Report Action

cursor[bot]

This comment was marked as outdated.

@socket-security
Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​safe-global/​safe-apps-sdk@​9.1.010010010079100
Added@​safe-global/​safe-apps-provider@​0.18.61001009181100
Added@​sentry/​core@​8.55.010010081100100
Addedreact@​19.1.01001008397100
Added@​sentry/​nextjs@​8.55.09610090100100
Added@​sentry/​browser@​7.120.39910090100100
Added@​sentry/​react@​7.120.39910098100100

View full report

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Incorrect Native Currency Symbol in Error Handling

When balance fetching fails, the native currency symbol is hardcoded to 'ETH' in the error fallback. This is inconsistent with successful fetches, which correctly use caipNetwork.nativeCurrency.symbol. Consequently, on non-Ethereum networks (e.g., Polygon, BSC), a failed balance fetch will incorrectly display 'ETH' instead of the actual native currency symbol (e.g., 'MATIC', 'BNB').

packages/adapters/ethers/src/client.ts#L695-L698

resolve({ balance: formattedBalance, symbol: caipNetwork.nativeCurrency.symbol })
} catch (error) {
resolve({ balance: '0.00', symbol: 'ETH' })
}

packages/adapters/ethers5/src/client.ts#L702-L705

resolve({ balance: formattedBalance, symbol: caipNetwork.nativeCurrency.symbol })
} catch (error) {
resolve({ balance: '0.00', symbol: 'ETH' })
}

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

@enesozturk enesozturk added this pull request to the merge queue Jul 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 1, 2025
@enesozturk enesozturk added this pull request to the merge queue Jul 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 1, 2025
@enesozturk enesozturk added this pull request to the merge queue Jul 1, 2025
@tomiir tomiir removed this pull request from the merge queue due to a manual request Jul 1, 2025
@tomiir tomiir merged commit 6ff6759 into main Jul 1, 2025
41 checks passed
@tomiir tomiir deleted the enes/apkt-3158-balance-calls-blocking-the-appkit-initialization-if-fails branch July 1, 2025 12:04
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.

4 participants