├── .gitignore
├── LICENSE
├── README.md
├── dist
├── components
│ ├── AddressButton.vue.d.ts
│ ├── ConnectWalletButton.vue.d.ts
│ └── Jazzicon.vue.d.ts
├── env.d.ts
├── index.d.ts
├── style.css
├── utils
│ └── useMetaMaskWallet.d.ts
├── vcw.es.js
└── vcw.umd.js
├── images
└── VueConnectWallet.png
├── index.html
├── package.json
├── src
├── App.vue
├── components
│ ├── AddressButton.vue
│ ├── ConnectWalletButton.vue
│ ├── Jazzicon.vue
│ └── Spinner.vue
├── env.d.ts
├── index.ts
├── main.ts
└── utils
│ └── useMetaMaskWallet.ts
├── tsconfig.json
├── tsconfig.node.json
├── vite.config.ts
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist-ssr
12 | *.local
13 |
14 | # Editor directories and files
15 | .vscode/*
16 | !.vscode/extensions.json
17 | .idea
18 | .DS_Store
19 | *.suo
20 | *.ntvs*
21 | *.njsproj
22 | *.sln
23 | *.sw?
24 |
25 | ToDo.md
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 |
vue-connect-wallet
4 |
5 |
6 |
7 |
8 |
9 |
10 | Bootstrap your decentralized applications by delegating the tedious and repetitive task of wallet connection and button design to this plugin.
11 |
12 | Provides a ready-made and fully-customizable UI button and utility functions for connecting to a web3 wallet (MetaMask). It has built-in Typescript support and supports Dark mode.
13 |
14 | The button takes care of displaying the user's wallet address, their identicon / avatar and pending transactions.
15 | Utility functions for connecting to a MetaMask wallet are provided. More wallets can be added in the future as per public request. Feel free to contribute yourself!
16 |
17 | **Table of Contents**
18 |
19 | - [Getting started](#getting-started)
20 | - [Installation](#installation)
21 | - [Registering the component](#registering-the-component)
22 | - [Usage](#usage)
23 | - [Button component](#button-component)
24 | - [Simple usage](#simple-usage)
25 | - [Advanced Usage](#advanced-usage)
26 | - [MetaMask Utils](#metamask-utils)
27 | - [Example](#example)
28 | - [Contributing](#contributing)
29 | - [Miscellaneous](#miscellaneous)
30 | - [Stargazers](#stargazers)
31 | - [Author](#author)
32 |
33 | # Getting started
34 |
35 | This plugin uses `vue-demi` to support both Vue 2 and Vue 3, but usage in Vue 2 is prone to issues, so **Vue 3** is the recommended version of vue for this plugin.
36 |
37 | ## Installation
38 |
39 | Use Yarn or npm to install the library **vue-connect-wallet**.
40 |
41 | ```console
42 | yarn add vue-connect-wallet
43 | ```
44 |
45 | ```console
46 | npm install vue-connect-wallet
47 | ```
48 |
49 | ## Registering the component
50 |
51 | In the `main.js` file, import the styles.
52 |
53 | ```js
54 | import "vue-connect-wallet/dist/style.css";
55 | ```
56 |
57 | Then, you can either register **ConnectWalletButton** as a global component or specifically import it in the components you need (recommended).
58 |
59 | To register as global component, in your `main.js`:
60 |
61 | ```js
62 | import VueConnectWallet from "vue-connect-wallet";
63 | createApp(App).use(VueConnectWallet).mount("#app");
64 | ```
65 |
66 | To import individually (recommended):
67 |
68 | ```js
69 | import { ConnectWalletButton } from "vue-connect-wallet";
70 | export default {
71 | components: {
72 | ConnectWalletButton,
73 | },
74 | };
75 | ```
76 |
77 | **\*Note**: If using <script setup>, you only need to import the component without registering it.\*
78 |
79 | # Usage
80 |
81 | ## Button component
82 |
83 | If the `address` is **empty** or doesn't start with **0x**, the "Connect Wallet" button will be shown. If an address is provided, it will instead display the identicon and the sliced address.
84 |
85 | ### Simple usage
86 |
87 | ```html
88 |
89 | ```
90 |
91 | ### Advanced Usage
92 |
93 | ```html
94 |
99 |
100 | Connect Wallet!
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | ```
123 |
124 | ## MetaMask Utils
125 |
126 | Provides functions to easily connect to a MetaMask wallet, get accounts and listen to changes when an account is changed and when a chain/network is changed.
127 |
128 | ```js
129 | import { useMetaMaskWallet } from "vue-connect-wallet";
130 |
131 | const wallet = useMetaMaskWallet();
132 | ```
133 |
134 | Utilities provided in `useMetaMaskWallet`:
135 |
136 | ```ts
137 | /** Returns boolean value indicating if MetaMask is detected on the browser **/
138 | wallet.isMetaMask: boolean;
139 | /**
140 | * Returns account address array if wallet is connected otherwise opens MetaMask popup.
141 | * On error, returns a single string with the error message
142 | */
143 | wallet.connect(): Promise;
144 | /**
145 | * Get all connected accounts addresses. Returns an empty array if none connected
146 | * On error, returns a single string with the error message
147 | */
148 | wallet.getAccounts(): Promise;
149 | /**
150 | * Opens a MetaMask popup to connect/disconnect from a list of user's accounts. Returns an array.
151 | * The popup opens even if the user has already connected some accounts.
152 | * On error, returns a single string with the error message
153 | */
154 | wallet.switchAccounts(): Promise;
155 | /**
156 | * Add a token to MetaMask
157 | * @param symbol Symbol of the token, upto 5 characters
158 | * @param address Address of the token
159 | * @param imageURL String URL of the token image
160 | * @param decimals (Optional) 18 by default
161 | * @param type (Optional) ERC20 by default
162 | */
163 | wallet.addTokenToWallet: (symbol: string, address: string, imageURL: string, decimals?: number, type?: string) => Promise;
164 | /**
165 | * Switch to a chain or add the chain if the user does not have it
166 | * @param chainId ChainID as an Integer
167 | * @param chainConfig (Optional) Chain Config Interface used for adding new chain
168 | */
169 | wallet.switchOrAddChain: (chainId: number, chainConfig?: ChainConfig | undefined) => Promise;
170 | /**
171 | * Event handler for when the user changes the account in MetaMask
172 | *
173 | * Reference for event handlers: https://docs.metamask.io/guide/ethereum-provider.html#events
174 | * @param callback Function that takes accounts string array as an argument
175 | */
176 | wallet.onAccountsChanged: (callback: (accounts: string[]) => void) => void;
177 | /**
178 | * Event handler for when the user changes the active chain in MetaMask
179 | *
180 | * Reference for event handlers: https://docs.metamask.io/guide/ethereum-provider.html#events
181 | * @param callback Function that takes chainId number as an argument
182 | */
183 | wallet.onChainChanged: (callback: (chainId: number) => void) => void;
184 | ```
185 |
186 | # Example
187 |
188 | Example usage in Vue 3 with Typescript, using <script setup lang="ts">:
189 |
190 | ```ts
191 | import { useMetaMaskWallet } from "vue-connect-wallet";
192 |
193 | const address = ref("");
194 | const wallet = useMetaMaskWallet();
195 |
196 | wallet.onAccountsChanged((accounts: string[]) => {
197 | console.log("account changed to: ", accounts[0]);
198 | });
199 | wallet.onChainChanged((chainId: number) => {
200 | console.log("chain changed to:", chainId);
201 | });
202 |
203 | const connect = async () => {
204 | const accounts = await wallet.connect();
205 | if (typeof accounts === "string") {
206 | console.log("An error occurred" + accounts);
207 | }
208 | address.value = accounts[0];
209 | };
210 |
211 | const switchAccount = async () => {
212 | await wallet.switchAccounts();
213 | connect();
214 | };
215 |
216 | const isConnected = async () => {
217 | const accounts = await wallet.getAccounts();
218 | if (typeof accounts === "string") return false;
219 | return accounts.length > 0;
220 | };
221 | ```
222 |
223 | # Contributing
224 |
225 | Conribution in any area is welcome. Adding support for new wallets would be very much appreciated.
226 |
227 | To develop in this repo, just clone it and run `yarn` to install all the dependencies. Look at the `package.json` to understand the scripts.
228 |
229 | # Miscellaneous
230 |
231 | **Note on Identicons (Jazzicon)**
232 | This package comes with the Jazzicon from the library [vue3-jazzicon](https://github.com/samuveth/vue3-jazzicon). Installing it as a dependency in the plugin raised import errors due to which I bundled the component in this plugin itself.
233 |
234 | # Stargazers
235 |
236 | [](https://github.com/neelansh15/vue-connect-wallet/stargazers)
237 |
238 | # Author
239 |
240 | Hi! I am Neelansh Mathur. I am a freelancer specializing in Frontend development for Blockchain applications, and currently studying Computer Engineering. You can find out more about me at my social links.
241 |
242 | I made this plugin because I was having to repeatedly use the same code and redesign buttons for every dApp I develop for. This has made my life easier and I hope it does the same for you 💚.
243 |
244 | **Twitter**: https://twitter.com/mneelansh15
245 | **LinkedIn**: https://www.linkedin.com/in/neelansh-mathur/
246 | **Dev.to**: https://dev.to/neelansh15
247 | **Github**: https://github.com/neelansh15
248 |
--------------------------------------------------------------------------------
/dist/components/AddressButton.vue.d.ts:
--------------------------------------------------------------------------------
1 | declare const _sfc_main: import("vue").DefineComponent, {}>;
2 | export default _sfc_main;
3 |
--------------------------------------------------------------------------------
/dist/components/ConnectWalletButton.vue.d.ts:
--------------------------------------------------------------------------------
1 | declare const _sfc_main: import("vue").DefineComponent<{
2 | txnCount: {
3 | type: NumberConstructor;
4 | default: number;
5 | };
6 | address: {
7 | type: StringConstructor;
8 | required: true;
9 | };
10 | dark: {
11 | type: BooleanConstructor;
12 | default: boolean;
13 | };
14 | }, {
15 | props: Readonly> & {
29 | [x: string & `on${string}`]: ((...args: any[]) => any) | ((...args: unknown[]) => any) | undefined;
30 | }>>;
31 | connected: import("vue").ComputedRef;
32 | Spinner: import("vue").DefineComponent<{}, {}, any, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly>, {}>;
33 | AddressButton: import("vue").DefineComponent, {}>;
34 | Jazzicon: {
35 | name: string;
36 | props: {
37 | seed: {
38 | type: NumberConstructor;
39 | default: number;
40 | };
41 | diameter: {
42 | type: NumberConstructor;
43 | default: number;
44 | };
45 | address: {
46 | type: StringConstructor;
47 | default: null;
48 | };
49 | shapeCount: {
50 | type: NumberConstructor;
51 | default: number;
52 | };
53 | colors: {
54 | type: ArrayConstructor;
55 | default: () => string[];
56 | };
57 | };
58 | data(): {
59 | generator: null;
60 | svgns: string;
61 | };
62 | watch: {
63 | seed: {
64 | handler(): void;
65 | };
66 | address: {
67 | handler(): void;
68 | };
69 | diameter: {
70 | handler(): void;
71 | };
72 | };
73 | mounted(): void;
74 | methods: {
75 | addressToNumber(address: any): number;
76 | icon(): Promise;
77 | newPaper(diameter: any, color: any): {
78 | container: HTMLDivElement;
79 | };
80 | generateIdenticon(diameter: any, seed: any): HTMLDivElement;
81 | genShape(remainingColors: any, diameter: any, i: any, total: any, svg: any): void;
82 | genColor(colors: any): any;
83 | hueShift(colors: any, generator: any): any;
84 | };
85 | };
86 | }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly>, {
100 | txnCount: number;
101 | dark: boolean;
102 | }>;
103 | export default _sfc_main;
104 |
--------------------------------------------------------------------------------
/dist/components/Jazzicon.vue.d.ts:
--------------------------------------------------------------------------------
1 | export default _sfc_main;
2 | declare namespace _sfc_main {
3 | const name: string;
4 | namespace props {
5 | namespace seed {
6 | export const type: NumberConstructor;
7 | const _default: number;
8 | export { _default as default };
9 | }
10 | namespace diameter {
11 | const type_1: NumberConstructor;
12 | export { type_1 as type };
13 | const _default_1: number;
14 | export { _default_1 as default };
15 | }
16 | namespace address {
17 | const type_2: StringConstructor;
18 | export { type_2 as type };
19 | const _default_2: null;
20 | export { _default_2 as default };
21 | }
22 | namespace shapeCount {
23 | const type_3: NumberConstructor;
24 | export { type_3 as type };
25 | const _default_3: number;
26 | export { _default_3 as default };
27 | }
28 | namespace colors {
29 | const type_4: ArrayConstructor;
30 | export { type_4 as type };
31 | function _default_4(): string[];
32 | export { _default_4 as default };
33 | }
34 | }
35 | function data(): {
36 | generator: null;
37 | svgns: string;
38 | };
39 | function data(): {
40 | generator: null;
41 | svgns: string;
42 | };
43 | namespace watch {
44 | export namespace seed_1 {
45 | function handler(): void;
46 | function handler(): void;
47 | }
48 | export { seed_1 as seed };
49 | export namespace address_1 {
50 | function handler(): void;
51 | function handler(): void;
52 | }
53 | export { address_1 as address };
54 | export namespace diameter_1 {
55 | function handler(): void;
56 | function handler(): void;
57 | }
58 | export { diameter_1 as diameter };
59 | }
60 | function mounted(): void;
61 | function mounted(): void;
62 | namespace methods {
63 | function addressToNumber(address: any): number;
64 | function addressToNumber(address: any): number;
65 | function icon(): Promise;
66 | function icon(): Promise;
67 | function newPaper(diameter: any, color: any): {
68 | container: HTMLDivElement;
69 | };
70 | function newPaper(diameter: any, color: any): {
71 | container: HTMLDivElement;
72 | };
73 | function generateIdenticon(diameter: any, seed: any): HTMLDivElement;
74 | function generateIdenticon(diameter: any, seed: any): HTMLDivElement;
75 | function genShape(remainingColors: any, diameter: any, i: any, total: any, svg: any): void;
76 | function genShape(remainingColors: any, diameter: any, i: any, total: any, svg: any): void;
77 | function genColor(colors: any): any;
78 | function genColor(colors: any): any;
79 | function hueShift(colors: any, generator: any): any;
80 | function hueShift(colors: any, generator: any): any;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/dist/env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | declare module '*.vue' {
4 | import type { DefineComponent } from 'vue'
5 | // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
6 | const component: DefineComponent<{}, {}, any>
7 | export default component
8 | }
9 |
--------------------------------------------------------------------------------
/dist/index.d.ts:
--------------------------------------------------------------------------------
1 | import { App } from "vue-demi";
2 | import ConnectWalletButton from "./components/ConnectWalletButton.vue";
3 | import Jazzicon from "./components/Jazzicon.vue";
4 | import useMetaMaskWallet from "./utils/useMetaMaskWallet";
5 | declare const _default: {
6 | install: (app: App) => void;
7 | };
8 | export default _default;
9 | export { ConnectWalletButton, Jazzicon, useMetaMaskWallet };
10 |
--------------------------------------------------------------------------------
/dist/style.css:
--------------------------------------------------------------------------------
1 | @keyframes ldio-gpklibk3god-3468742b{0%{transform:translate(-50%,-50%) rotate(0)}to{transform:translate(-50%,-50%) rotate(360deg)}}.ldio-gpklibk3god div[data-v-3468742b]{position:absolute;width:50px;height:50px;border:10px solid #ffffff;border-top-color:transparent;border-radius:50%}.ldio-gpklibk3god div[data-v-3468742b]{animation:ldio-gpklibk3god-3468742b 2.5027027027027026s linear infinite;top:50px;left:50px}.loadingio-spinner-rolling-9f4hja5xffr[data-v-3468742b]{width:18px;height:18px;display:inline-block;overflow:hidden;background:none}.ldio-gpklibk3god[data-v-3468742b]{width:100%;height:100%;position:relative;transform:translateZ(0) scale(.21);backface-visibility:hidden;transform-origin:0 0}.ldio-gpklibk3god div[data-v-3468742b]{box-sizing:content-box}.v-address-btn[data-v-16b91a1b]{border-radius:11px;padding:.65em 1.25em .65em 1em}.v-address-btn-light[data-v-16b91a1b]{background-color:#eee}.v-address-btn-dark[data-v-16b91a1b]{background-color:#212121;color:#fff}.v-address-btn-clickable[data-v-16b91a1b]{cursor:pointer}.v-address-btn-light.v-address-btn-clickable[data-v-16b91a1b]:hover{background-color:#ddd}.v-address-btn-dark.v-address-btn-clickable[data-v-16b91a1b]:hover{background-color:#353535}.v-address-box[data-v-16b91a1b]{display:flex;align-items:center;gap:8px}.v-btn-container[data-v-61db7636]{display:flex;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Open Sans,Helvetica Neue,sans-serif;font-size:12px}.v-pending[data-v-61db7636]{padding:.6em 1.5em .7em 1em;margin-right:-10px;background-color:#005eff;color:#fff;border-top-left-radius:11px;border-bottom-left-radius:11px;display:flex;align-items:center;gap:8px;z-index:9}.v-btn[data-v-61db7636]{outline:none;border:none;transition:all .5s;z-index:10}.v-connect-btn[data-v-61db7636]{padding:.75em 1.5em;cursor:pointer;border-radius:10px;outline:none}.v-connect-btn-light[data-v-61db7636]{background-color:#407df8;color:#fff}.v-connect-btn-dark[data-v-61db7636]{background-color:#f0efef;color:#202020}.v-connect-btn-light[data-v-61db7636]:hover{background-color:#2968e6}.v-connect-btn-dark[data-v-61db7636]:hover{background-color:#f5f3f3}.pending-txn-transition-enter-active[data-v-61db7636],.pending-txn-transition-leave-active[data-v-61db7636]{transition:all .5s ease-out}.pending-txn-transition-enter-from[data-v-61db7636],.pending-txn-transition-leave-to[data-v-61db7636]{opacity:0;transform:translate(50px)}
2 |
--------------------------------------------------------------------------------
/dist/utils/useMetaMaskWallet.d.ts:
--------------------------------------------------------------------------------
1 | declare global {
2 | interface Window {
3 | ethereum: any;
4 | }
5 | }
6 | interface ChainConfig {
7 | chainName: string;
8 | rpcUrls: string[];
9 | nativeCurrency: {
10 | name: string;
11 | symbol: string;
12 | decimals: number;
13 | };
14 | blockExplorerUrls: string[];
15 | }
16 | /**
17 | * Returns account address array if wallet is connected otherwise opens MetaMask popup.
18 | * On error, returns a single string with the error message
19 | */
20 | declare function connect(): Promise;
21 | /**
22 | * Get all connected accounts addresses. Returns an empty array if none connected
23 | * On error, returns a single string with the error message
24 | */
25 | declare function getAccounts(): Promise;
26 | /**
27 | * Opens a MetaMask popup to connect/disconnect from a list of user's accounts.
28 | * Returns an array.
29 | * The popup opens even if the user has already connected some accounts.
30 | * On error, returns a single string with the error message
31 | */
32 | declare function switchAccounts(): Promise;
33 | /**
34 | * Add a token to MetaMask
35 | * @param symbol Symbol of the token, upto 5 characters
36 | * @param address Address of the token
37 | * @param imageURL String URL of the token image
38 | * @param decimals (Optional) 18 by default
39 | * @param type (Optional) ERC20 by default
40 | */
41 | export declare const addTokenToWallet: (symbol: string, address: string, imageURL: string, decimals?: number, type?: string) => Promise;
42 | /**
43 | * Switch to a chain or add the chain if user does not have it
44 | * @param chainId ChainID as an Integer
45 | * @param chainConfig (Optional) Chain Config Interface used for adding new chain
46 | */
47 | export declare const switchOrAddChain: (chainId: number, chainConfig?: ChainConfig | undefined) => Promise;
48 | /**
49 | * Event handler for when the user changes the account in MetaMask
50 | *
51 | * Reference for event handlers: https://docs.metamask.io/guide/ethereum-provider.html#events
52 | * @param callback Function that takes accounts string array as an argument
53 | */
54 | export declare const onAccountsChanged: (callback: (accounts: string[]) => void) => void;
55 | /**
56 | * Event handler for when the user changes the active chain in MetaMask
57 | *
58 | * Reference for event handlers: https://docs.metamask.io/guide/ethereum-provider.html#events
59 | * @param callback Function that takes chainId number as an argument
60 | */
61 | export declare const onChainChanged: (callback: (chainId: number) => void) => void;
62 | export declare const useMetaMaskWallet: () => {
63 | isMetaMask: boolean;
64 | connect: typeof connect;
65 | getAccounts: typeof getAccounts;
66 | switchAccounts: typeof switchAccounts;
67 | addTokenToWallet: (symbol: string, address: string, imageURL: string, decimals?: number, type?: string) => Promise;
68 | switchOrAddChain: (chainId: number, chainConfig?: ChainConfig | undefined) => Promise;
69 | onAccountsChanged: (callback: (accounts: string[]) => void) => void;
70 | onChainChanged: (callback: (chainId: number) => void) => void;
71 | };
72 | export default useMetaMaskWallet;
73 |
--------------------------------------------------------------------------------
/dist/vcw.umd.js:
--------------------------------------------------------------------------------
1 | var ne=Object.defineProperty,ie=Object.defineProperties;var se=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var Z=(v,h,k)=>h in v?ne(v,h,{enumerable:!0,configurable:!0,writable:!0,value:k}):v[h]=k,V=(v,h)=>{for(var k in h||(h={}))oe.call(h,k)&&Z(v,k,h[k]);if(Y)for(var k of Y(h))le.call(h,k)&&Z(v,k,h[k]);return v},rr=(v,h)=>ie(v,se(h));(function(v,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],h):(v=typeof globalThis!="undefined"?globalThis:v||self,h(v.vcw={},v.Vue))})(this,function(v,h){"use strict";var k="",C=(r,e)=>{const t=r.__vccOpts||r;for(const[a,n]of e)t[a]=n;return t};const er={},tr=r=>(h.pushScopeId("data-v-3468742b"),r=r(),h.popScopeId(),r),ar={class:"loadingio-spinner-rolling-9f4hja5xffr"},nr=[tr(()=>h.createElementVNode("div",{class:"ldio-gpklibk3god"},[h.createElementVNode("div")],-1))];function ir(r,e){return h.openBlock(),h.createElementBlock("div",ar,nr)}var sr=C(er,[["render",ir],["__scopeId","data-v-3468742b"]]),ue="";const or=["title"],lr={key:0,class:"v-address-box"},hr={key:1};var ur=C(h.defineComponent({props:{address:null,dark:{type:Boolean}},setup(r){return(e,t)=>(h.openBlock(),h.createElementBlock("button",{class:h.normalizeClass(["v-btn v-address-btn",[e.$attrs.onClick?"v-address-btn-clickable":null,r.dark?"v-address-btn-dark":"v-address-btn-light"]]),title:r.address},[r.address?(h.openBlock(),h.createElementBlock("div",lr,[h.renderSlot(e.$slots,"default",{},void 0,!0),h.createElementVNode("b",null,h.toDisplayString(r.address.substring(0,6)+"..."+r.address.substring(r.address.length-4)),1)])):(h.openBlock(),h.createElementBlock("span",hr,"Connected"))],10,or))}}),[["__scopeId","data-v-16b91a1b"]]),M=function(r){r==null&&(r=new Date().getTime()),this.N=624,this.M=397,this.MATRIX_A=2567483615,this.UPPER_MASK=2147483648,this.LOWER_MASK=2147483647,this.mt=new Array(this.N),this.mti=this.N+1,r.constructor==Array?this.init_by_array(r,r.length):this.init_seed(r)};M.prototype.init_seed=function(r){for(this.mt[0]=r>>>0,this.mti=1;this.mti>>30;this.mt[this.mti]=(((r&4294901760)>>>16)*1812433253<<16)+(r&65535)*1812433253+this.mti,this.mt[this.mti]>>>=0}},M.prototype.init_by_array=function(r,e){var t,a,n;for(this.init_seed(19650218),t=1,a=0,n=this.N>e?this.N:e;n;n--){var s=this.mt[t-1]^this.mt[t-1]>>>30;this.mt[t]=(this.mt[t]^(((s&4294901760)>>>16)*1664525<<16)+(s&65535)*1664525)+r[a]+a,this.mt[t]>>>=0,t++,a++,t>=this.N&&(this.mt[0]=this.mt[this.N-1],t=1),a>=e&&(a=0)}for(n=this.N-1;n;n--){var s=this.mt[t-1]^this.mt[t-1]>>>30;this.mt[t]=(this.mt[t]^(((s&4294901760)>>>16)*1566083941<<16)+(s&65535)*1566083941)-t,this.mt[t]>>>=0,t++,t>=this.N&&(this.mt[0]=this.mt[this.N-1],t=1)}this.mt[0]=2147483648},M.prototype.random_int=function(){var r,e=new Array(0,this.MATRIX_A);if(this.mti>=this.N){var t;for(this.mti==this.N+1&&this.init_seed(5489),t=0;t>>1^e[r&1];for(;t>>1^e[r&1];r=this.mt[this.N-1]&this.UPPER_MASK|this.mt[0]&this.LOWER_MASK,this.mt[this.N-1]=this.mt[this.M-1]^r>>>1^e[r&1],this.mti=0}return r=this.mt[this.mti++],r^=r>>>11,r^=r<<7&2636928640,r^=r<<15&4022730752,r^=r>>>18,r>>>0},M.prototype.random_int31=function(){return this.random_int()>>>1},M.prototype.random_incl=function(){return this.random_int()*(1/4294967295)},M.prototype.random=function(){return this.random_int()*(1/4294967296)},M.prototype.random_excl=function(){return(this.random_int()+.5)*(1/4294967296)},M.prototype.random_long=function(){var r=this.random_int()>>>5,e=this.random_int()>>>6;return(r*67108864+e)*(1/9007199254740992)};var cr=M,K={exports:{}},dr={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},D={exports:{}},vr=function(e){return!e||typeof e=="string"?!1:e instanceof Array||Array.isArray(e)||e.length>=0&&(e.splice instanceof Function||Object.getOwnPropertyDescriptor(e,e.length-1)&&e.constructor.name!=="String")},fr=vr,gr=Array.prototype.concat,mr=Array.prototype.slice,L=D.exports=function(e){for(var t=[],a=0,n=e.length;a=4&&r[3]!==1&&(e=", "+r[3]),"hwb("+r[0]+", "+r[1]+"%, "+r[2]+"%"+e+")"},b.to.keyword=function(r){return j[r.slice(0,3)]};function x(r,e,t){return Math.min(Math.max(e,r),t)}function $(r){var e=Math.round(r).toString(16).toUpperCase();return e.length<2?"0"+e:e}var P={exports:{}},pr={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},_=pr,H={};for(var I in _)_.hasOwnProperty(I)&&(H[_[I]]=I);var u=P.exports={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};for(var p in u)if(u.hasOwnProperty(p)){if(!("channels"in u[p]))throw new Error("missing channels property: "+p);if(!("labels"in u[p]))throw new Error("missing channel labels property: "+p);if(u[p].labels.length!==u[p].channels)throw new Error("channel and label counts mismatch: "+p);var br=u[p].channels,yr=u[p].labels;delete u[p].channels,delete u[p].labels,Object.defineProperty(u[p],"channels",{value:br}),Object.defineProperty(u[p],"labels",{value:yr})}u.rgb.hsl=function(r){var e=r[0]/255,t=r[1]/255,a=r[2]/255,n=Math.min(e,t,a),s=Math.max(e,t,a),i=s-n,o,l,c;return s===n?o=0:e===s?o=(t-a)/i:t===s?o=2+(a-e)/i:a===s&&(o=4+(e-t)/i),o=Math.min(o*60,360),o<0&&(o+=360),c=(n+s)/2,s===n?l=0:c<=.5?l=i/(s+n):l=i/(2-s-n),[o,l*100,c*100]},u.rgb.hsv=function(r){var e,t,a,n,s,i=r[0]/255,o=r[1]/255,l=r[2]/255,c=Math.max(i,o,l),g=c-Math.min(i,o,l),w=function(W){return(c-W)/6/g+1/2};return g===0?n=s=0:(s=g/c,e=w(i),t=w(o),a=w(l),i===c?n=a-t:o===c?n=1/3+e-a:l===c&&(n=2/3+t-e),n<0?n+=1:n>1&&(n-=1)),[n*360,s*100,c*100]},u.rgb.hwb=function(r){var e=r[0],t=r[1],a=r[2],n=u.rgb.hsl(r)[0],s=1/255*Math.min(e,Math.min(t,a));return a=1-1/255*Math.max(e,Math.max(t,a)),[n,s*100,a*100]},u.rgb.cmyk=function(r){var e=r[0]/255,t=r[1]/255,a=r[2]/255,n,s,i,o;return o=Math.min(1-e,1-t,1-a),n=(1-e-o)/(1-o)||0,s=(1-t-o)/(1-o)||0,i=(1-a-o)/(1-o)||0,[n*100,s*100,i*100,o*100]};function wr(r,e){return Math.pow(r[0]-e[0],2)+Math.pow(r[1]-e[1],2)+Math.pow(r[2]-e[2],2)}u.rgb.keyword=function(r){var e=H[r];if(e)return e;var t=1/0,a;for(var n in _)if(_.hasOwnProperty(n)){var s=_[n],i=wr(r,s);i.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92,a=a>.04045?Math.pow((a+.055)/1.055,2.4):a/12.92;var n=e*.4124+t*.3576+a*.1805,s=e*.2126+t*.7152+a*.0722,i=e*.0193+t*.1192+a*.9505;return[n*100,s*100,i*100]},u.rgb.lab=function(r){var e=u.rgb.xyz(r),t=e[0],a=e[1],n=e[2],s,i,o;return t/=95.047,a/=100,n/=108.883,t=t>.008856?Math.pow(t,1/3):7.787*t+16/116,a=a>.008856?Math.pow(a,1/3):7.787*a+16/116,n=n>.008856?Math.pow(n,1/3):7.787*n+16/116,s=116*a-16,i=500*(t-a),o=200*(a-n),[s,i,o]},u.hsl.rgb=function(r){var e=r[0]/360,t=r[1]/100,a=r[2]/100,n,s,i,o,l;if(t===0)return l=a*255,[l,l,l];a<.5?s=a*(1+t):s=a+t-a*t,n=2*a-s,o=[0,0,0];for(var c=0;c<3;c++)i=e+1/3*-(c-1),i<0&&i++,i>1&&i--,6*i<1?l=n+(s-n)*6*i:2*i<1?l=s:3*i<2?l=n+(s-n)*(2/3-i)*6:l=n,o[c]=l*255;return o},u.hsl.hsv=function(r){var e=r[0],t=r[1]/100,a=r[2]/100,n=t,s=Math.max(a,.01),i,o;return a*=2,t*=a<=1?a:2-a,n*=s<=1?s:2-s,o=(a+t)/2,i=a===0?2*n/(s+n):2*t/(a+t),[e,i*100,o*100]},u.hsv.rgb=function(r){var e=r[0]/60,t=r[1]/100,a=r[2]/100,n=Math.floor(e)%6,s=e-Math.floor(e),i=255*a*(1-t),o=255*a*(1-t*s),l=255*a*(1-t*(1-s));switch(a*=255,n){case 0:return[a,l,i];case 1:return[o,a,i];case 2:return[i,a,l];case 3:return[i,o,a];case 4:return[l,i,a];case 5:return[a,i,o]}},u.hsv.hsl=function(r){var e=r[0],t=r[1]/100,a=r[2]/100,n=Math.max(a,.01),s,i,o;return o=(2-t)*a,s=(2-t)*n,i=t*n,i/=s<=1?s:2-s,i=i||0,o/=2,[e,i*100,o*100]},u.hwb.rgb=function(r){var e=r[0]/360,t=r[1]/100,a=r[2]/100,n=t+a,s,i,o,l;n>1&&(t/=n,a/=n),s=Math.floor(6*e),i=1-a,o=6*e-s,(s&1)!==0&&(o=1-o),l=t+o*(i-t);var c,g,w;switch(s){default:case 6:case 0:c=i,g=l,w=t;break;case 1:c=l,g=i,w=t;break;case 2:c=t,g=i,w=l;break;case 3:c=t,g=l,w=i;break;case 4:c=l,g=t,w=i;break;case 5:c=i,g=t,w=l;break}return[c*255,g*255,w*255]},u.cmyk.rgb=function(r){var e=r[0]/100,t=r[1]/100,a=r[2]/100,n=r[3]/100,s,i,o;return s=1-Math.min(1,e*(1-n)+n),i=1-Math.min(1,t*(1-n)+n),o=1-Math.min(1,a*(1-n)+n),[s*255,i*255,o*255]},u.xyz.rgb=function(r){var e=r[0]/100,t=r[1]/100,a=r[2]/100,n,s,i;return n=e*3.2406+t*-1.5372+a*-.4986,s=e*-.9689+t*1.8758+a*.0415,i=e*.0557+t*-.204+a*1.057,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:n*12.92,s=s>.0031308?1.055*Math.pow(s,1/2.4)-.055:s*12.92,i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:i*12.92,n=Math.min(Math.max(0,n),1),s=Math.min(Math.max(0,s),1),i=Math.min(Math.max(0,i),1),[n*255,s*255,i*255]},u.xyz.lab=function(r){var e=r[0],t=r[1],a=r[2],n,s,i;return e/=95.047,t/=100,a/=108.883,e=e>.008856?Math.pow(e,1/3):7.787*e+16/116,t=t>.008856?Math.pow(t,1/3):7.787*t+16/116,a=a>.008856?Math.pow(a,1/3):7.787*a+16/116,n=116*t-16,s=500*(e-t),i=200*(t-a),[n,s,i]},u.lab.xyz=function(r){var e=r[0],t=r[1],a=r[2],n,s,i;s=(e+16)/116,n=t/500+s,i=s-a/200;var o=Math.pow(s,3),l=Math.pow(n,3),c=Math.pow(i,3);return s=o>.008856?o:(s-16/116)/7.787,n=l>.008856?l:(n-16/116)/7.787,i=c>.008856?c:(i-16/116)/7.787,n*=95.047,s*=100,i*=108.883,[n,s,i]},u.lab.lch=function(r){var e=r[0],t=r[1],a=r[2],n,s,i;return n=Math.atan2(a,t),s=n*360/2/Math.PI,s<0&&(s+=360),i=Math.sqrt(t*t+a*a),[e,i,s]},u.lch.lab=function(r){var e=r[0],t=r[1],a=r[2],n,s,i;return i=a/360*2*Math.PI,n=t*Math.cos(i),s=t*Math.sin(i),[e,n,s]},u.rgb.ansi16=function(r){var e=r[0],t=r[1],a=r[2],n=1 in arguments?arguments[1]:u.rgb.hsv(r)[2];if(n=Math.round(n/50),n===0)return 30;var s=30+(Math.round(a/255)<<2|Math.round(t/255)<<1|Math.round(e/255));return n===2&&(s+=60),s},u.hsv.ansi16=function(r){return u.rgb.ansi16(u.hsv.rgb(r),r[2])},u.rgb.ansi256=function(r){var e=r[0],t=r[1],a=r[2];if(e===t&&t===a)return e<8?16:e>248?231:Math.round((e-8)/247*24)+232;var n=16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(a/255*5);return n},u.ansi16.rgb=function(r){var e=r%10;if(e===0||e===7)return r>50&&(e+=3.5),e=e/10.5*255,[e,e,e];var t=(~~(r>50)+1)*.5,a=(e&1)*t*255,n=(e>>1&1)*t*255,s=(e>>2&1)*t*255;return[a,n,s]},u.ansi256.rgb=function(r){if(r>=232){var e=(r-232)*10+8;return[e,e,e]}r-=16;var t,a=Math.floor(r/36)/5*255,n=Math.floor((t=r%36)/6)/5*255,s=t%6/5*255;return[a,n,s]},u.rgb.hex=function(r){var e=((Math.round(r[0])&255)<<16)+((Math.round(r[1])&255)<<8)+(Math.round(r[2])&255),t=e.toString(16).toUpperCase();return"000000".substring(t.length)+t},u.hex.rgb=function(r){var e=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!e)return[0,0,0];var t=e[0];e[0].length===3&&(t=t.split("").map(function(o){return o+o}).join(""));var a=parseInt(t,16),n=a>>16&255,s=a>>8&255,i=a&255;return[n,s,i]},u.rgb.hcg=function(r){var e=r[0]/255,t=r[1]/255,a=r[2]/255,n=Math.max(Math.max(e,t),a),s=Math.min(Math.min(e,t),a),i=n-s,o,l;return i<1?o=s/(1-i):o=0,i<=0?l=0:n===e?l=(t-a)/i%6:n===t?l=2+(a-e)/i:l=4+(e-t)/i+4,l/=6,l%=1,[l*360,i*100,o*100]},u.hsl.hcg=function(r){var e=r[1]/100,t=r[2]/100,a=1,n=0;return t<.5?a=2*e*t:a=2*e*(1-t),a<1&&(n=(t-.5*a)/(1-a)),[r[0],a*100,n*100]},u.hsv.hcg=function(r){var e=r[1]/100,t=r[2]/100,a=e*t,n=0;return a<1&&(n=(t-a)/(1-a)),[r[0],a*100,n*100]},u.hcg.rgb=function(r){var e=r[0]/360,t=r[1]/100,a=r[2]/100;if(t===0)return[a*255,a*255,a*255];var n=[0,0,0],s=e%1*6,i=s%1,o=1-i,l=0;switch(Math.floor(s)){case 0:n[0]=1,n[1]=i,n[2]=0;break;case 1:n[0]=o,n[1]=1,n[2]=0;break;case 2:n[0]=0,n[1]=1,n[2]=i;break;case 3:n[0]=0,n[1]=o,n[2]=1;break;case 4:n[0]=i,n[1]=0,n[2]=1;break;default:n[0]=1,n[1]=0,n[2]=o}return l=(1-t)*a,[(t*n[0]+l)*255,(t*n[1]+l)*255,(t*n[2]+l)*255]},u.hcg.hsv=function(r){var e=r[1]/100,t=r[2]/100,a=e+t*(1-e),n=0;return a>0&&(n=e/a),[r[0],n*100,a*100]},u.hcg.hsl=function(r){var e=r[1]/100,t=r[2]/100,a=t*(1-e)+.5*e,n=0;return a>0&&a<.5?n=e/(2*a):a>=.5&&a<1&&(n=e/(2*(1-a))),[r[0],n*100,a*100]},u.hcg.hwb=function(r){var e=r[1]/100,t=r[2]/100,a=e+t*(1-e);return[r[0],(a-e)*100,(1-a)*100]},u.hwb.hcg=function(r){var e=r[1]/100,t=r[2]/100,a=1-t,n=a-e,s=0;return n<1&&(s=(a-n)/(1-n)),[r[0],n*100,s*100]},u.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},u.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},u.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},u.gray.hsl=u.gray.hsv=function(r){return[0,0,r[0]]},u.gray.hwb=function(r){return[0,100,r[0]]},u.gray.cmyk=function(r){return[0,0,0,r[0]]},u.gray.lab=function(r){return[r[0],0,0]},u.gray.hex=function(r){var e=Math.round(r[0]/100*255)&255,t=(e<<16)+(e<<8)+e,a=t.toString(16).toUpperCase();return"000000".substring(a.length)+a},u.rgb.gray=function(r){var e=(r[0]+r[1]+r[2])/3;return[e/255*100]};var z=P.exports;function kr(){for(var r={},e=Object.keys(z),t=e.length,a=0;a1&&(t=Array.prototype.slice.call(arguments)),r(t))};return"conversion"in r&&(e.conversion=r.conversion),e}function Er(r){var e=function(t){if(t==null)return t;arguments.length>1&&(t=Array.prototype.slice.call(arguments));var a=r(t);if(typeof a=="object")for(var n=a.length,s=0;s>16&255,r>>8&255,r&255],this.valpha=1;else{this.valpha=1;var i=Object.keys(r);"alpha"in r&&(i.splice(i.indexOf("alpha"),1),this.valpha=typeof r.alpha=="number"?r.alpha:0);var o=i.sort().join("");if(!(o in T))throw new Error("Unable to parse color from object: "+JSON.stringify(r));this.model=T[o];var l=y[this.model].labels,c=[];for(t=0;tt?(e+.05)/(t+.05):(t+.05)/(e+.05)},level:function(r){var e=this.contrast(r);return e>=7.1?"AAA":e>=4.5?"AA":""},isDark:function(){var r=this.rgb().color,e=(r[0]*299+r[1]*587+r[2]*114)/1e3;return e<128},isLight:function(){return!this.isDark()},negate:function(){for(var r=this.rgb(),e=0;e<3;e++)r.color[e]=255-r.color[e];return r},lighten:function(r){var e=this.hsl();return e.color[2]+=e.color[2]*r,e},darken:function(r){var e=this.hsl();return e.color[2]-=e.color[2]*r,e},saturate:function(r){var e=this.hsl();return e.color[1]+=e.color[1]*r,e},desaturate:function(r){var e=this.hsl();return e.color[1]-=e.color[1]*r,e},whiten:function(r){var e=this.hwb();return e.color[1]+=e.color[1]*r,e},blacken:function(r){var e=this.hwb();return e.color[2]+=e.color[2]*r,e},grayscale:function(){var r=this.rgb().color,e=r[0]*.3+r[1]*.59+r[2]*.11;return m.rgb(e,e,e)},fade:function(r){return this.alpha(this.valpha-this.valpha*r)},opaquer:function(r){return this.alpha(this.valpha+this.valpha*r)},rotate:function(r){var e=this.hsl(),t=e.color[0];return t=(t+r)%360,t=t<0?360+t:t,e.color[0]=t,e},mix:function(r,e){if(!r||!r.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof r);var t=r.rgb(),a=this.rgb(),n=e===void 0?.5:e,s=2*n-1,i=t.alpha()-a.alpha(),o=((s*i===-1?s:(s+i)/(1+s*i))+1)/2,l=1-o;return m.rgb(o*t.red()+l*a.red(),o*t.green()+l*a.green(),o*t.blue()+l*a.blue(),t.alpha()*n+a.alpha()*(1-n))}},Object.keys(y).forEach(function(r){if(X.indexOf(r)===-1){var e=y[r].channels;m.prototype[r]=function(){if(this.model===r)return new m(this);if(arguments.length)return new m(arguments,r);var t=typeof arguments[e]=="number"?e:this.valpha;return new m(qr(y[this.model][r].raw(this.color)).concat(t),r)},m[r]=function(t){return typeof t=="number"&&(t=U(R.call(arguments),e)),new m(t,r)}}});function $r(r,e){return Number(r.toFixed(e))}function zr(r){return function(e){return $r(e,r)}}function d(r,e,t){return r=Array.isArray(r)?r:[r],r.forEach(function(a){(q[a]||(q[a]=[]))[e]=t}),r=r[0],function(a){var n;return arguments.length?(t&&(a=t(a)),n=this[r](),n.color[e]=a,n):(n=this[r]().color[e],t&&(n=t(n)),n)}}function f(r){return function(e){return Math.max(0,Math.min(r,e))}}function qr(r){return Array.isArray(r)?r:[r]}function U(r,e){for(var t=0;t["#01888C","#FC7500","#034F5D","#F73F01","#FC1960","#C7144C","#F3C100","#1598F2","#2465E1","#F19E02"]}},data(){return{generator:null,svgns:"http://www.w3.org/2000/svg"}},watch:{seed:{handler(){this.icon()}},address:{handler(){this.icon()}},diameter:{handler(){this.icon()}}},mounted(){this.icon()},methods:{addressToNumber(r){return parseInt(r.slice(2,10),16)},async icon(){const r=this.address?this.addressToNumber(this.address):this.seed;this.$refs.jazzicon.innerHTML="";const e=await this.generateIdenticon(this.diameter,r);await this.$refs.jazzicon.append(e)},newPaper(r,e){const t=document.createElement("div");return t.style.borderRadius=`${r/2}px`,t.style.overflow="hidden",t.style.padding="0px",t.style.margin="0px",t.style.width=""+r+"px",t.style.height=""+r+"px",t.style.display="inline-block",t.style.background=e,{container:t}},generateIdenticon(r,e){this.generator=new cr(e);const t=this.hueShift(this.colors.slice(),this.generator),n=this.newPaper(r,this.genColor(t)).container,s=document.createElementNS(this.svgns,"svg");s.setAttributeNS(null,"x","0"),s.setAttributeNS(null,"y","0"),s.setAttributeNS(null,"width",r),s.setAttributeNS(null,"height",r),n.appendChild(s);for(let i=0;ie.address&&e.address.length>0&&e.address.startsWith("0x"));return(a,n)=>(h.openBlock(),h.createElementBlock("div",Rr,[h.createVNode(h.Transition,{name:"pending-txn-transition"},{default:h.withCtx(()=>[r.txnCount&&h.unref(t)?h.renderSlot(a.$slots,"pending",{key:0},()=>[h.createElementVNode("div",Tr,[h.renderSlot(a.$slots,"spinner",{},()=>[h.createVNode(sr)],!0),h.createElementVNode("span",Ur,h.toDisplayString(r.txnCount)+" pending ",1)])],!0):h.createCommentVNode("",!0)]),_:3}),h.unref(t)?h.renderSlot(a.$slots,"addressButton",{key:1},()=>[h.createVNode(ur,h.mergeProps(a.$attrs,{address:r.address,dark:r.dark,title:r.address}),{default:h.withCtx(()=>[h.renderSlot(a.$slots,"identicon",{},()=>[h.createVNode(G,{address:r.address,diameter:15,style:{"margin-top":"3px"}},null,8,["address"])],!0)]),_:3},16,["address","dark","title"])],!0):h.renderSlot(a.$slots,"connectWalletButton",{key:0},()=>[h.createElementVNode("button",h.mergeProps(a.$attrs,{class:["v-btn v-connect-btn",r.dark?"v-connect-btn-dark":"v-connect-btn-light"]}),[h.renderSlot(a.$slots,"default",{},()=>[Wr],!0)],16)],!0)]))}}));var Q=C(Kr,[["__scopeId","data-v-61db7636"]]);const N=typeof window.ethereum!="undefined"&&window.ethereum.isMetaMask;async function Dr(){if(N)try{return await window.ethereum.request({method:"eth_requestAccounts"})}catch(r){return"Error: Unable to execute request: "+r.message}else return"Error: MetaMask not detected"}async function Lr(){if(N)try{return await window.ethereum.request({method:"eth_accounts"})}catch(r){return"Error: Unable to execute request: "+r.message}else return"Error: MetaMask not detected"}async function Jr(){if(N)try{return await window.ethereum.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]})}catch(r){return"Error: Unable to execute request: "+r.message}else return"Error: MetaMask not detected"}const jr=async(r,e,t,a=18,n="ERC20")=>{await window.ethereum.request({method:"wallet_watchAsset",params:{type:n,options:{address:e,symbol:r,decimals:a,image:t}}})},Hr=async(r,e)=>{const t="0x"+parseInt(r.toString(),10).toString(16);try{await window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:t}]})}catch(a){if(a.code===4902&&e)try{await window.ethereum.request({method:"wallet_addEthereumChain",params:[V({chainId:t},e)]})}catch{throw new Error("Couldn't add network, it's possible that user has rejected the change")}else throw new Error("Couldn't switch networks. Error: "+a)}},Xr=r=>{N&&(h.onMounted(()=>{window.ethereum.on("accountsChanged",r)}),h.onUnmounted(()=>{window.ethereum.removeListener("accountsChanged",r)}))},Gr=r=>{N&&(h.onMounted(()=>{window.ethereum.on("chainChanged",r)}),h.onUnmounted(()=>{window.ethereum.removeListener("chainChanged",r)}))},Qr=()=>({isMetaMask:N,connect:Dr,getAccounts:Lr,switchAccounts:Jr,addTokenToWallet:jr,switchOrAddChain:Hr,onAccountsChanged:Xr,onChainChanged:Gr});var Yr={install:r=>{r.component("ConnectWalletButton",Q)}};v.ConnectWalletButton=Q,v.Jazzicon=G,v.default=Yr,v.useMetaMaskWallet=Qr,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
2 |
--------------------------------------------------------------------------------
/images/VueConnectWallet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neelansh15/vue-connect-wallet/e078fc340d494f8fd7137ac33d51875bbf062e13/images/VueConnectWallet.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite App
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-connect-wallet",
3 | "description": "Vue UI Button + Utils for Connecting a web3 Wallet (TS Support)",
4 | "private": false,
5 | "version": "0.1.7",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "vue-tsc --noEmit && vite build",
9 | "preview": "vite preview"
10 | },
11 | "main": "./dist/vcw.umd.js",
12 | "module": "./dist/vcw.es.js",
13 | "exports": {
14 | ".": {
15 | "import": "./dist/vcw.es.js",
16 | "require": "./dist/vcw.umd.js"
17 | },
18 | "./dist/style.css": "./dist/style.css"
19 | },
20 | "files": [
21 | "dist"
22 | ],
23 | "types": "./dist",
24 | "author": {
25 | "name": "Neelansh Mathur",
26 | "email": "neelansh.m@somaiya.edu",
27 | "url": "https://github.com/neelansh15"
28 | },
29 | "keywords": ["vue", "vue3", "vuejs", "connect wallet", "useWallet", "vue connect wallet", "vue-connect-wallet", "metamask", "connect"],
30 | "license": "Apache-2.0",
31 | "dependencies": {
32 | "color": "^3.1.0",
33 | "mersenne-twister": "^1.1.0",
34 | "vue-demi": "latest"
35 | },
36 | "devDependencies": {
37 | "@types/node": "^17.0.25",
38 | "@vitejs/plugin-vue": "^2.3.1",
39 | "tsup": "^5.12.7",
40 | "typescript": "^4.5.4",
41 | "vite": "^2.9.5",
42 | "vite-plugin-dts": "^1.1.1",
43 | "vue": "^3.2.25",
44 | "vue-tsc": "^0.34.7"
45 | },
46 | "peerDependencies": {
47 | "@vue/composition-api": "^1.0.0-rc.1",
48 | "vue": "^2.0.0 || >=3.0.0"
49 | },
50 | "peerDependenciesMeta": {
51 | "@vue/composition-api": {
52 | "optional": true
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
49 |
50 |
51 |