Compare commits

...

50 Commits

Author SHA1 Message Date
Georges KABBOUCHI
1d10cfb64f nuxt 0.11.1 2023-09-28 20:09:47 +03:00
Georges KABBOUCHI
382192068b fix 2023-09-28 20:07:04 +03:00
Georges KABBOUCHI
ddfdab416c Update npm-publish.yml 2023-09-28 19:51:13 +03:00
Georges KABBOUCHI
1b8472b128 update nuxt 2023-09-28 19:49:24 +03:00
Georges KABBOUCHI
9d74a5ff4e support viem 2023-09-28 19:45:53 +03:00
Georges KABBOUCHI
9da073d3b0 upgrade vue-demi 2023-01-25 15:02:49 +02:00
Georges KABBOUCHI
a958d3a5e0 Update package.json 2023-01-24 20:15:33 +02:00
Georges KABBOUCHI
0a062c65c3 nuxt 3.1 2023-01-24 20:14:49 +02:00
Georges KABBOUCHI
339338cfc4
Merge pull request #4 from Instadapp/nuxt-upgrade 2022-11-23 21:26:12 +02:00
Georges KABBOUCHI
1e0bc6b93a wip 2022-11-23 21:21:04 +02:00
Georges KABBOUCHI
ef8b9ddab3 wip 2022-11-23 21:15:40 +02:00
Georges KABBOUCHI
7605997d3d
Update README.md 2022-10-17 16:36:24 +03:00
Georges KABBOUCHI
17af518a01
Update README.md 2022-10-17 16:35:04 +03:00
Georges KABBOUCHI
9295792224 fix 2022-10-17 15:57:05 +03:00
Georges KABBOUCHI
a80111bf30 Update index.ts 2022-10-17 15:50:12 +03:00
Georges KABBOUCHI
d4322fee4b 0.9.6 2022-10-17 15:42:33 +03:00
Georges KABBOUCHI
698f74d7a8 wip 2022-10-17 15:35:45 +03:00
Georges KABBOUCHI
6ec829ad2e Update yarn.lock 2022-10-17 15:33:08 +03:00
Georges KABBOUCHI
f1609df4ea Update package.json 2022-10-17 15:30:35 +03:00
Georges KABBOUCHI
d6bdf479b8 0.9.5 2022-10-17 15:27:43 +03:00
Georges KABBOUCHI
1fd4eebfad Merge branch 'master' of https://github.com/Instadapp/vue-web3 2022-10-17 15:08:56 +03:00
Georges KABBOUCHI
b4eed7bf5c export library type 2022-10-17 15:08:37 +03:00
Georges KABBOUCHI
58613ea67a
Update README.md 2022-10-17 15:02:19 +03:00
Georges KABBOUCHI
acc6b9ac55
Update README.md 2022-10-17 15:01:11 +03:00
Georges KABBOUCHI
2daca3af95 Update README.md 2022-10-07 20:33:57 +03:00
Georges KABBOUCHI
ac8e0e6684 wip 2022-10-07 20:29:00 +03:00
Georges KABBOUCHI
bffb6ac7f2 fixes 2022-10-07 20:24:55 +03:00
Georges KABBOUCHI
4c92b73950 Update module.ts 2022-10-07 20:19:20 +03:00
Georges KABBOUCHI
58b650a2e3 Update npm-publish.yml 2022-10-07 20:15:53 +03:00
Georges KABBOUCHI
9a0c564958 Update npm-publish.yml 2022-10-07 20:12:53 +03:00
Georges KABBOUCHI
54cafb2931 nuxt package 2022-10-07 20:07:35 +03:00
Georges KABBOUCHI
22bd3f71b6 fix imports 2022-10-07 19:00:35 +03:00
Georges KABBOUCHI
37fad40f13 use shallowRef for connector, provider and library 2022-06-15 17:37:37 +03:00
Georges KABBOUCHI
00ad34076c wip 2022-06-06 15:24:42 +03:00
Georges KABBOUCHI
70966a6f72 Update package.json 2022-06-06 15:20:30 +03:00
Georges KABBOUCHI
7289fc81fa wip 2022-06-06 15:18:59 +03:00
Georges KABBOUCHI
4a5234473d wip 2022-06-06 15:17:33 +03:00
Georges KABBOUCHI
f24060c5d0 fix 2022-06-06 15:06:43 +03:00
Georges KABBOUCHI
fc8a2efe0b wip 2022-06-06 14:58:47 +03:00
Georges KABBOUCHI
f4ed18d54c wip 2022-06-06 14:41:02 +03:00
Georges KABBOUCHI
fc00be181c wip 2022-06-06 14:35:37 +03:00
Georges KABBOUCHI
69c4722d37 Add nuxt module 2022-06-06 14:31:36 +03:00
Georges KABBOUCHI
a4178e79d2 Update README.md 2022-04-29 20:12:49 +03:00
Georges KABBOUCHI
1422e6f2bc fix UnsupportedChainIdError prototype 2022-04-29 19:32:48 +03:00
Georges KABBOUCHI
14a21a1711 fix UnsupportedChainIdError constructor name 2022-04-29 19:15:43 +03:00
Georges KABBOUCHI
a8dcb6a556
Update README.md 2022-03-02 16:16:01 +02:00
Georges KABBOUCHI
9656d5172b
Update README.md 2022-01-14 19:29:50 +02:00
Georges KABBOUCHI
a8af89adb4 refactor cjs + mjs 2021-10-31 01:29:33 +02:00
27dd25aada Bump version 0.4.0 2021-10-15 10:30:11 +05:30
Georges KABBOUCHI
8604bf0d0f Upgrade vue-demi 2021-10-14 22:24:02 +03:00
21 changed files with 11192 additions and 356 deletions

