From 4c482f80ad501d2463bf2a86bb1f50c2c5bb9b14 Mon Sep 17 00:00:00 2001 From: apanizo Date: Thu, 11 Oct 2018 10:04:20 +0200 Subject: [PATCH] Adding wrong network notification --- .../wallets/store/actions/fetchProvider.js | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/logic/wallets/store/actions/fetchProvider.js b/src/logic/wallets/store/actions/fetchProvider.js index c203444d..14bbcbef 100644 --- a/src/logic/wallets/store/actions/fetchProvider.js +++ b/src/logic/wallets/store/actions/fetchProvider.js @@ -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) }