Skip to content

616: (feat) prevent multiple fidelity bonds with same expiry date#741

Merged
theborakompanioni merged 6 commits intojoinmarket-webui:masterfrom
bhaveshg16:checkLockdateExists
Apr 23, 2024
Merged

616: (feat) prevent multiple fidelity bonds with same expiry date#741
theborakompanioni merged 6 commits intojoinmarket-webui:masterfrom
bhaveshg16:checkLockdateExists

Conversation

@bhaveshg16
Copy link
Contributor

This PR fixes #616
Implementation is done in lockdateForm.js component, that shows a warning message while selecting expiry date whenever a user creates a new fidelity bond.
When is warning message displayed? if there already exists fidelity bonds, and a user create a new one. But he selects an expiry date same as in any of the previous bonds. Then the message is displayed warning the user.

@bhaveshg16
Copy link
Contributor Author

bhaveshg16 commented Apr 16, 2024

This is how it works. I have two fidelity bonds already made with expiry date august,2024 and october,2025. There is no warning message when i create a new FB with different expiry date.
Screenshot from 2024-04-13 21-54-26
But as i select date october,2025 for my new FB. It gives a warning like this
Screenshot from 2024-04-16 11-07-15

It works smoothly. The warning vanishes when you set the date to a legal one.
Let me know if you see any issues, especially with the warning message(My English is not that good).
@theborakompanioni
@editwentyone

@bhaveshg16 bhaveshg16 marked this pull request as ready for review April 16, 2024 05:52
@editwentyone
Copy link

think about, to remove the text inside () and maybe add this comment instead: #616 (comment)

@theborakompanioni
Copy link
Collaborator

Hey @barrytra! Conecpt ACK!

As discussed, maybe it is a good idea to keep knowledge of Fidelity Bonds out of component LockdateForm.
Let me know once you need a review, want a question answered, or need any other help. 🙏

@bhaveshg16
Copy link
Contributor Author

bhaveshg16 commented Apr 17, 2024

As required, Information of Fidelity bonds has been moved to CreateFidelityBond file.
UX works fine as earlier.
Please suggest if any changes required @theborakompanioni

@theborakompanioni
Copy link
Collaborator

theborakompanioni commented Apr 17, 2024

As required, Information of Fidelity bonds has been moved to CreateFidelityBond file. UX works fine as earlier. Please suggest if any changes required @theborakompanioni

Nice : -)
Looks better and better!

Some notes from my side:

  • The alert is better placed inside the SelectDate component, instead of LockdateForm - in fact, the LockdateForm component should not need any changes at all.
  • Instead of a state variable + function + effect (useState/useEffect), have you considered using useMemo?

e.g.

const [lockDateExists, setLockDateExists] = useState(false)

const ifLockTimeExists = (fidelityBonds: Utxos, lockDate: Api.Lockdate): void => {
    setLockDateExists(false)
    if (lockDate)
      // eslint-disable-next-line array-callback-return
      fidelityBonds.map((fidelityBond) => {
        const locktime = fb.utxo.getLocktime(fidelityBond)
        if (locktime === fb.lockdate.toTimestamp(lockDate)) {
          setLockDateExists(true)
        }
      })
  }

  useEffect(() => {
    if (lockDate) ifLockTimeExists(fidelityBonds, lockDate)
  }, [fidelityBonds, lockDate])

Can be replaced with something like:

const bondWithSelectedLockDateAlreadyExists = useMemo(() => {
  return lockDate && fidelityBonds.some(it => fb.utxo.getLocktime(it) === fb.lockdate.toTimestamp(lockDate))
}, [fidelityBonds, lockDate])

What do you think?

@bhaveshg16
Copy link
Contributor Author

Ahh yes, that should work and would be much better. And also Alert is shifted to createFidelityBond component.
I am working on it

@bhaveshg16
Copy link
Contributor Author

bhaveshg16 commented Apr 18, 2024

Suggested changes are made. Now lockdatefrom and fidelitybondSteps components are untouched.
This looks fine to me now. what are your suggestions?

@theborakompanioni
Copy link
Collaborator

Suggested changes are made. Now lockdatefrom and fidelitybondSteps components are untouched. This looks fine to me now. what are your suggestions?

Awesome!

Now we just have to adapt the message a little bit and we are ready to merge. 🚀

Great work @barrytra!

@theborakompanioni theborakompanioni self-requested a review April 20, 2024 17:19
@theborakompanioni theborakompanioni added the UI/UX Issue related to cosmetics, design, or user experience label Apr 20, 2024
@bhaveshg16
Copy link
Contributor Author

I think everything is covered now. Message has been fixed as well. Is there anything else we need to do?

@theborakompanioni
Copy link
Collaborator

I think everything is covered now. Message has been fixed as well. Is there anything else we need to do?

Waiting for comments or approval from @editwentyone - then it is ready to be merged! 🚀

@theborakompanioni theborakompanioni merged commit c04007d into joinmarket-webui:master Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

UI/UX Issue related to cosmetics, design, or user experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Prevent creating multiple fidelity bonds with same expiry date

3 participants