mirror of
https://github.com/status-im/safe-react.git
synced 2025-03-01 09:50:43 +00:00
use web3connect to get provider
This commit is contained in:
parent
3d8082c4d7
commit
6c99942530
@ -1,10 +1,13 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import * as React from 'react'
|
import React, { useEffect } from 'react'
|
||||||
|
import { withSnackbar } from 'notistack'
|
||||||
|
import { connect } from 'react-redux'
|
||||||
import Web3Connect from 'web3connect'
|
import Web3Connect from 'web3connect'
|
||||||
import WalletConnectProvider from '@walletconnect/web3-provider'
|
import WalletConnectProvider from '@walletconnect/web3-provider'
|
||||||
import Portis from '@portis/web3'
|
import Portis from '@portis/web3'
|
||||||
import Fortmatic from 'fortmatic'
|
import Fortmatic from 'fortmatic'
|
||||||
import Button from '~/components/layout/Button'
|
import Button from '~/components/layout/Button'
|
||||||
|
import { fetchProvider } from '~/logic/wallets/store/actions'
|
||||||
|
|
||||||
const web3Connect = new Web3Connect.Core({
|
const web3Connect = new Web3Connect.Core({
|
||||||
network: 'rinkeby',
|
network: 'rinkeby',
|
||||||
@ -30,13 +33,24 @@ const web3Connect = new Web3Connect.Core({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
web3Connect.on('connect', (provider: any) => {
|
type Props = {
|
||||||
if (provider) {
|
registerProvider: Function,
|
||||||
console.log('wop')
|
enqueueSnackbar: Function,
|
||||||
}
|
closeSnackbar: Function,
|
||||||
})
|
}
|
||||||
|
|
||||||
const ConnectButton = (props: Object) => (
|
const ConnectButton = ({
|
||||||
|
registerProvider, enqueueSnackbar, closeSnackbar, ...props
|
||||||
|
}: Props) => {
|
||||||
|
useEffect(() => {
|
||||||
|
web3Connect.on('connect', (provider: any) => {
|
||||||
|
if (provider) {
|
||||||
|
registerProvider(provider, enqueueSnackbar, closeSnackbar)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@ -48,6 +62,10 @@ const ConnectButton = (props: Object) => (
|
|||||||
>
|
>
|
||||||
Connect
|
Connect
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default ConnectButton
|
export default connect(
|
||||||
|
null,
|
||||||
|
{ registerProvider: fetchProvider },
|
||||||
|
)(withSnackbar(ConnectButton))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
import type { Dispatch as ReduxDispatch } from 'redux'
|
||||||
import { ETHEREUM_NETWORK_IDS, ETHEREUM_NETWORK } from '~/logic/wallets/getWeb3'
|
import { ETHEREUM_NETWORK_IDS, ETHEREUM_NETWORK, getProviderInfo } from '~/logic/wallets/getWeb3'
|
||||||
import { getNetwork } from '~/config'
|
import { getNetwork } from '~/config'
|
||||||
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'
|
||||||
@ -28,7 +28,7 @@ const handleProviderNotification = (
|
|||||||
enqueueSnackbar: Function,
|
enqueueSnackbar: Function,
|
||||||
closeSnackbar: Function,
|
closeSnackbar: Function,
|
||||||
) => {
|
) => {
|
||||||
const { loaded, available, network } = provider
|
const { loaded, network, available } = provider
|
||||||
|
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
showSnackbar(NOTIFICATIONS.CONNECT_WALLET_ERROR_MSG, enqueueSnackbar, closeSnackbar)
|
showSnackbar(NOTIFICATIONS.CONNECT_WALLET_ERROR_MSG, enqueueSnackbar, closeSnackbar)
|
||||||
@ -55,9 +55,10 @@ const handleProviderNotification = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (provider: ProviderProps, enqueueSnackbar: Function, closeSnackbar: Function) => (
|
export default (provider: Object, enqueueSnackbar: Function, closeSnackbar: Function) => async (
|
||||||
dispatch: ReduxDispatch<*>,
|
dispatch: ReduxDispatch<*>,
|
||||||
) => {
|
) => {
|
||||||
handleProviderNotification(provider, enqueueSnackbar, closeSnackbar)
|
const providerInfo: ProviderProps = await getProviderInfo(provider)
|
||||||
processProviderResponse(dispatch, provider)
|
await handleProviderNotification(providerInfo, enqueueSnackbar, closeSnackbar)
|
||||||
|
processProviderResponse(dispatch, providerInfo)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user