Skip to content

Fetch portfolio global props & account via Hive RPC instead of external gateway#20

Merged
feruzm merged 1 commit into
mainfrom
bugfix/portfolio-direct-rpc-globalprops
May 27, 2026
Merged

Fetch portfolio global props & account via Hive RPC instead of external gateway#20
feruzm merged 1 commit into
mainfrom
bugfix/portfolio-direct-rpc-globalprops

Conversation

@feruzm

@feruzm feruzm commented May 27, 2026

Copy link
Copy Markdown
Member

Problem

The portfolio endpoints (/private-api/portfolio v1 and v2 in wallet-api.ts) fetch dynamic global properties and account data through hive-explorer.ts, which made REST GETs to an external gateway. Both calls run inside a Promise.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 globalProps while the upstream returned 502.

Fix

Fetch both pieces of chain data directly from Hive RPC via the @hiveio/dhive Client (already a dependency, same pattern as private-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 own hapi.ecency.com node first, so a single slow/unavailable node no longer takes down the portfolio endpoint. Removes the now-unused baseApiRequest/parseAsset imports.

The existing _getVestAmount helper 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.
  • Verified hapi.ecency.com returns 200 with the expected fields for both condenser_api.get_dynamic_global_properties and condenser_api.get_accounts (~90ms).

Summary by CodeRabbit

  • Improvements
    • Enhanced data fetching reliability with direct blockchain access and automatic failover capabilities.
    • Improved system resilience with configured timeout and multi-node failover settings for better uptime.

Review Change Stack

…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.
@feruzm feruzm merged commit cc22ac5 into main May 27, 2026
1 check was pending

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR migrates Hive data fetching from REST endpoints to direct RPC calls using @hiveio/dhive. A configured Client with multiple RPC nodes, failover, and timeout settings is introduced. fetchGlobalProps and getAccount are updated to use RPC library methods instead of HTTP requests.

Changes

Dhive RPC Migration

Layer / File(s) Summary
RPC client configuration and fetchGlobalProps migration
src/server/handlers/hive-explorer.ts
A @hiveio/dhive Client is configured with multiple RPC endpoints, 2 second timeout, and failover behavior. fetchGlobalProps calls client.database.getDynamicGlobalProperties() and computes derived values (hivePerMVests, hbdApr, hpApr), replacing the prior REST-based baseApiRequest call.
getAccount RPC migration
src/server/handlers/hive-explorer.ts
getAccount calls client.database.getAccounts([username]) and extracts the account from the result, replacing the prior REST request to get_accounts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 The Hive now speaks through RPC nodes so fast,
No REST endpoints, no slow detours vast,
With failover grace and a two-second beat,
Direct from the chain, the data's complete!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and clearly summarizes the main change: replacing external gateway REST calls with direct Hive RPC node calls for fetching global properties and account data.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/portfolio-direct-rpc-globalprops

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@feruzm feruzm deleted the bugfix/portfolio-direct-rpc-globalprops branch May 27, 2026 21:34
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