Skip to content

feat: use react 19 form actions#81

Open
rmeena840 wants to merge 1 commit intomasterfrom
80-use-react-19-form-actions-for-nbtc-buy
Open

feat: use react 19 form actions#81
rmeena840 wants to merge 1 commit intomasterfrom
80-use-react-19-form-actions-for-nbtc-buy

Conversation

@rmeena840
Copy link
Contributor

@rmeena840 rmeena840 commented Jun 4, 2025

Description

Closes: #80


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • added appropriate labels to the PR
  • provided a link to the relevant issue or specification
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary

Summary by Sourcery

Migrate the Buy nBTC form to React 19 form actions by removing react-hook-form and adopting native form submission with useActionState, custom validation, and NumericInput components

Enhancements:

  • Replace react-hook-form with React 19 form actions using useActionState for form submission
  • Swap FormNumericInput for the unified NumericInput component across the form
  • Move form state to useState and inline onChange handlers instead of useForm hooks
  • Implement validateTransaction for client-side checks with toasts for account presence, invalid amounts, and insufficient balance
  • Simplify YouReceive component by removing unnecessary props and relying on NumericInput

Signed-off-by: rmeena840 <rmeena840@gmail.com>
@rmeena840 rmeena840 linked an issue Jun 4, 2025 that may be closed by this pull request
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 4, 2025

Reviewer's Guide

Refactors the BuyNBTC component to adopt React 19 form actions via useActionState, removes react-hook-form integration, replaces FormNumericInput with NumericInput, centralizes transaction validation, and streamlines form reset and the YouReceive component.

File-Level Changes

Change Details Files
Migrated form handling from react-hook-form to React 19 form actions
  • Removed useForm, FormProvider, watch, trigger, handleSubmit, reset hooks
  • Replaced form submit handling with using useActionState
  • Replaced handleSubmit callback signature with new handleTransaction receiving FormData
app/components/BuyNBTC/BuyNBTC.tsx
Replaced FormNumericInput with NumericInput
  • Swapped imports from FormNumericInput to NumericInput
  • Updated props: added id, value binding, onChange, removed rules and createEmptySpace
app/components/BuyNBTC/BuyNBTC.tsx
Extracted and centralized transaction validation logic
  • Introduced validateTransaction for account, amount, and balance checks
  • Moved toast error handling into validation function and returned validation result
app/components/BuyNBTC/BuyNBTC.tsx
Simplified form reset and local state management
  • Replaced react-hook-form reset with setSUIAmount and resetMutation
  • Removed BuyNBTCForm interface and related types
app/components/BuyNBTC/BuyNBTC.tsx
Streamlined YouReceive component
  • Removed isSuiWalletConnected prop
  • Simplified value and placeholder logic using calculateYouReceive
app/components/BuyNBTC/BuyNBTC.tsx

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @rmeena840 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

return { isValid: true };
};

const handleTransaction = async (_: unknown, formData: FormData) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Unused formData parameter in handler

Please remove the unused formData parameter or update the function to use formData.get('suiAmount') instead of reading from state.

const handleTransaction = async (_: unknown, formData: FormData) => {
const mistAmount = parseSUI(suiAmount);
const { isValid } = validateTransaction(mistAmount);
if (!isValid) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!isValid) return;
if (!isValid) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

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.

Use React-19 Form Actions for nBTC Buy

1 participant