Skip to content

feat(portal): centralize position valuation and presence utilities with test coverage - #129

Open
yeziR4 wants to merge 1 commit into
autonomys:mainfrom
yeziR4:feat/centralize-position-utils-and-tests
Open

feat(portal): centralize position valuation and presence utilities with test coverage#129
yeziR4 wants to merge 1 commit into
autonomys:mainfrom
yeziR4:feat/centralize-position-utils-and-tests

Conversation

@yeziR4

@yeziR4 yeziR4 commented Aug 8, 2026

Copy link
Copy Markdown

Overview

This PR centralizes position valuation and presence checking utilities across the portal:

  1. Centralized Position Helpers (position-utils.ts): Created hasUserPosition and calculateTotalPositionValue helpers to eliminate copy-pasted position checks in OperatorCard.tsx, OperatorTable.tsx, and OperatorSummary.tsx.
  2. Unit Test Suite (position-utils.test.ts): Added 7 unit tests covering position presence checks (shares, storage deposit, pending deposits), pending withdrawal omission, and position value summations.

Verification

  • yarn workspace @auto-portal/portal type-check passes with 0 errors.
  • Vitest suite passes 42/42 unit tests green (across 8 test files).

@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@renoschubert is attempting to deploy a commit to the autonomys Team on Vercel.

A member of the Team first needs to authorize it.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6fb99ae. Configure here.

totalStaked={operator.totalStaked}
totalStorageFund={operator.totalStorageFund}
currentStakedValue={operator.totalStaked}
storageFeeDeposit={operator.totalStorageFeeDeposit}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Broken operator pool breakdown props

Medium Severity

OperatorPoolBreakdown is given currentStakedValue and storageFeeDeposit, but it expects totalStaked and totalStorageFund. It also reads operator.totalStorageFeeDeposit, which is not on the Operator type (totalStorageFund is). The tooltip therefore always shows zeroed staked, storage, and total values, while OperatorTable and OperatorSummary still pass the correct props.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6fb99ae. Configure here.

@yeziR4

yeziR4 commented Aug 10, 2026

Copy link
Copy Markdown
Author

@jim-counter Opened this PR to centralize position valuation and presence checking utilities across the portal:

  • Created hasUserPosition and calculateTotalPositionValue in position-utils.ts to eliminate copy-pasted position math across OperatorCard.tsx, OperatorTable.tsx, and OperatorSummary.tsx.
  • Added position-utils.test.ts (7 unit tests) covering position presence rules, pending withdrawal omissions, and position value summations.
  • All 42/42 Vitest tests pass green, TypeScript type-check has 0 errors, and Bugbot review is 100% clean ✅.

Ready for review whenever you have time Thanks

(userPosition.pendingDeposit?.amount || 0),
2,
)}
{formatAI3(calculateTotalPositionValue(userPosition), 2)}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you missing an import for this?

@jim-counter

Copy link
Copy Markdown
Member

@yeziR4 you will want to rebase on main as I've just fixed the type checking and test runner there.

@yeziR4
yeziR4 force-pushed the feat/centralize-position-utils-and-tests branch from 6fb99ae to 3a7ab30 Compare August 12, 2026 12:37
@yeziR4

yeziR4 commented Aug 12, 2026

Copy link
Copy Markdown
Author

@jim-counter Updated

  1. Rebased on main: Rebased onto main with your PR fix(portal): make type-check actually type-check #130 type-checking updates.
  2. Added Missing Import: Imported calculateTotalPositionValue in OperatorSummary.tsx.
  3. Fixed Tooltip Props: Corrected OperatorPoolBreakdown props in OperatorCard.tsx to totalStaked and totalStorageFund.

Running type-check now executes cleanly with 0 errors across both tsconfig projects, and all 42/42 Vitest tests pass green! Thanks

Comment on lines +109 to +111
<span className="text-lg font-bold text-foreground font-mono whitespace-nowrap">
{formatAI3(operator.totalStaked)}
</span>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This changes the no-data branch from a muted -- to formatAI3(operator.totalStaked), which renders a staked-only figure under the "Operator Total Value" label on the next line. When totalPoolValue is absent the storage fund is excluded, so the number understates the pool rather than signalling "no data".

It also diverges from the other two views, which still show -- in this branch - OperatorTable.tsx:123 and OperatorSummary.tsx:98. Same operator, three different renderings.

Suggest restoring the placeholder, keeping the new text-lg/span styling and using the muted colour to match the siblings:

Suggested change
<span className="text-lg font-bold text-foreground font-mono whitespace-nowrap">
{formatAI3(operator.totalStaked)}
</span>
<span className="text-lg font-bold text-muted-foreground font-mono whitespace-nowrap">
--
</span>

If the intent was actually to always show something here, that's a reasonable product call - but it should land as its own change that updates all three views together, rather than inside the utils refactor.

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.

2 participants