Skip to content

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

Merged
merged 32 commits into from
Sep 22, 2022
Merged

MAS UI integration v2 #189

merged 32 commits into from
Sep 22, 2022

Conversation

r-czajkowski
Copy link
Contributor

@r-czajkowski r-czajkowski commented Sep 12, 2022

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

    obraz

  • display authorized status in staking application card,

    Screenshots

    obraz

  • 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

    obraz

  • multi staking applications authorization flow- pre-submit tx modal and success modal.

    Screenshots

    obraz
    obraz

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.
@r-czajkowski r-czajkowski changed the base branch from main to mas-integration September 12, 2022 14:55
Display correct statuses for authorized app such as:
- check icon,
- `authorized` label,
- total authorized balance.
@github-actions
Copy link

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.
@github-actions
Copy link

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.
@github-actions
Copy link

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.
`displayNewAuthToAuthrozieAppModalEffect` -> `displayNewAppsToAuthrozieModalEffect`

`shouldDisplayNewAuthToAuthrozieAppModal` -> `shouldDisplayNewAppsToAuthrozieModal`
@github-actions
Copy link

1 similar comment
@github-actions
Copy link

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.
Pass the staking application address to a `AuthorizeStakingApps` as a
prop- the staking app address is required to authrize app.
@github-actions
Copy link

@r-czajkowski r-czajkowski marked this pull request as ready for review September 15, 2022 13:02
@@ -60,6 +76,16 @@ export const AppAuthorizationInfo: FC<AppAuthorizationInfoProps> = ({
{`${formatPercentage(slashingPercentage, 0, true)}`}
</BoxLabel>
</HStack>
{isAuthorizationRequired && isAuthorized && (
Copy link
Contributor

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</>}

Copy link
Contributor Author

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?

Copy link
Contributor

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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")}
Copy link
Contributor

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`)
Copy link
Contributor

@georgeweiler georgeweiler Sep 20, 2022

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

`hasAnyUnauthroizedStakes` -> `hasAnyUnauthorizedStakes`
@github-actions
Copy link

georgeweiler
georgeweiler previously approved these changes Sep 21, 2022
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.
@github-actions
Copy link

1 similar comment
@github-actions
Copy link

The effect should be triggered once we get data for staking providers
for random beacon and tbtc app.
@github-actions
Copy link

Format percentage value more precisely- print the lower than and bigger
than signs.
@github-actions
Copy link

Copy link
Contributor

@michalsmiarowski michalsmiarowski left a 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

Wrap the `ExternalLink` component with `forwardRef` to make the `as`
prop to work as well.
@github-actions
Copy link

To display `100%` if calculated percentage value is 100 instead of
`>99%` and `0%` if the calculated percentage value is 0 instead of
`<1%`.
@github-actions
Copy link

@michalsmiarowski michalsmiarowski self-requested a review September 22, 2022 12:18
Copy link
Contributor

@michalsmiarowski michalsmiarowski left a comment

Choose a reason for hiding this comment

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

LGTM 🏋️

@michalsmiarowski michalsmiarowski merged commit 4a3568e into main Sep 22, 2022
@michalsmiarowski michalsmiarowski deleted the mas-integration-v2 branch September 22, 2022 12:35
@r-czajkowski r-czajkowski added this to the v1.3.0 milestone Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants