Skip to content
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

Use webext-redux in extension #787

Merged
merged 3 commits into from
Apr 6, 2022
Merged

Conversation

buberdds
Copy link
Contributor

@buberdds buberdds commented Apr 1, 2022

To use webext-redux and reuse what we have in web in a new extension I think we need to:

  • remove connected-router. While redux state was updated correctly, popup routing was never affected by history push called from saga. Moreover, this lib is not working with newer router and react router team recommend to "not to keep your routes in your Redux store at all".
  • redux-injectors are not compatible with Proxy story as they check store schema and Proxy is incompatible

It would be good if someone had time for similar research maybe we don't need such overhaul.

@buberdds buberdds changed the title Shareable logic between web and extension Use webext-redux in extension Apr 1, 2022
@buberdds buberdds requested review from lukaw3d and pro-wh April 1, 2022 16:11
Copy link
Member

@lukaw3d lukaw3d left a comment

Choose a reason for hiding this comment

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

Nice!

Comment on lines +7 to +17
export const useRouteRedirects = () => {
const activeWalletIndex = useSelector(selectActiveWalletId)
const address = useSelector(selectAddress)
const history = useHistory()

useEffect(() => {
if (typeof activeWalletIndex !== 'undefined' && address) {
history.push(`/account/${address}`)
}
}, [activeWalletIndex, address, history])
}
Copy link
Member

Choose a reason for hiding this comment

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

For a separate PR:

Oh this is tough. It was an effect in saga before (https://github.com/oasisprotocol/oasis-wallet-web/blob/5cebb40/src/app/state/wallet/saga.ts#L150) but saga now runs in background page.

One benefit of this is: when you open a popup with stored state, it redirects to your wallet.
One issue is: it always redirects. Even if you have chrome-extension://jplembhokmkioddbchbohdfkmjdmepbb/popup.html#/create-wallet open as a tab, and reload.

Use cases:

  • when active wallet changes, redirect to it
  • when clicking extension icon to open popup, redirect to active wallet (ideally use history.replace)
    • or (Tadej's preference) clicking extension icon to open popup redirects to last url (ideally use history.replace)
      (conflicts with "not to keep your routes in your Redux store at all" recommendation)
  • when reloading an existing popup, don't redirect
  • when opening popup with specific URL (e.g. to confirm dapp action), don't redirect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh yes for "don't redirect" we will need to compare with prev value. I will move this task to clickup.

src/store/configureStore.ts Show resolved Hide resolved
src/store/sagas.ts Outdated Show resolved Hide resolved
src/store/sagas.ts Show resolved Hide resolved
src/utils/types/injector-typings.ts Show resolved Hide resolved
src/store/reducers.ts Show resolved Hide resolved
src/app/useRouteRedirects.test.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants