Allow passing dismissAll to closeSnackbar action, to be polished

This commit is contained in:
Mikhail Mikheev 2019-11-08 19:02:42 +04:00
parent cca6fda0a3
commit d5e076a307
5 changed files with 40 additions and 21 deletions

View File

@ -43,7 +43,7 @@
"axios": "0.19.0",
"bignumber.js": "9.0.0",
"connected-react-router": "6.5.2",
"date-fns": "2.6.0",
"date-fns": "2.7.0",
"ethereum-ens": "0.7.8",
"final-form": "4.18.6",
"history": "4.10.1",
@ -118,7 +118,7 @@
"eslint-config-airbnb": "18.0.1",
"eslint-plugin-flowtype": "4.3.0",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-jest": "23.0.2",
"eslint-plugin-jest": "23.0.3",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-react": "7.16.0",
"ethereumjs-abi": "0.6.8",
@ -141,7 +141,7 @@
"storybook-host": "5.1.0",
"storybook-router": "^0.3.4",
"style-loader": "1.0.0",
"truffle": "5.0.43",
"truffle": "5.0.44",
"truffle-contract": "4.0.31",
"truffle-solidity-loader": "0.1.32",
"uglifyjs-webpack-plugin": "2.2.0",

View File

@ -152,7 +152,7 @@ export const enhanceSnackbarForAction = (notification: Notification) => ({
options: {
...notification.options,
action: (key) => (
<IconButton onClick={() => store.dispatch(closeSnackbarAction(key))}>
<IconButton onClick={() => store.dispatch(closeSnackbarAction({key}))}>
<IconClose />
</IconButton>
),

View File

@ -18,9 +18,20 @@ export default handleActions<NotificationReducerState, *>(
return state.set(notification.key, makeNotification(notification))
},
[CLOSE_SNACKBAR]: (state: NotificationReducerState, action: ActionType<Function>): NotificationReducerState => {
const key = action.payload
const { key, dismissAll } = action.payload
return state.update(key, (prev) => prev.set('dismissed', true))
if (key) {
return state.update(key, (prev) => prev.set('dismissed', true))
}
if (dismissAll) {
return state.withMutations((map) => {
map.forEach((notification, notificationKey) => {
map.set(notificationKey, notification.set('dismissed', true))
})
})
}
return state
},
[REMOVE_SNACKBAR]: (state: NotificationReducerState, action: ActionType<Function>): NotificationReducerState => {
const key = action.payload

View File

@ -2,9 +2,10 @@
import type { Store, AnyAction } from 'redux'
import { type GlobalState } from '~/store/'
import { ADD_PROVIDER, REMOVE_PROVIDER } from '../actions'
import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3'
import { getWeb3, getProviderInfo, WALLET_PROVIDER } from '~/logic/wallets/getWeb3'
import { fetchProvider } from '~/logic/wallets/store/actions'
import { loadFromStorage, saveToStorage, removeFromStorage } from '~/utils/storage'
import closeSnackbar from '~/logic/notifications/store/actions/closeSnackbar'
const watchedActions = [ADD_PROVIDER, REMOVE_PROVIDER]
@ -30,17 +31,24 @@ const providerWatcherMware = (store: Store<GlobalState>) => (next: Function) =>
clearInterval(watcherInterval)
}
if (currentProviderProps.name === WALLET_PROVIDER.METAMASK && window.ethereum) {
window.ethereum.autoRefreshOnNetworkChange = false
}
saveToStorage(LAST_USED_PROVIDER_KEY, currentProviderProps.name)
watcherInterval = setInterval(async () => {
const web3 = getWeb3()
const providerInfo = await getProviderInfo(web3)
const networkChanged = currentProviderProps.network !== providerInfo.network
store.dispatch(closeSnackbar({ dismissAll: true }))
if (
currentProviderProps.account !== providerInfo.account
|| currentProviderProps.network !== providerInfo.network
|| networkChanged
) {
store.dispatch(fetchProvider(web3, () => {}, () => {}))
store.dispatch(fetchProvider(web3))
}
}, 2000)

View File

@ -6570,10 +6570,10 @@ data-urls@^1.0.0:
whatwg-mimetype "^2.2.0"
whatwg-url "^7.0.0"
date-fns@2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.6.0.tgz#a5bc82e6a4c3995ae124b0ba1a71aec7b8cbd666"
integrity sha512-F55YxqRdEfP/eYQmQjLN798v0AwLjmZ8nMBjdQvNwEE3N/zWVrlkkqT+9seBlPlsbkybG4JmWg3Ee3dIV9BcGQ==
date-fns@2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.7.0.tgz#8271d943cc4636a1f27698f1b8d6a9f1ceb74026"
integrity sha512-wxYp2PGoUDN5ZEACc61aOtYFvSsJUylIvCjpjDOqM1UDaKIIuMJ9fAnMYFHV3TQaDpfTVxhwNK/GiCaHKuemTA==
debug-fabulous@0.0.X:
version "0.0.4"
@ -7493,10 +7493,10 @@ eslint-plugin-import@2.18.2:
read-pkg-up "^2.0.0"
resolve "^1.11.0"
eslint-plugin-jest@23.0.2:
version "23.0.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.0.2.tgz#54a59bfe77245186afe13711a297067aefefff0a"
integrity sha512-fkxcvOJm0hC/jbJqYJjtuC9mvpTJqXd0Nixx7joVQvJoBQuXk/ws3+MtRYzD/4TcKSgvr21uuSLdwSxKJKC2cg==
eslint-plugin-jest@23.0.3:
version "23.0.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.0.3.tgz#d3f157f7791f97713372c13259ba1dfc436eb4c1"
integrity sha512-9cNxr66zeOyz1S9AkQL4/ouilR6QHpYj8vKOQZ60fu9hAt5PJWS4KqWqfr1aqN5NFEZSPjFOla2Azn+KTWiGwg==
dependencies:
"@typescript-eslint/experimental-utils" "^2.5.0"
@ -18120,10 +18120,10 @@ truffle-solidity-loader@0.1.32:
truffle-config "^1.1.19"
truffle-core "^5.0.33"
truffle@5.0.43:
version "5.0.43"
resolved "https://registry.yarnpkg.com/truffle/-/truffle-5.0.43.tgz#b5508807ec59789b90749daefb16f8b6fef8ce96"
integrity sha512-PbqOjgtYlkNAbJqzHeiMGvgBCLSuPVAWbM4+TNIGsRyqVCRIvXdLeQXUmdCRcGMWMteCvQ9Knhu4zNzT2Eo53A==
truffle@5.0.44:
version "5.0.44"
resolved "https://registry.yarnpkg.com/truffle/-/truffle-5.0.44.tgz#791df87992e32cf87840d3a58450e9e0331ccc0c"
integrity sha512-nbJAu5P76AU7wZxbQl/yPhf8g8gXMkVQtWZGRec5lz6w4fc4cOLrbAD6G6IJYVJqK3s8FTIjox0YKsI/Az/O6w==
dependencies:
app-module-path "^2.2.0"
mocha "5.2.0"