Refactor provider notifications
This commit is contained in:
parent
b413d90f01
commit
227d011c7d
|
@ -3,6 +3,7 @@ import * as React from 'react'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { logComponentStack, type Info } from '~/utils/logBoundaries'
|
import { logComponentStack, type Info } from '~/utils/logBoundaries'
|
||||||
import { SharedSnackbarConsumer, type Variant } from '~/components/SharedSnackBar/Context'
|
import { SharedSnackbarConsumer, type Variant } from '~/components/SharedSnackBar/Context'
|
||||||
|
import { WALLET_ERROR_MSG } from '~/logic/wallets/store/actions'
|
||||||
import ProviderInfo from './component/ProviderInfo'
|
import ProviderInfo from './component/ProviderInfo'
|
||||||
import ProviderDetails from './component/ProviderInfo/UserDetails'
|
import ProviderDetails from './component/ProviderInfo/UserDetails'
|
||||||
import ProviderDisconnected from './component/ProviderDisconnected'
|
import ProviderDisconnected from './component/ProviderDisconnected'
|
||||||
|
@ -30,7 +31,7 @@ class HeaderComponent extends React.PureComponent<Props, State> {
|
||||||
|
|
||||||
componentDidCatch(error: Error, info: Info) {
|
componentDidCatch(error: Error, info: Info) {
|
||||||
this.setState({ hasError: true })
|
this.setState({ hasError: true })
|
||||||
this.props.openSnackbar('Error connecting to your wallet', 'error')
|
this.props.openSnackbar(WALLET_ERROR_MSG, 'error')
|
||||||
|
|
||||||
logComponentStack(error, info)
|
logComponentStack(error, info)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,24 @@ 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'
|
||||||
|
export const WALLET_ERROR_MSG = 'Error connecting to your wallet'
|
||||||
|
|
||||||
export default (openSnackbar: Function) => async (dispatch: ReduxDispatch<*>) => {
|
const handleProviderNotification = (loaded: boolean, available: boolean, openSnackbar: Function) => {
|
||||||
const response: ProviderProps = await getProviderInfo()
|
if (!loaded) {
|
||||||
|
openSnackbar(WALLET_ERROR_MSG, 'error')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const { available } = response
|
|
||||||
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<*>) => {
|
||||||
|
const response: ProviderProps = await getProviderInfo()
|
||||||
|
const { loaded, available } = response
|
||||||
|
|
||||||
|
handleProviderNotification(loaded, available, openSnackbar)
|
||||||
|
|
||||||
processProviderResponse(dispatch, response)
|
processProviderResponse(dispatch, response)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue