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

fix: claim delay field validation #2435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joanna-pagepro
Copy link
Contributor

Description

Claim delay field validation updated so that a user has to add a number between 0.0001 and 99999.

Testing

  • Step 1. Open action sidebar and select Payment builder action type
  • Step 2. Edit Claim delay field inside the table with payments and check if the validation works as it should.

Diffs

New stuff

  • ClaimDelayField component - uses cleave-zen inside

Changes 🏗

  • delay field validation updated
  • claim delay column value formatting updated for completed action

Deletions ⚰️

TODO

Resolves #2368

@joanna-pagepro joanna-pagepro self-assigned this May 23, 2024
@joanna-pagepro joanna-pagepro requested review from a team as code owners May 23, 2024 10:36
@joanna-pagepro joanna-pagepro force-pushed the fix/15912172-claim-delay-decimals branch from 962a158 to e94b723 Compare May 23, 2024 10:38
davecreaser
davecreaser previously approved these changes May 23, 2024
Copy link
Contributor

@davecreaser davecreaser left a comment

Choose a reason for hiding this comment

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

All looks good to me. Tested and the validation is working as expected for both min and max.

Copy link

@marcocolony marcocolony left a comment

Choose a reason for hiding this comment

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

Hey @joanna-pagepro, thanks for picking this one up!

  • Minimum and maximum values validation is working ✅
  • Only up to 4 decimal points can be entered ✅
  • I'm able to proceed with the payment creation when a number bigger than one is entered ✅
  • Values over 99999 can be entered ❌
  • The error message that was previously displayed whenever a decimal number was entered is no longer there, but I'm unable to proceed and an error is thrown in the console ❌

Export-1716478734658

Export-1716479096742

image

@arrenv
Copy link
Member

arrenv commented May 24, 2024

@joanna-pagepro
If possible, it would be good to solve the live validation lag issue when we have a lot of rows.

If not possible, then it would be good to limit the field length to 5 digits with 0.0001 and 99999.

If that is not possible due to the decimal place, then it would still be good to limit the length to 5 digits with 0.001 and 99999

@joanna-pagepro joanna-pagepro force-pushed the fix/15912172-claim-delay-decimals branch 3 times, most recently from 8aa1027 to de24bc0 Compare May 24, 2024 12:56
@joanna-pagepro
Copy link
Contributor Author

@marcocolony can you review it again?

Copy link

@marcocolony marcocolony left a comment

Choose a reason for hiding this comment

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

Hey @joanna-pagepro

I don't think it's quite fixed just yet, please see the examples I tested below

Export-1716569121298

@joanna-pagepro joanna-pagepro force-pushed the fix/15912172-claim-delay-decimals branch from de24bc0 to 67561de Compare May 27, 2024 07:15
Copy link

@melyndav melyndav left a comment

Choose a reason for hiding this comment

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

Hey @joanna-pagepro great start on this one.

When attempting to test this, I get default validation.

image

Can we remove step="0.001" to avoid the default validation?

@joanna-pagepro
Copy link
Contributor Author

@marcocolony @melyndav can you check again?

Copy link

@marcocolony marcocolony left a comment

Choose a reason for hiding this comment

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

@joanna-pagepro Thanks for looking into this again

I'm afraid I'm still able to enter as many digits as I want here.
Export-1716817246817

But the decimal values look great, always limited to 4 🙌

@joanna-pagepro
Copy link
Contributor Author

@marcocolony as discussed during the last daily - you will see an error on submit, it's not validated live. You should be able to enter as many digits as you want, but you shouldn't be able to submit the form if the value is bigger than 99999 or smaller than 0.0001

Copy link

@marcocolony marcocolony left a comment

Choose a reason for hiding this comment

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

Thank's @joanna-pagepro, everything looks good!

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

Nice start @joanna-pagepro, please be aware that incoming claim delay (fetched from the DB) can be up to 2^256 so we need to do all the maths operations using BigNumber.

On a side note, allowing setting the claim delay as fractional number exposes us to rounding issues such as this one. It's not a code issue, as it converted 0.1111 hr to 400 mins, then 400 mins / 3600 = 0.11111111111 seconds. @arrenv something to be aware of I suppose.

Screen.Recording.2024-05-28.at.23.20.23.mov

Comment on lines 116 to 120
const totalHours = BigNumber.from(
expendituresGlobalClaimDelayHours,
)
.add(BigNumber.from(dataRef.current[row.index]?.delay || 0))
.toNumber();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can't be easily tested since there's no saga to set the global claim delay, however I spotted some issues:

The problem with toNumber here is that it's possible for expendituresGlobalClaimDelayHours to be > 2^53 which will cause it to throw an error (and it wouldn't be caught). All claim delay calculations should use BigNumbers (great shout on already switching it here) and strings.

This made me realise the expendituresGlobalClaimDelayHours will not be set correctly because of line 29 where we check if global claim delay's type is number, which it will never be.

And, if dataRef.current[row.index]?.delay is a floating point number, BigNumber will throw an error.

Feel free to ping me on Discord and I'll provide you with instructions on how to set the global claim delay for testing.

const formattedHours = Math.floor(
Number(row.original.claimDelay) / 3600,
);
const formattedHours = row.original.claimDelay / 3600;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should use BigNumber

Comment on lines 171 to 173
claimDelay:
Number(item.claimDelay) +
Number(expendituresGlobalClaimDelay ?? '0'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should use BigNumber

@arrenv
Copy link
Member

arrenv commented May 29, 2024

On a side note, allowing setting the claim delay as fractional number exposes us to rounding issues such as this one. It's not a code issue, as it converted 0.1111 hr to 400 mins, then 400 mins / 3600 = 0.11111111111 seconds. @arrenv something to be aware of I suppose.

@jakubcolony I am not understanding the rounding to 400 mins here? Could we not just convert it to seconds in all cases? i.e. 0.1111 * 3600 then as it comes back / 3600?

@jakubcolony
Copy link
Collaborator

@arrenv Apologies, I meant seconds!

0.1111 hours * 3600 = 399.96 ≈ 400 seconds (what we send and store on chain)

Then back in the UI:

400 seconds / 3600 = 0.11111111111 hours

The solution could simply be to round to 4 decimal places when we display the delay too.

Copy link

@melyndav melyndav left a comment

Choose a reason for hiding this comment

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

Hey @joanna-pagepro just confirming if you're still seeing the validation as I am?

image

@joanna-pagepro
Copy link
Contributor Author

@melyndav no, I'm not seeing this. I've disabled the default form validation, but maybe it doesn't work the same on every browser. I will check it on Monday.

@arrenv
Copy link
Member

arrenv commented May 30, 2024

@arrenv Apologies, I meant seconds!

0.1111 hours * 3600 = 399.96 ≈ 400 seconds (what we send and store on chain)

Then back in the UI:

400 seconds / 3600 = 0.11111111111 hours

The solution could simply be to round to 4 decimal places when we display the delay too.

Oh, I made an error in mine as well, haha. Makes sense the rounding of the seconds.

@joanna-pagepro Can we please round to 4 decimal places on the completed view in the UI as @jakubcolony has suggested.

@joanna-pagepro joanna-pagepro force-pushed the fix/15912172-claim-delay-decimals branch from 3e2b56a to 59e77a7 Compare June 6, 2024 08:47
@joanna-pagepro
Copy link
Contributor Author

@arrenv @jakubcolony can you review again?

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

Codewise looking good, however there's an issue with claim delays starting with multiple zeros:

Screen.Recording.2024-06-09.at.22.11.56.mov

@joanna-pagepro
Copy link
Contributor Author

@arrenv @jakubcolony can you review this one?

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

Not sure what happened since last review but I started to see the native browser validation:

Screen.Recording.2024-06-12.at.21.56.20.mov

@joanna-pagepro
Copy link
Contributor Author

@jakubcolony it should be ok now

Copy link
Contributor

@bassgeta bassgeta left a comment

Choose a reason for hiding this comment

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

Nice one, works for minimum and maximum checks 👌
image
LGTM!

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

I'm unable to set the claim delay to 0 since the validation requires it to be at least 0.0001. I'm not sure this is correct, you should not be able to set it to something such as 0.00000001 but it should still be possible to create a payment with no claim delay.

image

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.

Decimals issue in claim delay input
7 participants