Skip to content

Fix multi-app staking flow #268

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 4 commits into from
Oct 24, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions src/pages/Staking/AuthorizeStakingApps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
} = {
Expand All @@ -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)
}
Expand Down Expand Up @@ -275,15 +287,17 @@ const AuthorizeStakingAppsPage: FC = () => {
/>
</>
)}
<Button
disabled={selectedApps.length === 0 || !isLoggedInAsAuthorizer}
variant="outline"
width="100%"
mt={5}
onClick={onAuthorizeApps}
>
Authorize selected apps
</Button>
{(!tbtcApp.isAuthorized || !randomBeaconApp.isAuthorized) && (
<Button
disabled={selectedApps.length === 0 || !isLoggedInAsAuthorizer}
variant="outline"
width="100%"
mt={5}
onClick={onAuthorizeApps}
>
Authorize Selected Apps
</Button>
)}
</Card>
</>
) : (
Expand Down