-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
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.
Nice!
src/app/components/Toolbar/Features/NetworkSelector/__tests__/index.test.tsx
Outdated
Show resolved
Hide resolved
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]) | ||
} |
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.
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)
- or (Tadej's preference) clicking extension icon to open popup redirects to last url (ideally use history.replace)
- when reloading an existing popup, don't redirect
- when opening popup with specific URL (e.g. to confirm dapp action), don't redirect
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.
ahh yes for "don't redirect" we will need to compare with prev value. I will add a new task.
To use
webext-redux
and reuse what we have in web in a new extension I think we need to: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".It would be good if someone had time for similar research maybe we don't need such overhaul.