add ethereumnetworks type

This commit is contained in:
Mikhail Mikheev 2020-07-15 19:12:23 +04:00
parent 4eb5a6b12f
commit a6600c703d
2 changed files with 17 additions and 12 deletions

View File

@ -9,15 +9,17 @@ import { provider as Provider } from 'web3-core'
import { ProviderProps } from './store/model/provider'
export const ETHEREUM_NETWORK = {
MAINNET: 'MAINNET',
MORDEN: 'MORDEN',
ROPSTEN: 'ROPSTEN',
RINKEBY: 'RINKEBY',
GOERLI: 'GOERLI',
KOVAN: 'KOVAN',
UNKNOWN: 'UNKNOWN',
MAINNET: 'MAINNET' as const,
MORDEN: 'MORDEN' as const,
ROPSTEN: 'ROPSTEN' as const,
RINKEBY: 'RINKEBY' as const,
GOERLI: 'GOERLI' as const,
KOVAN: 'KOVAN' as const,
UNKNOWN: 'UNKNOWN' as const,
}
export type EthereumNetworks = typeof ETHEREUM_NETWORK[keyof typeof ETHEREUM_NETWORK]
export const WALLET_PROVIDER = {
SAFE: 'SAFE',
METAMASK: 'METAMASK',

View File

@ -1,6 +1,6 @@
import { createSelector } from 'reselect'
import { ETHEREUM_NETWORK, ETHEREUM_NETWORK_IDS } from 'src/logic/wallets/getWeb3'
import { ETHEREUM_NETWORK, ETHEREUM_NETWORK_IDS, EthereumNetworks } from 'src/logic/wallets/getWeb3'
import { PROVIDER_REDUCER_ID, ProviderState } from 'src/logic/wallets/store/reducer/provider'
import { AppReduxState } from 'src/store'
@ -16,10 +16,13 @@ export const providerNameSelector = createSelector(providerSelector, (provider:
return name ? name.toLowerCase() : undefined
})
export const networkSelector = createSelector(providerSelector, (provider: ProviderState): string => {
export const networkSelector = createSelector(
providerSelector,
(provider: ProviderState): EthereumNetworks => {
const networkId = provider.get('network')
return ETHEREUM_NETWORK_IDS[networkId] || ETHEREUM_NETWORK.UNKNOWN
})
},
)
export const loadedSelector = createSelector(providerSelector, (provider: ProviderState): boolean =>
provider.get('loaded'),