Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code quality for useCreateOffer and useAcceptOffer #130

Open
antho1404 opened this issue Jan 29, 2023 · 0 comments
Open

Improve code quality for useCreateOffer and useAcceptOffer #130

antho1404 opened this issue Jan 29, 2023 · 0 comments

Comments

@antho1404
Copy link
Member

          Instead of dealing with 2 useEffect to try to synchronize a state, I think it would be better to have a `useMemo` as we already have all the information.

Maybe something like that (didn't test, just a quick write)

const [signing, setSigning] = useState(false)
  const activeStep = useMemo(() => {
    if (signing) return CreateOfferStep.SIGNATURE
    if (
      approveCurrencyActiveStep === ApproveCurrencyStep.PENDING ||
      approveCollectionActiveStep === ApproveCollectionStep.PENDING
    ) {
      return CreateOfferStep.APPROVAL_PENDING
    }
    if (
      approveCurrencyActiveStep === ApproveCurrencyStep.SIGNATURE ||
      approveCollectionActiveStep === ApproveCollectionStep.SIGNATURE
    ) {
      return CreateOfferStep.APPROVAL_SIGNATURE
    }
    return CreateOfferStep.INITIAL
  }, [signing, approveCurrencyActiveStep, approveCollectionActiveStep])

As "internally" we only need to know if it's initial state or signing state, this could be replaced by an simple boolean state

Similar comment for the rest.

Also, when using a useEffect we need to make sure to have the cleanup function when dealing with states

Originally posted by @antho1404 in #117 (comment)

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

No branches or pull requests

1 participant