Feature 309: Listen for web3connect disconnect event (#324)

* add 'disconnect' event listener for web3connect

* Update web3connect, set preventDuplicate to true for disconnected message

Co-authored-by: Germán Martínez <germartinez@users.noreply.github.com>
This commit is contained in:
Mikhail Mikheev 2019-12-20 17:31:57 +04:00 committed by GitHub
parent ac4a72ca08
commit 9b32cc9dc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 454 additions and 969 deletions

View File

@ -76,7 +76,7 @@
"semver": "^7.1.1", "semver": "^7.1.1",
"squarelink": "^1.1.4", "squarelink": "^1.1.4",
"web3": "1.2.4", "web3": "1.2.4",
"web3connect": "^1.0.0-beta.23" "web3connect": "^1.0.0-beta.25"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "7.7.5", "@babel/cli": "7.7.5",

View File

@ -7,7 +7,7 @@ import Fortmatic from 'fortmatic'
import Portis from '@portis/web3' import Portis from '@portis/web3'
import Squarelink from 'squarelink' import Squarelink from 'squarelink'
import Button from '~/components/layout/Button' import Button from '~/components/layout/Button'
import { fetchProvider } from '~/logic/wallets/store/actions' import { fetchProvider, removeProvider } from '~/logic/wallets/store/actions'
import { getNetwork } from '~/config' import { getNetwork } from '~/config'
import { store } from '~/store' import { store } from '~/store'
@ -62,6 +62,10 @@ web3Connect.on('connect', (provider: any) => {
} }
}) })
web3Connect.on('disconnect', () => {
store.dispatch(removeProvider())
})
type Props = { type Props = {
enqueueSnackbar: Function, enqueueSnackbar: Function,
closeSnackbar: Function, closeSnackbar: Function,

View File

@ -89,6 +89,7 @@ export const NOTIFICATIONS: Notifications = {
variant: SUCCESS, variant: SUCCESS,
persist: false, persist: false,
autoHideDuration: shortDuration, autoHideDuration: shortDuration,
preventDuplicate: true,
}, },
}, },
UNLOCK_WALLET_MSG: { UNLOCK_WALLET_MSG: {

View File

@ -1,15 +1,16 @@
// @flow // @flow
import { createAction } from 'redux-actions' import { createAction } from 'redux-actions'
import type { Dispatch as ReduxDispatch } from 'redux' import type { Dispatch as ReduxDispatch } from 'redux'
import { NOTIFICATIONS, showSnackbar } from '~/logic/notifications' import { NOTIFICATIONS, enhanceSnackbarForAction } from '~/logic/notifications'
import { getWeb3, resetWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3, resetWeb3 } from '~/logic/wallets/getWeb3'
import enqueueSnackbar from '~/logic/notifications/store/actions/enqueueSnackbar'
export const REMOVE_PROVIDER = 'REMOVE_PROVIDER' export const REMOVE_PROVIDER = 'REMOVE_PROVIDER'
const removeProvider = createAction<string, *, *>(REMOVE_PROVIDER) const removeProvider = createAction<string, *, *>(REMOVE_PROVIDER)
export default (enqueueSnackbar: Function, closeSnackbar: Function) => (dispatch: ReduxDispatch<*>) => { export default () => (dispatch: ReduxDispatch<*>) => {
showSnackbar(NOTIFICATIONS.WALLET_DISCONNECTED_MSG, enqueueSnackbar, closeSnackbar) dispatch(enqueueSnackbar(enhanceSnackbarForAction(NOTIFICATIONS.WALLET_DISCONNECTED_MSG)))
const web3 = getWeb3() const web3 = getWeb3()

1407
yarn.lock

File diff suppressed because it is too large Load Diff