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

Commit

Permalink
Merge pull request #165 from unicape/1.x
Browse files Browse the repository at this point in the history
chore: Update dependencies
  • Loading branch information
unicape authored Feb 19, 2024
2 parents 6496f74 + 16b855c commit 8046a6a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-mugs-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"use-wagmi": patch
---

Update dependencies
4 changes: 2 additions & 2 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
}
},
"dependencies": {
"@wagmi/connectors": "4.1.13",
"@wagmi/core": "2.6.4",
"@wagmi/connectors": "4.1.14",
"@wagmi/core": "2.6.5",
"vue": "3.3.8",
"vue-demi": "^0.14.6"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/vue/src/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export {
useChainId,
} from '../hooks/useChainId.js'

export {
type UseChainsParameters,
type UseChainsReturnType,
useChains,
} from '../hooks/useChains.js'

export {
type UseClientParameters,
type UseClientReturnType,
Expand Down
36 changes: 36 additions & 0 deletions packages/vue/src/hooks/useChains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use client'

import {
type Config,
type GetChainsReturnType,
type ResolvedRegister,
getChains,
} from '@wagmi/core'
import { watchChains } from '@wagmi/core/internal'
import { type Ref, ref } from 'vue-demi'

import type { ConfigParameter, MaybeRefDeep } from '../types.js'
import { useConfig } from './useConfig.js'

export type UseChainsParameters<config extends Config = Config> = MaybeRefDeep<
ConfigParameter<config>
>

export type UseChainsReturnType<config extends Config = Config> = Ref<
GetChainsReturnType<config>
>
/** https://wagmi.sh/react/api/hooks/useChains */
export function useChains<config extends Config = ResolvedRegister['config']>(
parameters: UseChainsParameters<config> = {},
): UseChainsReturnType<config> {
const config = useConfig(parameters)
const chains = ref(getChains(config))

watchChains(config, {
onChange () {
chains.value = getChains(config)
}
})

return chains
}
2 changes: 1 addition & 1 deletion packages/vue/src/hooks/useDisconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function useDisconnect<context = unknown>(
return {
...result,
connectors: computed(() =>
useConnections().value.map((connection) => connection.connector),
useConnections({ config }).value.map((connection) => connection.connector),
),
disconnect: mutate,
disconnectAsync: mutateAsync,
Expand Down
14 changes: 3 additions & 11 deletions packages/vue/src/hooks/useSwitchAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
type Connector,
type ResolvedRegister,
type SwitchAccountErrorType,
getConnections,
watchConnections,
} from '@wagmi/core'
import type { Evaluate } from '@wagmi/core/internal'
import {
Expand All @@ -17,14 +15,15 @@ import {
type SwitchAccountVariables,
switchAccountMutationOptions,
} from '@wagmi/core/query'
import { type Ref, computed, shallowRef } from 'vue-demi'
import { type Ref, computed } from 'vue-demi'

import type { ConfigParameter, MaybeRefDeep } from '../types.js'
import type {
UseMutationParameters,
UseMutationReturnType,
} from '../utils/query.js'
import { useConfig } from './useConfig.js'
import { useConnections } from './useConnections.js'

export type UseSwitchAccountParameters<
config extends Config = Config,
Expand Down Expand Up @@ -68,13 +67,6 @@ export function useSwitchAccount<
const { mutation } = parameters

const config = useConfig(parameters)
const connections = shallowRef(getConnections(config))

watchConnections(config, {
onChange() {
connections.value = getConnections(config)
},
})

const mutationOptions = switchAccountMutationOptions(config)
const { mutate, mutateAsync, ...result } = useMutation({
Expand All @@ -85,7 +77,7 @@ export function useSwitchAccount<
return {
...result,
connectors: computed(() =>
connections.value.map((connection) => connection.connector),
useConnections({ config }).value.map((connection) => connection.connector),
),
switchAccount: mutate,
switchAccountAsync: mutateAsync,
Expand Down
7 changes: 5 additions & 2 deletions packages/vue/src/hooks/useSwitchChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useMutation } from '@tanstack/vue-query'
import type {
Config,
GetChainsReturnType,
ResolvedRegister,
SwitchChainErrorType,
} from '@wagmi/core'
Expand All @@ -15,11 +16,13 @@ import {
switchChainMutationOptions,
} from '@wagmi/core/query'

import type { Ref } from 'vue-demi'
import type { ConfigParameter, MaybeRefDeep } from '../types.js'
import type {
UseMutationParameters,
UseMutationReturnType,
} from '../utils/query.js'
import { useChains } from './useChains.js'
import { useConfig } from './useConfig.js'

export type UseSwitchChainParameters<
Expand Down Expand Up @@ -48,7 +51,7 @@ export type UseSwitchChainReturnType<
SwitchChainVariables<config, config['chains'][number]['id']>,
context
> & {
chains: config['chains']
chains: Ref<Evaluate<GetChainsReturnType<config>>>
switchChain: SwitchChainMutate<config, context>
switchChainAsync: SwitchChainMutateAsync<config, context>
}
Expand All @@ -73,7 +76,7 @@ export function useSwitchChain<

return {
...result,
chains: config.chains,
chains: useChains({ config }),
switchChain: mutate,
switchChainAsync: mutateAsync,
} as UseSwitchChainReturnType<config, context>
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8046a6a

Please sign in to comment.