-
Notifications
You must be signed in to change notification settings - Fork 363
fix: Sync current safe address into store #3761
Conversation
CLA Assistant Lite All Contributors have signed the CLA. |
808b462
to
f4474b6
Compare
src/components/App/index.tsx
Outdated
const { safeActionsState, onShow, onHide, showSendFunds, hideSendFunds } = useSafeActions() | ||
const currentCurrency = useSelector(currentCurrencySelector) | ||
const granted = useSelector(grantedSelector) | ||
const sidebarItems = useSidebarItems() | ||
const { address: safeAddress } = useSelector(currentSafeWithNames) | ||
const safeAddress = extractSafeAddress() |
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 thought the issue stemmed from this function? I would be apprehensive to rely on this. It feels as though the Safe may not be rendering when the Safe address in the URL changes. How does a different selector fix this?
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.
It would be better to fix the root cause: the selector.
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.
extractSafeAddress
is not a selector. The issue is that we call extractSafeAddress
inside the currentSafe
selector which apparently uses a cached value instead of always calling extractSafeAddress
again. Having the call inside the component ensures that it will always extract the current safe address when rerendering.
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 know it's not a selector. It's not triggering a rerender because it isn't. I would much prefer we fix the currentSafe
selector instead of hackily selecting the data we want as a workaround. The current fix is relying on other selectors to re-render the component, hence having the latested value returned from extractSafeAddress
.
ESLint Summary View Full Report
Report generated by eslint-plus-action |
ESLint Summary View Full Report
Report generated by eslint-plus-action |
Pull Request Test Coverage Report for Build 2201465937
💛 - Coveralls |
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.
Really nice approach! I've left a few comments.
return safes.get(address, baseSafe(address)) ?? {} | ||
}, | ||
) | ||
export const currentSafeAddress = (state: AppReduxState): string => state[CURRENT_SESSION_REDUCER_ID].currentSafeAddress |
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 should live in the folder for currentSession
selectors. You could reselect the currentSession
state selector as the basis for this as well.
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! Will move it to the other folder.
Note: once we've merged this. We should remove all instances of |
917c279
to
3ca4a00
Compare
ESLint Summary View Full Report
Report generated by eslint-plus-action |
Added a new issue #3801 to address this. |
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.
🚀
2909e1f
to
8f3305d
Compare
@francovenica could you test one more time after clearing and disabling your cache and throttling the network to Slow 3G? |
Also tested this successfully. The safe address in the sidebar immediately changes. Other values like balance take longer to update which is expected. |
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 to go then! 🚀
What it solves
Resolves #3760
How this PR fixes it
Instead of relying on the
currentSafe
selector, we handle the logic inside the component by getting all safes from the store, extracting the current safe address from the url and finally selecting the current safe.How to test it