From 69c17ee91a53ff6780d66da8ba4351d9700e531c Mon Sep 17 00:00:00 2001 From: Johnson Date: Mon, 17 Oct 2022 23:52:13 +0800 Subject: [PATCH] feat: automatically load MetaMask wallet, close #80 --- README.md | 27 ++++++++++-------- demo/src/main.ts | 41 +++++++++++++++------------- docs/index.md | 27 ++++++++++-------- src/components/Board.vue | 53 +++++++++++++++++++++++++++++------- src/composables/useWallet.ts | 10 ++++++- src/plugin.ts | 16 +++++++++-- src/wallets/metaMask.ts | 11 ++++++++ 7 files changed, 128 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index cec3204..6056795 100644 --- a/README.md +++ b/README.md @@ -42,20 +42,23 @@ Step 2. By default, VueDapp includes `Mainnet` and `Goerli` networks, but you ca ```javascript app.use(VueDapp, { + autoConnect: true, // Automatically connect MetaMask wallet when the page is loaded + networks: { 80001: { - chainId: ethers.utils.hexValue(80001), - blockExplorerUrls: ['https://mumbai.polygonscan.com/'], - chainName: 'Mumbai', - rpcUrls: ['https://rpc-mumbai.maticvigil.com/'], - nativeCurrency: { - name: 'Mumbai', - decimals: 18, - symbol: 'MATIC', - }, + chainId: ethers.utils.hexValue(80001), + blockExplorerUrls: ['https://mumbai.polygonscan.com/'], + chainName: 'Mumbai', + rpcUrls: ['https://rpc-mumbai.maticvigil.com/'], + nativeCurrency: { + name: 'Mumbai', + decimals: 18, + symbol: 'MATIC', + }, + }, + 42161: { + ... }, - 1336: { - ... - } + }, }); ``` diff --git a/demo/src/main.ts b/demo/src/main.ts index 4e6ba2d..f391bf2 100644 --- a/demo/src/main.ts +++ b/demo/src/main.ts @@ -8,26 +8,29 @@ import { ethers } from 'ethers' const app = createApp(App) app.use(VueDapp, { - 80001: { - chainId: ethers.utils.hexValue(80001), - blockExplorerUrls: ['https://mumbai.polygonscan.com/'], - chainName: 'Mumbai', - rpcUrls: ['https://rpc-mumbai.maticvigil.com/'], - nativeCurrency: { - name: 'Mumbai', - decimals: 18, - symbol: 'MATIC', + autoConnect: true, + networks: { + 80001: { + chainId: ethers.utils.hexValue(80001), + blockExplorerUrls: ['https://mumbai.polygonscan.com/'], + chainName: 'Mumbai', + rpcUrls: ['https://rpc-mumbai.maticvigil.com/'], + nativeCurrency: { + name: 'Mumbai', + decimals: 18, + symbol: 'MATIC', + }, }, - }, - 42161: { - chainId: ethers.utils.hexValue(42161), - blockExplorerUrls: ['https://arbiscan.io'], - chainName: 'Arbitrum One', - rpcUrls: ['https://arb1.arbitrum.io/rpc'], - nativeCurrency: { - name: 'Arbitrum', - symbol: 'ETH', - decimals: 18, + 42161: { + chainId: ethers.utils.hexValue(42161), + blockExplorerUrls: ['https://arbiscan.io'], + chainName: 'Arbitrum One', + rpcUrls: ['https://arb1.arbitrum.io/rpc'], + nativeCurrency: { + name: 'Arbitrum', + symbol: 'ETH', + decimals: 18, + }, }, }, }) diff --git a/docs/index.md b/docs/index.md index 52b8a02..07b426e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -22,20 +22,23 @@ Step 2. By default, VueDapp includes `Mainnet` and `Goerli` networks, but you ca ```javascript app.use(VueDapp, { + autoConnect: true, // Automatically connect MetaMask wallet when the page is loaded + networks: { 80001: { - chainId: ethers.utils.hexValue(80001), - blockExplorerUrls: ['https://mumbai.polygonscan.com/'], - chainName: 'Mumbai', - rpcUrls: ['https://rpc-mumbai.maticvigil.com/'], - nativeCurrency: { - name: 'Mumbai', - decimals: 18, - symbol: 'MATIC', - }, + chainId: ethers.utils.hexValue(80001), + blockExplorerUrls: ['https://mumbai.polygonscan.com/'], + chainName: 'Mumbai', + rpcUrls: ['https://rpc-mumbai.maticvigil.com/'], + nativeCurrency: { + name: 'Mumbai', + decimals: 18, + symbol: 'MATIC', + }, }, - 1336: { - ... - } + 42161: { + ... + }, + }, }); ``` diff --git a/src/components/Board.vue b/src/components/Board.vue index fa22d2d..30b29af 100644 --- a/src/components/Board.vue +++ b/src/components/Board.vue @@ -1,5 +1,5 @@