Skip to content

Aggragated balance customizing#767

Merged
feruzm merged 4 commits intodevelopfrom
add
Apr 28, 2026
Merged

Aggragated balance customizing#767
feruzm merged 4 commits intodevelopfrom
add

Conversation

@feruzm
Copy link
Copy Markdown
Member

@feruzm feruzm commented Apr 28, 2026

Summary by CodeRabbit

  • New Features

    • Balance history supports yearly, monthly, and daily granularities.
    • Period selector lets you view specific buckets within a granularity.
    • UI stat titles and period labels update dynamically (including a “Now” label).
  • Bug Fixes

    • Chart data is deduplicated and validated to prevent malformed points and improve rendering.
    • Poll vote submission error handling and reporting improved.
  • Documentation

    • Added localization strings for new granularities, period labels, and summary metrics.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 48c3d450-102d-46ab-bafa-43d2e2360e56

📥 Commits

Reviewing files that changed from the base of the PR and between 292c99b and 7e5f5ec.

📒 Files selected for processing (7)
  • apps/web/src/app/(dynamicPages)/profile/[username]/wallet/(token)/_components/aggregated-balance-card.tsx
  • apps/web/src/features/i18n/locales/en-US.json
  • apps/web/src/features/polls/api/sign-poll-vote.ts
  • packages/sdk/CHANGELOG.md
  • packages/sdk/package.json
  • packages/wallets/CHANGELOG.md
  • packages/wallets/package.json

📝 Walkthrough

Walkthrough

Adds selectable balance aggregation granularity (yearly/monthly/daily) across UI and SDK, clamps and selects period buckets for metrics, deduplicates chart points by second, extends query keys/options to include granularity, updates i18n strings, and switches poll vote broadcast to usePollVote with stricter validation.

Changes

Cohort / File(s) Summary
Balance Aggregation UI
apps/web/src/app/(dynamicPages)/profile/[username]/wallet/(token)/_components/aggregated-balance-card.tsx
Adds granularity state and periodIndex selector, clamps indices when changing granularity, computes current/change/min/max from selected period with prior-period fallback, and switches i18n keys to granularity-aware labels. Review period-index bounds and fallback logic.
Chart Data Preparation
apps/web/src/app/(dynamicPages)/profile/[username]/wallet/(token)/_components/balance-history-chart.tsx
Replaces flat mapping with dedupe-by-second using a Map that retains the entry with highest operation_id per second; filters missing/invalid timestamps and non-finite values, then sorts by time. Verify dedupe and filtering correctness.
i18n
apps/web/src/features/i18n/locales/en-US.json
Adds g.now, no-choice-selected, granularity selector labels, and monthly/daily summary and metric keys (change/min/max).
SDK: Query Options
packages/sdk/src/modules/accounts/queries/get-aggregated-balance-query-options.ts
Adds exported BalanceAggregationGranularity type and new granularity parameter (default "yearly") included in queryKey and passed to the aggregated-history REST call.
SDK: Query Keys
packages/sdk/src/modules/core/query-keys.ts
Extends QueryKeys.wallet.aggregatedHistory to accept optional granularity and adds QueryKeys.polls.vote(author?, permlink?). Confirm cache key compatibility.
Polls: Vote Mutation & UI
packages/sdk/src/modules/polls/mutations/use-poll-vote.ts, apps/web/src/features/polls/api/sign-poll-vote.ts
usePollVote now derives mutation key from QueryKeys.polls.vote(...); UI vote broadcast moved to usePollVote with getWebBroadcastAdapter() and stricter input validation that throws errors handled via onError. Check mutation key change and error handling paths.
Monorepo Metadata
packages/sdk/CHANGELOG.md, packages/sdk/package.json, packages/wallets/CHANGELOG.md, packages/wallets/package.json
Bump @ecency/sdk to 2.2.9 and @ecency/wallets to 4.0.7; add changelog entries. No API/behavior changes beyond versioning.

Sequence Diagram(s)

sequenceDiagram
  participant UI as Client UI
  participant Q as React Query
  participant SDK as SDK (getAggregatedBalanceQueryOptions)
  participant API as REST API

  UI->>Q: request aggregated history (username, coinType, granularity)
  Q->>SDK: build query key & options (includes granularity)
  SDK->>API: GET /aggregated-history?granularity=...
  API-->>SDK: aggregated periods response
  SDK-->>Q: return data
  Q-->>UI: provide aggregated periods
  UI->>UI: clamp periodIndex, compute current/change/min/max from selected period
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

patch

Poem

🐰 I nibble buckets, day to year,
I sort and dedupe every second clear.
Keys and queries now match my hop,
Periods pick, indices don’t drop,
Balance blooms — a tidy cheer! 📈✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Aggragated balance customizing' contains a spelling error ('Aggragated' instead of 'Aggregated') and is grammatically awkward. However, it does relate to the main changes in the PR, which add customization options for aggregated balance display. Correct the spelling to 'Aggregated balance customizing' or use a more polished phrasing like 'Add granularity customization for aggregated balance display' to improve clarity and professionalism.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 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.

❤️ Share

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

coderabbitai[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/features/polls/api/sign-poll-vote.ts (1)

39-49: ⚠️ Potential issue | 🟡 Minor

Guard against activeUser becoming undefined during async mutation.

The activeUser reference is captured from the hook's render-time closure. If the user logs out while the mutation is in flight, activeUser could be undefined when onSuccess fires, potentially causing issues in PollsVotesManagement.processVoting.

🛡️ Proposed defensive guard
     onSuccess: (resp) =>
       queryClient.setQueryData<Poll>(
         QueryKeys.polls.details(poll?.author ?? "", poll?.permlink ?? ""),
         (data) => {
-          if (!data || !resp) {
+          if (!data || !resp || !activeUser) {
             return data;
           }

           return PollsVotesManagement.processVoting(activeUser, data, resp.choiceNums);
         }
       ),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/features/polls/api/sign-poll-vote.ts` around lines 39 - 49, The
onSuccess handler captures activeUser from render-time and may be undefined when
the mutation completes; update the handler in sign-poll-vote.ts (the onSuccess
-> queryClient.setQueryData callback) to defensively guard before calling
PollsVotesManagement.processVoting: if activeUser is falsy, either return the
existing data unchanged or resolve the current active user from the query cache
(e.g., read the auth/user query from queryClient) and only call
PollsVotesManagement.processVoting when a non-null user is available; ensure you
reference the same symbols (onSuccess, queryClient.setQueryData,
PollsVotesManagement.processVoting, activeUser) so the guard lives right before
the processVoting call.
♻️ Duplicate comments (1)
apps/web/src/app/(dynamicPages)/profile/[username]/wallet/(token)/_components/aggregated-balance-card.tsx (1)

164-170: ⚠️ Potential issue | 🟡 Minor

Granularity select is still missing an accessible label.

Line 164 renders a <select> without an associated <label> or aria-label, so assistive tech may announce it as unlabeled. Please add a translated visible label or aria-label (similar to Line 185 usage).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/web/src/app/`(dynamicPages)/profile/[username]/wallet/(token)/_components/aggregated-balance-card.tsx
around lines 164 - 170, The select rendered by the FormControl component (props:
full, type="select", size="xs", value={granularity},
onChange={handleGranularityChange}) lacks an accessible label; update the
FormControl usage to include an associated visible translated label or an
aria-label (use the same translation key/pattern used on Line 185) so assistive
technologies can announce it; ensure the label text comes from the i18n/t
function and that the label prop or aria-label value clearly describes the
granularity control.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/web/src/features/polls/api/sign-poll-vote.ts`:
- Around line 31-33: The check for empty choices uses the same error key as the
"not found" case which is misleading; update the i18next call in
sign-poll-vote.ts (the branch that checks choiceNums.length === 0) to use a new
key like "polls.no-choice-selected" instead of "polls.not-found", and add the
corresponding string ("Please select at least one choice") to the locale file
(e.g., en-US.json) so the new key resolves correctly.

---

Outside diff comments:
In `@apps/web/src/features/polls/api/sign-poll-vote.ts`:
- Around line 39-49: The onSuccess handler captures activeUser from render-time
and may be undefined when the mutation completes; update the handler in
sign-poll-vote.ts (the onSuccess -> queryClient.setQueryData callback) to
defensively guard before calling PollsVotesManagement.processVoting: if
activeUser is falsy, either return the existing data unchanged or resolve the
current active user from the query cache (e.g., read the auth/user query from
queryClient) and only call PollsVotesManagement.processVoting when a non-null
user is available; ensure you reference the same symbols (onSuccess,
queryClient.setQueryData, PollsVotesManagement.processVoting, activeUser) so the
guard lives right before the processVoting call.

---

Duplicate comments:
In
`@apps/web/src/app/`(dynamicPages)/profile/[username]/wallet/(token)/_components/aggregated-balance-card.tsx:
- Around line 164-170: The select rendered by the FormControl component (props:
full, type="select", size="xs", value={granularity},
onChange={handleGranularityChange}) lacks an accessible label; update the
FormControl usage to include an associated visible translated label or an
aria-label (use the same translation key/pattern used on Line 185) so assistive
technologies can announce it; ensure the label text comes from the i18n/t
function and that the label prop or aria-label value clearly describes the
granularity control.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d14bf74-928d-4d5a-a122-7d0dbda32e27

📥 Commits

Reviewing files that changed from the base of the PR and between 930b410 and 292c99b.

⛔ Files ignored due to path filters (7)
  • packages/sdk/dist/browser/index.d.ts is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.cjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.cjs.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.mjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.mjs.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (7)
  • apps/web/public/sw.js
  • apps/web/src/app/(dynamicPages)/profile/[username]/wallet/(token)/_components/aggregated-balance-card.tsx
  • apps/web/src/app/(dynamicPages)/profile/[username]/wallet/(token)/_components/balance-history-chart.tsx
  • apps/web/src/features/i18n/locales/en-US.json
  • apps/web/src/features/polls/api/sign-poll-vote.ts
  • packages/sdk/src/modules/core/query-keys.ts
  • packages/sdk/src/modules/polls/mutations/use-poll-vote.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/sdk/src/modules/polls/mutations/use-poll-vote.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/web/src/app/(dynamicPages)/profile/[username]/wallet/(token)/_components/balance-history-chart.tsx
  • packages/sdk/src/modules/core/query-keys.ts
  • apps/web/src/features/i18n/locales/en-US.json

Comment thread apps/web/src/features/polls/api/sign-poll-vote.ts
@feruzm feruzm added the patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR label Apr 28, 2026
@feruzm feruzm merged commit 51878ae into develop Apr 28, 2026
1 check was pending
@feruzm feruzm deleted the add branch April 28, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant