-
Notifications
You must be signed in to change notification settings - Fork 29
Operator mapping - code cleaning #223
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
Changes from 17 commits
5822c8d
3dc60ea
b09cf35
ca8a09b
c1694a0
6b98f55
000ef3d
04e6e42
2d66a01
007f883
73490d2
008179b
2e665b4
2cf5d87
497617a
e381413
4f160ef
8860313
530837e
45c0b72
4fd84b4
369c9c9
cdf3180
ae4231d
a1810ef
45a5009
0de4912
08e6e15
d35e967
d3c637b
47639bf
eae8d07
64677b3
7ed1d17
009344d
c5453fd
2fd7154
676058f
f754bc4
390eaea
7cf4736
111117d
96105de
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 |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { FC, Ref } from "react" | |
| import { FormikProps, FormikErrors, withFormik } from "formik" | ||
| import { Form, FormikInput } from "../../Forms" | ||
| import { getErrorsObj, validateETHAddress } from "../../../utils/forms" | ||
| import { OperatorMappedToStakingProviderHelpers } from "../../../hooks/staking-applications/useOperatorMappedToStakingProviderHelpers" | ||
| import { isAddressZero } from "../../../web3/utils" | ||
|
|
||
| export interface MapOperatorToStakingProviderFormValues { | ||
| operator: string | ||
|
|
@@ -28,8 +28,9 @@ const MapOperatorToStakingProviderFormBase: FC< | |
|
|
||
| type MapOperatorToStakingProviderFormProps = { | ||
| initialAddress: string | ||
| mappedOperatorTbtc: string | ||
| mappedOperatorRandomBeacon: string | ||
| innerRef: Ref<FormikProps<MapOperatorToStakingProviderFormValues>> | ||
| operatorMappedToStakingProviderHelpers: OperatorMappedToStakingProviderHelpers | ||
| checkIfOperatorIsMappedToAnotherStakingProvider: ( | ||
| operator: string | ||
| ) => Promise<boolean> | ||
|
|
@@ -45,15 +46,18 @@ const MapOperatorToStakingProviderForm = withFormik< | |
| }), | ||
| validate: async (values, props) => { | ||
| const { | ||
| mappedOperatorTbtc, | ||
| mappedOperatorRandomBeacon, | ||
| checkIfOperatorIsMappedToAnotherStakingProvider, | ||
| operatorMappedToStakingProviderHelpers, | ||
| } = props | ||
| const { | ||
| operatorMappedRandomBeacon, | ||
| operatorMappedTbtc, | ||
| isOperatorMappedOnlyInRandomBeacon, | ||
| isOperatorMappedOnlyInTbtc, | ||
| } = operatorMappedToStakingProviderHelpers | ||
|
|
||
| const isOperatorMappedOnlyInTbtc = | ||
| !isAddressZero(mappedOperatorTbtc) && | ||
| isAddressZero(mappedOperatorRandomBeacon) | ||
|
|
||
| const isOperatorMappedOnlyInRandomBeacon = | ||
| isAddressZero(mappedOperatorTbtc) && | ||
| !isAddressZero(mappedOperatorRandomBeacon) | ||
| const errors: FormikErrors<MapOperatorToStakingProviderFormValues> = {} | ||
|
|
||
| errors.operator = validateETHAddress(values.operator) | ||
r-czajkowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -69,14 +73,14 @@ const MapOperatorToStakingProviderForm = withFormik< | |
| } | ||
| if ( | ||
| isOperatorMappedOnlyInRandomBeacon && | ||
| values.operator !== operatorMappedRandomBeacon | ||
| values.operator !== mappedOperatorRandomBeacon | ||
r-czajkowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
| validationMsg = | ||
| "The operator address doesn't match the one used in tbtc app" | ||
|
||
| } | ||
| if ( | ||
| isOperatorMappedOnlyInTbtc && | ||
| values.operator !== operatorMappedTbtc | ||
| values.operator !== mappedOperatorTbtc | ||
| ) { | ||
| validationMsg = | ||
| "The operator address doesn't match the one used in random beacon app" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { FC } from "react" | ||
| import { FC, Fragment } from "react" | ||
| import { | ||
| BodyMd, | ||
| BodySm, | ||
|
|
@@ -37,43 +37,50 @@ const MapOperatorToStakingProviderSuccessBase: FC< | |
| body={ | ||
| <> | ||
| <List spacing="2" mb={"4rem"}> | ||
|
||
| <ListItem key="map_operator_succes_modal__operator"> | ||
| <ListItem key="map_operator_succes_modal__staking_provider"> | ||
|
||
| <HStack justify="space-between"> | ||
| <BodySm>Operator</BodySm> | ||
| <BodySm>Provider Address</BodySm> | ||
| <BodySm> | ||
| {shortenAddress(transactions[0].application.operator)} | ||
| {shortenAddress(transactions[0].application.stakingProvider)} | ||
| </BodySm> | ||
| </HStack> | ||
| </ListItem> | ||
| <ListItem key="map_operator_succes_modal__staking_provider"> | ||
| <ListItem key="map_operator_succes_modal__operator"> | ||
|
||
| <HStack justify="space-between"> | ||
| <BodySm>Staking Provider</BodySm> | ||
| <BodySm>Operator Address</BodySm> | ||
| <BodySm> | ||
| {shortenAddress(transactions[0].application.stakingProvider)} | ||
| {shortenAddress(transactions[0].application.operator)} | ||
| </BodySm> | ||
| </HStack> | ||
| </ListItem> | ||
| </List> | ||
| {transactions.map((transaction, i) => { | ||
| const text = `${camelCaseToNormal( | ||
| transaction.application.appName | ||
| )} transaction` | ||
| return ( | ||
| <BodySm | ||
| align="center" | ||
| mt={1} | ||
| key={`map_operator_transaction_${i}`} | ||
| > | ||
| View{" "} | ||
| <BodySm align="center" mt={"1"}> | ||
| {transactions.length === 1 ? ( | ||
| <> | ||
| <ViewInBlockExplorer | ||
| text={text} | ||
| id={transaction.txHash} | ||
| text="View" | ||
| id={`map_operator_transaction_${transactions[0].txHash}`} | ||
|
||
| type={ExplorerDataType.TRANSACTION} | ||
| />{" "} | ||
| transaction on Etherscan | ||
| </> | ||
| ) : ( | ||
| <> | ||
| View{" "} | ||
| {transactions.map((_, index) => ( | ||
| <Fragment key={`map_operator_transaction_${index}`}> | ||
r-czajkowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <ViewInBlockExplorer | ||
| text={`transaction ${index + 1}`} | ||
| id={_.txHash} | ||
| type={ExplorerDataType.TRANSACTION} | ||
| /> | ||
| {index + 1 === transactions.length ? " " : " and "} | ||
| </Fragment> | ||
| ))} | ||
| on Etherscan | ||
| </BodySm> | ||
| ) | ||
| })} | ||
| </> | ||
| )} | ||
| </BodySm> | ||
| </> | ||
| } | ||
| /> | ||
|
|
||
This file was deleted.
This file was deleted.
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.
why remove this helper hook? seems like it saved some duplicate code. What if we added the tbtc & random beacon addresses as parameters so we don't have to rewrite the logic?
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.
This will be addressed in #278