View File

@ -1,6 +1,7 @@
name: npm-publish name: npm-publish
on: on:
workflow_dispatch:
release: release:
types: [released] types: [released]
@ -12,9 +13,16 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 14 node-version: 16
- uses: JS-DevTools/npm-publish@v1 - uses: JS-DevTools/npm-publish@v1
with: with:
token: ${{ secrets.NPM_AUTH_TOKEN }} token: ${{ secrets.NPM_AUTH_TOKEN }}
access: public access: public
check-version: true check-version: true
package: ./package.json
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_AUTH_TOKEN }}
access: public
check-version: true
package: ./nuxt/package.json

View File

@ -1,10 +1,10 @@
# @instadapp/vue-web3 # @instadapp/vue-web3
Vue 2/3 wrapper for web3 built on top of [react-web3](https://github.com/NoahZinsmeister/web3-react). Vue 2/3 wrapper for web3 built on top of [react-web3@v6](https://github.com/NoahZinsmeister/web3-react/tree/v6).
## 🚀 Quick Start ## 🚀 Quick Start
Install: #### Install:
```bash ```bash
# npm # npm
@ -14,7 +14,7 @@ npm i @instadapp/vue-web3
yarn add @instadapp/vue-web3 yarn add @instadapp/vue-web3
``` ```
Usage: #### Usage:
```js ```js
import { useWeb3, setWeb3LibraryCallback } from '@instadapp/vue-web3' import { useWeb3, setWeb3LibraryCallback } from '@instadapp/vue-web3'
@ -32,8 +32,24 @@ const walletconnect = new WalletConnectConnector({
qrcode: true, qrcode: true,
}) })
// web3.js v1
setWeb3LibraryCallback((provider) => new Web3(provider)) setWeb3LibraryCallback((provider) => new Web3(provider))
// ethers.js v5
setWeb3LibraryCallback((provider) => new Web3Provider(provider, "any"))
// viem
setWeb3LibraryCallback((provider, _connector, account) => ({
public: createPublicClient({
transport: custom(provider),
}),
wallet: createWalletClient({
account,
chain: null as unknown as Chain,
transport: custom(provider),
}),
}))
defineComponent({ defineComponent({
setup() { setup() {
const { active, activate, account, library } = useWeb3() const { active, activate, account, library } = useWeb3()
@ -55,7 +71,10 @@ defineComponent({
}, },
}) })
``` ```
Typescript:
#### Typescript:
using generic:
```js ```js
import Web3 from 'web3' import Web3 from 'web3'
@ -69,4 +88,51 @@ import { Web3Provider } from "@ethersproject/providers";
const { library } = useWeb3<Web3Provider>() const { library } = useWeb3<Web3Provider>()
``` ```
Demo: https://github.com/KABBOUCHI/nuxt-vue-web3 using global types:
```ts
// global.d.ts
import type Web3 from 'web3'
declare module '@instadapp/vue-web3' {
interface IVueWeb3Library extends Web3 {}
}
```
#### Nuxt 3
```bash
yarn add @instadapp/vue-web3-nuxt -D
```
```ts
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@instadapp/vue-web3-nuxt'],
web3: {
autoImport: false, // default `true`
},
})
```
If you disabled `@instadapp/vue-web3-nuxt` auto import:
```ts
//composables/useWeb3.ts
import Web3 from 'web3'
// import { Web3Provider } from "@ethersproject/providers";
import { useWeb3 as useWeb3Generic } from '@instadapp/vue-web3'
const useWeb3 = () => useWeb3Generic<Web3>()
// const useWeb3 = () => useWeb3Generic<Web3Provider>();
export { useWeb3 }
```
## <br />
<br />
Demo (Nuxt 2): https://github.com/KABBOUCHI/nuxt-vue-web3
Demo (Nuxt 3): https://github.com/KABBOUCHI/nuxt3-vue-web3

7
index.cjs Normal file
View File

@ -0,0 +1,7 @@
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/vue-web3.prod.cjs')
} else {
module.exports = require('./dist/vue-web3.cjs')
}

7
index.js Normal file
View File

@ -0,0 +1,7 @@
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/vue-web3.prod.cjs')
} else {
module.exports = require('./dist/vue-web3.cjs')
}

