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

Feature 309: Listen for web3connect disconnect event #324

Merged
merged 5 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"reselect": "^4.0.0",
"squarelink": "^1.1.3",
"web3": "1.2.4",
"web3connect": "^1.0.0-beta.23",
"web3connect": "^1.0.0-beta.25",
"react-ga": "^2.7.0"
},
"devDependencies": {
Expand Down
6 changes: 5 additions & 1 deletion src/components/ConnectButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import WalletConnectProvider from '@walletconnect/web3-provider'
import Portis from '@portis/web3'
import Squarelink from 'squarelink'
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 { store } from '~/store'

Expand Down Expand Up @@ -52,6 +52,10 @@ web3Connect.on('connect', (provider: any) => {
}
})

web3Connect.on('disconnect', () => {
store.dispatch(removeProvider())
})

type Props = {
enqueueSnackbar: Function,
closeSnackbar: Function,
Expand Down
7 changes: 4 additions & 3 deletions src/logic/wallets/store/actions/removeProvider.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// @flow
import { createAction } from 'redux-actions'
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 enqueueSnackbar from '~/logic/notifications/store/actions/enqueueSnackbar'

export const REMOVE_PROVIDER = 'REMOVE_PROVIDER'

const removeProvider = createAction<string, *, *>(REMOVE_PROVIDER)

export default (enqueueSnackbar: Function, closeSnackbar: Function) => (dispatch: ReduxDispatch<*>) => {
showSnackbar(NOTIFICATIONS.WALLET_DISCONNECTED_MSG, enqueueSnackbar, closeSnackbar)
export default () => (dispatch: ReduxDispatch<*>) => {
dispatch(enqueueSnackbar(enhanceSnackbarForAction(NOTIFICATIONS.WALLET_DISCONNECTED_MSG)))

const web3 = getWeb3()

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18983,7 +18983,7 @@ web3@^0.18.2, web3@^0.18.4:
xhr2 "*"
xmlhttprequest "*"

web3connect@^1.0.0-beta.23:
web3connect@^1.0.0-beta.25:
version "1.0.0-beta.25"
resolved "https://registry.yarnpkg.com/web3connect/-/web3connect-1.0.0-beta.25.tgz#b8c49715a2e2dcd580423654f5dd3b432dcb4a9c"
integrity sha512-LXfOlsgijX7ep2DcGsE2aoMwek8nHceJJQ6BF4jILdGezYKhpn4RllJOOJ6PTvcNrWDJDtPleoDqoVzHbKMv1w==
Expand Down