create `ProviderState`

done out of consistency, but with `ProviderRecord` it would have been enough
This commit is contained in:
fernandomg 2020-07-14 13:18:47 -03:00
parent c314910713
commit d9e428c4ed
3 changed files with 13 additions and 13 deletions

View File

@ -6,11 +6,13 @@ import { makeProvider, ProviderRecord, ProviderProps } from 'src/logic/wallets/s
export const PROVIDER_REDUCER_ID = 'providers' export const PROVIDER_REDUCER_ID = 'providers'
export type ProviderState = ProviderRecord
export default handleActions( export default handleActions(
{ {
[ADD_PROVIDER]: (state: { providers: ProviderProps }, { payload }: { payload: ProviderProps }): ProviderRecord => [ADD_PROVIDER]: (state: ProviderState, { payload }: { payload: ProviderProps }): ProviderState =>
makeProvider(payload), makeProvider(payload),
[REMOVE_PROVIDER]: (): ProviderRecord => makeProvider(), [REMOVE_PROVIDER]: (): ProviderState => makeProvider(),
}, },
makeProvider(), makeProvider(),
) )

View File

@ -1,31 +1,30 @@
import { createSelector } from 'reselect' import { createSelector } from 'reselect'
import { ETHEREUM_NETWORK, ETHEREUM_NETWORK_IDS } from 'src/logic/wallets/getWeb3' import { ETHEREUM_NETWORK, ETHEREUM_NETWORK_IDS } from 'src/logic/wallets/getWeb3'
import { PROVIDER_REDUCER_ID } from 'src/logic/wallets/store/reducer/provider' import { PROVIDER_REDUCER_ID, ProviderState } from 'src/logic/wallets/store/reducer/provider'
import { AppReduxState } from 'src/store' import { AppReduxState } from 'src/store'
import { ProviderRecord } from 'src/logic/wallets/store/model/provider'
export const providerSelector = (state: AppReduxState): ProviderRecord => state[PROVIDER_REDUCER_ID] export const providerSelector = (state: AppReduxState): ProviderState => state[PROVIDER_REDUCER_ID]
export const userAccountSelector = createSelector(providerSelector, (provider: ProviderRecord): string => { export const userAccountSelector = createSelector(providerSelector, (provider: ProviderState): string => {
const account = provider.get('account') const account = provider.get('account')
return account || '' return account || ''
}) })
export const providerNameSelector = createSelector(providerSelector, (provider: ProviderRecord): string | undefined => { export const providerNameSelector = createSelector(providerSelector, (provider: ProviderState): string | undefined => {
const name = provider.get('name') const name = provider.get('name')
return name ? name.toLowerCase() : undefined return name ? name.toLowerCase() : undefined
}) })
export const networkSelector = createSelector(providerSelector, (provider: ProviderRecord): string => { export const networkSelector = createSelector(providerSelector, (provider: ProviderState): string => {
const networkId = provider.get('network') const networkId = provider.get('network')
return ETHEREUM_NETWORK_IDS[networkId] || ETHEREUM_NETWORK.UNKNOWN return ETHEREUM_NETWORK_IDS[networkId] || ETHEREUM_NETWORK.UNKNOWN
}) })
export const loadedSelector = createSelector(providerSelector, (provider: ProviderRecord): boolean => export const loadedSelector = createSelector(providerSelector, (provider: ProviderState): boolean =>
provider.get('loaded'), provider.get('loaded'),
) )
export const availableSelector = createSelector(providerSelector, (provider: ProviderRecord): boolean => export const availableSelector = createSelector(providerSelector, (provider: ProviderState): boolean =>
provider.get('available'), provider.get('available'),
) )

View File

@ -19,7 +19,7 @@ import currentSession, { CURRENT_SESSION_REDUCER_ID } from 'src/logic/currentSes
import notifications, { NOTIFICATIONS_REDUCER_ID } from 'src/logic/notifications/store/reducer/notifications' import notifications, { NOTIFICATIONS_REDUCER_ID } from 'src/logic/notifications/store/reducer/notifications'
import tokens, { TOKEN_REDUCER_ID, TokenState } from 'src/logic/tokens/store/reducer/tokens' import tokens, { TOKEN_REDUCER_ID, TokenState } from 'src/logic/tokens/store/reducer/tokens'
import providerWatcher from 'src/logic/wallets/store/middlewares/providerWatcher' import providerWatcher from 'src/logic/wallets/store/middlewares/providerWatcher'
import provider, { PROVIDER_REDUCER_ID } from 'src/logic/wallets/store/reducer/provider' import provider, { PROVIDER_REDUCER_ID, ProviderState } from 'src/logic/wallets/store/reducer/provider'
import notificationsMiddleware from 'src/routes/safe/store/middleware/notificationsMiddleware' import notificationsMiddleware from 'src/routes/safe/store/middleware/notificationsMiddleware'
import safeStorage from 'src/routes/safe/store/middleware/safeStorage' import safeStorage from 'src/routes/safe/store/middleware/safeStorage'
import cancellationTransactions, { import cancellationTransactions, {
@ -30,7 +30,6 @@ import incomingTransactions, {
} from 'src/routes/safe/store/reducer/incomingTransactions' } from 'src/routes/safe/store/reducer/incomingTransactions'
import safe, { SAFE_REDUCER_ID, SafeReducerMap } from 'src/routes/safe/store/reducer/safe' import safe, { SAFE_REDUCER_ID, SafeReducerMap } from 'src/routes/safe/store/reducer/safe'
import transactions, { TRANSACTIONS_REDUCER_ID } from 'src/routes/safe/store/reducer/transactions' import transactions, { TRANSACTIONS_REDUCER_ID } from 'src/routes/safe/store/reducer/transactions'
import { ProviderRecord } from 'src/logic/wallets/store/model/provider'
import { NFTAssets, NFTTokens } from 'src/logic/collectibles/sources/OpenSea' import { NFTAssets, NFTTokens } from 'src/logic/collectibles/sources/OpenSea'
export const history = createHashHistory({ hashType: 'slash' }) export const history = createHashHistory({ hashType: 'slash' })
@ -67,7 +66,7 @@ const reducers = combineReducers({
}) })
export type AppReduxState = CombinedState<{ export type AppReduxState = CombinedState<{
[PROVIDER_REDUCER_ID]?: ProviderRecord [PROVIDER_REDUCER_ID]?: ProviderState
[SAFE_REDUCER_ID]: SafeReducerMap [SAFE_REDUCER_ID]: SafeReducerMap
[NFT_ASSETS_REDUCER_ID]?: NFTAssets [NFT_ASSETS_REDUCER_ID]?: NFTAssets
[NFT_TOKENS_REDUCER_ID]?: NFTTokens [NFT_TOKENS_REDUCER_ID]?: NFTTokens