-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* initial ui for test my node use svg for node path add stories for test my node * add initial rewards calculation * update validation for rewards playground * init playground with default values * get node uptime * get mixnode reward estimation * calculate saturation calculate stake saturation * Make ComputeRewardEstParam derive Debug * set active set to be always true Co-authored-by: Jon Häggblad <[email protected]> Co-authored-by: Jon Häggblad <[email protected]>
- Loading branch information
Showing
68 changed files
with
672 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
19 changes: 19 additions & 0 deletions
19
nym-wallet/src/components/RewardsPlayground/InclusionProbability.tsx
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,19 @@ | ||
import React from 'react'; | ||
import { Typography } from '@mui/material'; | ||
import { SelectionChance } from '@nymproject/types'; | ||
|
||
const colorMap: { [key in SelectionChance]: string } = { | ||
Low: 'error.main', | ||
Good: 'warning.main', | ||
High: 'success.main', | ||
}; | ||
|
||
const textMap: { [key in SelectionChance]: string } = { | ||
Low: 'Low', | ||
Good: 'Good', | ||
High: 'High', | ||
}; | ||
|
||
export const InclusionProbability = ({ probability }: { probability: SelectionChance }) => ( | ||
<Typography sx={{ color: colorMap[probability] }}>{textMap[probability]}</Typography> | ||
); |
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,91 @@ | ||
import React, { useCallback } from 'react'; | ||
import { yupResolver } from '@hookform/resolvers/yup'; | ||
import { Button, Grid, TextField, Typography } from '@mui/material'; | ||
import { useForm } from 'react-hook-form'; | ||
import { DefaultInputValues } from 'src/pages/bonding/node-settings/apy-playground'; | ||
import { inputValidationSchema } from './inputsValidationSchema'; | ||
|
||
export type InputFields = { | ||
label: string; | ||
name: 'profitMargin' | 'uptime' | 'bond' | 'delegations' | 'operatorCost' | 'uptime'; | ||
isPercentage?: boolean; | ||
}[]; | ||
|
||
export type CalculateArgs = { | ||
bond: string; | ||
delegations: string; | ||
uptime: string; | ||
profitMargin: string; | ||
operatorCost: string; | ||
}; | ||
|
||
const inputFields: InputFields = [ | ||
{ label: 'Profit margin', name: 'profitMargin', isPercentage: true }, | ||
{ label: 'Operator cost', name: 'operatorCost' }, | ||
{ label: 'Bond', name: 'bond' }, | ||
{ label: 'Delegations', name: 'delegations' }, | ||
{ label: 'Uptime', name: 'uptime', isPercentage: true }, | ||
]; | ||
|
||
export const Inputs = ({ | ||
onCalculate, | ||
defaultValues, | ||
}: { | ||
onCalculate: (args: CalculateArgs) => Promise<void>; | ||
defaultValues: DefaultInputValues; | ||
}) => { | ||
const handleCalculate = useCallback( | ||
async (args: CalculateArgs) => { | ||
onCalculate({ | ||
bond: args.bond, | ||
delegations: args.delegations, | ||
uptime: args.uptime, | ||
profitMargin: args.profitMargin, | ||
operatorCost: args.operatorCost, | ||
}); | ||
}, | ||
[onCalculate], | ||
); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
} = useForm({ | ||
resolver: yupResolver(inputValidationSchema), | ||
defaultValues, | ||
}); | ||
|
||
return ( | ||
<Grid container spacing={3}> | ||
{inputFields.map((field) => ( | ||
<Grid item xs={12} lg={2} key={field.name}> | ||
<TextField | ||
{...register(field.name)} | ||
fullWidth | ||
label={field.label} | ||
name={field.name} | ||
error={Boolean(errors[field.name])} | ||
helperText={errors[field.name]?.message} | ||
InputProps={{ | ||
endAdornment: <Typography sx={{ color: 'grey.600' }}>{field.isPercentage ? '%' : 'NYM'}</Typography>, | ||
}} | ||
InputLabelProps={{ shrink: true }} | ||
/> | ||
</Grid> | ||
))}{' '} | ||
<Grid item xs={12} lg={2}> | ||
<Button | ||
variant="contained" | ||
disableElevation | ||
onClick={handleSubmit(handleCalculate)} | ||
size="large" | ||
fullWidth | ||
disabled={Boolean(Object.keys(errors).length)} | ||
> | ||
Calculate | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |
Oops, something went wrong.