joinmarket-webui / jam

Your sats. Your privacy. Your profit.
https://jamapp.org
MIT License
236 stars 48 forks source link

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

Closed barrytra closed 2 months ago

barrytra commented 2 months ago

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.

barrytra commented 2 months ago

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

editwentyone commented 2 months ago

think about, to remove the text inside () and maybe add this comment instead: https://github.com/joinmarket-webui/jam/issues/616#issuecomment-2058529662

theborakompanioni commented 2 months ago

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. :pray:

barrytra commented 2 months ago

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 commented 2 months ago

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:

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?

barrytra commented 2 months ago

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

barrytra commented 2 months ago

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

theborakompanioni commented 2 months ago

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. :rocket:

Great work @barrytra!

barrytra commented 2 months ago

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

theborakompanioni commented 2 months ago

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! :rocket: