Adding wrong network notification

This commit is contained in:
apanizo 2018-10-11 10:04:20 +02:00
parent 227d011c7d
commit 4c482f80ad
1 changed files with 15 additions and 8 deletions

View File

@ -1,14 +1,14 @@
// @flow
import type { Dispatch as ReduxDispatch } from 'redux'
import { getProviderInfo } from '~/logic/wallets/getWeb3'
import { getProviderInfo, ETHEREUM_NETWORK_IDS, ETHEREUM_NETWORK } from '~/logic/wallets/getWeb3'
import type { ProviderProps } from '~/logic/wallets/store/model/provider'
import { makeProvider } from '~/logic/wallets/store/model/provider'
import addProvider from './addProvider'
export const processProviderResponse = (dispatch: ReduxDispatch<*>, response: ProviderProps) => {
export const processProviderResponse = (dispatch: ReduxDispatch<*>, provider: ProviderProps) => {
const {
name, available, loaded, account, network,
} = response
} = provider
const walletRecord = makeProvider({
name, available, loaded, account, network,
@ -19,24 +19,31 @@ export const processProviderResponse = (dispatch: ReduxDispatch<*>, response: Pr
const SUCCESS_MSG = 'Wallet connected sucessfully'
const UNLOCK_MSG = 'Unlock your wallet to connect'
const WRONG_NETWORK = 'You are connected to wrong network. Please use RINKEBY'
export const WALLET_ERROR_MSG = 'Error connecting to your wallet'
const handleProviderNotification = (loaded: boolean, available: boolean, openSnackbar: Function) => {
const handleProviderNotification = (openSnackbar: Function, provider: ProviderProps) => {
const { loaded, available, network } = provider
if (!loaded) {
openSnackbar(WALLET_ERROR_MSG, 'error')
return
}
if (ETHEREUM_NETWORK_IDS[network] !== ETHEREUM_NETWORK.RINKEBY) {
openSnackbar(WRONG_NETWORK, 'error')
return
}
const msg = available ? SUCCESS_MSG : UNLOCK_MSG
const variant = available ? 'success' : 'warning'
openSnackbar(msg, variant)
}
export default (openSnackbar: Function) => async (dispatch: ReduxDispatch<*>) => {
const response: ProviderProps = await getProviderInfo()
const { loaded, available } = response
const provider: ProviderProps = await getProviderInfo()
handleProviderNotification(loaded, available, openSnackbar)
handleProviderNotification(openSnackbar, provider)
processProviderResponse(dispatch, response)
processProviderResponse(dispatch, provider)
}