-
Notifications
You must be signed in to change notification settings - Fork 89
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(frontend): It is ambiguous on what scale is the withdrawal and deposit input #2817
Conversation
… withdraw liquidity components
…d withdraw liquidity components
✅ Deploy Preview for brilliant-pasca-3e80ec ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
<p>Based on the asset:</p> | ||
<p>Amount {amount} = {amount / Math.pow(10, asset.scale)} {asset.code} </p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be simplified a bit. I don't think we need to restate the amount since its in the input nor that it's translating to the current asset scale because of the context.
I think this would be fine:
<p>Based on the asset:</p> | |
<p>Amount {amount} = {amount / Math.pow(10, asset.scale)} {asset.code} </p> | |
<p> | |
{amount / Math.pow(10, asset.scale)} {asset.code}{' '} | |
</p> |
But perhaps a dummy input field for the asset scale really drives home the point (user can see 0 and 100 => 100, 2 and 100 => 1, etc.):
<Input
required
disabled
type='number'
label='Asset Scale'
value={asset.scale}
/>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Emanuel-Palestino thank you for the contribution - this looks great. Functionality is good, just left a couple style suggestions.
Thanks Blair. Iwiill add my review on Wednesday as well. Just OOO right now. |
Added styles for fields consistent Co-authored-by: Blair Currey <12960453+BlairCurrey@users.noreply.github.com>
Hello @BlairCurrey , I was thinking about your suggestions using a simplified description and the possibility of adding a dummy input. I think the best option is to use a simplified description, I coded it. I also thought in another approach:
I would like to know your feedback too @JoblersTune c: |
@Emanuel-Palestino that's a great suggestion to use the
This way with the visible input we can display the value in asset scale 0, the same way we display the liquidity info, but with the hidden field we can submit the value in the relevant asset scale. What do you think? |
|
||
return ( | ||
<LiquidityDialog | ||
onClose={dismissDialog} | ||
title='Deposit asset liquidity' | ||
type='Deposit' | ||
asset={asset} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asset={asset} | |
asset={{ code: asset.code, scale: asset.scale }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understand why you suggested this change, can you explain me please? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Since the definition for the BasicAsset is only scale and code this makes it more clear what we are passing in (not the entire asset is used, only code and scale). In other words it has better type matching.
type BasicAsset = {
code: string
scale: number
}
type LiquidityDialogProps = {
title: string
onClose: () => void
type: 'Deposit' | 'Withdraw'
asset: BasicAsset
}
So having
return (
<LiquidityDialog
onClose={dismissDialog}
title='Deposit asset liquidity'
type='Deposit'
asset={{ code: asset.code, scale: asset.scale }}
/>
)
Explicitly matches what we have set in the props definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, it makes sense thank you
|
||
return ( | ||
<LiquidityDialog | ||
onClose={dismissDialog} | ||
title='Withdraw asset liquidity' | ||
type='Withdraw' | ||
asset={asset} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asset={asset} | |
asset={{ code: asset.code, scale: asset.scale }} |
|
||
return ( | ||
<LiquidityDialog | ||
onClose={dismissDialog} | ||
title='Deposit peer liquidity' | ||
type='Deposit' | ||
asset={asset} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asset={asset} | |
asset={{ code: asset.code, scale: asset.scale }} |
|
||
return ( | ||
<LiquidityDialog | ||
onClose={dismissDialog} | ||
title='Withdraw peer liquidity' | ||
type='Withdraw' | ||
asset={asset} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asset={asset} | |
asset={{ code: asset.code, scale: asset.scale }} |
|
@JoblersTune that's a great implementation. I will work on it. |
…s passed as a prop
… on change input event
I have made the implementation. Waiting for your feedback c: Additionally, working in the project I found and issue and a suggestion to improve de UX related to assets and peers pages.
I don't know if I can make this changes in this pull request, or I have to open a new issue. |
Looks good to me @Emanuel-Palestino. Just a small fix to make prettier happy. #2817 (comment) The UX suggestions are good. Lets address that in another issue. Made one here: #2825 Feel free to assign yourself if you'd like. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I move the input out of the form, but I notice when the user submits the form it doesn't make the native html validation and it doesn't prevent the user from submitting any amount. The validation is made succesfully until the amount reaches the backend.
I understand that what you mention is also important. What do you think? @JoblersTune
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I was hoping the error message would cover that, even more so with your added minimum specification. Can you give me an example of where it is still failing @Emanuel-Palestino?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. When I submit a negative value or a very small value, it submits to the backend.
-
Negative values, the error message doesn't appear and the validation is made in the backend.
-
With very small value, the error message appear (although it doesn't prevent to the user from submit). The validation is made in the backend.
The message displayed at the top, is made by the backend. @JoblersTune these are the examples where it fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Emanuel-Palestino good catch on the negative values, thanks. We do most of our validation on the backend already. It creates a simpler frontend with faster load times and less JS complexity. We want to validate our input on the backend since that is where we'll be using it, so while it's nice to have frontend, reactive and immediate feedback it can lead to slower load times and some redundancy since backend validation is required as well.
So it's fine to get a server-side error for incorrect data entries. However, let's mitigate this by just adding a frontend message for the case where the value is negative as well, to give users a clearer error where we can.
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
const userInput = e.target.value
const scaledInput = parseFloat(userInput) * Math.pow(10, asset.scale)
const integerScaledInput = Math.floor(scaledInput)
if (scaledInput < 0) {
const error = 'The amount should be a positive value'
setErrorMessage(error)
} else if (scaledInput !== integerScaledInput) {
const error = 'The asset scale cannot accomodate this value'
setErrorMessage(error)
} else {
setErrorMessage('')
}
setActualAmount(integerScaledInput)
}
And then keep that input value above the form element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, I'll make the changes c:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for your positive and engaged contribution!
…posit input (#2817) * fix(frontend): asset scale consistency in liquidity dialogs. * Ensure asset scale consistency when displaying and withdrawing liquidity by adding asset info to the liquidity dialog component and updating the input handling in Rafiki Admin UI. --------- Co-authored-by: Blair Currey <12960453+BlairCurrey@users.noreply.github.com>
Changes proposed in this pull request
getPeer
api method.getAssetInfo
api method.Context
In the rafiki Admin UI, the liquidity information of peer and asset details are displayed using the current asset scale. When the user wants to deposit or withdraw liquidity, the amount introduced is handle using a scale of 0. So it is ambiguous on what scale the user is withdrawing or depositing.
Fixes: #2798