1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 00:28:06 +01:00
metamask-extension/ui/app/ducks/alerts/invalid-custom-network.js
Erik Marks 088d4c34f1
Merge pull request from GHSA-c2xw-px2x-pr65
* Remove network config store
* Remove inline networks variable in network controller
* Re-key network controller 'rpcTarget' to 'rpcUrl'
* Require chainId in lookupNetwork, implement eth_chainId
* Require chain ID in network form
* Add alert, migrations, and tests
* Add chainId validation to addToFrequentRpcList
* Update public config state selector to match new network controller
state
* Use network enums in networks-tab.constants
* Ensure chainId in provider config is current
* Update tests
2020-10-06 15:27:02 -02:30

52 lines
1.0 KiB
JavaScript

import { createSlice } from '@reduxjs/toolkit'
import { ALERT_TYPES } from '../../../../app/scripts/controllers/alert'
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 }