-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
88b0f4c
Add success state to OperatorAddressMappingCard
michalsmiarowski 652c33a
Merge branch 'operator-mapping-code-cleaning' into operator-mapping-c…
michalsmiarowski 955aeb9
Merge branch 'operator-mapping-code-cleaning' into operator-mapping-c…
michalsmiarowski 4402d03
Change design of OperatorAddressMappingCard
michalsmiarowski 5b8ad8b
Change variable name
michalsmiarowski 91ae27c
Merge branch 'operator-mapping-code-cleaning' into operator-mapping-c…
michalsmiarowski 45ecf0c
Merge branch 'operator-mapping-code-cleaning' into operator-mapping-c…
michalsmiarowski ed0ce57
Merge branch 'main' into operator-mapping-card-success-state
michalsmiarowski d818bfa
Use getSakingAppLabel function
michalsmiarowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,54 @@ | ||
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 { useAppSelector } from "../../hooks/store" | ||
import { useModal } from "../../hooks/useModal" | ||
import { selectMappedOperators } from "../../store/account/selectors" | ||
import shortenAddress from "../../utils/shortenAddress" | ||
import { isAddressZero } from "../../web3/utils" | ||
import { FcCheckmark, FiLink2 } from "react-icons/all" | ||
import { getSakingAppLabel } from "../../utils/getStakingAppLabel" | ||
import { StakingAppName } from "../../store/staking-applications" | ||
|
||
const OperatorAddressMappingCard: FC = () => { | ||
const OperatorAddressMappingCard: FC<{ stakingProvider: string }> = ({ | ||
stakingProvider, | ||
}) => { | ||
const { openModal } = useModal() | ||
const { | ||
mappedOperatorTbtc, | ||
mappedOperatorRandomBeacon, | ||
isOneOfTheAppsNotMapped, | ||
} = useAppSelector(selectMappedOperators) | ||
|
||
const { isOneOfTheAppsNotMapped } = useAppSelector(selectMappedOperators) | ||
const shoudlDisplaySuccessState = | ||
!isAddressZero(mappedOperatorTbtc) && | ||
!isAddressZero(mappedOperatorRandomBeacon) | ||
|
||
const onStartMappingClick = () => { | ||
openModal(ModalType.MapOperatorToStakingProvider) | ||
} | ||
|
||
const mappedOperators = { | ||
tbtc: mappedOperatorTbtc, | ||
randomBeacon: mappedOperatorRandomBeacon, | ||
} | ||
|
||
return ( | ||
<Card borderColor={isOneOfTheAppsNotMapped ? "red.500" : "gray.100"}> | ||
<HStack justifyContent={"space-between"}> | ||
|
@@ -31,22 +57,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}`}> | ||
<HStack mt={5}> | ||
<BoxLabel status="secondary" size={"sm"}> | ||
{getSakingAppLabel(appName as StakingAppName)} 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> | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we can get rid of the
Box
component and useHstack
directly. Also adding thedivider
prop to theHStack
we can get rid of the logic for rendering the line divider, I mean this code snippet: