Adding wrong network notification
This commit is contained in:
parent
227d011c7d
commit
4c482f80ad
|
@ -1,14 +1,14 @@
|
||||||
// @flow
|
// @flow
|
||||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
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 type { ProviderProps } from '~/logic/wallets/store/model/provider'
|
||||||
import { makeProvider } from '~/logic/wallets/store/model/provider'
|
import { makeProvider } from '~/logic/wallets/store/model/provider'
|
||||||
import addProvider from './addProvider'
|
import addProvider from './addProvider'
|
||||||
|
|
||||||
export const processProviderResponse = (dispatch: ReduxDispatch<*>, response: ProviderProps) => {
|
export const processProviderResponse = (dispatch: ReduxDispatch<*>, provider: ProviderProps) => {
|
||||||
const {
|
const {
|
||||||
name, available, loaded, account, network,
|
name, available, loaded, account, network,
|
||||||
} = response
|
} = provider
|
||||||
|
|
||||||
const walletRecord = makeProvider({
|
const walletRecord = makeProvider({
|
||||||
name, available, loaded, account, network,
|
name, available, loaded, account, network,
|
||||||
|
@ -19,24 +19,31 @@ export const processProviderResponse = (dispatch: ReduxDispatch<*>, response: Pr
|
||||||
|
|
||||||
const SUCCESS_MSG = 'Wallet connected sucessfully'
|
const SUCCESS_MSG = 'Wallet connected sucessfully'
|
||||||
const UNLOCK_MSG = 'Unlock your wallet to connect'
|
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'
|
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) {
|
if (!loaded) {
|
||||||
openSnackbar(WALLET_ERROR_MSG, 'error')
|
openSnackbar(WALLET_ERROR_MSG, 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ETHEREUM_NETWORK_IDS[network] !== ETHEREUM_NETWORK.RINKEBY) {
|
||||||
|
openSnackbar(WRONG_NETWORK, 'error')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const msg = available ? SUCCESS_MSG : UNLOCK_MSG
|
const msg = available ? SUCCESS_MSG : UNLOCK_MSG
|
||||||
const variant = available ? 'success' : 'warning'
|
const variant = available ? 'success' : 'warning'
|
||||||
openSnackbar(msg, variant)
|
openSnackbar(msg, variant)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (openSnackbar: Function) => async (dispatch: ReduxDispatch<*>) => {
|
export default (openSnackbar: Function) => async (dispatch: ReduxDispatch<*>) => {
|
||||||
const response: ProviderProps = await getProviderInfo()
|
const provider: ProviderProps = await getProviderInfo()
|
||||||
const { loaded, available } = response
|
|
||||||
|
|
||||||
handleProviderNotification(loaded, available, openSnackbar)
|
handleProviderNotification(openSnackbar, provider)
|
||||||
|
|
||||||
processProviderResponse(dispatch, response)
|
processProviderResponse(dispatch, provider)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue