Skip to content

Commit 8b8fb81

Browse files
🧹 General clean-up (#44)
1 parent dfa48f5 commit 8b8fb81

File tree

19 files changed

+163
-59
lines changed

19 files changed

+163
-59
lines changed

.changeset/brave-pigs-admire.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@usedapp/core": patch
3+
"@usedapp/example": patch
4+
---
5+
6+
🧹 General clean-up
7+
8+
* Introduce EthersProvider and activateBrowserWallet
9+
* Introduce Config, ConfigProvider and useConfig
10+
* Fix Goerli name
11+
* Add missing MULTICALL_ADDRESSES
12+
* Update docs structure and README

docs/source/core.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,35 @@ Providers
88

99
Provides basic DApp services for hooks ...
1010

11-
Combines following components: ``<Web3ReactProvider>``, <BlockNumberProvider>``, ``<ChainStateProvider>``, ``<ReadOnlyProviderActivator>``
11+
It combines following components: ``<ConfigProvider>``, ``<EthersProvider>``, ``<BlockNumberProvider>``, ``<ChainStateProvider>`` and ``<ReadOnlyProviderActivator>``
12+
13+
**<ConfigProvider>**
14+
15+
**<EthersProvider>**
1216

1317
**<BlockNumberProvider>**
1418

1519
**<ChainStateProvider>**
1620

1721
**<ReadOnlyProviderActivator>**
1822

23+
24+
Configuration
25+
-------------
26+
27+
**readOnlyChain**
28+
29+
chainId of a chain to connect in read-only mode
30+
31+
**readOnlyUrls**
32+
33+
**multicallAddresses**
34+
35+
**supportedChains**
36+
37+
**pollingInterval**
38+
New block checking polling interval
39+
1940
Hooks
2041
-----
2142

packages/core/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@ ReactDOM.render(
5050
)
5151

5252
export function App() {
53-
const { activate, account } = useEthers()
53+
const { activateBrowserWallet, account } = useEthers()
5454
return (
5555
<div>
56-
<button onClick={() => activate(injected)}>Connect</button>
56+
<button onClick={() => activateBrowserWallet()}>Connect</button>
5757
</div>
5858
{account && <p>Account: {account}</p>}
5959
</div>
6060
)
6161
}
6262
```
6363

64+
Example application is available [here](https://app.netlify.com/sites/usedapp-example/overview).
65+
6466

6567
## Documentation
6668
For detailed feature walkthrough checkout [documentation](https://usedapp.readthedocs.io/en/latest/).

packages/core/src/constants/chainId.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export enum ChainId {
22
Mainnet = 1,
33
Ropsten = 3,
44
Rinkeby = 4,
5-
Gorli = 5,
5+
Goerli = 5,
66
Kovan = 42,
77
xDai = 100,
88
}
@@ -12,7 +12,7 @@ export const SUPPORTED_CHAINS = [
1212
ChainId.Ropsten,
1313
ChainId.Kovan,
1414
ChainId.Rinkeby,
15-
ChainId.Gorli,
15+
ChainId.Goerli,
1616
ChainId.Kovan,
1717
ChainId.xDai,
1818
]
@@ -21,7 +21,7 @@ export const MULTICALL_ADDRESSES = {
2121
[ChainId.Mainnet]: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441',
2222
[ChainId.Ropsten]: '0x53c43764255c17bd724f74c4ef150724ac50a3ed',
2323
[ChainId.Rinkeby]: '0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821',
24-
// [ChainId.Goerli]: '0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e',
24+
[ChainId.Goerli]: '0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e',
2525
[ChainId.Kovan]: '0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a',
26-
// [ChainId.XDAI]: '0xb5b692a88bdfc81ca69dcb1d924f59f0413a602a',
26+
[ChainId.xDai]: '0xb5b692a88bdfc81ca69dcb1d924f59f0413a602a',
2727
}
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import { useWeb3React } from '@web3-react/core'
22
import { Web3Provider } from '@ethersproject/providers'
33
import { ChainId } from '../constants'
4+
import { useMemo } from 'react'
5+
import { useConfig } from '../providers/config/context'
6+
import { InjectedConnector } from '@web3-react/injected-connector'
47

5-
export type Web3Ethers = ReturnType<typeof useWeb3React> & { library?: Web3Provider; chainId?: ChainId }
8+
export type Web3Ethers = ReturnType<typeof useWeb3React> & {
9+
library?: Web3Provider
10+
chainId?: ChainId
11+
activateBrowserWallet: () => void
12+
}
613

714
export function useEthers(): Web3Ethers {
8-
return useWeb3React<Web3Provider>()
15+
const result = useWeb3React<Web3Provider>()
16+
const { supportedChains } = useConfig()
17+
const activateBrowserWallet = useMemo(() => {
18+
const injected = new InjectedConnector({ supportedChainIds: supportedChains })
19+
return () => result.activate(injected)
20+
}, [supportedChains])
21+
return { ...result, activateBrowserWallet }
922
}

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './constants'
22
export * from './providers'
33
export * from './hooks'
4+
export * from './model'

packages/core/src/model/Config.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ChainId } from '../../constants'
2+
3+
export type NodeUrls = {
4+
[chainId: number]: string
5+
}
6+
7+
export type MulticallAddresses = {
8+
[chainId: number]: string
9+
}
10+
11+
export type FullConfig = {
12+
readOnlyChainId?: ChainId
13+
readOnlyUrls?: NodeUrls
14+
multicallAddresses?: MulticallAddresses
15+
supportedChains: number[]
16+
pollingInterval?: number
17+
}
18+
19+
export type Config = Partial<FullConfig>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ChainId } from '../../constants'
2+
import { FullConfig } from './Config'
3+
4+
export const DEFAULT_CONFIG: FullConfig = {
5+
pollingInterval: 15000,
6+
supportedChains: [ChainId.Mainnet, ChainId.Goerli, ChainId.Kovan, ChainId.Rinkeby, ChainId.Ropsten, ChainId.xDai],
7+
}

packages/core/src/model/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './Currency'
2+
export * from './config/Config'

0 commit comments

Comments
 (0)