Refactor fetch provider
This commit is contained in:
parent
5444e56401
commit
b615d20a65
|
@ -1,14 +1,12 @@
|
|||
// @flow
|
||||
import { fetchProvider, recurrentFetchProvider, removeProvider } from '~/logic/wallets/store/actions'
|
||||
import { fetchProvider, removeProvider } from '~/logic/wallets/store/actions'
|
||||
|
||||
export type Actions = {
|
||||
fetchProvider: typeof fetchProvider,
|
||||
recurrentFetchProvider: typeof recurrentFetchProvider,
|
||||
removeProvider: typeof removeProvider,
|
||||
}
|
||||
|
||||
export default {
|
||||
fetchProvider,
|
||||
recurrentFetchProvider,
|
||||
removeProvider,
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import { connect } from 'react-redux'
|
|||
import { logComponentStack, type Info } from '~/utils/logBoundaries'
|
||||
import { SharedSnackbarConsumer, type Variant } from '~/components/SharedSnackBar/Context'
|
||||
import { WALLET_ERROR_MSG } from '~/logic/wallets/store/actions'
|
||||
import { getProviderInfo } from '~/logic/wallets/getWeb3'
|
||||
import ProviderAccesible from './component/ProviderInfo/ProviderAccesible'
|
||||
import UserDetails from './component/ProviderDetails/UserDetails'
|
||||
import ProviderDisconnected from './component/ProviderInfo/ProviderDisconnected'
|
||||
|
@ -26,7 +27,7 @@ class HeaderComponent extends React.PureComponent<Props, State> {
|
|||
hasError: false,
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
componentDidMount() {
|
||||
this.onConnect()
|
||||
}
|
||||
|
||||
|
@ -39,19 +40,25 @@ class HeaderComponent extends React.PureComponent<Props, State> {
|
|||
}
|
||||
|
||||
onDisconnect = () => {
|
||||
const { removeProvider } = this.props
|
||||
const { removeProvider, openSnackbar } = this.props
|
||||
clearInterval(this.providerListener)
|
||||
|
||||
removeProvider(this.props.openSnackbar)
|
||||
removeProvider(openSnackbar)
|
||||
}
|
||||
|
||||
onConnect = async () => {
|
||||
const { fetchProvider, recurrentFetchProvider } = this.props
|
||||
|
||||
const { fetchProvider, openSnackbar } = this.props
|
||||
|
||||
clearInterval(this.providerListener)
|
||||
let currentProvider: ProviderProps = await fetchProvider(this.props.openSnackbar)
|
||||
this.providerListener = setInterval(async () => {
|
||||
currentProvider = await recurrentFetchProvider(currentProvider, this.props.openSnackbar)
|
||||
let currentProvider: ProviderProps = await getProviderInfo()
|
||||
fetchProvider(currentProvider, openSnackbar)
|
||||
|
||||
this.providerListener = setInterval(async () => {
|
||||
const newProvider: ProviderProps = await getProviderInfo()
|
||||
if (JSON.stringify(currentProvider) !== JSON.stringify(newProvider)) {
|
||||
fetchProvider(newProvider, openSnackbar)
|
||||
}
|
||||
currentProvider = newProvider
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// @flow
|
||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
||||
import { getProviderInfo, ETHEREUM_NETWORK_IDS, ETHEREUM_NETWORK } from '~/logic/wallets/getWeb3'
|
||||
import { 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'
|
||||
|
@ -44,24 +44,7 @@ const handleProviderNotification = (openSnackbar: Function, provider: ProviderPr
|
|||
openSnackbar(msg, variant)
|
||||
}
|
||||
|
||||
export const recurrentFetchProvider = (currentProvider: ProviderProps, openSnackbar: Function) => async (
|
||||
dispatch: ReduxDispatch<*>,
|
||||
) => {
|
||||
const newProvider: ProviderProps = await getProviderInfo()
|
||||
|
||||
if (JSON.stringify(currentProvider) !== JSON.stringify(newProvider)) {
|
||||
handleProviderNotification(openSnackbar, newProvider)
|
||||
processProviderResponse(dispatch, newProvider)
|
||||
}
|
||||
|
||||
return newProvider
|
||||
}
|
||||
|
||||
export default (openSnackbar: Function) => async (dispatch: ReduxDispatch<*>) => {
|
||||
const provider: ProviderProps = await getProviderInfo()
|
||||
export default (provider: ProviderProps, openSnackbar: Function) => (dispatch: ReduxDispatch<*>) => {
|
||||
handleProviderNotification(openSnackbar, provider)
|
||||
|
||||
processProviderResponse(dispatch, provider)
|
||||
|
||||
return provider
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue