Fetch portfolio global props & account via Hive RPC instead of external gateway#20
Conversation
…eway The portfolio endpoints fetched dynamic global properties and account data through an external REST gateway. When that gateway is unavailable, the whole portfolio Promise.all rejects and the endpoint returns HTTP 500 (no degraded fallback), breaking wallet/portfolio for all users. Switch both fetchGlobalProps() and getAccount() to direct Hive RPC via dhive, which fails over across a node list and prefers our own hapi.ecency.com node first. Removes the unused baseApiRequest/parseAsset imports.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08edbcb6d0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| const data = response.data | ||
| if (data.length) { | ||
| return data[0]; |
There was a problem hiding this comment.
Preserve asset amounts before returning account data
When this path switches to client.database.getAccounts, dhive/database_api can return balances and vesting fields as NAI asset objects rather than the string assets the old REST gateway returned. The portfolio builder still calls parseToken(accountData.balance), parseToken(accountData.vesting_shares), etc., and parseToken only accepts strings, so those object values parse to 0 and every Hive/HBD/HP balance is reported as zero for affected users. Please normalize the returned account asset fields back to strings or update the downstream parser to handle dhive Asset/NAI objects before returning data[0].
Useful? React with 👍 / 👎.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe PR migrates Hive data fetching from REST endpoints to direct RPC calls using ChangesDhive RPC Migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The portfolio endpoints (
/private-api/portfoliov1 and v2 inwallet-api.ts) fetch dynamic global properties and account data throughhive-explorer.ts, which made RESTGETs to an external gateway. Both calls run inside aPromise.all, so when that gateway is unavailable the entire portfolio request rejects and returns HTTP 500 — there is no degraded fallback, so wallet/portfolio breaks for every user.This was observed live: portfolio v2 was logging a steady stream of
failed to compile portfolio v2 Error: Failed to get globalPropswhile the upstream returned 502.Fix
Fetch both pieces of chain data directly from Hive RPC via the
@hiveio/dhiveClient(already a dependency, same pattern asprivate-api.ts):fetchGlobalProps()→client.database.getDynamicGlobalProperties()getAccount()→client.database.getAccounts([username])dhive fails over across a node list (2s timeout,
failoverThreshold: 2) and is configured to try our ownhapi.ecency.comnode first, so a single slow/unavailable node no longer takes down the portfolio endpoint. Removes the now-unusedbaseApiRequest/parseAssetimports.The existing
_getVestAmounthelper already handles both string assets (condenser) and nai objects, so the downstream math is unchanged.Test
tsc --noEmit(TS 3.9.3, project tsconfig): 0 source errors.hapi.ecency.comreturns 200 with the expected fields for bothcondenser_api.get_dynamic_global_propertiesandcondenser_api.get_accounts(~90ms).Summary by CodeRabbit