Skip to content

Commit

Permalink
feat: Add support for TACo staking application
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Sep 1, 2023
1 parent 01fda78 commit fb5d1b6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const MapOperatorToStakingProviderConfirmationModal: FC<
operator,
isOperatorMappedOnlyInTbtc,
isOperatorMappedOnlyInRandomBeacon,
isOperatorMappedOnlyInTaco,
closeModal,
}) => {
const { account } = useWeb3React()
Expand Down Expand Up @@ -155,6 +156,13 @@ const MapOperatorToStakingProviderConfirmationModal: FC<
stakingProvider={account ? account : AddressZero}
/>
)}
{!isOperatorMappedOnlyInTaco && (
<OperatorMappingConfirmation
appName="taco"
operator={operator}
stakingProvider={account ? account : AddressZero}
/>
)}
</ModalBody>
<ModalFooter>
<Button onClick={closeModal} variant="outline" mr={2}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const MapOperatorToStakingProviderModal: FC<
<ModalCloseButton />
<ModalBody>
<InfoBox variant="modal">
{isOperatorMappedOnlyInRandomBeacon || isOperatorMappedOnlyInTbtc ? (
{isOperatorMappedOnlyInRandomBeacon || isOperatorMappedOnlyInTbtc || isOperatorMappedOnlyInTaco ? (
<H5>
We noticed you've only mapped 1 application's Operator Address.
</H5>
Expand Down
22 changes: 14 additions & 8 deletions src/pages/Staking/AuthorizeStakingApps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,28 @@ const AuthorizeStakingAppsPage: FC = () => {
const { openModal } = useModal()
const tbtcAppFormRef = useRef<FormikProps<FormValues>>(null)
const randomBeaconAppFormRef = useRef<FormikProps<FormValues>>(null)
const preAppFormRef = useRef<FormikProps<FormValues>>(null)
const tacoAppFormRef = useRef<FormikProps<FormValues>>(null)
const stakinAppNameToFormRef: Record<
AppAuthDataProps["stakingAppId"],
RefObject<FormikProps<FormValues>>
> = {
tbtc: tbtcAppFormRef,
randomBeacon: randomBeaconAppFormRef,
pre: preAppFormRef,
taco: tacoAppFormRef,
}

const dispatch = useAppDispatch()

const tbtcAppAddress = useStakingApplicationAddress("tbtc")
const randomBeaconAddress = useStakingApplicationAddress("randomBeacon")
const TACoAddress = useStakingApplicationAddress("taco")
const stakinAppNameToAddress: Record<
AppAuthDataProps["stakingAppId"],
string
> = {
tbtc: tbtcAppAddress,
randomBeacon: randomBeaconAddress,
pre: AddressZero,
taco: TACoAddress,
}

useEffect(() => {
Expand All @@ -91,6 +92,10 @@ const AuthorizeStakingAppsPage: FC = () => {
"randomBeacon",
stakingProviderAddress || AddressZero
)
const TACoApp = useStakingAppDataByStakingProvider(
"taco",
stakingProviderAddress || AddressZero
)

const appsAuthData: {
[appName: string]: AppAuthDataProps & { address?: string }
Expand All @@ -108,9 +113,10 @@ const AuthorizeStakingAppsPage: FC = () => {
label: "Random Beacon",
},
pre: {
stakingAppId: "pre",
label: "PRE",
status: "authorization-not-required",
...TACoApp,
stakingAppId: "taco",
label: "TACo",
address: TACoAddress,
},
}

Expand Down Expand Up @@ -285,10 +291,10 @@ const AuthorizeStakingAppsPage: FC = () => {
/>
<AuthorizeApplicationsCardCheckbox
mt={5}
appAuthData={appsAuthData.pre}
appAuthData={appsAuthData.taco}
totalInTStake={stake.totalInTStake}
onCheckboxClick={onCheckboxClick}
isSelected={isAppSelected("pre")}
isSelected={isAppSelected("taco")}
maxAuthAmount={stake.totalInTStake}
minAuthAmount={"0"}
stakingProvider={stakingProviderAddress!}
Expand Down
13 changes: 9 additions & 4 deletions src/pages/Staking/StakeCard/StakeApplications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ const StakeApplications: FC<{ stakingProvider: string }> = ({
"randomBeacon",
stakingProvider
)
const tacoApp = useStakingAppDataByStakingProvider("taco", stakingProvider)
const isTbtcFetching = useAppSelector(
(state) => state.applications.tbtc.stakingProviders.isFetching
)
const isRandomBeaconFetching = useAppSelector(
(state) => state.applications.randomBeacon.stakingProviders.isFetching
)
const isTacoFetching = useAppSelector(
(state) => state.applications.taco.stakingProviders.isFetching
)

const { isInactiveStake } = useStakeCardContext()

return (
<Box>
<BodyMd mb="4">Applications</BodyMd>
{(!tbtcApp.isAuthorized || !randomBeaconApp.isAuthorized) &&
{(!tbtcApp.isAuthorized || !randomBeaconApp.isAuthorized || !tacoApp.isAuthorized) &&
!isTbtcFetching &&
!isTacoFetching &&
!isRandomBeaconFetching && <BundledRewardsAlert mb="4" />}
<List spacing={4}>
<AuthorizeApplicationRow
Expand All @@ -47,9 +52,9 @@ const StakeApplications: FC<{ stakingProvider: string }> = ({
/>
<AuthorizeApplicationRow
as="li"
label="PRE"
isAuthorized={true}
percentage={isInactiveStake ? 0 : 100}
label="TACo"
isAuthorized={tacoApp.isAuthorized}
percentage={tacoApp.percentage}
stakingProvider={stakingProvider}
/>
</List>
Expand Down
9 changes: 7 additions & 2 deletions src/pages/Staking/StakeDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const StakeDetailsPage: FC = () => {
stakingProviderAddress || AddressZero
)

const tacoApp = useStakingAppDataByStakingProvider(
"taco",
stakingProviderAddress || AddressZero
)

const isInActiveStake = BigNumber.from(stake?.totalInTStake ?? "0").isZero()

const { total: rewardsForStake } = useAppSelector((state) =>
Expand Down Expand Up @@ -134,8 +139,8 @@ const StakeDetailsPage: FC = () => {
isAddress
address={stake.beneficiary}
/>
<StakeDetailRow label="PRE Node Status">
<NodeStatusLabel isAuthorized />
<StakeDetailRow label="TACo Node Status">
<NodeStatusLabel isAuthorized={tacoApp.isAuthorized} />
</StakeDetailRow>
<StakeDetailRow label="tBTC Node Status">
<NodeStatusLabel isAuthorized={tbtcApp.isAuthorized} />
Expand Down
18 changes: 17 additions & 1 deletion src/store/staking-applications/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface StakingApplicationsState {
randomBeacon: StakingApplicationState
}

export type StakingAppName = "tbtc" | "randomBeacon"
export type StakingAppName = "tbtc" | "randomBeacon" | "taco"

export const stakingApplicationsSlice = createSlice({
name: "staking-applications",
Expand Down Expand Up @@ -77,6 +77,22 @@ export const stakingApplicationsSlice = createSlice({
data: {},
},
},
taco: {
parameters: {
isFetching: false,
error: "",
data: {
authorizationDecreaseChangePeriod: "0",
minimumAuthorization: "0",
authorizationDecreaseDelay: "0",
},
},
stakingProviders: {
isFetching: false,
error: "",
data: {},
},
},
} as StakingApplicationsState,
reducers: {
getSupportedApps: (state: StakingApplicationsState, action) => {},
Expand Down

0 comments on commit fb5d1b6

Please sign in to comment.