From 650e218cd262e5d248b2ad9a1369d01e3568677c Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Mon, 10 Oct 2022 17:09:32 +0200 Subject: [PATCH 1/4] Update the auth page Remove `Authorize Selected Apps` button if all apps have been authorized because htere arre no longer any more apps to select. --- .../Staking/AuthorizeStakingApps/index.tsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pages/Staking/AuthorizeStakingApps/index.tsx b/src/pages/Staking/AuthorizeStakingApps/index.tsx index 2f3ef6386..caa85c304 100644 --- a/src/pages/Staking/AuthorizeStakingApps/index.tsx +++ b/src/pages/Staking/AuthorizeStakingApps/index.tsx @@ -275,15 +275,17 @@ const AuthorizeStakingAppsPage: FC = () => { /> )} - + {(!tbtcApp.isAuthorized || !randomBeaconApp.isAuthorized) && ( + + )} ) : ( From 7ae1e56ab51510167ee3183ec8cbe96aa6d56c5b Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Mon, 10 Oct 2022 17:10:54 +0200 Subject: [PATCH 2/4] Update the multi app staking flow Remove the authorized app from selected apps state if the application has been authorized. In the previous impl was an issue that selected apps were still selected after authorization tx and user was able to click the `Authorize Selected Apps` again. This commit fixes this issue. --- .../Staking/AuthorizeStakingApps/index.tsx | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/pages/Staking/AuthorizeStakingApps/index.tsx b/src/pages/Staking/AuthorizeStakingApps/index.tsx index caa85c304..017cb3cc2 100644 --- a/src/pages/Staking/AuthorizeStakingApps/index.tsx +++ b/src/pages/Staking/AuthorizeStakingApps/index.tsx @@ -83,10 +83,6 @@ const AuthorizeStakingAppsPage: FC = () => { dispatch(stakingApplicationsSlice.actions.getSupportedApps({})) }, [dispatch, account]) - const tbtcMinAuthAmount = useStakingAppMinAuthorizationAmount("tbtc") - const randomBeaconMinAuthAmount = - useStakingAppMinAuthorizationAmount("randomBeacon") - const tbtcApp = useStakingAppDataByStakingProvider( "tbtc", stakingProviderAddress || AddressZero @@ -96,17 +92,6 @@ const AuthorizeStakingAppsPage: FC = () => { stakingProviderAddress || AddressZero ) - const stake = useSelector((state: RootState) => - selectStakeByStakingProvider(state, stakingProviderAddress!) - ) as StakeData - - const isLoggedInAsAuthorizer = - stake && account ? isSameETHAddress(stake.authorizer, account) : false - - const isInactiveStake = stake - ? BigNumber.from(stake?.totalInTStake).isZero() - : false - const appsAuthData: { [appName: string]: AppAuthDataProps & { address?: string } } = { @@ -130,6 +115,33 @@ const AuthorizeStakingAppsPage: FC = () => { }, } + useEffect(() => { + if (tbtcApp.isAuthorized) { + setSelectedApps((selectedApps) => + selectedApps.filter(({ stakingAppId }) => stakingAppId !== "tbtc") + ) + } + + if (randomBeaconApp.isAuthorized) { + selectedApps.filter(({ stakingAppId }) => stakingAppId !== "randomBeacon") + } + }, [tbtcApp.isAuthorized, randomBeaconApp.isAuthorized]) + + const tbtcMinAuthAmount = useStakingAppMinAuthorizationAmount("tbtc") + const randomBeaconMinAuthAmount = + useStakingAppMinAuthorizationAmount("randomBeacon") + + const stake = useSelector((state: RootState) => + selectStakeByStakingProvider(state, stakingProviderAddress!) + ) as StakeData + + const isLoggedInAsAuthorizer = + stake && account ? isSameETHAddress(stake.authorizer, account) : false + + const isInactiveStake = stake + ? BigNumber.from(stake?.totalInTStake).isZero() + : false + const isAppSelected = (stakingAppName: AppAuthDataProps["stakingAppId"]) => { return selectedApps.map((app) => app.stakingAppId).includes(stakingAppName) } From 67766478d637cd273caf276014f5288dff56ae3c Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Tue, 11 Oct 2022 12:09:27 +0200 Subject: [PATCH 3/4] Update button txt Each word on the button should start with capital letters. --- src/pages/Staking/AuthorizeStakingApps/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Staking/AuthorizeStakingApps/index.tsx b/src/pages/Staking/AuthorizeStakingApps/index.tsx index 017cb3cc2..063fffac1 100644 --- a/src/pages/Staking/AuthorizeStakingApps/index.tsx +++ b/src/pages/Staking/AuthorizeStakingApps/index.tsx @@ -295,7 +295,7 @@ const AuthorizeStakingAppsPage: FC = () => { mt={5} onClick={onAuthorizeApps} > - Authorize selected apps + Authorize Selected Apps )} From cd3636a2c52db48e365fd0af6cf1c6524bc09259 Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Mon, 24 Oct 2022 13:54:49 +0200 Subject: [PATCH 4/4] Fix updating state in hook We should use the `selectedApps` param from a callback function of `useState` hook to filter out the `randomBeacon` app if needed. --- src/pages/Staking/AuthorizeStakingApps/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/Staking/AuthorizeStakingApps/index.tsx b/src/pages/Staking/AuthorizeStakingApps/index.tsx index 063fffac1..eaf1f30ac 100644 --- a/src/pages/Staking/AuthorizeStakingApps/index.tsx +++ b/src/pages/Staking/AuthorizeStakingApps/index.tsx @@ -123,7 +123,11 @@ const AuthorizeStakingAppsPage: FC = () => { } if (randomBeaconApp.isAuthorized) { - selectedApps.filter(({ stakingAppId }) => stakingAppId !== "randomBeacon") + setSelectedApps((selectedApps) => + selectedApps.filter( + ({ stakingAppId }) => stakingAppId !== "randomBeacon" + ) + ) } }, [tbtcApp.isAuthorized, randomBeaconApp.isAuthorized])