Skip to content

feat(portfolio): dividend reinvestment button to compound earnings into more keys (#824) - #834

Merged
Chucks1093 merged 1 commit into
accesslayerorg:devfrom
meem08:feat/reinvest-dividends-824
Aug 29, 2026
Merged

feat(portfolio): dividend reinvestment button to compound earnings into more keys (#824)#834
Chucks1093 merged 1 commit into
accesslayerorg:devfrom
meem08:feat/reinvest-dividends-824

Conversation

@meem08

@meem08 meem08 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #824

Holders with unclaimed dividends previously had no UI to reinvest them. This PR adds a Reinvest action on portfolio holding rows so eligible holders can compound their unclaimed dividend earnings back into more creator keys, directly surfacing and submitting the reinvest_dividend contract call.

Scope / What changed

Data model

  • Added unclaimedDividend (XLM) to HeldKeyPosition in src/utils/portfolioValue.utils.ts so holding rows know when a dividend balance is available.

Reinvestment math (src/utils/reinvestDividend.utils.ts)

  • estimateReinvest — computes the whole keys a dividend buys at the current key price plus the XLM remainder that can't convert to a whole key.
  • hasUnclaimedDividend / xlmToStroops helpers.

UI (src/components/common/PortfolioHoldingRow.tsx, ReinvestDividendDialog.tsx)

  • Unclaimed dividend badge shown on holding rows where unclaimedDividend > 0.
  • A Reinvest button that opens a confirmation modal displaying: the unclaimed amount, the per-key price, the estimated whole keys, and any XLM remainder.
  • On confirm, the dialog submits the reinvestment and closes on success.

Contract call (src/hooks/useWallet.tsuseReinvestDividendMutation)

  • Follows the existing useTradeMutation pattern (optimistic cache update, rollback on error, invalidation on settle).
  • mutationFn targets the reinvest_dividend contract function with the holding's key_id (= creatorId).
  • On success the holding row is optimistically updated (adds the received keys and clears the compounded dividend) and the wallet holdings cache is invalidated.

Toast (src/pages/LandingPage.tsx)

  • Shows Reinvested [amount] XLM — received [keys] keys on confirmation.

Tests

  • src/utils/__tests__/reinvestDividend.utils.test.ts — estimate/remainder matrix.
  • src/components/common/__tests__/PortfolioHoldingRow.reinvest.test.tsx — badge shown only when eligible, button hidden without a handler, modal content, onReinvest called with correct key_id, disabled confirm when no whole key is purchasable.
  • src/components/common/__tests__/ReinvestDividendDialog.test.tsx — displayed values and unavailable-estimate state.

Acceptance criteria

  • Unclaimed dividend badge shown on eligible rows
  • Modal shows correct estimated keys and remainder
  • Contract called with correct key_id on confirm
  • Success toast shows reinvested amount and keys received
  • Holding balance updated after successful reinvestment

Verification

  • tsc -b passes
  • eslint passes on all changed files
  • New + affected existing unit tests pass (20 tests)

Notes

Real on-chain calls in this repository are currently simulated (see the existing useTradeMutation comment); useReinvestDividendMutation wires the key_id payload and follows the same shape so the actual reinvest_dividend contract call can be dropped in once ABIs/TypeChain bindings land. This follows the established pattern and keeps the change minimal.

Add a Reinvest action on portfolio holding rows so holders can compound
their unclaimed dividend earnings back into more creator keys.

- Show an unclaimed dividend badge on holding rows where the
  unclaimedDividend balance is greater than zero
- Add a Reinvest button that opens a confirmation modal showing the
  unclaimed amount, estimated whole keys to be bought, and any XLM
  remainder (via the new estimateReinvest helper)
- Submit on confirm through the new useReinvestDividendMutation hook, which
  targets the reinvest_dividend contract function with the holding's
  key_id (creatorId)
- Show a success toast 'Reinvested [amount] XLM — received [keys] keys'
- Optimistically update the holding row (keys received and unclaimed
  balance cleared) and invalidate the wallet holdings cache afterwards

Adds HeldKeyPosition.unclaimedDividend, a ReinvestDividendDialog component,
the reinvestDividend utils, and unit tests for the helper, dialog, and
holding-row badge/button/modal flow.
@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@meem08 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093
Chucks1093 merged commit 68eebeb into accesslayerorg:dev Aug 29, 2026
1 check passed
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.

Add a dividend reinvestment button on the portfolio page to compound dividend earnings into more keys

2 participants