mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-18 07:23:21 +01:00
54e9c53b27
* Add web3 shim usage alert background state and logic * Cleanup alert background state, constants * Implement web3 shim usage notification and settings * nodeify alert controller background hooks * Remove svg icon, again * Tweak alert controller initialization * Add support article URL * Un-thunk alert UI "actions" * Delete connect.svg file (unused)
49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
import { createSlice } from '@reduxjs/toolkit'
|
|
|
|
import { ALERT_TYPES } from '../../../../shared/constants/alerts'
|
|
import { ALERT_STATE } from './enums'
|
|
|
|
// Constants
|
|
|
|
const name = ALERT_TYPES.invalidCustomNetwork
|
|
|
|
const initialState = {
|
|
state: ALERT_STATE.CLOSED,
|
|
networkName: '',
|
|
}
|
|
|
|
// Slice (reducer plus auto-generated actions and action creators)
|
|
|
|
const slice = createSlice({
|
|
name,
|
|
initialState,
|
|
reducers: {
|
|
openAlert: (state, action) => {
|
|
state.state = ALERT_STATE.OPEN
|
|
state.networkName = action.payload
|
|
},
|
|
dismissAlert: (state) => {
|
|
state.state = ALERT_STATE.CLOSED
|
|
state.networkName = ''
|
|
},
|
|
},
|
|
})
|
|
|
|
const { actions, reducer } = slice
|
|
|
|
export default reducer
|
|
|
|
// Selectors
|
|
|
|
export const getAlertState = (state) => state[name].state
|
|
|
|
export const getNetworkName = (state) => state[name].networkName
|
|
|
|
export const alertIsOpen = (state) => state[name].state !== ALERT_STATE.CLOSED
|
|
|
|
// Actions / action-creators
|
|
|
|
const { openAlert, dismissAlert } = actions
|
|
|
|
export { openAlert, dismissAlert }
|