-
Notifications
You must be signed in to change notification settings - Fork 28
MAS UI integration v2 #189
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
Conversation
Open a modal to authorize apps for a given staking provider. This modal should be displayed when a user connects to a wallet and at least one staking provider doesn't have authorized at least one staking application.
Display correct statuses for authorized app such as: - check icon, - `authorized` label, - total authorized balance.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
Add `FlexProps` so we can change the styles for the main wrapper.
Create a modal that will be displayed when a user wants to authorize the staking application.
Open a `AuthorizeStakingApps` modal when a user wants to authorize staking applications. We want to display this modal only if the application is not authorized. For increasing authroization amount we want to display a different modal.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
Add validation befor submitting the `Authorize selected apps`.If a user wants to authorize multiple apps they have to select apps using checkboxes and fill the form for each selected app. Before submitting form the dapp triggers validation of selected forms to make sure all forms have been completed by the user.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
If more than one app was selected the validation didn't work correctly. This commit fixes it.
Create a `useSendTransactionFromFn` hook that allows sending transacion from funcion instance so we can pass the instance of funcion from threshold ts library. The `useSendTransacion` use the newly created hook so api of `useSendTransaction` hook remains unchanged.
`appNameToAppService` -> `stakingAppNameToThresholdAppService`. We want to export this variable because will be useful in other places.
Create the new hook that returns the staking application address based on the staking app name.
Just to define type we will implement this modal in follow-up work.
Add hook that authorizes multiple applications and increases the authorization for application.
Add submit function to authorize selected applications.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
1 similar comment
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
The `arrow` icon color is set to `currentColor` so will always match to the text color because an arrow is a child of `Link` component. The previous impl won't work in some cases eg: ``` <Button variant="outline" as={ExternalLink} mr={2} href={link} text="text" withArrow /> ``` This will render the arrow in default color even if we pass `color` prop, an arrow won't inherit color from parent.
Open success modal.
Pass the staking application address to a `AuthorizeStakingApps` as a prop- the staking app address is required to authrize app.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
@@ -60,6 +76,16 @@ export const AppAuthorizationInfo: FC<AppAuthorizationInfoProps> = ({ | |||
{`${formatPercentage(slashingPercentage, 0, true)}`} | |||
</BoxLabel> | |||
</HStack> | |||
{isAuthorizationRequired && isAuthorized && ( |
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'm running into an issue where my authorizedStake
value is undefined
for a moment before it loads. This causes formatTokenAmount
to crash the app because BigNumber can't handle undefined
. Maybe it's a local config issue? The value eventually loads for me, so adding this fixed the issue. Up to you if you think it's worth it. Do you think we we see this bug in production?
{isAuthorizationRequired && isAuthorized && !!authorizedStake && <>content</>}
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 it will be addressed once we add support for fetching data when a user goes to the auth page directly see #189 (comment). Does it work for you if I address it in a separate PR?
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.
yes that works
} | ||
|
||
const onAuthorizeApps = async () => { | ||
const isTbtcSelected = isAppSelected("tbtc") |
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.
if think you pull these out into their own variables in the component state such as:
const isTbtcSelected = useMemo(() => isAppSelected("tbtc"))
then you can reference them in this function and in the JSX below without re-rendering the component an 2 extra times when that value is calculated.
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.
The same thing as here #189 (comment). It won't be memoized value because isAppSelected
function uses the selectedApps
array. To achieve that we should refactor this component to be more "static"- I mean store the boolean for each app in a separate variable like that instead of storing selected apps in an array:
const [isTbtcAppSelected, setTbtcAppSelected] = useState(false)
const [isRandomBeaconAppSelected, setRandomBeaconAppSelected] = useState(false)
...
<AuthorizeApplicationsCardCheckbox
<...otherProps>
onCheckboxClick={(_, isChecked: boolean) => setTbtcAppSelected(isChecked)}
isSelected={isTbtcAppSelected}
/>
I think this approach is OK, at least for now, because we have only 2 staking apps. Let me know what you think and maybe let's refactor in a separate PR.
onCheckboxClick={onCheckboxClick} | ||
isSelected={selectedApps.map((app) => app.label).includes("tBTC")} | ||
isSelected={isAppSelected("tbtc")} |
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.
see comment above about extracting this to a variable
const navigate = useNavigate() | ||
const onAuthorizeOtherApps = async () => { | ||
closeModal() | ||
navigate(`/staking/${stakingProvider}/authorize`) |
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 is OK for now because I am doing the same in many modals, and I don't have a good solution to implement before the launch. But it's going to throw a warning, see:
https://dev.to/jexperton/how-to-fix-the-react-memory-leak-warning-d4i
also nit: why async method here?
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.
Yeah we need to get rid of the warning some day. Reagrding async- it is unnecessary. I'll remove.
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.
To match Figma designs.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
Print the lower than and bigger than signs. For example when the authorize stake is `44.900 T` for the stake that has `45.000 T` staked it will display that `>99%` is authorized instead of `100%`.
Register MAS listeners only if the `MULTI_APP_STAKING` feature flag is enabled.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
1 similar comment
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
The effect should be triggered once we get data for staking providers for random beacon and tbtc app.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
Format percentage value more precisely- print the lower than and bigger than signs.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
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.
Left few minor comments that I would like to be addressed before the merge
src/components/Modal/StakingApplications/StakingApplicationsAuthorized.tsx
Outdated
Show resolved
Hide resolved
Wrap the `ExternalLink` component with `forwardRef` to make the `as` prop to work as well.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
To display `100%` if calculated percentage value is 100 instead of `>99%` and `0%` if the calculated percentage value is 0 instead of `<1%`.
Preview uploaded to https://preview.dashboard.test.threshold.network/mas-integration-v2/index.html. |
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.
LGTM 🏋️
Depends on: #178
This PR adds support for multi-staking apps authorization.
Changes
display new apps to authorize when a user connects to a wallet and at least one staking provider has an unauthorized staking application,
Screenshots
display
authorized
status in staking application card,Screenshots
add validation for multi app staking form- if a user selects an application to authorize they must fill the form otherwise we should display validation messages,
Screenshots
multi staking applications authorization flow- pre-submit tx modal and success modal.
Screenshots