Skip to content
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

Add success state to OperatorAddressMappingCard #261

Merged
merged 9 commits into from
Oct 26, 2022
75 changes: 56 additions & 19 deletions src/pages/Staking/OperatorAddressMappingCard.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import { CheckCircleIcon, Icon } from "@chakra-ui/icons"
import {
Alert,
AlertIcon,
Badge,
BodyMd,
BodyXs,
BoxLabel,
Button,
Card,
HStack,
Tooltip,
useColorModeValue,
} from "@threshold-network/components"
import { LabelSm } from "@threshold-network/components"
import { FC } from "react"
import { ModalType } from "../../enums"
// import { useOperatorMappedtoStakingProviderHelpers } from "../../hooks/staking-applications/useOperatorMappedToStakingProviderHelpers"
import { useModal } from "../../hooks/useModal"
import shortenAddress from "../../utils/shortenAddress"
import { isAddressZero } from "../../web3/utils"
import { FiLink2 } from "react-icons/all"

//TODO: Fix this
const OperatorAddressMappingCard: FC<{
stakingProvider: string
mappedOperatorTbtc: string
mappedOperatorRandomBeacon: string
}> = ({ mappedOperatorTbtc, mappedOperatorRandomBeacon }) => {
}> = ({ stakingProvider, mappedOperatorTbtc, mappedOperatorRandomBeacon }) => {
const { openModal } = useModal()
const isOperatorMappedOnlyInTbtc =
!isAddressZero(mappedOperatorTbtc) &&
Expand All @@ -31,6 +37,10 @@ const OperatorAddressMappingCard: FC<{
const isOneOfTheAppsNotMapped =
isOperatorMappedOnlyInRandomBeacon || isOperatorMappedOnlyInTbtc

const areAllAppsMappedSuccessfuly =
!isAddressZero(mappedOperatorTbtc) &&
!isAddressZero(mappedOperatorRandomBeacon)

const onStartMappingClick = () => {
openModal(ModalType.MapOperatorToStakingProvider, {
mappedOperatorTbtc,
Expand All @@ -46,22 +56,49 @@ const OperatorAddressMappingCard: FC<{
Node operators only
</Badge>
</HStack>
<Alert
status={isOneOfTheAppsNotMapped ? "error" : "warning"}
alignItems={"center"}
mt={5}
p={"8px 10px"}
>
<AlertIcon h={"14px"} as={"div"} alignSelf="auto" />
<BodyXs>
{isOneOfTheAppsNotMapped
? "One application from the tBTC + Random Beacon Rewards Bundle Suite requires the Operator Address mapped."
: "This section is for Staking Providers and self-operating stakers only. Map your Operator Address to your Provider Address for a better support for your hardware wallet in the node setup."}
</BodyXs>
</Alert>
<Button size="lg" w="100%" mt="5" onClick={onStartMappingClick}>
Start mapping
</Button>
{areAllAppsMappedSuccessfuly ? (
<HStack justify="space-between" mt={5}>
<BoxLabel
status="secondary"
size={"sm"}
icon={<CheckCircleIcon w={4} h={4} color="green.500" />}
>
Operator Mapped
</BoxLabel>
<HStack>
<BodyMd color={useColorModeValue("brand.500", "brand.550")}>
<Tooltip label={`Staking provider`}>
{shortenAddress(stakingProvider)}
</Tooltip>
</BodyMd>
<Icon color="gray.500" boxSize="16px" as={FiLink2} />
<BodyMd color={useColorModeValue("gray.500", "gray.300")}>
<Tooltip label={`Operator`}>
{shortenAddress(mappedOperatorTbtc)}
</Tooltip>
</BodyMd>
</HStack>
</HStack>
) : (
<>
<Alert
status={isOneOfTheAppsNotMapped ? "error" : "warning"}
alignItems={"center"}
mt={5}
p={"8px 10px"}
>
<AlertIcon h={"14px"} as={"div"} alignSelf="auto" />
<BodyXs>
{isOneOfTheAppsNotMapped
? "One application from the tBTC + Random Beacon Rewards Bundle Suite requires the Operator Address mapped."
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that this matches designs, but I think it might be more clear to tell the user which app needs to be mapped. wdyt? worth bringing up?

: "This section is for Staking Providers and self-operating stakers only. Map your Operator Address to your Provider Address for a better support for your hardware wallet in the node setup."}
</BodyXs>
</Alert>
<Button size="lg" w="100%" mt="5" onClick={onStartMappingClick}>
Start mapping
</Button>
</>
)}
</Card>
)
}
Expand Down
24 changes: 20 additions & 4 deletions src/pages/Staking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ const StakingPage: PageComponent = (props) => {
const hasStakes = stakes.length > 0

const {
isInitialFetchDone: isOperatorMappingInitialFetchDone,
data: { isUsedAsStakingProvider, mappedOperators },
} = useSelector((state: RootState) => state.connectedAccount.operatorMapping)
address,
operatorMapping: {
isInitialFetchDone: isOperatorMappingInitialFetchDone,
data: { isUsedAsStakingProvider, mappedOperators },
},
} = useSelector((state: RootState) => state.connectedAccount)

return (
<PageLayout pages={props.pages} title={props.title} maxW={"100%"}>
Expand All @@ -67,11 +70,13 @@ const StakingPage: PageComponent = (props) => {
>
Your Stake
</H4>
{isUsedAsStakingProvider &&
{address &&
isUsedAsStakingProvider &&
isOperatorMappingInitialFetchDone &&
(isAddressZero(mappedOperators.tbtc) ||
isAddressZero(mappedOperators.randomBeacon)) && (
<OperatorAddressMappingCard
stakingProvider={address}
mappedOperatorTbtc={mappedOperators.tbtc}
mappedOperatorRandomBeacon={mappedOperators.randomBeacon}
/>
Expand All @@ -83,6 +88,17 @@ const StakingPage: PageComponent = (props) => {
) : (
<NewStakeCard />
)}
{address &&
isUsedAsStakingProvider &&
isOperatorMappingInitialFetchDone &&
!isAddressZero(mappedOperators.tbtc) &&
!isAddressZero(mappedOperators.randomBeacon) && (
<OperatorAddressMappingCard
stakingProvider={address}
mappedOperatorTbtc={mappedOperators.tbtc}
mappedOperatorRandomBeacon={mappedOperators.randomBeacon}
/>
)}
</VStack>

<VStack w={"100%"} spacing={5}>
Expand Down