12
nuxt/.editorconfig Normal file
View File

@ -0,0 +1,12 @@
root = true
[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

2
nuxt/.eslintignore Normal file
View File

@ -0,0 +1,2 @@
dist
node_modules

10
nuxt/.eslintrc Normal file
View File

@ -0,0 +1,10 @@
{
"extends": [
"@nuxtjs/eslint-config-typescript"
],
"rules": {
"@typescript-eslint/no-unused-vars": [
"off"
]
}
}

51
nuxt/.gitignore vendored Normal file
View File

@ -0,0 +1,51 @@
# Dependencies
node_modules
# Logs
*.log*
# Temp directories
.temp
.tmp
.cache
# Yarn
**/.yarn/cache
**/.yarn/*state*
# Generated dirs
dist
# Nuxt
.nuxt
.output
.vercel_build_output
.build-*
.env
.netlify
# Env
.env
# Testing
reports
coverage
*.lcov
.nyc_output
# VSCode
.vscode
# Intellij idea
*.iml
.idea
# OSX
.DS_Store
.AppleDouble
.LSOverride
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

6
nuxt/README.md Normal file
View File

@ -0,0 +1,6 @@
# Nuxt Module
## Development
- Run `npm run dev:prepare` to generate type stubs.
- Use `npm run dev` to start [playground](./playground) in development mode.

39
nuxt/package.json Normal file
View File

@ -0,0 +1,39 @@
{
"name": "@instadapp/vue-web3-nuxt",
"version": "0.11.1",
"license": "MIT",
"type": "module",
"exports": {
".": {
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
],
"scripts": {
"prepack": "nuxt-module-build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground"
},
"dependencies": {
"@instadapp/vue-web3": "^0.11.1",
"@nuxt/kit": "^3.1.0",
"mkdirp-promise": "4",
"vite-plugin-node-polyfills": "^0.7.0"
},
"devDependencies": {
"@nuxt/module-builder": "^0.2.1",
"@nuxt/ui": "^0.4.0",
"@nuxtjs/eslint-config-typescript": "11.0.0",
"@web3-react/injected-connector": "^6.0.7",
"@web3-react/network-connector": "^6.2.9",
"@web3-react/walletconnect-connector": "^6.2.13",
"eslint": "8.32.0",
"nuxt": "^3.1.0"
}
}

45
nuxt/playground/app.vue Normal file
View File

@ -0,0 +1,45 @@
<template>
<div class="relative p-10 n-bg-base">
<div class="container w-full mx-auto flex flex-col gap-4">
<div class="flex justify-between items-center">
<div class="text-4xl">
Web3 + Nuxt
</div>
</div>
<NCard class="p4">
<pre>{{ {account, active, error} }}</pre>
</NCard>
<NCard class="p4 flex gap-4">
<NButton @click="connectMetamask">
Connect using MetaMask
</NButton>
<NButton @click="connectWalletConnect">
Connect using WalletConnect
</NButton>
</NCard>
</div>
</div>
</template>
<script setup>
const { active, account, activate, error } = useWeb3()
const connectMetamask = async () => {
const { InjectedConnector } = await import('@web3-react/injected-connector')
await activate(
new InjectedConnector({})
)
}
const connectWalletConnect = async () => {
const { WalletConnectConnector } = await import('@web3-react/walletconnect-connector')
await activate(
new WalletConnectConnector({})
)
}
</script>

View File

@ -0,0 +1,7 @@
import MyModule from '..'
export default defineNuxtConfig({
modules: ['@nuxt/ui', MyModule],
web3: {},
})

View File

@ -0,0 +1,11 @@
{
"private": true,
"name": "my-module-playground",
"dependencies": {
"@web3-react/injected-connector": "^6.0.7",
"@web3-react/walletconnect-connector": "^6.2.13"
},
"devDependencies": {
"@nuxt/ui": "^0.3.3"
}
}

2336
nuxt/playground/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

26
nuxt/src/module.ts Normal file
View File

@ -0,0 +1,26 @@
import { addImports, addVitePlugin, defineNuxtModule } from '@nuxt/kit'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
export interface ModuleOptions {
autoImport: boolean
}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'vue-web3',
configKey: 'web3',
},
defaults: {
autoImport: true,
},
setup(options, nuxt) {
addVitePlugin(nodePolyfills())
if (options.autoImport) {
addImports({
name: 'useWeb3',
from: '@instadapp/vue-web3',
})
}
},
})

3
nuxt/tsconfig.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "./playground/.nuxt/tsconfig.json"
}

7970
nuxt/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,48 @@
{ {
"name": "@instadapp/vue-web3", "name": "@instadapp/vue-web3",
"version": "0.3.0", "version": "0.11.1",
"description": "Vue web3 composition api", "description": "Vue web3 composition api",
"license": "MIT", "license": "MIT",
"main": "dist/cjs/index.js", "main": "index.js",
"module": "dist/esm/index.js", "module": "dist/vue-web3.mjs",
"unpkg": "dist/global/index.js", "unpkg": "dist/vue-web3.iife.js",
"types": "dist/esm/src/index.d.ts", "jsdelivr": "dist/vue-web3.iife.js",
"types": "dist/src/index.d.ts",
"exports": {
".": {
"browser": "./dist/vue-web3.esm-browser.js",
"node": {
"import": "./dist/vue-web3.mjs",
"require": {
"production": "./dist/vue-web3.prod.cjs",
"development": "./dist/vue-web3.cjs",
"default": "./index.js"
}
},
"import": "./dist/vue-web3.mjs"
},
"./package.json": "./package.json",
"./dist/*": "./dist/*",
"./nuxt/*": "./nuxt/*",
"./nuxt": {
"import": "./nuxt/dist/module.mjs",
"require": "./nuxt/dist/module.cjs"
}
},
"sideEffects": false, "sideEffects": false,
"scripts": { "scripts": {
"prepublishOnly": "npm i && npm run build", "prepublishOnly": "yarn install && yarn build && cd nuxt && yarn install && yarn dev:prepare && yarn prepack",
"build": "rollup -c rollup.config.js", "build": "rollup -c rollup.config.js",
"dev": "rollup -w -c rollup.config.js", "dev": "rollup -w -c rollup.config.js",
"lint": "prettier -c --parser typescript \"{src,__tests__,e2e}/**/*.[jt]s?(x)\"", "lint": "prettier -c --parser typescript \"{src,__tests__,e2e}/**/*.[jt]s?(x)\"",
"lint:fix": "yarn run lint --write" "lint:fix": "yarn run lint --write"
}, },
"files": [ "files": [
"nuxt/package.json",
"nuxt/dist/**/*",
"dist/**/*", "dist/**/*",
"index.js",
"index.cjs",
"LICENSE", "LICENSE",
"README.md" "README.md"
], ],
@ -25,10 +51,13 @@
"@ethersproject/keccak256": "^5.4.0", "@ethersproject/keccak256": "^5.4.0",
"@web3-react/abstract-connector": "^6.0.7", "@web3-react/abstract-connector": "^6.0.7",
"@web3-react/types": "^6.0.7", "@web3-react/types": "^6.0.7",
"events": "^3.3.0",
"tiny-invariant": "^1.1.0", "tiny-invariant": "^1.1.0",
"vue-demi": "^0.11.3" "vue-demi": "^0.13.11"
}, },
"devDependencies": { "devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"@rollup/plugin-alias": "^3.1.2", "@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^17.1.0", "@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.2.0", "@rollup/plugin-node-resolve": "^11.2.0",
@ -40,11 +69,12 @@
"prettier": "^2.2.1", "prettier": "^2.2.1",
"rollup": "^2.39.0", "rollup": "^2.39.0",
"rollup-plugin-delete": "^2.0.0", "rollup-plugin-delete": "^2.0.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-terser": "^7.0.2", "rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0", "rollup-plugin-typescript2": "^0.30.0",
"typescript": "^4.1.5", "typescript": "^4.1.5",
"yorkie": "^2.0.0", "vue": "^3.2.6",
"vue": "^3.2.6" "yorkie": "^2.0.0"
}, },
"peerDependencies": { "peerDependencies": {
"@vue/composition-api": "^1.0.0-rc.1", "@vue/composition-api": "^1.0.0-rc.1",

View File

@ -1,25 +1,21 @@
// @ts-nocheck
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import pascalcase from 'pascalcase'
import path from 'path' import path from 'path'
import del from 'rollup-plugin-delete'
import ts from 'rollup-plugin-typescript2' import ts from 'rollup-plugin-typescript2'
import replace from '@rollup/plugin-replace'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import pascalcase from 'pascalcase'
const pkg = require('./package.json') const pkg = require('./package.json')
const name = pkg.name const name = 'vue-web3'
function getAuthors(pkg) { function getAuthors(pkg) {
const { contributors, author } = pkg const { contributors, author } = pkg
const authors = new Set() const authors = new Set()
if (contributors && contributors) if (contributors && contributors)
contributors.forEach((contributor) => { contributors.forEach((contributor) => {
authors.add(contributor.name) authors.add(contributor.name)
}) })
if (author) authors.add(author.name) if (author) authors.add(author.name)
return Array.from(authors).join(', ') return Array.from(authors).join(', ')
@ -37,47 +33,60 @@ let hasTSChecked = false
const outputConfigs = { const outputConfigs = {
// each file name has the format: `dist/${name}.${format}.js` // each file name has the format: `dist/${name}.${format}.js`
// format being a key of this object // format being a key of this object
esm: { mjs: {
dir: 'dist/esm', file: pkg.module,
format: `es`, format: `es`,
}, },
cjs: { cjs: {
dir: 'dist/cjs', file: pkg.module.replace('mjs', 'cjs'),
format: 'cjs', format: `cjs`,
exports: 'named',
}, },
global: { global: {
dir: 'dist/global', file: pkg.unpkg,
format: 'iife', format: `iife`,
},
browser: {
file: 'dist/vue-web3.esm-browser.js',
format: `es`,
}, },
} }
const allFormats = Object.keys(outputConfigs) const packageBuilds = Object.keys(outputConfigs)
const packageFormats = allFormats const packageConfigs = packageBuilds.map((format) =>
const packageConfigs = packageFormats.map((format) => createConfig(format, outputConfigs[format]),
format === 'global'
? createMinifiedConfig(format)
: createConfig(format, outputConfigs[format]),
) )
// only add the production ready if we are bundling the options
packageBuilds.forEach((buildName) => {
if (buildName === 'cjs') {
packageConfigs.push(createProductionConfig(buildName))
} else if (buildName === 'global') {
packageConfigs.push(createMinifiedConfig(buildName))
}
})
export default packageConfigs export default packageConfigs
function createConfig(format, output, plugins = []) { function createConfig(buildName, output, plugins = []) {
if (!output) { if (!output) {
console.log(require('chalk').yellow(`invalid format: "${format}"`)) console.log(require('chalk').yellow(`invalid format: "${buildName}"`))
process.exit(1) process.exit(1)
} }
output.sourcemap = !!process.env.SOURCE_MAP output.sourcemap = !!process.env.SOURCE_MAP
output.banner = banner output.banner = banner
output.externalLiveBindings = false output.externalLiveBindings = false
output.globals = { vue: 'Vue' } output.globals = {
'vue-demi': 'VueDemi',
vue: 'Vue',
'@vue/composition-api': 'vueCompositionApi',
}
const isProductionBuild = /\.prod\.js$/.test(output.file) const isProductionBuild = /\.prod\.[cmj]s$/.test(output.file)
const isGlobalBuild = format === 'global' const isGlobalBuild = buildName === 'global'
const isRawESMBuild = format === 'esm' const isRawESMBuild = buildName === 'browser'
const isNodeBuild = format === 'cjs' const isNodeBuild = buildName === 'cjs'
const isBundlerESMBuild = /esm-bundler/.test(format) const isBundlerESMBuild = buildName === 'browser' || buildName === 'mjs'
if (isGlobalBuild) output.name = pascalcase(pkg.name) if (isGlobalBuild) output.name = pascalcase(pkg.name)
@ -85,15 +94,14 @@ function createConfig(format, output, plugins = []) {
const tsPlugin = ts({ const tsPlugin = ts({
check: !hasTSChecked, check: !hasTSChecked,
tsconfig: path.resolve(__dirname, 'tsconfig.json'), tsconfig: path.resolve(__dirname, './tsconfig.json'),
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'), cacheRoot: path.resolve(__dirname, './node_modules/.rts2_cache'),
tsconfigOverride: { tsconfigOverride: {
compilerOptions: { compilerOptions: {
sourceMap: output.sourcemap, sourceMap: output.sourcemap,
declaration: shouldEmitDeclarations, declaration: shouldEmitDeclarations,
declarationMap: shouldEmitDeclarations, declarationMap: shouldEmitDeclarations,
}, },
exclude: ['__tests__', 'test-dts'],
}, },
}) })
// we only need to check TS and generate declarations once for each build. // we only need to check TS and generate declarations once for each build.
@ -101,11 +109,7 @@ function createConfig(format, output, plugins = []) {
// during a single build. // during a single build.
hasTSChecked = true hasTSChecked = true
const external = ['vue'] const external = ['vue-demi', 'vue', '@vue/composition-api']
if (!isGlobalBuild) {
external.push('vue-demi')
}
const nodePlugins = [resolve(), commonjs()] const nodePlugins = [resolve(), commonjs()]
@ -114,13 +118,12 @@ function createConfig(format, output, plugins = []) {
// Global and Browser ESM builds inlines everything so that they can be // Global and Browser ESM builds inlines everything so that they can be
// used alone. // used alone.
external, external,
inlineDynamicImports: isGlobalBuild,
plugins: [ plugins: [
del({ targets: `dist/${format}` }),
tsPlugin, tsPlugin,
createReplacePlugin( createReplacePlugin(
isProductionBuild, isProductionBuild,
isBundlerESMBuild, isBundlerESMBuild,
// isBrowserBuild?
isGlobalBuild || isRawESMBuild || isBundlerESMBuild, isGlobalBuild || isRawESMBuild || isBundlerESMBuild,
isGlobalBuild, isGlobalBuild,
isNodeBuild, isNodeBuild,
@ -129,6 +132,11 @@ function createConfig(format, output, plugins = []) {
...plugins, ...plugins,
], ],
output, output,
// onwarn: (msg, warn) => {
// if (!/Circular/.test(msg)) {
// warn(msg)
// }
// },
} }
} }
@ -142,22 +150,25 @@ function createReplacePlugin(
const replacements = { const replacements = {
__COMMIT__: `"${process.env.COMMIT}"`, __COMMIT__: `"${process.env.COMMIT}"`,
__VERSION__: `"${pkg.version}"`, __VERSION__: `"${pkg.version}"`,
__DEV__: isBundlerESMBuild __DEV__:
? // preserve to be handled by bundlers isBundlerESMBuild || (isNodeBuild && !isProduction)
`(process.env.NODE_ENV !== 'production')` ? // preserve to be handled by bundlers
: // hard coded dev/prod builds `(process.env.NODE_ENV !== 'production')`
!isProduction, : // hard coded dev/prod builds
JSON.stringify(!isProduction),
// this is only used during tests // this is only used during tests
__TEST__: isBundlerESMBuild ? `(process.env.NODE_ENV === 'test')` : false, __TEST__:
isBundlerESMBuild || isNodeBuild
? `(process.env.NODE_ENV === 'test')`
: 'false',
// If the build is expected to run directly in the browser (global / esm builds) // If the build is expected to run directly in the browser (global / esm builds)
__BROWSER__: isBrowserBuild, __BROWSER__: JSON.stringify(isBrowserBuild),
// is targeting bundlers? // is targeting bundlers?
__BUNDLER__: isBundlerESMBuild, __BUNDLER__: JSON.stringify(isBundlerESMBuild),
__GLOBAL__: isGlobalBuild, __GLOBAL__: JSON.stringify(isGlobalBuild),
// is targeting Node (SSR)? // is targeting Node (SSR)?
__NODE_JS__: isNodeBuild, __NODE_JS__: JSON.stringify(isNodeBuild),
} }
// allow inline overrides like // allow inline overrides like
//__RUNTIME_COMPILE__=true yarn build //__RUNTIME_COMPILE__=true yarn build
Object.keys(replacements).forEach((key) => { Object.keys(replacements).forEach((key) => {
@ -165,20 +176,27 @@ function createReplacePlugin(
replacements[key] = process.env[key] replacements[key] = process.env[key]
} }
}) })
return replace({ return replace({
values: replacements,
preventAssignment: true, preventAssignment: true,
values: replacements,
})
}
function createProductionConfig(format) {
const extension = format === 'cjs' ? 'cjs' : 'js'
const descriptor = format === 'cjs' ? '' : `.${format}`
return createConfig(format, {
file: `dist/${name}${descriptor}.prod.${extension}`,
format: outputConfigs[format].format,
}) })
} }
function createMinifiedConfig(format) { function createMinifiedConfig(format) {
const { terser } = require('rollup-plugin-terser') const { terser } = require('rollup-plugin-terser')
return createConfig( return createConfig(
format, format,
{ {
dir: `dist/${format}/`, file: `dist/${name}.${format === 'global' ? 'iife' : format}.prod.js`,
format: outputConfigs[format].format, format: outputConfigs[format].format,
}, },
[ [

View File

@ -1,7 +1,14 @@
import { AbstractConnector } from '@web3-react/abstract-connector' import { AbstractConnector } from '@web3-react/abstract-connector'
import { normalizeAccount, normalizeChainId } from './normalizers' import { normalizeAccount, normalizeChainId } from './normalizers'
import { ConnectorEvent, ConnectorUpdate } from '@web3-react/types' import { ConnectorEvent, ConnectorUpdate } from '@web3-react/types'
import { computed, onBeforeUnmount, Ref, ref, watch } from 'vue-demi' import {
computed,
onBeforeUnmount,
Ref,
ref,
shallowRef,
watch,
} from 'vue-demi'
export class UnsupportedChainIdError extends Error { export class UnsupportedChainIdError extends Error {
public constructor( public constructor(
@ -9,15 +16,17 @@ export class UnsupportedChainIdError extends Error {
supportedChainIds?: readonly number[], supportedChainIds?: readonly number[],
) { ) {
super() super()
this.name = this.constructor.name this.name = 'UnsupportedChainIdError'
this.message = `Unsupported chain id: ${unsupportedChainId}. Supported chain ids are: ${supportedChainIds}.` this.message = `Unsupported chain id: ${unsupportedChainId}. Supported chain ids are: ${supportedChainIds}.`
Object.setPrototypeOf(this, UnsupportedChainIdError.prototype)
} }
} }
const connector = ref<AbstractConnector>() const connector = shallowRef<AbstractConnector>()
const chainId = ref() const chainId = ref()
const account = ref<null | string>() const account = ref<null | string>()
const provider = ref<any>() const provider = shallowRef<any>()
const error = ref<Error>() const error = ref<Error>()
const active = computed( const active = computed(
() => () =>
@ -26,17 +35,23 @@ const active = computed(
account.value !== undefined && account.value !== undefined &&
!!!error.value, !!!error.value,
) )
const library = ref() const library = shallowRef()
let getLibrary: any = (provider?: any, connector?: any) => (): any => null let getLibrary: any =
(provider: any, connector: any, account: `0x${string}`) => (): any =>
null
export const setWeb3LibraryCallback = ( export const setWeb3LibraryCallback = (
cb: (provider?: any, connector?: any) => any, cb: (provider: any, connector: any, account: `0x${string}`) => any,
) => { ) => {
getLibrary = cb getLibrary = cb
} }
export const useWeb3 = <TLibrary = any>() => { export interface IVueWeb3Library {
[key: string]: any
}
export const useWeb3 = <TVueWeb3Library extends IVueWeb3Library>() => {
const onErrorCb = ref<(error: Error) => void>() const onErrorCb = ref<(error: Error) => void>()
const activate = async ( const activate = async (
@ -147,13 +162,13 @@ export const useWeb3 = <TLibrary = any>() => {
library.value = undefined library.value = undefined
} }
watch([active, provider, connector, chainId], () => { watch([active, provider, connector, chainId, account], () => {
library.value = library.value =
active.value && active.value &&
chainId.value !== undefined && chainId.value !== undefined &&
Number.isInteger(chainId.value) && Number.isInteger(chainId.value) &&
!!connector.value !!connector.value
? getLibrary(provider.value, connector.value) ? getLibrary(provider.value, connector.value, account.value)
: undefined : undefined
}) })
@ -180,7 +195,7 @@ export const useWeb3 = <TLibrary = any>() => {
}) })
return { return {
library: library as Ref<TLibrary>, library: library as Ref<TVueWeb3Library>,
active, active,
activate, activate,
deactivate, deactivate,

717
yarn.lock

File diff suppressed because it is too large Load Diff