Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 99bc0e6

Browse files
authored
Merge pull request #10 from unicape/example-nuxt
feat: examples nuxt
2 parents e78a289 + 216d3fb commit 99bc0e6

12 files changed

Lines changed: 3785 additions & 686 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*.local
22
.DS_Store
33
.eslintcache
4-
.next
4+
.nuxt
55
.pnpm-debug.log*
66
cache
77
coverage

.npmrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
link-workspace-packages=false
22
prefer-workspace-packages=false
33
strict-peer-dependencies=false
4-
ignore-workspace-root-check=true
4+
ignore-workspace-root-check=true
5+
shamefully-hoist=true

examples/nuxt/app.vue

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<template>
2+
<div>
3+
<div>
4+
<button
5+
v-for="x in connectors"
6+
:key="x.name"
7+
:disabled="!x.ready || isReconnecting || connector?.id === x.id"
8+
@click="() => connect({ connector: x })"
9+
>
10+
<span>{{ x.name }}</span>
11+
<span v-if="!x.ready"> (unsupported)</span>
12+
<span v-if="isLoading && x.id === pendingConnector?.id">…</span>
13+
</button>
14+
</div>
15+
16+
<div>{{ error && error.message }}</div>
17+
18+
<div>
19+
<span>{{ ensName ?? address }}</span>
20+
<span v-if="ensName"> ({{ address }})</span>
21+
</div>
22+
23+
<img v-if="ensAvatar" :src="ensAvatar" width="40" height="40">
24+
25+
<div>
26+
<button v-if="address" @click="() => disconnect()">Disconnect</button>
27+
<span v-if="connector?.name">Connected to {{ connector.name }}</span>
28+
</div>
29+
</div>
30+
</template>
31+
32+
<script lang="ts" setup>
33+
import { useAccount, useDisconnect, useEnsAvatar, useEnsName, useConnect } from 'use-wagmi'
34+
35+
const { connector, isReconnecting } = useAccount()
36+
const { connect, connectors, isLoading, error, pendingConnector } = useConnect()
37+
38+
const { address } = useAccount({
39+
onConnect: (data) => console.log('connected', data),
40+
onDisconnect: () => console.log('disconnected')
41+
})
42+
43+
const { data: ensName } = useEnsName({
44+
address,
45+
chainId: 1
46+
})
47+
48+
const { data: ensAvatar } = useEnsAvatar({
49+
name: ensName,
50+
chainId: 1
51+
})
52+
53+
const { disconnect } = useDisconnect()
54+
</script>

examples/nuxt/nuxt.config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
3+
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
4+
5+
export default defineNuxtConfig({
6+
vite: {
7+
resolve: {
8+
alias: {
9+
process: 'process/browser',
10+
util: 'util',
11+
},
12+
},
13+
optimizeDeps: {
14+
esbuildOptions: {
15+
target: 'esnext',
16+
define: {
17+
global: 'globalThis',
18+
},
19+
plugins: [
20+
NodeGlobalsPolyfillPlugin({
21+
process: true,
22+
buffer: true
23+
}),
24+
NodeModulesPolyfillPlugin()
25+
],
26+
supported: {
27+
bigint: true,
28+
},
29+
},
30+
},
31+
}
32+
})

examples/nuxt/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "nuxt",
3+
"private": true,
4+
"scripts": {
5+
"build": "nuxt build",
6+
"dev": "nuxt dev",
7+
"generate": "nuxt generate",
8+
"preview": "nuxt preview",
9+
"postinstall": "nuxt prepare"
10+
},
11+
"dependencies": {
12+
"use-wagmi": "workspace:*",
13+
"viem": "~0.3.18"
14+
},
15+
"devDependencies": {
16+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
17+
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
18+
"@types/node": "^18",
19+
"nuxt": "^3.4.3"
20+
}
21+
}

examples/nuxt/plugins/use-wagmi.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { UseWagmiPlugin, configureChains, createConfig } from 'use-wagmi'
2+
import { avalanche, goerli, mainnet, optimism } from 'use-wagmi/chains'
3+
4+
import { CoinbaseWalletConnector } from 'use-wagmi/connectors/coinbaseWallet'
5+
import { InjectedConnector } from 'use-wagmi/connectors/injected'
6+
import { LedgerConnector } from 'use-wagmi/connectors/ledger'
7+
import { MetaMaskConnector } from 'use-wagmi/connectors/metaMask'
8+
import { SafeConnector } from 'use-wagmi/connectors/safe'
9+
import { WalletConnectConnector } from 'use-wagmi/connectors/walletConnect'
10+
import { WalletConnectLegacyConnector } from 'use-wagmi/connectors/walletConnectLegacy'
11+
12+
import { alchemyProvider } from 'use-wagmi/providers/alchemy'
13+
import { infuraProvider } from 'use-wagmi/providers/infura'
14+
import { publicProvider } from 'use-wagmi/providers/public'
15+
16+
export default defineNuxtPlugin(nuxtApp => {
17+
const { chains, publicClient, webSocketPublicClient } = configureChains(
18+
[mainnet, goerli, optimism, avalanche],
19+
[
20+
alchemyProvider({ apiKey: '' }), //TODO: your API Key
21+
infuraProvider({ apiKey: '' }), //TODO: your API Key
22+
publicProvider(),
23+
],
24+
)
25+
26+
const config = createConfig({
27+
autoConnect: true,
28+
connectors: [
29+
new MetaMaskConnector({
30+
chains,
31+
options: {
32+
UNSTABLE_shimOnConnectSelectAccount: true,
33+
},
34+
}),
35+
new CoinbaseWalletConnector({
36+
chains,
37+
options: {
38+
appName: 'use-wagmi',
39+
},
40+
}),
41+
new WalletConnectConnector({
42+
chains,
43+
options: {
44+
projectId: '', //TODO: your project ID
45+
},
46+
}),
47+
new WalletConnectLegacyConnector({
48+
chains,
49+
options: {
50+
qrcode: true,
51+
},
52+
}),
53+
new LedgerConnector({
54+
chains,
55+
}),
56+
new InjectedConnector({
57+
chains,
58+
options: {
59+
name: (detectedName) =>
60+
`Injected (${
61+
typeof detectedName === 'string'
62+
? detectedName
63+
: detectedName.join(', ')
64+
})`,
65+
shimDisconnect: true,
66+
},
67+
}),
68+
new SafeConnector({
69+
chains,
70+
options: {
71+
allowedDomains: [/https:\/\/app.safe.global$/],
72+
debug: false,
73+
},
74+
}),
75+
],
76+
publicClient,
77+
webSocketPublicClient,
78+
})
79+
80+
nuxtApp.vueApp.use(UseWagmiPlugin, config)
81+
})

examples/nuxt/public/favicon.ico

4.19 KB
Binary file not shown.

examples/nuxt/server/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./.nuxt/tsconfig.server.json"
3+
}

examples/nuxt/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./.nuxt/tsconfig.json"
3+
}

examples/vite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"vue": "^3.2.47"
1818
},
1919
"devDependencies": {
20-
"@vitejs/plugin-vue": "^4.1.0",
20+
"@vitejs/plugin-vue": "^4.2.3",
2121
"typescript": "^5.0.4",
22-
"vite": "^3.2.5",
22+
"vite": "^4.3.6",
2323
"vue-tsc": "^1.2.0"
2424
}
2525
}

0 commit comments

Comments
 (0)