Skip to content

Commit a8c15a2

Browse files
committed
fix: wevm#72
1 parent 21d6de3 commit a8c15a2

19 files changed

+228
-406
lines changed

examples/next/next.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const withPreconstruct = require('@preconstruct/next')
2-
31
/** @type {import('next').NextConfig} */
4-
module.exports = withPreconstruct({
2+
module.exports = {
53
reactStrictMode: true,
6-
})
4+
}

examples/next/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"wagmi": "0.1.3"
1616
},
1717
"devDependencies": {
18-
"@preconstruct/next": "^3.0.1",
1918
"@types/node": "17.0.5",
2019
"@types/react": "17.0.38",
2120
"eslint": "8.5.0",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from 'react'
2+
import { useAccount } from 'wagmi'
3+
4+
export const Account = () => {
5+
const [{ data: accountData }, disconnect] = useAccount({
6+
fetchEns: true,
7+
})
8+
9+
if (!accountData) return <div>No account connected</div>
10+
11+
return (
12+
<div>
13+
<div>
14+
<button onClick={() => disconnect()}>
15+
Disconnect from {accountData?.connector?.name}
16+
</button>
17+
</div>
18+
19+
<div>
20+
{accountData?.ens?.name ?? accountData?.address}
21+
{accountData?.ens ? ` (${accountData?.address})` : null}
22+
</div>
23+
24+
{accountData?.ens?.avatar && (
25+
<img src={accountData.ens.avatar} style={{ height: 40, width: 40 }} />
26+
)}
27+
</div>
28+
)
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react'
2+
import { useConnect } from 'wagmi'
3+
4+
export const Connect = () => {
5+
const [
6+
{
7+
data: { connector, connectors },
8+
error,
9+
loading,
10+
},
11+
connect,
12+
] = useConnect()
13+
14+
return (
15+
<div>
16+
<div>
17+
{connectors.map((x) => (
18+
<button disabled={!x.ready} key={x.name} onClick={() => connect(x)}>
19+
{x.name}
20+
{!x.ready && ' (unsupported)'}
21+
{loading && x.name === connector?.name && '…'}
22+
</button>
23+
))}
24+
</div>
25+
<div>{error && (error?.message ?? 'Failed to connect')}</div>
26+
</div>
27+
)
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react'
2+
import { useNetwork } from 'wagmi'
3+
4+
export const NetworkSwitcher = () => {
5+
const [{ data: networkData, error: switchNetworkError }, switchNetwork] =
6+
useNetwork()
7+
8+
return (
9+
<div>
10+
<div>
11+
Connected to {networkData.chain?.name ?? networkData.chain?.id}{' '}
12+
{networkData.chain?.unsupported && '(unsupported)'}
13+
</div>
14+
15+
{switchNetwork &&
16+
networkData.chains.map((x) =>
17+
x.id === networkData.chain?.id ? null : (
18+
<button key={x.id} onClick={() => switchNetwork(x.id)}>
19+
Switch to {x.name}
20+
</button>
21+
),
22+
)}
23+
24+
{switchNetworkError && switchNetworkError?.message}
25+
</div>
26+
)
27+
}

examples/next/src/components/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { Account } from './Account'
2+
export { Connect } from './Connect'
3+
export { NetworkSwitcher } from './NetworkSwitcher'

examples/next/src/pages/index.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import * as React from 'react'
2+
import { useAccount } from 'wagmi'
3+
4+
import { Account, Connect, NetworkSwitcher } from '../components'
25

36
const Page = () => {
4-
return <main>wagmi</main>
7+
const [{ data: accountData }] = useAccount()
8+
9+
if (accountData?.address)
10+
return (
11+
<>
12+
<Account />
13+
<NetworkSwitcher />
14+
</>
15+
)
16+
17+
return <Connect />
518
}
619

720
export default Page

examples/next/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"extends": "../../tsconfig.json",
32
"compilerOptions": {
43
"target": "es5",
54
"lib": ["dom", "dom.iterable", "esnext"],

examples/vite-react/src/App.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
11
import { useAccount } from 'wagmi'
22

3-
import {
4-
Account,
5-
Connect,
6-
ContractFunction,
7-
NetworkSwitcher,
8-
SignMessage,
9-
Transaction,
10-
} from './components'
3+
import { Account, Connect, NetworkSwitcher } from './components'
114

125
export const App = () => {
136
const [{ data: accountData }] = useAccount()
147

158
if (accountData?.address)
169
return (
17-
<main style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
10+
<>
1811
<Account />
1912
<NetworkSwitcher />
20-
<Transaction />
21-
<SignMessage />
22-
<ContractFunction />
23-
</main>
13+
</>
2414
)
2515

26-
return (
27-
<main>
28-
<Connect />
29-
</main>
30-
)
16+
return <Connect />
3117
}

examples/vite-react/src/components/ContractFunction.tsx

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)