test(staking): add unit tests for staking panel claim button lock state - #891
Merged
Chucks1093 merged 4 commits intoSep 5, 2026
Merged
Conversation
Add the staking panel's Claim button, gated on unlock_ledger, plus the claim_stake contract hook, and unit tests using fake timers asserting button state across the lock lifecycle (disabled/enabled, countdown format, auto-enable at zero, and claim invoked with the correct key_id). Closes accesslayerorg#815
|
@Ajibose 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! 🚀 |
Merge commit e498adc concatenated two independent, unrelated implementations that landed under the same file paths instead of picking one — accesslayerorg#872 vs accesslayerorg#877 for slippageTolerance.utils.ts / SlippageToleranceSelector.tsx, and accesslayerorg#875 vs accesslayerorg#887 for KeySimulationTool.tsx. The result had duplicate/interleaved declarations and broken syntax, failing `tsc` outright. Restores each file to the version that's actually wired into the app (TradeDialog's value/onChange selector API and CreatorDetailPage's currentSupply/protocolFeeBps/creatorFeeBps props) and matches the surviving test files; the orphaned, never-integrated duplicate implementations are dropped. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K2iSG6NcphR3o7H3FLGLYf
3 tasks
Merges dev (via fix/dev-broken-merge-slippage-keysim, which also repairs the pre-existing corruption in slippageTolerance.utils.ts / SlippageToleranceSelector.tsx / KeySimulationTool.tsx) into this branch. Resolves the resulting useWallet.ts conflict by keeping both useClaimStakeMutation (this branch, accesslayerorg#815) and useRedeemDeprecatedKeyMutation (dev, accesslayerorg#871) as separate exports. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K2iSG6NcphR3o7H3FLGLYf
Member
|
Fix Merge conflict |
Member
|
CI is green but this PR has a merge conflict with dev and cannot be auto-merged. Pull the latest dev into your branch with git fetch origin && git checkout your-branch && git merge origin/dev, resolve any conflicts, then run npm run build and npm run lint to confirm everything is clean before pushing. |
Resolves conflicts in slippageTolerance.utils.ts and its test file (accesslayerorg#872 vs accesslayerorg#877 additions landed adjacent to each other) — both sides are purely additive, so both blocks are kept. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCiPXzfWN9jdJAfNQQ6nbW
Closed
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #815
Summary
The staking panel had no Claim button gated on the stake's lock expiry, so the unit tests requested in #815 had nothing to exercise. This PR adds a production
StakingPanelcomponent (Claim button + live lock-expiry countdown) alongside its contract-call hook, and the unit tests that assert the button's state across the lock lifecycle using fake timers.New files
src/components/common/StakingPanel.tsx— staking panel with a live lock-expiry countdown and a Claim button gated onunlockLedger.src/utils/stakingClaim.utils.ts— pure helpercomputeRemainingClaimSeconds(unlockLedger, nowMs)computing seconds remaining until unlock; reuses the existingformatCountdownTimefromlockupCountdown.utils.tsforHH:MM:SSformatting.src/components/common/__tests__/StakingPanel.test.tsx— component tests (below).src/utils/__tests__/stakingClaim.utils.test.ts— pure-function tests forcomputeRemainingClaimSeconds.Modified files
src/hooks/useWallet.ts— addeduseClaimStakeMutation, a holder-facing mutation that submits theclaim_stakecontract call with the holder'skey_id, following the existinguseReinvestDividendMutation/useCreatorContractActionssimulated-contract-call pattern (toast on success/error, invalidatesqueryKeys.wallet.holdings). No existing exports were changed.Implementation details
StakingPaneltakeskeyId,unlockLedger(unix seconds), anonClaim(keyId)callback, and an optionalisClaimingflag — mirroring the decoupled prop pattern already used byLaunchPenaltyPanel(parent wires the actual mutation viaonClaim, e.g.useClaimStakeMutation), which keeps the component presentational and easy to unit test without aQueryClientProvider.setIntervalticks every second (cleared on unmount / prop change), recomputingcomputeRemainingClaimSeconds(unlockLedger)and re-rendering the countdown — the button'sdisabledstate is derived directly fromremainingSeconds > 0, so it flips to enabled the instant the countdown reaches zero, no reload needed.data-testids:staking-panel,staking-lock-countdown,staking-claim-button.Tests added
src/components/common/__tests__/StakingPanel.test.tsx(describe('StakingPanel (#815)'), usingvi.useFakeTimers()/vi.setSystemTime()):unlockLedgeris in the future.unlockLedgerhas passed.HH:MM:SSvalue (e.g.01:01:01for 3661s remaining).vi.advanceTimersByTimeand reaches00:00:00, with the Claim button enabling automatically — no reload/re-render trigger from the test.onClaimwith the correctkey_id(covers both string and numeric ids).isClaimingis true (in-flight guard).src/utils/__tests__/stakingClaim.utils.test.ts:unlockLedgerreturns the correct remaining-seconds count.unlockLedgerreturns0.0.How to test
pnpm install pnpm test -- src/components/common/__tests__/StakingPanel.test.tsx src/utils/__tests__/stakingClaim.utils.test.ts pnpm lint pnpm buildAll 9 new tests pass,
pnpm lintis clean, andpnpm exec tsc -bsucceeds. The fullpnpm testsuite was also run; it has 43 pre-existing failing files unrelated to this change (aWagmiProviderwallet-connector test setup issue), none of which touchStakingPanel,stakingClaim.utils, oruseWallet.ts.