-
Notifications
You must be signed in to change notification settings - Fork 26
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
Operator mapping - code cleaning #223
Conversation
We decided that we don't have to store the data related to operator mapping in the redux store. This commit adds that. I've also commented out `OperatorAddressMappingCard`. This card will be addressed in the future commits when working on subcribtion to "OperatorRegistered" event
There was a bug where when you close the login modal too quick, before `setStakes` action was dispatched, then the effect got blocked on `await listenerApi.condition` and was waiting for another action to dispatch and there were not any at that particular moment. To fix that I've added a condition to check if login modal was closed, if not, then we wait with the `condition()` function since the `displayMapOperatorToStakingProviderModalEffect` effect is run on a `setStakes` action, so we have all needed data fetcher already.
Fix displaying operator mapping modal when changins accouns. The display of this modal is based on the condition that the user closed succesfull login modal. We store this flag in `modalQueue` redux store. When changing accounts this modal is not displayed thus the flag is not set. To fix that we wil set this flag to true when resetting redux store action is called.
Adds data about operator mapping to the connectedAccount slice: { isUsedAsStakingProvider: boolean mappedOperator: { tbtc: string randomBeacon: string } } This data is neede to properly display the OperatorMappingCard that is on the Staking page.
Gets the proper data from redux store and conditionally display OperatorAddressMappingCard in staking page
Move operatorMapped event to connectedAddress slice and rename it to operatorRegistered to indicate it's relation with `OperatorRegistered` event.
`stakingProvider` prop was not used in `MapOperatorToStakingProviderModal` so we are removing it.
Use mappedOperators data from the store instead of calling the `getMappedOperatorsForStakingProvider` method from threshold lib in `useRegisterMultipleOperatorsTransaction` hook.
Operator Address Mapping Card should be displayed when tbtc mapped operator is AddressZero OR (not AND) random beacon mapped operator is AddressZero. This commit fixes that.
Move the store related to modal queue inside `modal` property since it's related to modal.
- move provider address to the top - change `Staking Provider` -> `Provider Address` - change `Operator` -> `Operator Address` - Display `View transaction 1 and transaction 2` in one row instead of two separate rows foe each app.
The operator mapping modal and new apps to authorize modal were not displayed properly when changin accounts in MetaMask. This commit fixes that.
Property `isFetching` was wrongly set to true and stays at this value when the connected account was not a staking provider. This commit fixes that.
|
||
const operatorMappedToStakingProviderHelpers = |
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
@@ -69,14 +73,14 @@ const MapOperatorToStakingProviderForm = withFormik< | |||
} | |||
if ( | |||
isOperatorMappedOnlyInRandomBeacon && | |||
values.operator !== operatorMappedRandomBeacon | |||
values.operator !== mappedOperatorRandomBeacon | |||
) { | |||
validationMsg = | |||
"The operator address doesn't match the one used in tbtc app" |
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 tBTC
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.
Good catch! Fixed in a1810ef
- use `isSameEthAddress` function in some conditions instead of `!==` - move large part of the validation to a new `validateInputtedOperatorAddress` function
Use `isAddressZero` instead of `isZeroAddress`
setAccountAddress -> walletConnected
isUsedAsStakingProvider -> isStakingProvider Also move it outside of mappedOperators object and keep it in the root of the account slice.
We don't need mapped operator in `account` slice because we already have `operatorMapping` property.
Rename the `setFetchingOperatorMapping` action to `fetchingOperatorMapping` and set the fetching to true automatically.
1 similar comment
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.
LGTM!
@georgeweiler is on vacation, all his requested changes were addressed and we have an approval from @r-czajkowski
Closes #232 (64677b3)
Closes #255 (ae4231d)
Operator mapping code cleaning
Main changes:
OperatorAddressMappingCard
shouldDisplayMapOperatorToStakingProviderModal
effectMapOperatorToStakingProvider
modal to not be displayed when we changed accounts in MetaMaskTODO in the future:
Change details
rearrange the operator mapping related data in redux store
Previously we keep the data needed to operator mapping in the redux store in this format:
(1)
rolesOf
property inconnected-account
slice:This indicated if the currently logged account is used as a staking provider in other stakes. We fetched the data from the contract.
(2)
mappedOperator
property instaking-applications
slice:This stored the data related to currently logged staking provider and it's mapped operator for each application. This could wrongly indicate that the data is more related to the staking app itself (since it was in the
staking-application
slice) when in reality it was more related to currently connected account.At first the idea was to not store this data in redux store at all, but unfrotunately this didn't went as smooth as I thogught and I think we must store them mainly to properly display
OperatorAddressMappingCard
in the staking page for all staking providers that don't have the operator mapped. I've encoutered problems with implementing it without using the store when the staking provider !=== owner.This is why i decided to go back to keeping the data in the redux store (you can see all this in the commit history) but in better (and i think simpler) form.
Right now we will store this data in
account
slice and we ditched the wholerolesOf
property which was object, to justisStakingProvider
which is boolean value. After the changes theconnected-account
is renamed toaccount
and looks like this:adds operator and staking provider addresses as props to the Operator Mapping related modals and
OperatorAddressMappingCard
For these components we are adding a props that contains operator address and staking provider address:
OperatorAddressMappingCard
MapOperatorToStakingProviderModal
MapOperatorToStakingProviderSuccessModal
MapOperatorToStakingProviderConfirmationModal
MapOperatorToStakingProviderForm
removes unnecessary shouldDisplayMapOperatorToStakingProviderModal effect
This effect was unnecessary. Instead of using
predicate
(from redux-toolkit) when callingdisplayMapOperatorToStakingProviderModalEffect
we now useactionCreator
(also from redux-toolkit) to call this effect onoperatorMappingInitialFetchDone
action call which in turn is called bysetStakes
action. This way we are sure we have all needed that in redux store and we can use them indisplayMapOperatorToStakingProviderModalEffect
fix some of the review comments from #199
Most comment were either fixed by itself during the refactor process (the part of code that was commented does no longer exist) and other ones I've tried to fix. For some I've added comments there to start a discussion.
fix a bug that caused the
MapOperatorToStakingProvider
modal to not be displayed when we changed accounts in MetaMaskWe are setting the
isSuccessfullLoginModalClosed
flag to false when resetting the store now, because the reset happend when we change the accounts and the login modal is not displayed in such case. We also setisMappingOperatorToStakingProviderModalClosed
flag back to false in this case.Additional note: The modal queue was also moved in the store to
modal
prop since it's related to modal. In the furue we are planning to create a real modal queue.update text in operator mapping modal
Update text based on Figma designs in
OperatorAddressMappingCard
component and inMapOperatorToStakingProviderModal
. For more details see #232