Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

fix: Sync current safe address into store #3761

Merged
merged 8 commits into from
Apr 25, 2022
Merged

Conversation

usame-algan
Copy link
Member

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

  1. Open a Safe
  2. Switch to a different Safe
  3. Observe that Safe name, address, balance, icon updates in the sidebar

@github-actions
Copy link

github-actions bot commented Apr 5, 2022

CLA Assistant Lite All Contributors have signed the CLA.

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()
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@github-actions
Copy link

github-actions bot commented Apr 5, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@github-actions
Copy link

github-actions bot commented Apr 5, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@github-actions
Copy link

github-actions bot commented Apr 5, 2022

Deployment links

🟠 Rinkeby Mainnet 🟣 Polygon 🟡 BSC Arbitrum 🟢 Gnosis Chain

@coveralls
Copy link

coveralls commented Apr 5, 2022

Pull Request Test Coverage Report for Build 2201465937

  • 6 of 15 (40.0%) changed or added relevant lines in 6 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.009%) to 35.546%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/App/index.tsx 0 1 0.0%
src/logic/currentSession/store/reducer/currentSession.ts 0 3 0.0%
src/logic/currentSession/hooks/useCurrentSafeAddressSync.ts 0 5 0.0%
Files with Coverage Reduction New Missed Lines %
src/components/App/index.tsx 1 0%
Totals Coverage Status
Change from base Build 2195129238: -0.009%
Covered Lines: 3558
Relevant Lines: 9056

💛 - Coveralls

Copy link
Member

@iamacook iamacook left a 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
Copy link
Member

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.

Copy link
Member Author

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.

@iamacook
Copy link
Member

Note: once we've merged this. We should remove all instances of extractSafeAddress() where we can readily use a selector.

@github-actions
Copy link

github-actions bot commented Apr 20, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 2 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@usame-algan
Copy link
Member Author

Note: once we've merged this. We should remove all instances of extractSafeAddress() where we can readily use a selector.

Added a new issue #3801 to address this.

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@francovenica
Copy link
Contributor

Looks good to me.
Switched between safes, the ones added by "Load safe" and the ones in the "Safe owned" list and also between networks. The sidebar updates right away.
04-20-2022_x(4718)

@katspaugh
Copy link
Member

@francovenica could you test one more time after clearing and disabling your cache and throttling the network to Slow 3G?

Screenshot 2022-04-21 at 08 02 34

@usame-algan usame-algan changed the title fix: Get current safe address outside of selector fix: Sync current safe address into store Apr 21, 2022
@usame-algan
Copy link
Member Author

@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.

Copy link
Member

@katspaugh katspaugh left a 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! 🚀

@usame-algan usame-algan merged commit 71bd092 into dev Apr 25, 2022
@usame-algan usame-algan deleted the fix-switch-safe-sidebar branch April 25, 2022 14:35
@github-actions github-actions bot locked and limited conversation to collaborators Apr 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sidebar is not updating when switching between Safes
5 participants