Skip to content

Commit b834bd0

Browse files
authored
docs(vue): refactor README code snippets (#1944)
1 parent f75b8d9 commit b834bd0

File tree

1 file changed

+54
-99
lines changed

1 file changed

+54
-99
lines changed

packages/vue/README.md

Lines changed: 54 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ const web3Onboard = init({
4646
]
4747
})
4848

49-
const { wallets, connectWallet, disconnectConnectedWallet, connectedWallet } =
50-
useOnboard()
49+
const { wallets, connectWallet, disconnectConnectedWallet, connectedWallet } = useOnboard()
5150

5251
if (connectedWallet) {
5352
// if using ethers v6 this is:
@@ -97,11 +96,13 @@ const web3Onboard = init({
9796

9897
```typescript
9998
import { useOnboard } from '@web3-onboard/vue'
99+
100100
// Use the composable
101101
const onboard = useOnboard()
102+
102103
// Or destructure it
103-
const { wallets, connectWallet, disconnectConnectedWallet, connectedWallet } =
104-
useOnboard()
104+
const { wallets, connectWallet, disconnectConnectedWallet, connectedWallet } = useOnboard()
105+
105106
// do stuff
106107
```
107108

@@ -112,15 +113,10 @@ Function to open the onboard modal and connect to a wallet provider. For referen
112113
### Example usage
113114

114115
```vue
115-
<script>
116+
<script setup>
116117
import { useOnboard } from '@web3-onboard/vue'
117-
export default {
118-
setup() {
119-
const { connectWallet } = useOnboard()
120-
const connect = async () => connectWallet()
121-
return { connect }
122-
}
123-
}
118+
119+
const { connectWallet: connect } = useOnboard()
124120
</script>
125121
126122
<template>
@@ -135,14 +131,10 @@ Computed property that contains the current chain to which `connectedWallet` is
135131
### Example usage
136132

137133
```vue
138-
<script>
134+
<script setup>
139135
import { useOnboard } from '@web3-onboard/vue'
140-
export default {
141-
setup() {
142-
const { connectedChain } = useOnboard()
143-
return { connectedChain }
144-
}
145-
}
136+
137+
const { connectedChain } = useOnboard()
146138
</script>
147139
148140
<template>
@@ -157,14 +149,10 @@ Computed property that contains the latest connected wallet
157149
### Example usage
158150

159151
```vue
160-
<script>
152+
<script setup>
161153
import { useOnboard } from '@web3-onboard/vue'
162-
export default {
163-
setup() {
164-
const { connectedWallet } = useOnboard()
165-
return { connectedWallet }
166-
}
167-
}
154+
155+
const { connectedWallet } = useOnboard()
168156
</script>
169157
170158
<template>
@@ -179,14 +167,10 @@ Readonly boolean ref that tracks the state of the wallet connection status
179167
### Example usage
180168

181169
```vue
182-
<script>
170+
<script setup>
183171
import { useOnboard } from '@web3-onboard/vue'
184-
export default {
185-
setup() {
186-
const { connectingWallet } = useOnboard()
187-
return { connectingWallet }
188-
}
189-
}
172+
173+
const { connectingWallet } = useOnboard()
190174
</script>
191175
192176
<template>
@@ -201,15 +185,11 @@ Function to disconnect a specific wallet
201185
### Example usage
202186

203187
```vue
204-
<script>
188+
<script setup>
205189
import { useOnboard } from '@web3-onboard/vue'
206-
export default {
207-
setup() {
208-
const { disconnectWallet } = useOnboard()
209-
const disconnect = async () => disconnectWallet('MetaMask')
210-
return { disconnect }
211-
}
212-
}
190+
191+
const { disconnectWallet } = useOnboard()
192+
const disconnect = async () => disconnectWallet('MetaMask')
213193
</script>
214194
215195
<template>
@@ -224,14 +204,10 @@ Function to disconnect the `connectedWallet`
224204
### Example usage
225205

226206
```vue
227-
<script>
207+
<script setup>
228208
import { useOnboard } from '@web3-onboard/vue'
229-
export default {
230-
setup() {
231-
const { disconnectConnectedWallet } = useOnboard()
232-
return { disconnectConnectedWallet }
233-
}
234-
}
209+
210+
const { disconnectConnectedWallet } = useOnboard()
235211
</script>
236212
237213
<template>
@@ -248,14 +224,10 @@ Function that returns the current chain a wallet is connected to
248224
### Example usage
249225

250226
```vue
251-
<script>
227+
<script setup>
252228
import { useOnboard } from '@web3-onboard/vue'
253-
export default {
254-
setup() {
255-
const { getChain } = useOnboard()
256-
return { getChain }
257-
}
258-
}
229+
230+
const { getChain } = useOnboard()
259231
</script>
260232
261233
<template>
@@ -270,15 +242,11 @@ Function to set the chain of a wallet
270242
### Example usage
271243

272244
```vue
273-
<script>
245+
<script setup>
274246
import { useOnboard } from '@web3-onboard/vue'
275-
export default {
276-
setup() {
277-
const { setChain } = useOnboard()
278-
const set = () => setChain({ wallet: 'MetaMask', chainId: '0x1' })
279-
return { set }
280-
}
281-
}
247+
248+
const { setChain } = useOnboard()
249+
const set = () => setChain({ wallet: 'MetaMask', chainId: '0x1' })
282250
</script>
283251
284252
<template>
@@ -293,14 +261,10 @@ Readonly boolean ref that tracks the status of setting the chain
293261
### Example usage
294262

295263
```vue
296-
<script>
264+
<script setup>
297265
import { useOnboard } from '@web3-onboard/vue'
298-
export default {
299-
setup() {
300-
const { settingChain } = useOnboard()
301-
return { settingChain }
302-
}
303-
}
266+
267+
const { settingChain } = useOnboard()
304268
</script>
305269
306270
<template>
@@ -315,38 +279,34 @@ Readonly ref that contains every wallet that has been connected
315279
### Example usage
316280

317281
```vue
318-
<script>
282+
<script setup>
319283
import { useOnboard } from '@web3-onboard/vue'
320-
export default {
321-
setup() {
322-
const { wallets } = useOnboard()
323-
return { wallets }
324-
}
325-
}
284+
285+
const { wallets } = useOnboard()
286+
</script>
287+
288+
<template>
289+
<div v-for="wallet in wallets">
290+
<span>Label: {{ wallet.label }}</span>
291+
</div>
292+
</template>
326293
```
327294

328295
### `alreadyConnectedWallets`
329296

330-
Readonly ref that contains every wallet that user connected to in the past; useful to reconnect wallets automatically after a reload
297+
Readonly ref that contains every wallet that user connected to in the past, useful to reconnect wallets automatically after a reload
331298

332299
### Example usage
333300

334-
```
335-
vue
336-
<script>
301+
```vue
302+
<script setup>
337303
import { useOnboard } from '@web3-onboard/vue'
338-
export default {
339-
setup() {
340-
const { alreadyConnectedWallets } = useOnboard()
341-
return { alreadyConnectedWallets }
342-
}
343-
}
304+
305+
const { alreadyConnectedWallets } = useOnboard()
344306
</script>
345307
346308
<template>
347-
<div v-for="wallet in wallets">
348-
<span>Label: {{wallet.label}}</span>
349-
</div>
309+
<span>{{ alreadyConnectedWallets }}</span>
350310
</template>
351311
```
352312

@@ -356,16 +316,11 @@ Readonly ref that contains the last time that the user connected a wallet in mil
356316

357317
### Example usage
358318

359-
```
360-
vue
361-
<script>
319+
```vue
320+
<script setup>
362321
import { useOnboard } from '@web3-onboard/vue'
363-
export default {
364-
setup() {
365-
const { lastConnectedTimestamp } = useOnboard()
366-
return { lastConnectedTimestamp }
367-
}
368-
}
322+
323+
const { lastConnectedTimestamp } = useOnboard()
369324
</script>
370325
371326
<template>

0 commit comments

Comments
 (0)