Skip to content

Commit 786d9db

Browse files
committed
added wallet type to account info
1 parent 772f366 commit 786d9db

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,19 @@ app.use(createWeb3Auth({
147147
148148
## Basic usage
149149
150-
### Connect wallet button
150+
### Info about the user's connected wallet and wallet type
151+
152+
```ts
153+
import { account } from '@kolirt/vue-web3-auth'
154+
155+
account.connected // if connected
156+
account.address // current account address
157+
account.shortAddress // current account address with 3 dots
158+
account.wallet.id // current wallet id
159+
account.wallet.name // current wallet name
160+
```
161+
162+
### Connect wallet button````
151163
152164
```vue
153165
<script setup lang="ts">
@@ -159,11 +171,11 @@ import { account, accountDetails, connect, disconnect } from '@kolirt/vue-web3-a
159171
<button @click="accountDetails()">
160172
{{ account.address }}
161173
</button>
162-
<button @click="disconnect()">Disconnect</button>
174+
<button @click="disconnect()">Disconnect from {{ account.wallet.name }}</button>
163175
</div>
164176
<button v-else @click="connect()">Connect wallet</button>
165177
</template>
166-
```
178+
```````
167179
168180
### Switch chain
169181
To switch the chain, you need to add it during [configuration](#configuration).

lib/account.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { disconnect as masterDisconnect } from '@wagmi/core'
2-
import { reactive, watchEffect } from 'vue'
2+
import { reactive, readonly, watchEffect } from 'vue'
33

44
import { state as optionsState } from './options'
55
import type { AccountState, Chain, ConnectedAccount } from './types'
@@ -11,12 +11,18 @@ export const state = reactive<AccountState>({
1111
currentAccount: null
1212
})
1313

14-
export const account = reactive<ConnectedAccount>({
14+
const accountState = reactive<ConnectedAccount>({
1515
connected: false,
1616
address: undefined,
17-
shortAddress: undefined
17+
shortAddress: undefined,
18+
wallet: {
19+
id: undefined,
20+
name: undefined
21+
}
1822
})
1923

24+
export const account = readonly(accountState)
25+
2026
export async function disconnect() {
2127
await masterDisconnect()
2228
}
@@ -46,12 +52,16 @@ export function shortAddressFilter(value = '') {
4652

4753
watchEffect(() => {
4854
if (state.currentAccount) {
49-
account.connected = true
50-
account.address = state.currentAccount.address
51-
account.shortAddress = shortAddressFilter(state.currentAccount.address)
55+
accountState.connected = true
56+
accountState.address = state.currentAccount.address
57+
accountState.shortAddress = shortAddressFilter(state.currentAccount.address)
58+
accountState.wallet.id = state.currentAccount.connector?.id
59+
accountState.wallet.name = state.currentAccount.connector?.name
5260
} else {
53-
account.connected = false
54-
account.address = undefined
55-
account.shortAddress = undefined
61+
accountState.connected = false
62+
accountState.address = undefined
63+
accountState.shortAddress = undefined
64+
accountState.wallet.id = undefined
65+
accountState.wallet.name = undefined
5666
}
5767
})

lib/types.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Chain, Unit } from '@wagmi/core'
1+
import type { Chain, GetAccountResult, Unit } from '@wagmi/core'
22
import type { ThemeCtrlState } from '@web3modal/core'
33
import type { EthereumClient } from '@web3modal/ethereum'
44
import type { WatchAssetParams } from 'viem/src/types/eip1193'
@@ -41,6 +41,10 @@ export type ConnectedAccount = {
4141
connected: boolean
4242
address?: `0x${string}`
4343
shortAddress?: string
44+
wallet: {
45+
id?: string
46+
name?: string
47+
}
4448
}
4549

4650
export type BufferChain = Chain & { unsupported?: boolean }
@@ -55,8 +59,8 @@ export type WcState = {
5559
}
5660

5761
export type AccountState = {
58-
bufferAccount: any
59-
currentAccount: any
62+
bufferAccount: GetAccountResult | null
63+
currentAccount: GetAccountResult | null
6064
}
6165

6266
export type MulticallContract = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kolirt/vue-web3-auth",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Web3 authentication for Vue3 apps based on WalletConnect Web3Modal v2",
55
"author": "kolirt",
66
"license": "MIT",

0 commit comments

Comments
 (0)