@wagmi/vue 0.0.0-vue-20240513033839
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/actions/package.json +5 -0
- package/chains/package.json +5 -0
- package/connectors/package.json +5 -0
- package/dist/esm/composables/useAccount.js +18 -0
- package/dist/esm/composables/useAccount.js.map +1 -0
- package/dist/esm/composables/useAccountEffect.js +37 -0
- package/dist/esm/composables/useAccountEffect.js.map +1 -0
- package/dist/esm/composables/useBlockNumber.js +46 -0
- package/dist/esm/composables/useBlockNumber.js.map +1 -0
- package/dist/esm/composables/useChainId.js +17 -0
- package/dist/esm/composables/useChainId.js.map +1 -0
- package/dist/esm/composables/useChains.js +17 -0
- package/dist/esm/composables/useChains.js.map +1 -0
- package/dist/esm/composables/useClient.js +23 -0
- package/dist/esm/composables/useClient.js.map +1 -0
- package/dist/esm/composables/useConfig.js +19 -0
- package/dist/esm/composables/useConfig.js.map +1 -0
- package/dist/esm/composables/useConnect.js +29 -0
- package/dist/esm/composables/useConnect.js.map +1 -0
- package/dist/esm/composables/useConnections.js +16 -0
- package/dist/esm/composables/useConnections.js.map +1 -0
- package/dist/esm/composables/useConnectorClient.js +49 -0
- package/dist/esm/composables/useConnectorClient.js.map +1 -0
- package/dist/esm/composables/useConnectors.js +16 -0
- package/dist/esm/composables/useConnectors.js.map +1 -0
- package/dist/esm/composables/useDisconnect.js +24 -0
- package/dist/esm/composables/useDisconnect.js.map +1 -0
- package/dist/esm/composables/useReconnect.js +21 -0
- package/dist/esm/composables/useReconnect.js.map +1 -0
- package/dist/esm/composables/useSwitchAccount.js +23 -0
- package/dist/esm/composables/useSwitchAccount.js.map +1 -0
- package/dist/esm/composables/useSwitchChain.js +25 -0
- package/dist/esm/composables/useSwitchChain.js.map +1 -0
- package/dist/esm/composables/useWatchBlockNumber.js +27 -0
- package/dist/esm/composables/useWatchBlockNumber.js.map +1 -0
- package/dist/esm/errors/base.js +20 -0
- package/dist/esm/errors/base.js.map +1 -0
- package/dist/esm/errors/plugin.js +28 -0
- package/dist/esm/errors/plugin.js.map +1 -0
- package/dist/esm/exports/actions.js +5 -0
- package/dist/esm/exports/actions.js.map +1 -0
- package/dist/esm/exports/chains.js +5 -0
- package/dist/esm/exports/chains.js.map +1 -0
- package/dist/esm/exports/connectors.js +5 -0
- package/dist/esm/exports/connectors.js.map +1 -0
- package/dist/esm/exports/index.js +41 -0
- package/dist/esm/exports/index.js.map +1 -0
- package/dist/esm/exports/nuxt.js +4 -0
- package/dist/esm/exports/nuxt.js.map +1 -0
- package/dist/esm/exports/query.js +7 -0
- package/dist/esm/exports/query.js.map +1 -0
- package/dist/esm/nuxt/module.js +19 -0
- package/dist/esm/nuxt/module.js.map +1 -0
- package/dist/esm/plugin.js +14 -0
- package/dist/esm/plugin.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/types/properties.js +2 -0
- package/dist/esm/types/properties.js.map +1 -0
- package/dist/esm/types/ref.js +3 -0
- package/dist/esm/types/ref.js.map +1 -0
- package/dist/esm/utils/cloneDeep.js +36 -0
- package/dist/esm/utils/cloneDeep.js.map +1 -0
- package/dist/esm/utils/getVersion.js +3 -0
- package/dist/esm/utils/getVersion.js.map +1 -0
- package/dist/esm/utils/query.js +73 -0
- package/dist/esm/utils/query.js.map +1 -0
- package/dist/esm/utils/updateState.js +7 -0
- package/dist/esm/utils/updateState.js.map +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/composables/useAccount.d.ts +8 -0
- package/dist/types/composables/useAccount.d.ts.map +1 -0
- package/dist/types/composables/useAccountEffect.d.ts +15 -0
- package/dist/types/composables/useAccountEffect.d.ts.map +1 -0
- package/dist/types/composables/useBlockNumber.d.ts +14 -0
- package/dist/types/composables/useBlockNumber.d.ts.map +1 -0
- package/dist/types/composables/useChainId.d.ts +8 -0
- package/dist/types/composables/useChainId.d.ts.map +1 -0
- package/dist/types/composables/useChains.d.ts +9 -0
- package/dist/types/composables/useChains.d.ts.map +1 -0
- package/dist/types/composables/useClient.d.ts +10 -0
- package/dist/types/composables/useClient.d.ts.map +1 -0
- package/dist/types/composables/useConfig.d.ts +8 -0
- package/dist/types/composables/useConfig.d.ts.map +1 -0
- package/dist/types/composables/useConnect.d.ts +16 -0
- package/dist/types/composables/useConnect.d.ts.map +1 -0
- package/dist/types/composables/useConnections.d.ts +8 -0
- package/dist/types/composables/useConnections.d.ts.map +1 -0
- package/dist/types/composables/useConnectorClient.d.ts +13 -0
- package/dist/types/composables/useConnectorClient.d.ts.map +1 -0
- package/dist/types/composables/useConnectors.d.ts +8 -0
- package/dist/types/composables/useConnectors.d.ts.map +1 -0
- package/dist/types/composables/useDisconnect.d.ts +17 -0
- package/dist/types/composables/useDisconnect.d.ts.map +1 -0
- package/dist/types/composables/useReconnect.d.ts +16 -0
- package/dist/types/composables/useReconnect.d.ts.map +1 -0
- package/dist/types/composables/useSwitchAccount.d.ts +17 -0
- package/dist/types/composables/useSwitchAccount.d.ts.map +1 -0
- package/dist/types/composables/useSwitchChain.d.ts +17 -0
- package/dist/types/composables/useSwitchChain.d.ts.map +1 -0
- package/dist/types/composables/useWatchBlockNumber.d.ts +9 -0
- package/dist/types/composables/useWatchBlockNumber.d.ts.map +1 -0
- package/dist/types/errors/base.d.ts +10 -0
- package/dist/types/errors/base.d.ts.map +1 -0
- package/dist/types/errors/plugin.d.ts +16 -0
- package/dist/types/errors/plugin.d.ts.map +1 -0
- package/dist/types/exports/actions.d.ts +2 -0
- package/dist/types/exports/actions.d.ts.map +1 -0
- package/dist/types/exports/chains.d.ts +2 -0
- package/dist/types/exports/chains.d.ts.map +1 -0
- package/dist/types/exports/connectors.d.ts +2 -0
- package/dist/types/exports/connectors.d.ts.map +1 -0
- package/dist/types/exports/index.d.ts +22 -0
- package/dist/types/exports/index.d.ts.map +1 -0
- package/dist/types/exports/nuxt.d.ts +4 -0
- package/dist/types/exports/nuxt.d.ts.map +1 -0
- package/dist/types/exports/query.d.ts +4 -0
- package/dist/types/exports/query.d.ts.map +1 -0
- package/dist/types/nuxt/module.d.ts +4 -0
- package/dist/types/nuxt/module.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +11 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/types/properties.d.ts +15 -0
- package/dist/types/types/properties.d.ts.map +1 -0
- package/dist/types/types/ref.d.ts +12 -0
- package/dist/types/types/ref.d.ts.map +1 -0
- package/dist/types/utils/cloneDeep.d.ts +3 -0
- package/dist/types/utils/cloneDeep.d.ts.map +1 -0
- package/dist/types/utils/getVersion.d.ts +2 -0
- package/dist/types/utils/getVersion.d.ts.map +1 -0
- package/dist/types/utils/query.d.ts +17 -0
- package/dist/types/utils/query.d.ts.map +1 -0
- package/dist/types/utils/updateState.d.ts +2 -0
- package/dist/types/utils/updateState.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/nuxt/package.json +5 -0
- package/package.json +108 -0
- package/query/package.json +5 -0
- package/src/composables/useAccount.ts +37 -0
- package/src/composables/useAccountEffect.ts +66 -0
- package/src/composables/useBlockNumber.ts +118 -0
- package/src/composables/useChainId.ts +35 -0
- package/src/composables/useChains.ts +38 -0
- package/src/composables/useClient.ts +66 -0
- package/src/composables/useConfig.ts +34 -0
- package/src/composables/useConnect.ts +91 -0
- package/src/composables/useConnections.ts +30 -0
- package/src/composables/useConnectorClient.ts +127 -0
- package/src/composables/useConnectors.ts +30 -0
- package/src/composables/useDisconnect.ts +70 -0
- package/src/composables/useReconnect.ts +65 -0
- package/src/composables/useSwitchAccount.ts +84 -0
- package/src/composables/useSwitchChain.ts +80 -0
- package/src/composables/useWatchBlockNumber.ts +61 -0
- package/src/errors/base.ts +14 -0
- package/src/errors/plugin.ts +31 -0
- package/src/exports/actions.ts +5 -0
- package/src/exports/chains.ts +5 -0
- package/src/exports/connectors.ts +5 -0
- package/src/exports/index.ts +176 -0
- package/src/exports/nuxt.ts +4 -0
- package/src/exports/query.ts +17 -0
- package/src/nuxt/module.ts +25 -0
- package/src/plugin.ts +22 -0
- package/src/types/properties.ts +27 -0
- package/src/types/ref.ts +36 -0
- package/src/utils/cloneDeep.ts +43 -0
- package/src/utils/getVersion.ts +3 -0
- package/src/utils/query.ts +159 -0
- package/src/utils/updateState.ts +10 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from '@wagmi/core/query';
|
|
2
|
+
export { type UseMutationParameters, type UseMutationReturnType, useMutation, } from '../utils/query.js';
|
|
3
|
+
export { type UseQueryParameters, type UseQueryReturnType, useQuery, } from '../utils/query.js';
|
|
4
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/exports/query.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAA;AAEjC,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,WAAW,GACZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,QAAQ,GACT,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/nuxt/module.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C,MAAM,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAEnC,eAAO,MAAM,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAiBnD,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ResolvedRegister, type State } from '@wagmi/core';
|
|
2
|
+
export declare const configKey: unique symbol;
|
|
3
|
+
export type WagmiPluginOptions = {
|
|
4
|
+
config: ResolvedRegister['config'];
|
|
5
|
+
initialState?: State | undefined;
|
|
6
|
+
reconnectOnMount?: boolean | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare const WagmiPlugin: {
|
|
9
|
+
install(app: import("vue").App<any>, options: WagmiPluginOptions): void;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,KAAK,EAAW,MAAM,aAAa,CAAA;AAGxE,eAAO,MAAM,SAAS,eAAW,CAAA;AAEjC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAClC,YAAY,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IAChC,gBAAgB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACvC,CAAA;AAED,eAAO,MAAM,WAAW;;CAUc,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DefaultError, QueryKey } from '@tanstack/vue-query';
|
|
2
|
+
import type { Config } from '@wagmi/core';
|
|
3
|
+
import type { MaybeRef } from 'vue';
|
|
4
|
+
import type { UseQueryParameters } from '../utils/query.js';
|
|
5
|
+
import type { DeepUnwrapRef } from './ref.js';
|
|
6
|
+
export type ConfigParameter<config extends Config = Config> = {
|
|
7
|
+
config?: Config | config | undefined;
|
|
8
|
+
};
|
|
9
|
+
export type EnabledParameter = {
|
|
10
|
+
enabled?: MaybeRef<boolean> | undefined;
|
|
11
|
+
};
|
|
12
|
+
export type QueryParameter<queryFnData = unknown, error = DefaultError, data = queryFnData, queryKey extends QueryKey = QueryKey> = {
|
|
13
|
+
query?: Omit<DeepUnwrapRef<UseQueryParameters<queryFnData, error, data, queryKey>>, 'queryFn' | 'queryHash' | 'queryKey' | 'queryKeyHashFn' | 'throwOnError'> | undefined;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=properties.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../../../src/types/properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI;IAC5D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;CACxC,CAAA;AAED,MAAM,MAAM,cAAc,CACxB,WAAW,GAAG,OAAO,EACrB,KAAK,GAAG,YAAY,EACpB,IAAI,GAAG,WAAW,EAClB,QAAQ,SAAS,QAAQ,GAAG,QAAQ,IAClC;IACF,KAAK,CAAC,EACF,IAAI,CACF,aAAa,CAAC,kBAAkB,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,EACrE,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,gBAAgB,GAAG,cAAc,CACzE,GACD,SAAS,CAAA;CACd,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config } from '@wagmi/core';
|
|
2
|
+
import type { MaybeRef, Ref, UnwrapRef } from 'vue';
|
|
3
|
+
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
|
|
4
|
+
type UnwrapLeaf = Primitive | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any>;
|
|
5
|
+
export type DeepMaybeRef<value> = MaybeRef<value extends Function | Config ? value : value extends object ? {
|
|
6
|
+
[key in keyof value]: DeepMaybeRef<value[key]>;
|
|
7
|
+
} : value>;
|
|
8
|
+
export type DeepUnwrapRef<T> = T extends UnwrapLeaf ? T : T extends Ref<infer U> ? DeepUnwrapRef<U> : T extends {} ? {
|
|
9
|
+
[Property in keyof T]: DeepUnwrapRef<T[Property]>;
|
|
10
|
+
} : UnwrapRef<T>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../../src/types/ref.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEnD,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;AAC/E,KAAK,UAAU,GACX,SAAS,GACT,QAAQ,GACR,IAAI,GACJ,KAAK,GACL,MAAM,GACN,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GACb,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,GACjB,GAAG,CAAC,GAAG,CAAC,GACR,OAAO,CAAC,GAAG,CAAC,CAAA;AAEhB,MAAM,MAAM,YAAY,CAAC,KAAK,IAAI,QAAQ,CACxC,KAAK,SAAS,QAAQ,GAAG,MAAM,GAC3B,KAAK,GACL,KAAK,SAAS,MAAM,GACpB;KACG,GAAG,IAAI,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CAC/C,GACD,KAAK,CACV,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,GAC/C,CAAC,GACD,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,CAAC,GACtB,aAAa,CAAC,CAAC,CAAC,GAChB,CAAC,SAAS,EAAE,GACZ;KACG,QAAQ,IAAI,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CAClD,GACD,SAAS,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloneDeep.d.ts","sourceRoot":"","sources":["../../../src/utils/cloneDeep.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AA2BlE,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAKnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVersion.d.ts","sourceRoot":"","sources":["../../../src/utils/getVersion.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,cAAgC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DefaultError, type MutationObserverOptions, type QueryKey, type QueryObserverOptions, type UseMutationReturnType as tanstack_UseMutationReturnType, type UseQueryReturnType as tanstack_UseQueryReturnType, useMutation } from '@tanstack/vue-query';
|
|
2
|
+
import { type Evaluate, type ExactPartial, type Omit, type UnionOmit } from '@wagmi/core/internal';
|
|
3
|
+
import { type MaybeRef } from 'vue';
|
|
4
|
+
import type { DeepMaybeRef, DeepUnwrapRef } from '../types/ref.js';
|
|
5
|
+
export type UseMutationParameters<data = unknown, error = Error, variables = void, context = unknown> = Evaluate<DeepMaybeRef<Omit<DeepUnwrapRef<MutationObserverOptions<data, error, Evaluate<variables>, context>>, 'mutationFn' | 'mutationKey' | 'throwOnError'>>>;
|
|
6
|
+
export type UseMutationReturnType<data = unknown, error = Error, variables = void, context = unknown> = Evaluate<UnionOmit<tanstack_UseMutationReturnType<data, error, variables, context>, 'mutate' | 'mutateAsync'>>;
|
|
7
|
+
export { useMutation };
|
|
8
|
+
export type UseQueryParameters<queryFnData = unknown, error = DefaultError, data = queryFnData, queryKey extends QueryKey = QueryKey> = Evaluate<DeepMaybeRef<ExactPartial<Omit<DeepUnwrapRef<QueryObserverOptions<queryFnData, error, data, queryKey>>, 'initialData'>> & {
|
|
9
|
+
initialData?: DeepUnwrapRef<QueryObserverOptions<queryFnData, error, data, queryKey>>['initialData'] | undefined;
|
|
10
|
+
}>>;
|
|
11
|
+
export type UseQueryReturnType<data = unknown, error = DefaultError> = Evaluate<tanstack_UseQueryReturnType<data, error> & {
|
|
12
|
+
queryKey: QueryKey;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function useQuery<queryFnData, error, data, queryKey extends QueryKey>(parameters: MaybeRef<UseQueryParameters<queryFnData, error, data, queryKey> & {
|
|
15
|
+
queryKey: QueryKey;
|
|
16
|
+
}>): UseQueryReturnType<data, error>;
|
|
17
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/utils/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,IAAI,8BAA8B,EAC5D,KAAK,kBAAkB,IAAI,2BAA2B,EACtD,WAAW,EAEZ,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,SAAS,EACf,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,KAAK,QAAQ,EAAmB,MAAM,KAAK,CAAA;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAElE,MAAM,MAAM,qBAAqB,CAC/B,IAAI,GAAG,OAAO,EACd,KAAK,GAAG,KAAK,EACb,SAAS,GAAG,IAAI,EAChB,OAAO,GAAG,OAAO,IACf,QAAQ,CACV,YAAY,CACV,IAAI,CACF,aAAa,CACX,uBAAuB,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CACnE,EACD,YAAY,GAAG,aAAa,GAAG,cAAc,CAC9C,CACF,CACF,CAAA;AAED,MAAM,MAAM,qBAAqB,CAC/B,IAAI,GAAG,OAAO,EACd,KAAK,GAAG,KAAK,EACb,SAAS,GAAG,IAAI,EAChB,OAAO,GAAG,OAAO,IACf,QAAQ,CACV,SAAS,CACP,8BAA8B,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAC/D,QAAQ,GAAG,aAAa,CACzB,CACF,CAAA;AAED,OAAO,EAAE,WAAW,EAAE,CAAA;AAItB,MAAM,MAAM,kBAAkB,CAC5B,WAAW,GAAG,OAAO,EACrB,KAAK,GAAG,YAAY,EACpB,IAAI,GAAG,WAAW,EAClB,QAAQ,SAAS,QAAQ,GAAG,QAAQ,IAClC,QAAQ,CACV,YAAY,CACV,YAAY,CACV,IAAI,CACF,aAAa,CAAC,oBAAoB,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,EACvE,aAAa,CACd,CACF,GAAG;IAEF,WAAW,CAAC,EACR,aAAa,CACX,oBAAoB,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CACzD,CAAC,aAAa,CAAC,GAChB,SAAS,CAAA;CACd,CACF,CACF,CAAA;AAED,MAAM,MAAM,kBAAkB,CAAC,IAAI,GAAG,OAAO,EAAE,KAAK,GAAG,YAAY,IAAI,QAAQ,CAC7E,2BAA2B,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG;IACzC,QAAQ,EAAE,QAAQ,CAAA;CACnB,CACF,CAAA;AAKD,wBAAgB,QAAQ,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,SAAS,QAAQ,EAC1E,UAAU,EAAE,QAAQ,CAClB,kBAAkB,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG;IACvD,QAAQ,EAAE,QAAQ,CAAA;CACnB,CACF,GACA,kBAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,CAQjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateState.d.ts","sourceRoot":"","sources":["../../../src/utils/updateState.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,IAAI,CAIN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,6BAA6B,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wagmi/vue",
|
|
3
|
+
"description": "Vue Composables for Ethereum",
|
|
4
|
+
"version": "0.0.0-vue-20240513033839",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/wevm/wagmi.git",
|
|
9
|
+
"directory": "packages/vue"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**",
|
|
13
|
+
"!dist/**/*.tsbuildinfo",
|
|
14
|
+
"src/**/*.ts",
|
|
15
|
+
"!src/**/*.test.ts",
|
|
16
|
+
"!src/**/*.test-d.ts",
|
|
17
|
+
"/actions",
|
|
18
|
+
"/chains",
|
|
19
|
+
"/connectors",
|
|
20
|
+
"/nuxt",
|
|
21
|
+
"/query"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/esm/exports/index.js",
|
|
26
|
+
"types": "./dist/types/exports/index.d.ts",
|
|
27
|
+
"typings": "./dist/types/exports/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/types/exports/index.d.ts",
|
|
31
|
+
"default": "./dist/esm/exports/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./actions": {
|
|
34
|
+
"types": "./dist/types/exports/actions.d.ts",
|
|
35
|
+
"default": "./dist/esm/exports/actions.js"
|
|
36
|
+
},
|
|
37
|
+
"./chains": {
|
|
38
|
+
"types": "./dist/types/exports/chains.d.ts",
|
|
39
|
+
"default": "./dist/esm/exports/chains.js"
|
|
40
|
+
},
|
|
41
|
+
"./connectors": {
|
|
42
|
+
"types": "./dist/types/exports/connectors.d.ts",
|
|
43
|
+
"default": "./dist/esm/exports/connectors.js"
|
|
44
|
+
},
|
|
45
|
+
"./nuxt": {
|
|
46
|
+
"types": "./dist/types/exports/nuxt.d.ts",
|
|
47
|
+
"default": "./dist/esm/exports/nuxt.js"
|
|
48
|
+
},
|
|
49
|
+
"./query": {
|
|
50
|
+
"types": "./dist/types/exports/query.d.ts",
|
|
51
|
+
"default": "./dist/esm/exports/query.js"
|
|
52
|
+
},
|
|
53
|
+
"./package.json": "./package.json"
|
|
54
|
+
},
|
|
55
|
+
"typesVersions": {
|
|
56
|
+
"*": {
|
|
57
|
+
"actions": [
|
|
58
|
+
"./dist/types/exports/actions.d.ts"
|
|
59
|
+
],
|
|
60
|
+
"chains": [
|
|
61
|
+
"./dist/types/exports/chains.d.ts"
|
|
62
|
+
],
|
|
63
|
+
"connectors": [
|
|
64
|
+
"./dist/types/exports/connectors.d.ts"
|
|
65
|
+
],
|
|
66
|
+
"nuxt": [
|
|
67
|
+
"./dist/types/exports/nuxt.d.ts"
|
|
68
|
+
],
|
|
69
|
+
"query": [
|
|
70
|
+
"./dist/types/exports/query.d.ts"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@tanstack/vue-query": ">=5.0.0",
|
|
76
|
+
"nuxt": ">=3.0.0",
|
|
77
|
+
"typescript": ">=5.0.4",
|
|
78
|
+
"viem": "2.x",
|
|
79
|
+
"vue": ">=3"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"nuxt": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"typescript": {
|
|
86
|
+
"optional": true
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"@wagmi/connectors": "0.0.0-vue-20240513033839",
|
|
91
|
+
"@wagmi/core": "0.0.0-vue-20240513033839"
|
|
92
|
+
},
|
|
93
|
+
"contributors": [
|
|
94
|
+
"awkweb.eth <t@wevm.dev>",
|
|
95
|
+
"jxom.eth <j@wevm.dev>"
|
|
96
|
+
],
|
|
97
|
+
"funding": "https://github.com/sponsors/wevm",
|
|
98
|
+
"keywords": [
|
|
99
|
+
"wagmi",
|
|
100
|
+
"vue",
|
|
101
|
+
"composables",
|
|
102
|
+
"eth",
|
|
103
|
+
"ethereum",
|
|
104
|
+
"dapps",
|
|
105
|
+
"wallet",
|
|
106
|
+
"web3"
|
|
107
|
+
]
|
|
108
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetAccountReturnType,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
getAccount,
|
|
6
|
+
watchAccount,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import { type ToRefs, onScopeDispose, reactive, readonly, toRefs } from 'vue'
|
|
9
|
+
|
|
10
|
+
import { type ConfigParameter } from '../types/properties.js'
|
|
11
|
+
import { updateState } from '../utils/updateState.js'
|
|
12
|
+
import { useConfig } from './useConfig.js'
|
|
13
|
+
|
|
14
|
+
export type UseAccountParameters<config extends Config = Config> =
|
|
15
|
+
ConfigParameter<config>
|
|
16
|
+
|
|
17
|
+
export type UseAccountReturnType<config extends Config = Config> = ToRefs<
|
|
18
|
+
GetAccountReturnType<config>
|
|
19
|
+
>
|
|
20
|
+
|
|
21
|
+
/** https://wagmi.sh/vue/api/composables/useAccount */
|
|
22
|
+
export function useAccount<config extends Config = ResolvedRegister['config']>(
|
|
23
|
+
parameters: UseAccountParameters<config> = {},
|
|
24
|
+
): UseAccountReturnType<config> {
|
|
25
|
+
const config = useConfig(parameters)
|
|
26
|
+
|
|
27
|
+
const account = reactive(getAccount(config))
|
|
28
|
+
|
|
29
|
+
const unsubscribe = watchAccount(config, {
|
|
30
|
+
onChange(data) {
|
|
31
|
+
updateState(account, data)
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
onScopeDispose(() => unsubscribe())
|
|
35
|
+
|
|
36
|
+
return toRefs(readonly(account)) as UseAccountReturnType<config>
|
|
37
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type GetAccountReturnType, watchAccount } from '@wagmi/core'
|
|
2
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
3
|
+
import { watchEffect } from 'vue'
|
|
4
|
+
|
|
5
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
6
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
7
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
8
|
+
import { useConfig } from './useConfig.js'
|
|
9
|
+
|
|
10
|
+
export type UseAccountEffectParameters = Evaluate<
|
|
11
|
+
DeepMaybeRef<
|
|
12
|
+
{
|
|
13
|
+
onConnect?(
|
|
14
|
+
data: Evaluate<
|
|
15
|
+
Pick<
|
|
16
|
+
Extract<GetAccountReturnType, { status: 'connected' }>,
|
|
17
|
+
'address' | 'addresses' | 'chain' | 'chainId' | 'connector'
|
|
18
|
+
> & {
|
|
19
|
+
isReconnected: boolean
|
|
20
|
+
}
|
|
21
|
+
>,
|
|
22
|
+
): void
|
|
23
|
+
onDisconnect?(): void
|
|
24
|
+
} & ConfigParameter
|
|
25
|
+
>
|
|
26
|
+
>
|
|
27
|
+
|
|
28
|
+
/** https://wagmi.sh/vue/api/composables/useAccountEffect */
|
|
29
|
+
export function useAccountEffect(parameters: UseAccountEffectParameters = {}) {
|
|
30
|
+
const config = useConfig(parameters)
|
|
31
|
+
|
|
32
|
+
watchEffect((onCleanup) => {
|
|
33
|
+
const { onConnect, onDisconnect } = deepUnref(parameters)
|
|
34
|
+
|
|
35
|
+
const unwatch = watchAccount(config, {
|
|
36
|
+
onChange(data, prevData) {
|
|
37
|
+
if (
|
|
38
|
+
(prevData.status === 'reconnecting' ||
|
|
39
|
+
(prevData.status === 'connecting' &&
|
|
40
|
+
prevData.address === undefined)) &&
|
|
41
|
+
data.status === 'connected'
|
|
42
|
+
) {
|
|
43
|
+
const { address, addresses, chain, chainId, connector } = data
|
|
44
|
+
const isReconnected =
|
|
45
|
+
prevData.status === 'reconnecting' ||
|
|
46
|
+
// if `previousAccount.status` is `undefined`, the connector connected immediately.
|
|
47
|
+
prevData.status === undefined
|
|
48
|
+
onConnect?.({
|
|
49
|
+
address,
|
|
50
|
+
addresses,
|
|
51
|
+
chain,
|
|
52
|
+
chainId,
|
|
53
|
+
connector,
|
|
54
|
+
isReconnected,
|
|
55
|
+
})
|
|
56
|
+
} else if (
|
|
57
|
+
prevData.status === 'connected' &&
|
|
58
|
+
data.status === 'disconnected'
|
|
59
|
+
)
|
|
60
|
+
onDisconnect?.()
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
onCleanup(() => unwatch())
|
|
65
|
+
})
|
|
66
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import {
|
|
3
|
+
type Config,
|
|
4
|
+
type GetBlockNumberErrorType,
|
|
5
|
+
type ResolvedRegister,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import {
|
|
8
|
+
type Evaluate,
|
|
9
|
+
type UnionEvaluate,
|
|
10
|
+
type UnionOmit,
|
|
11
|
+
} from '@wagmi/core/internal'
|
|
12
|
+
import {
|
|
13
|
+
type GetBlockNumberData,
|
|
14
|
+
type GetBlockNumberOptions,
|
|
15
|
+
type GetBlockNumberQueryFnData,
|
|
16
|
+
type GetBlockNumberQueryKey,
|
|
17
|
+
getBlockNumberQueryOptions,
|
|
18
|
+
} from '@wagmi/core/query'
|
|
19
|
+
import { computed } from 'vue'
|
|
20
|
+
|
|
21
|
+
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
|
|
22
|
+
import type { DeepMaybeRef, DeepUnwrapRef } from '../types/ref.js'
|
|
23
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
24
|
+
import { type UseQueryReturnType, useQuery } from '../utils/query.js'
|
|
25
|
+
import { useChainId } from './useChainId.js'
|
|
26
|
+
import { useConfig } from './useConfig.js'
|
|
27
|
+
import {
|
|
28
|
+
type UseWatchBlockNumberParameters,
|
|
29
|
+
useWatchBlockNumber,
|
|
30
|
+
} from './useWatchBlockNumber.js'
|
|
31
|
+
|
|
32
|
+
export type UseBlockNumberParameters<
|
|
33
|
+
config extends Config = Config,
|
|
34
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
35
|
+
selectData = GetBlockNumberData,
|
|
36
|
+
> = Evaluate<
|
|
37
|
+
DeepMaybeRef<
|
|
38
|
+
GetBlockNumberOptions<config, chainId> &
|
|
39
|
+
ConfigParameter<config> &
|
|
40
|
+
QueryParameter<
|
|
41
|
+
GetBlockNumberQueryFnData,
|
|
42
|
+
GetBlockNumberErrorType,
|
|
43
|
+
selectData,
|
|
44
|
+
GetBlockNumberQueryKey<config, chainId>
|
|
45
|
+
> & {
|
|
46
|
+
watch?:
|
|
47
|
+
| boolean
|
|
48
|
+
| UnionEvaluate<
|
|
49
|
+
UnionOmit<
|
|
50
|
+
DeepUnwrapRef<UseWatchBlockNumberParameters<config, chainId>>,
|
|
51
|
+
'chainId' | 'config' | 'onBlockNumber' | 'onError'
|
|
52
|
+
>
|
|
53
|
+
>
|
|
54
|
+
| undefined
|
|
55
|
+
}
|
|
56
|
+
>
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
export type UseBlockNumberReturnType<selectData = GetBlockNumberData> =
|
|
60
|
+
UseQueryReturnType<selectData, GetBlockNumberErrorType>
|
|
61
|
+
|
|
62
|
+
/** https://wagmi.sh/vue/api/composables/useBlockNumber */
|
|
63
|
+
export function useBlockNumber<
|
|
64
|
+
config extends Config = ResolvedRegister['config'],
|
|
65
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
66
|
+
selectData = GetBlockNumberData,
|
|
67
|
+
>(
|
|
68
|
+
parameters_: UseBlockNumberParameters<config, chainId, selectData> = {},
|
|
69
|
+
): UseBlockNumberReturnType<selectData> {
|
|
70
|
+
const parameters = computed(() => deepUnref(parameters_))
|
|
71
|
+
|
|
72
|
+
const config = useConfig(parameters)
|
|
73
|
+
const queryClient = useQueryClient()
|
|
74
|
+
const configChainId = useChainId({ config })
|
|
75
|
+
|
|
76
|
+
const queryOptions = computed(() => {
|
|
77
|
+
const {
|
|
78
|
+
chainId = configChainId.value,
|
|
79
|
+
query = {},
|
|
80
|
+
watch: _,
|
|
81
|
+
...rest
|
|
82
|
+
} = parameters.value
|
|
83
|
+
const options = getBlockNumberQueryOptions(config, {
|
|
84
|
+
...deepUnref(rest),
|
|
85
|
+
chainId,
|
|
86
|
+
})
|
|
87
|
+
return {
|
|
88
|
+
...query,
|
|
89
|
+
...options,
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const watchBlockNumberArgs = computed(() => {
|
|
94
|
+
const {
|
|
95
|
+
config,
|
|
96
|
+
chainId = configChainId.value,
|
|
97
|
+
query,
|
|
98
|
+
watch,
|
|
99
|
+
} = parameters.value
|
|
100
|
+
return {
|
|
101
|
+
...({
|
|
102
|
+
config,
|
|
103
|
+
chainId,
|
|
104
|
+
...(typeof watch === 'object' ? watch : {}),
|
|
105
|
+
} as UseWatchBlockNumberParameters),
|
|
106
|
+
enabled:
|
|
107
|
+
(query?.enabled ?? true) &&
|
|
108
|
+
(typeof watch === 'object' ? watch.enabled : watch),
|
|
109
|
+
onBlockNumber(blockNumber) {
|
|
110
|
+
queryClient.setQueryData(queryOptions.value.queryKey, blockNumber)
|
|
111
|
+
},
|
|
112
|
+
} satisfies UseWatchBlockNumberParameters
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
useWatchBlockNumber(watchBlockNumberArgs)
|
|
116
|
+
|
|
117
|
+
return useQuery(queryOptions as any) as UseBlockNumberReturnType<selectData>
|
|
118
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetChainIdReturnType,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
getChainId,
|
|
6
|
+
watchChainId,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import { type Ref, onScopeDispose, readonly, ref } from 'vue'
|
|
9
|
+
|
|
10
|
+
import { type ConfigParameter } from '../types/properties.js'
|
|
11
|
+
import { useConfig } from './useConfig.js'
|
|
12
|
+
|
|
13
|
+
export type UseChainIdParameters<config extends Config = Config> =
|
|
14
|
+
ConfigParameter<config>
|
|
15
|
+
|
|
16
|
+
export type UseChainIdReturnType<config extends Config = Config> = Ref<
|
|
17
|
+
GetChainIdReturnType<config>
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
/** https://wagmi.sh/vue/api/composables/useChainId */
|
|
21
|
+
export function useChainId<config extends Config = ResolvedRegister['config']>(
|
|
22
|
+
parameters: UseChainIdParameters<config> = {},
|
|
23
|
+
): UseChainIdReturnType<config> {
|
|
24
|
+
const config = useConfig(parameters)
|
|
25
|
+
|
|
26
|
+
const chainId = ref<GetChainIdReturnType>(getChainId(config))
|
|
27
|
+
const unsubscribe = watchChainId(config, {
|
|
28
|
+
onChange(data) {
|
|
29
|
+
chainId.value = data
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
onScopeDispose(() => unsubscribe())
|
|
33
|
+
|
|
34
|
+
return readonly(chainId)
|
|
35
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetChainsReturnType,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
getChains,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import { watchChains } from '@wagmi/core/internal'
|
|
8
|
+
|
|
9
|
+
import type { Chain } from 'viem'
|
|
10
|
+
import { type Ref, onScopeDispose, readonly, ref } from 'vue'
|
|
11
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
12
|
+
import { useConfig } from './useConfig.js'
|
|
13
|
+
|
|
14
|
+
export type UseChainsParameters<config extends Config = Config> =
|
|
15
|
+
ConfigParameter<config>
|
|
16
|
+
|
|
17
|
+
export type UseChainsReturnType<config extends Config = Config> = Ref<
|
|
18
|
+
config['chains'] extends readonly [Chain, ...Chain[]]
|
|
19
|
+
? config['chains']
|
|
20
|
+
: readonly [Chain, ...Chain[]]
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
/** https://wagmi.sh/vue/api/composables/useChains */
|
|
24
|
+
export function useChains<config extends Config = ResolvedRegister['config']>(
|
|
25
|
+
parameters: UseChainsParameters<config> = {},
|
|
26
|
+
): UseChainsReturnType<config> {
|
|
27
|
+
const config = useConfig(parameters)
|
|
28
|
+
|
|
29
|
+
const chains = ref<GetChainsReturnType>(getChains(config))
|
|
30
|
+
const unsubscribe = watchChains(config, {
|
|
31
|
+
onChange(data) {
|
|
32
|
+
chains.value = data
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
onScopeDispose(() => unsubscribe())
|
|
36
|
+
|
|
37
|
+
return readonly(chains)
|
|
38
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetClientParameters,
|
|
4
|
+
type GetClientReturnType,
|
|
5
|
+
type ResolvedRegister,
|
|
6
|
+
getClient,
|
|
7
|
+
watchClient,
|
|
8
|
+
} from '@wagmi/core'
|
|
9
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
10
|
+
import {
|
|
11
|
+
type Ref,
|
|
12
|
+
computed,
|
|
13
|
+
onScopeDispose,
|
|
14
|
+
readonly,
|
|
15
|
+
ref,
|
|
16
|
+
watchEffect,
|
|
17
|
+
} from 'vue'
|
|
18
|
+
|
|
19
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
20
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
21
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
22
|
+
import { useConfig } from './useConfig.js'
|
|
23
|
+
|
|
24
|
+
export type UseClientParameters<
|
|
25
|
+
config extends Config = Config,
|
|
26
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
27
|
+
| config['chains'][number]['id']
|
|
28
|
+
| undefined,
|
|
29
|
+
> = Evaluate<
|
|
30
|
+
DeepMaybeRef<GetClientParameters<config, chainId> & ConfigParameter<config>>
|
|
31
|
+
>
|
|
32
|
+
|
|
33
|
+
export type UseClientReturnType<
|
|
34
|
+
config extends Config = Config,
|
|
35
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
36
|
+
| config['chains'][number]['id']
|
|
37
|
+
| undefined,
|
|
38
|
+
> = Ref<GetClientReturnType<config, chainId>>
|
|
39
|
+
|
|
40
|
+
/** https://wagmi.sh/vue/api/composables/useClient */
|
|
41
|
+
export function useClient<
|
|
42
|
+
config extends Config = ResolvedRegister['config'],
|
|
43
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
44
|
+
| config['chains'][number]['id']
|
|
45
|
+
| undefined,
|
|
46
|
+
>(
|
|
47
|
+
parameters: UseClientParameters<config, chainId> = {},
|
|
48
|
+
): UseClientReturnType<config, chainId> {
|
|
49
|
+
const params = computed(() => deepUnref(parameters))
|
|
50
|
+
|
|
51
|
+
const config = useConfig(params)
|
|
52
|
+
|
|
53
|
+
const client = ref(getClient(config, params.value as GetClientParameters))
|
|
54
|
+
watchEffect(() => {
|
|
55
|
+
client.value = getClient(config, params.value as GetClientParameters)
|
|
56
|
+
})
|
|
57
|
+
const unsubscribe = watchClient(config, {
|
|
58
|
+
onChange(data) {
|
|
59
|
+
if (client.value?.uid === data?.uid) return
|
|
60
|
+
client.value = data
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
onScopeDispose(() => unsubscribe())
|
|
64
|
+
|
|
65
|
+
return readonly(client) as UseClientReturnType<config, chainId>
|
|
66
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Config, type ResolvedRegister } from '@wagmi/core'
|
|
2
|
+
import { hasInjectionContext, inject, unref } from 'vue'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
WagmiInjectionContextError,
|
|
6
|
+
WagmiPluginNotFoundError,
|
|
7
|
+
} from '../errors/plugin.js'
|
|
8
|
+
import { configKey } from '../plugin.js'
|
|
9
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
10
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
11
|
+
|
|
12
|
+
export type UseConfigParameters<config extends Config = Config> = DeepMaybeRef<
|
|
13
|
+
ConfigParameter<config>
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
export type UseConfigReturnType<config extends Config = Config> = config
|
|
17
|
+
|
|
18
|
+
/** https://wagmi.sh/vue/api/composables/useConfig */
|
|
19
|
+
export function useConfig<config extends Config = ResolvedRegister['config']>(
|
|
20
|
+
parameters_: UseConfigParameters<config> = {},
|
|
21
|
+
): UseConfigReturnType<config> {
|
|
22
|
+
const parameters = unref(parameters_)
|
|
23
|
+
|
|
24
|
+
// passthrough config if provided
|
|
25
|
+
if (parameters.config) return parameters.config as UseConfigReturnType<config>
|
|
26
|
+
|
|
27
|
+
// ensures that `inject()` can be used
|
|
28
|
+
if (!hasInjectionContext()) throw new WagmiInjectionContextError()
|
|
29
|
+
|
|
30
|
+
const config = inject<Config | undefined>(configKey)
|
|
31
|
+
if (!config) throw new WagmiPluginNotFoundError()
|
|
32
|
+
|
|
33
|
+
return config as UseConfigReturnType<config>
|
|
34
|
+
}
|