forked from graphprotocol/everest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrap-with-providers.js
40 lines (33 loc) · 1.04 KB
/
wrap-with-providers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, { createContext } from 'react'
import PropTypes from 'prop-types'
import { ethers } from 'ethers'
import { ApolloProvider } from '@apollo/react-hooks'
import { Web3ReactProvider } from '@web3-react/core'
import client from './src/utils/apollo/client'
import Web3ReactConnect from './src/components/Web3ReactConnect'
const getLibrary = provider => {
const library = new ethers.providers.Web3Provider(provider)
library.pollingInterval = 10000
return library
}
export const ReactContext = createContext()
const wrapRootElement = ({ element }) => {
return (
<Web3ReactProvider getLibrary={getLibrary}>
<ApolloProvider client={client}>
<ReactContext.Provider>{element}</ReactContext.Provider>
</ApolloProvider>
</Web3ReactProvider>
)
}
wrapRootElement.propTypes = {
element: PropTypes.any,
}
const wrapPageElement = ({ element }) => (
<Web3ReactConnect>{element}</Web3ReactConnect>
)
wrapPageElement.propTypes = {
element: PropTypes.any,
props: PropTypes.any,
}
export { wrapRootElement, wrapPageElement }