-
Notifications
You must be signed in to change notification settings - Fork 1
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
PE-6149: delegated staking landing page and stake/unstake modal #8
Merged
kunstmusik
merged 15 commits into
develop
from
PE-6149-delegated-staking-landing-page-and-stake-unstake-modal
May 30, 2024
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
16f5954
feat: initial work on delegated staking section of app
kunstmusik 5c3a68b
feat: update validation rules and implement sdk calls for increasing/…
kunstmusik 807c615
feat: utility code for calculating gateway and user rewards (EEY, EAY)
kunstmusik dc0fccf
fix: adjust bg of bottom panel to match rest of dialog
kunstmusik 90bc8aa
chore: update to ar.io SDK 1.0.7-alpha.4 and update all write interac…
kunstmusik 9545666
chore: update to 1.0.7-alpha.5 and fix mIOToken reading issue
kunstmusik a6f9dff
fix: allow padding for tooltip in ErrorMessageIcon
kunstmusik 2802a66
feat: implement EAY calculations for staking/unstaking
kunstmusik ade02fe
chore: update SDK to 1.0.7
kunstmusik ece1b02
fix: remove unnecessary cast
kunstmusik 30b16e2
chore: updated to use unary plus to coerce numbers and added unit tes…
kunstmusik 8e43425
fix: convert delegate reward share ratio from a percentage to a multi…
kunstmusik bc3fcd8
fix: update reward share ratio in test
kunstmusik f131eab
chore: re-enable test on actions builds
kunstmusik fc79c94
chore: skip unused test
kunstmusik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as Tooltip from '@radix-ui/react-tooltip'; | ||
import { FormErrorIcon } from '../icons'; | ||
|
||
const ErrorMessageIcon = ({ | ||
errorMessage, | ||
tooltipPadding = 0, | ||
}: { | ||
errorMessage: string; | ||
tooltipPadding?: number; | ||
}) => { | ||
|
||
const marginBottom = tooltipPadding ? `mb-[${tooltipPadding}px]` : ''; | ||
|
||
return ( | ||
<div className="relative flex px-[12px] text-red-600"> | ||
<Tooltip.Provider> | ||
<Tooltip.Root> | ||
<Tooltip.Trigger> | ||
<FormErrorIcon /> | ||
</Tooltip.Trigger> | ||
<Tooltip.Portal> | ||
<Tooltip.Content className="z-50 w-fit max-w-[400px] rounded-md bg-red-1000 px-[24px] py-[12px]"> | ||
<Tooltip.Arrow className={`fill-red-1000 ${marginBottom}`} /> | ||
<div className="text-sm text-red-600">{errorMessage}</div> | ||
</Tooltip.Content> | ||
</Tooltip.Portal> | ||
</Tooltip.Root> | ||
</Tooltip.Provider> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ErrorMessageIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -54,12 +54,18 @@ export const validateIOAmount = ( | |||||
return (v: string) => { | ||||||
const value = parseFloat(v); | ||||||
|
||||||
if(max) { | ||||||
return value < min || value > max || isNaN(v as unknown as number) | ||||||
if (max) { | ||||||
if (isNaN(v as unknown as number) || isNaN(value)) { | ||||||
return `${propertyName} must be a number.`; | ||||||
} else if (max <= min && value < min) { | ||||||
return `${propertyName} must be a number >= ${min} IO.`; | ||||||
} | ||||||
|
||||||
return value < min || value > max | ||||||
? `${propertyName} must be a number from ${min} to ${max} IO.` | ||||||
: undefined; | ||||||
} | ||||||
return value < min || isNaN(v as unknown as number) | ||||||
return value < min || isNaN(v as unknown as number) || isNaN(value) | ||||||
? `${propertyName} must be a number >= ${min} IO.` | ||||||
: undefined; | ||||||
}; | ||||||
|
@@ -73,10 +79,45 @@ export const validateNumberRange = ( | |||||
return (v: string) => { | ||||||
const value = parseFloat(v); | ||||||
|
||||||
// because parseFloat parses initial valid numbers then discards any remaining invalid text, | ||||||
// need to use isNan(v as unknown as number) to check for invalid text like "3adsfwe". | ||||||
return value < min || value > max || isNaN(v as unknown as number) | ||||||
// because parseFloat parses initial valid numbers then discards any remaining invalid text, | ||||||
// need to use isNan(v as unknown as number) to check for invalid text like "3adsfwe". | ||||||
return value < min || | ||||||
value > max || | ||||||
isNaN(v as unknown as number) || | ||||||
isNaN(value) | ||||||
? `${propertyName} must be a number from ${min} to ${max}.` | ||||||
: undefined; | ||||||
}; | ||||||
}; | ||||||
|
||||||
export const validateUnstakeAmount = ( | ||||||
propertyName: string, | ||||||
currentStake: number, | ||||||
minDelegatedStake: number, | ||||||
): FormValidationFunction => { | ||||||
return (v: string) => { | ||||||
const value = parseFloat(v); | ||||||
|
||||||
if (isNaN(v as unknown as number) || isNaN(value)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing that out, I updated to coerce using unary plus in this file and added a unit test. |
||||||
return `${propertyName} must be a number.`; | ||||||
} | ||||||
|
||||||
if (value < 1) { | ||||||
return `${propertyName} must be at least 1 IO.`; | ||||||
} | ||||||
|
||||||
if (value > currentStake) { | ||||||
return `${propertyName} cannot be greater than your current stake of ${currentStake} IO.`; | ||||||
} | ||||||
|
||||||
if ( | ||||||
currentStake - value < minDelegatedStake && | ||||||
value != minDelegatedStake && | ||||||
value != currentStake | ||||||
) { | ||||||
return `Withdrawing this amount will put you below the gateway's minimum stake of ${minDelegatedStake} IO. You can either: withdraw a smaller amount so your remaining stake is above the minimum - or - withdraw your full delegated stake.`; | ||||||
} | ||||||
|
||||||
return undefined; | ||||||
}; | ||||||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: these params seem redundant no? Atleast with usage - "open" should handle the rendering internally right? If not, then "open" could just always be set to true and you just use this pattern to render it?
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 started with one style of using the param but then switched to using it with the conditional rendering so that it would get fully unmounted from the DOM when not used. I'll take on refactoring out the open param and require using the && pattern in the next PR to keep this PR moving forward.