Skip to content

Commit d9e47c9

Browse files
committed
feat: make chain list extendable
Update Board.vue Update useEthers.ts Update chainId.ts Update App.vue chore: extendable networks option chore: update docs Update index.md Update README.md fix: url and symbol Update README.md Update index.md
1 parent 9ed5b4a commit d9e47c9

File tree

11 files changed

+152
-205
lines changed

11 files changed

+152
-205
lines changed

README.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,39 @@ app.use(VueDapp);
3838
app.mount("#app");
3939
```
4040

41-
Step 2. Add `<vd-board />` to your `App.vue` and add a button to open the board:
41+
Step 2. By default, VueDapp includes `Mainnet` and `Goerli` networks, but you can extend it to include other networks:
42+
43+
```javascript
44+
app.use(VueDapp, {
45+
80001: {
46+
chainId: '0x' + 80001,
47+
blockExplorerUrls: ['https://mumbai.polygonscan.com/'],
48+
chainName: 'Mumbai',
49+
rpcUrls: ['https://rpc-mumbai.maticvigil.com/'],
50+
nativeCurrency: {
51+
name: 'Mumbai',
52+
decimals: 18,
53+
symbol: 'MATIC',
54+
},
55+
},
56+
1336: {
57+
...
58+
}
59+
});
60+
61+
```
62+
For more examples please check:
63+
https://github.com/wagmi-dev/wagmi/blob/main/packages/core/src/constants/chains.ts
64+
65+
66+
Step 3. Add `<vd-board />` to your `App.vue` and add a button to open the board:
4267

4368
```vue
4469
<button @click="open">Connect Wallet</button>
4570
<vd-board :connectors="connectors" dark />
4671
```
4772

48-
Step 3. Construct your connectors and use composable functions in your scripts:
73+
Step 4. Construct your connectors and use composable functions in your scripts:
4974

5075
```js
5176
import {
@@ -91,4 +116,4 @@ Gitcoin Grants: https://gitcoin.co/grants/3987/vue-dapp
91116

92117
## MIT license
93118

94-
Copyright (c) 2021-present, Johnson Chen ([@chnejohnson](https://twitter.com/chnejohnson))
119+
Copyright (c) 2021-present, Johnson Chen ([@chnejohnson](https://twitter.com/chnejohnson))

demo/src/App.vue

+6-7
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ const connectors = [
5656
}),
5757
]
5858
59-
const supportedChainId = [
60-
ChainId.Mainnet,
61-
ChainId.Rinkeby,
62-
ChainId.Arbitrum,
63-
ChainId.Rinkarby,
64-
ChainId.Polygon,
65-
]
59+
const { availableNetworks } = useEthers()
60+
61+
const supportedChainId = Object.keys(availableNetworks.value).map((key) =>
62+
Number(key),
63+
)
64+
6665
const selectedChainId = ref(0)
6766
6867
onActivated(() => {

demo/src/main.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ import { VueDapp } from 'vue-dapp'
66

77
const app = createApp(App)
88

9-
app.use(VueDapp)
9+
app.use(VueDapp, {
10+
80001: {
11+
chainId: '0x' + 80001,
12+
blockExplorerUrls: ['https://mumbai.polygonscan.com/'],
13+
chainName: 'Mumbai',
14+
rpcUrls: ['https://rpc-mumbai.maticvigil.com/'],
15+
nativeCurrency: {
16+
name: 'Mumbai',
17+
decimals: 18,
18+
symbol: 'MATIC',
19+
},
20+
},
21+
})
1022

1123
app.mount('#app')

docs/index.md

+60-32
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,89 @@
66
yarn add ethers vue-dapp
77
```
88

9-
109
## Quick Start
1110

1211
Step 1. Add plugin to your app:
1312

1413
```javascript
1514
import { VueDapp } from "vue-dapp";
15+
1616
const app = createApp(App);
1717
app.use(VueDapp);
1818
app.mount("#app");
1919
```
2020

21-
Step 2. Add `<vd-board />` to your `App.vue` and add a button to open the board:
21+
Step 2. By default, VueDapp includes `Mainnet` and `Goerli` networks, but you can extend it to include other networks:
22+
23+
```javascript
24+
app.use(VueDapp, {
25+
80001: {
26+
chainId: '0x' + 80001,
27+
blockExplorerUrls: ['https://mumbai.polygonscan.com/'],
28+
chainName: 'Mumbai',
29+
rpcUrls: ['https://rpc-mumbai.maticvigil.com/'],
30+
nativeCurrency: {
31+
name: 'Mumbai',
32+
decimals: 18,
33+
symbol: 'MATIC',
34+
},
35+
},
36+
1336: {
37+
...
38+
}
39+
});
40+
41+
```
42+
43+
For more examples please check:
44+
https://github.com/wagmi-dev/wagmi/blob/main/packages/core/src/constants/chains.ts
45+
46+
Step 3. Add `<vd-board />` to your `App.vue` and add a button to open the board:
2247

2348
```vue
49+
2450
<button @click="open">Connect Wallet</button>
2551
<vd-board :connectors="connectors" dark />
2652
```
2753

28-
Step 3. Construct your connectors and use composable functions in your scripts:
54+
Step 4. Construct your connectors and use composable functions in your scripts:
2955

3056
```js
3157
import {
32-
MetaMaskConnector,
33-
WalletConnectConnector,
34-
CoinbaseWalletConnector,
35-
useBoard,
58+
MetaMaskConnector,
59+
WalletConnectConnector,
60+
CoinbaseWalletConnector,
61+
useBoard,
3662
} from "vue-dapp";
3763

38-
setup() {
39-
const { open } = useBoard();
40-
const infuraId = "";
41-
const connectors = [
42-
new MetaMaskConnector({
43-
appUrl: "http://localhost:3000",
44-
}),
45-
new WalletConnectConnector({
46-
qrcode: true,
47-
rpc: {
48-
1: `https://mainnet.infura.io/v3/${infuraId}`,
49-
4: `https://rinkeby.infura.io/v3/${infuraId}`,
50-
},
51-
}),
52-
new CoinbaseWalletConnector({
53-
appName: "Vue Dapp",
54-
jsonRpcUrl: `https://mainnet.infura.io/v3/${infuraId}`,
55-
}),
56-
];
57-
return {
58-
connectors,
59-
open,
60-
};
64+
setup()
65+
{
66+
const { open } = useBoard();
67+
const infuraId = "";
68+
const connectors = [
69+
new MetaMaskConnector({
70+
appUrl: "http://localhost:3000",
71+
}),
72+
new WalletConnectConnector({
73+
qrcode: true,
74+
rpc: {
75+
1: `https://mainnet.infura.io/v3/${infuraId}`,
76+
4: `https://rinkeby.infura.io/v3/${infuraId}`,
77+
},
78+
}),
79+
new CoinbaseWalletConnector({
80+
appName: "Vue Dapp",
81+
jsonRpcUrl: `https://mainnet.infura.io/v3/${infuraId}`,
82+
}),
83+
];
84+
return {
85+
connectors,
86+
open,
87+
};
6188
}
6289
```
6390

64-
Take a look at [Configurations](https://vue-dapp-docs.netlify.app/configurations) for more informations about Vue CLI, Vite, and Nuxt3 configurations.
91+
Take a look at [Configurations](https://vue-dapp-docs.netlify.app/configurations) for more informations about Vue CLI,
92+
Vite, and Nuxt3 configurations.
6593

66-
To see the demo code, check it out [here](https://github.com/chnejohnson/vue-dapp/blob/main/demo/src/App.vue).
94+
To see the demo code, check it out [here](https://github.com/chnejohnson/vue-dapp/blob/main/demo/src/App.vue).

src/components/Board.vue

+2-8
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,7 @@ export default defineComponent({
103103
.wallet-item {
104104
display: flex;
105105
justify-content: center;
106-
padding-top: 1rem;
107-
padding-bottom: 0.6rem;
108-
padding-left: 1rem;
109-
padding-right: 1rem;
106+
padding: 1rem 1rem 0.6rem;
110107
margin: 0.5rem;
111108
border-radius: 0.75rem;
112109
cursor: pointer;
@@ -120,10 +117,7 @@ export default defineComponent({
120117
.wallet-item--dark {
121118
display: flex;
122119
justify-content: center;
123-
padding-top: 1rem;
124-
padding-bottom: 0.6rem;
125-
padding-left: 1rem;
126-
padding-right: 1rem;
120+
padding: 1rem 1rem 0.6rem;
127121
margin: 0.5rem;
128122
border-radius: 0.75rem;
129123
cursor: pointer;

src/composables/useEthers.ts

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
ExternalProvider,
66
} from '@ethersproject/providers'
77
import { BigNumber, Signer } from 'ethers'
8+
import { NETWORK_DETAILS } from '../constants'
9+
import { AddEthereumChainParameter } from '../wallets'
810

911
export type { Web3Provider, Signer, Network }
1012

@@ -17,6 +19,10 @@ const dnsAlias = ref('')
1719
const balance = ref<bigint>(BigInt(0))
1820
let updateBalanceInterval: any
1921

22+
const availableNetworks = ref<{ [key: number]: AddEthereumChainParameter }>({
23+
...NETWORK_DETAILS,
24+
})
25+
2026
const deactivate = () => {
2127
clearInterval(updateBalanceInterval)
2228
isActivated.value = false
@@ -136,6 +142,7 @@ export function useEthers() {
136142
address,
137143
dnsAlias,
138144
balance,
145+
availableNetworks,
139146

140147
// getters
141148
chainId,

0 commit comments

Comments
 (0)