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

frontend/backend: pass final tx. note to sendtx and remove propose-tx-note handler #2861

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

NicolaLS
Copy link
Contributor

Noticed this when planning the refactor of (frontend) send.tsx, this PR does not change anything and should be a pure refactor.

  • the propose-tx-note handler did nothing but setting a field on BaseAccount it did not validate anything, thus removing it and just using the final tx note reduces the code size but changes nothing.

We initially separated the note from the txProposal because we did not want to perform any actions when (e.g calculate fee) when user types a note:
4eb692c

It would be good to validate the note though to match the constrains here, but that would not be a refactor so maybe in another PR:

func (notes *Notes) SetTxNote(txID string, note string) (bool, error) {

@NicolaLS
Copy link
Contributor Author

(has a one line conflict with #2860)

err := handlers.account.SendTx()
var finalNote string
if err := json.NewDecoder(r.Body).Decode(&finalNote); err != nil {
handlers.log.WithError(err).Error("Failed to unmarshal transaction note")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: I decided to ignore the error on purpose here and only log it. it is better if users contact us with a bug that their notes do not get applied rather then I can't send any coins anymore

this should not happen anyways, and if it does proceeding with the zero string value is like the user never entered anything into the note field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

*what I mean is I don't return an error here and continue on purpose

Copy link
Contributor

Choose a reason for hiding this comment

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

please add this as a comment, otherwise the next person to look at this will think it's a bug and return an error 😄

Copy link
Contributor

@benma benma left a comment

Choose a reason for hiding this comment

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

Very nice, this is a great simplification. I am trying to think why I made this very clumsy way of adding the note, and if there was maybe a good reason for it, but I think it was just a blunder 😳

err := handlers.account.SendTx()
var finalNote string
if err := json.NewDecoder(r.Body).Decode(&finalNote); err != nil {
handlers.log.WithError(err).Error("Failed to unmarshal transaction note")
Copy link
Contributor

Choose a reason for hiding this comment

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

please add this as a comment, otherwise the next person to look at this will think it's a bug and return an error 😄

@benma
Copy link
Contributor

benma commented Aug 26, 2024

Also it should be one commit, it's one logical change.

@NicolaLS
Copy link
Contributor Author

(rebased)

Pass the final transaction note to the sendtx handler on submit (send)
instead of remembering a proposed transaction note which is set
separately using the propose-tx-note handler.

Currently there is no benefit of having a separate handler for the
transaction note for the active proposal. It was separated in this
commit because typing in the note field would cause the other fields to
be validated/calculated: 4eb692c

However since the backend does not perform any calculations or
validation on this handler, the final note can be submitted when
clicking send (calling the sendtx handler).
@NicolaLS
Copy link
Contributor Author

@benma thanks :) I rebased, squashed, and added a comment explaining why we don't return an error when unmarshaling the tx. note fails, PTAL.

Copy link
Contributor

@benma benma left a comment

Choose a reason for hiding this comment

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

tACK

@benma benma merged commit 9d8ce5c into BitBoxSwiss:master Aug 31, 2024
6 checks passed
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.

2 participants