-
Notifications
You must be signed in to change notification settings - Fork 24
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
Changes from 7 commits
88b0f4c
652c33a
955aeb9
4402d03
5b8ad8b
91ae27c
45ecf0c
ed0ce57
d818bfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,45 @@ | ||
import { Icon } from "@chakra-ui/icons" | ||
import { | ||
Alert, | ||
AlertIcon, | ||
Badge, | ||
BodyMd, | ||
BodyXs, | ||
Box, | ||
BoxLabel, | ||
Button, | ||
Card, | ||
HStack, | ||
LabelSm, | ||
LineDivider, | ||
Tooltip, | ||
useColorModeValue, | ||
} from "@threshold-network/components" | ||
import { FC } from "react" | ||
import { ModalType } from "../../enums" | ||
import { useModal } from "../../hooks/useModal" | ||
import shortenAddress from "../../utils/shortenAddress" | ||
import { isAddressZero } from "../../web3/utils" | ||
import { FcCheckmark, FiLink2 } from "react-icons/all" | ||
import { MappedOperatorsForStakingProvider } from "../../threshold-ts/mas" | ||
|
||
interface AppLabels { | ||
tbtc: string | ||
randomBeacon: string | ||
} | ||
|
||
const OperatorAddressMappingCard: FC<{ | ||
mappedOperatorTbtc: string | ||
mappedOperatorRandomBeacon: string | ||
}> = ({ mappedOperatorTbtc, mappedOperatorRandomBeacon }) => { | ||
stakingProvider: string | ||
mappedOperators: MappedOperatorsForStakingProvider | ||
}> = ({ stakingProvider, mappedOperators }) => { | ||
const { tbtc: mappedOperatorTbtc, randomBeacon: mappedOperatorRandomBeacon } = | ||
mappedOperators | ||
|
||
const appLabels: AppLabels = { | ||
tbtc: "tBTC", | ||
randomBeacon: "Random Beacon", | ||
} | ||
|
||
const { openModal } = useModal() | ||
const isOperatorMappedOnlyInTbtc = | ||
!isAddressZero(mappedOperatorTbtc) && | ||
|
@@ -29,6 +52,10 @@ const OperatorAddressMappingCard: FC<{ | |
const isOneOfTheAppsNotMapped = | ||
isOperatorMappedOnlyInRandomBeacon || isOperatorMappedOnlyInTbtc | ||
|
||
const shoudlDisplaySuccessState = | ||
!isAddressZero(mappedOperatorTbtc) && | ||
!isAddressZero(mappedOperatorRandomBeacon) | ||
|
||
const onStartMappingClick = () => { | ||
openModal(ModalType.MapOperatorToStakingProvider, { | ||
mappedOperatorTbtc, | ||
|
@@ -44,22 +71,66 @@ 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> | ||
{shoudlDisplaySuccessState ? ( | ||
Object.entries(mappedOperators).map(([appName, operator]) => { | ||
return ( | ||
<Box key={`mapped_operator_${appName}_${operator}`}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can get rid of the {Object.keys(mappedOperators)[
Object.keys(mappedOperators).length - 1
] !== appName && <LineDivider />} |
||
<HStack mt={5}> | ||
<BoxLabel status="secondary" size={"sm"}> | ||
{appLabels[appName as keyof AppLabels]} App | ||
</BoxLabel> | ||
<Badge variant="subtle" size={"md"} bgColor={"green.50"} py={1}> | ||
<HStack> | ||
<Icon as={FcCheckmark} />{" "} | ||
<LabelSm color={"green.500"}>Operator Mapped</LabelSm> | ||
</HStack> | ||
</Badge> | ||
</HStack> | ||
<HStack justify="space-between" mt={5}> | ||
<BoxLabel status="primary" size={"sm"}> | ||
Provider | ||
</BoxLabel> | ||
<BodyMd color={useColorModeValue("brand.500", "brand.550")}> | ||
<Tooltip label={`Staking provider`}> | ||
{shortenAddress(stakingProvider)} | ||
</Tooltip> | ||
</BodyMd> | ||
<Icon color="gray.500" boxSize="16px" as={FiLink2} /> | ||
<BoxLabel status="secondary" size={"sm"}> | ||
Operator | ||
</BoxLabel> | ||
<BodyMd color={useColorModeValue("gray.500", "gray.300")}> | ||
<Tooltip label={`Operator`}> | ||
{shortenAddress(operator)} | ||
</Tooltip> | ||
</BodyMd> | ||
</HStack> | ||
{Object.keys(mappedOperators)[ | ||
Object.keys(mappedOperators).length - 1 | ||
] !== appName && <LineDivider />} | ||
</Box> | ||
) | ||
}) | ||
) : ( | ||
<> | ||
<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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use a function from ea991e2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d818bfa