Skip to content

feat: make form state persistent between route changes#146

Merged
necipsagiro merged 5 commits into
mainfrom
feat/ui-state-persistence
Sep 11, 2025
Merged

feat: make form state persistent between route changes#146
necipsagiro merged 5 commits into
mainfrom
feat/ui-state-persistence

Conversation

@necipsagiro
Copy link
Copy Markdown
Contributor

continuation of babylonlabs-io/simple-staking#1525

i realized we can use the onChange prop on Form component, so changed the logic from functional component to current version.

solved the type inconsistency by introducing a new type StakingFormFields. this is required because we can't directly use FormData since the StakingForm expects validatorAddresses.

@necipsagiro necipsagiro changed the title Feat/UI state persistence feat: make form state persistent between route changes Sep 8, 2025
@necipsagiro necipsagiro marked this pull request as ready for review September 8, 2025 09:22
Copilot AI review requested due to automatic review settings September 8, 2025 09:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements form state persistence across route changes by introducing a FormPersistenceState that maintains draft data for both BTC and Baby staking forms. The solution uses the onChange prop on Form components to continuously save form data to React state.

  • Adds FormPersistenceState context to store draft form data in memory
  • Modifies Tabs component to support keepMounted prop for maintaining component state
  • Updates forms to use defaultValues from persisted drafts and save changes via onChange handlers

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
services/simple-staking/src/ui/common/state/index.tsx Registers FormPersistenceState in state provider list
services/simple-staking/src/ui/common/state/FormPersistenceState.tsx New state context for persisting BTC and Baby staking form drafts
services/simple-staking/src/ui/common/page.tsx Enables keepMounted prop on main Tabs component
services/simple-staking/src/ui/common/components/Tabs/Tabs.tsx Adds keepMounted option to render all tab content with visibility control
services/simple-staking/src/ui/common/components/Staking/FeeModal/index.tsx Adds currentFeeRate prop to initialize modal state based on current form values
services/simple-staking/src/ui/common/components/Multistaking/MultistakingForm/StakingFeesSection.tsx Removes automatic fee rate initialization and passes current rate to FeeModal
services/simple-staking/src/ui/common/components/Multistaking/MultistakingForm/MultistakingForm.tsx Integrates form persistence with defaultValues and onChange handler
services/simple-staking/src/ui/baby/widgets/StakingForm/index.tsx Adds StakingFormFields type and integrates form persistence for Baby staking
services/simple-staking/src/ui/baby/layout.tsx Enables keepMounted for Baby staking tabs

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

gbarkhatov
gbarkhatov previously approved these changes Sep 9, 2025
Copy link
Copy Markdown
Contributor

@gbarkhatov gbarkhatov left a comment

Choose a reason for hiding this comment

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

Approved with minor suggestions, @jeremy-babylonlabs @jrwbabylonlab @jonybur please also check

Comment thread services/simple-staking/src/ui/baby/widgets/StakingForm/index.tsx Outdated
@necipsagiro necipsagiro merged commit e122e56 into main Sep 11, 2025
4 checks passed
@necipsagiro necipsagiro deleted the feat/ui-state-persistence branch September 11, 2025 20:42
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.

4 participants