solid-wagmi 0.2.2 → 0.2.3
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/dist/esm/context.js +3 -3
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/hooks/useAccount.js +2 -2
- package/dist/esm/hooks/useAccount.js.map +1 -1
- package/dist/esm/hooks/useBalance.js +1 -1
- package/dist/esm/hooks/useBalance.js.map +1 -1
- package/dist/esm/hooks/useChainId.js +3 -3
- package/dist/esm/hooks/useChainId.js.map +1 -1
- package/dist/esm/hooks/useConfig.js +8 -6
- package/dist/esm/hooks/useConfig.js.map +1 -1
- package/dist/esm/hooks/useConnect.js +2 -2
- package/dist/esm/hooks/useConnect.js.map +1 -1
- package/dist/esm/hooks/useConnections.js +2 -2
- package/dist/esm/hooks/useConnections.js.map +1 -1
- package/dist/esm/hooks/useDisconnect.js +1 -1
- package/dist/esm/hooks/useDisconnect.js.map +1 -1
- package/dist/esm/hooks/useReadContract.js +1 -1
- package/dist/esm/hooks/useReadContract.js.map +1 -1
- package/dist/esm/hooks/useReadContracts.js +1 -1
- package/dist/esm/hooks/useReadContracts.js.map +1 -1
- package/dist/esm/hooks/useWriteContract.js +9 -6
- package/dist/esm/hooks/useWriteContract.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/context.d.ts +1 -5
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/hooks/useConfig.d.ts +1 -1
- package/dist/types/hooks/useConfig.d.ts.map +1 -1
- package/dist/types/hooks/useWriteContract.d.ts +3 -2
- package/dist/types/hooks/useWriteContract.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/context.ts +11 -9
- package/src/hooks/useAccount.ts +2 -2
- package/src/hooks/useBalance.ts +1 -1
- package/src/hooks/useChainId.ts +3 -3
- package/src/hooks/useConfig.ts +9 -7
- package/src/hooks/useConnect.ts +2 -2
- package/src/hooks/useConnections.ts +2 -2
- package/src/hooks/useDisconnect.ts +1 -1
- package/src/hooks/useReadContract.ts +1 -1
- package/src/hooks/useReadContracts.ts +1 -1
- package/src/hooks/useWriteContract.ts +17 -9
- package/src/types/index.ts +2 -2
package/dist/types/context.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { type Config, type State } from "@wagmi/core";
|
|
2
2
|
import { type JSX } from "solid-js";
|
|
3
|
-
export
|
|
4
|
-
config: Config;
|
|
5
|
-
initialState?: State;
|
|
6
|
-
};
|
|
7
|
-
export declare const WagmiContext: import("solid-js").Context<WagmiCtx | undefined>;
|
|
3
|
+
export declare const WagmiContext: import("solid-js").Context<Config | undefined>;
|
|
8
4
|
export declare function WagmiProvider(props: {
|
|
9
5
|
config: Config;
|
|
10
6
|
initialState?: State;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EAEX,KAAK,KAAK,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,GAAG,EACT,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,YAAY,gDAEb,CAAC;AAEb,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB,eAqBA"}
|
|
@@ -2,6 +2,6 @@ import type { Config, ResolvedRegister } from "@wagmi/core";
|
|
|
2
2
|
import { type Accessor } from "solid-js";
|
|
3
3
|
import type { ConfigParameter } from "../types/index.js";
|
|
4
4
|
export type UseConfigParameters<config extends Config = Config> = Accessor<ConfigParameter<config>>;
|
|
5
|
-
export type UseConfigReturnType<config extends Config = Config> = config
|
|
5
|
+
export type UseConfigReturnType<config extends Config = Config> = Accessor<config>;
|
|
6
6
|
export declare function useConfig<config extends Config = ResolvedRegister["config"]>(parameters?: UseConfigParameters<config>): UseConfigReturnType<config>;
|
|
7
7
|
//# sourceMappingURL=useConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConfig.d.ts","sourceRoot":"","sources":["../../../src/hooks/useConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"useConfig.d.ts","sourceRoot":"","sources":["../../../src/hooks/useConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAA0B,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI,QAAQ,CACxE,eAAe,CAAC,MAAM,CAAC,CACxB,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAC5D,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEnB,wBAAgB,SAAS,CAAC,MAAM,SAAS,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,EAC1E,UAAU,GAAE,mBAAmB,CAAC,MAAM,CAAc,GACnD,mBAAmB,CAAC,MAAM,CAAC,CAO7B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Config, WriteContractErrorType } from "@wagmi/core";
|
|
1
|
+
import type { Config, ResolvedRegister, WriteContractErrorType } from "@wagmi/core";
|
|
2
2
|
import { type WriteContractData, type WriteContractMutate, type WriteContractMutateAsync, type WriteContractVariables } from "@wagmi/core/query";
|
|
3
|
+
import type { Accessor } from "solid-js";
|
|
3
4
|
import type { Abi } from "viem";
|
|
4
5
|
import type { ConfigParameter, UseMutationParameters, UseMutationReturnType } from "../types/index.js";
|
|
5
6
|
export type UseWriteContractParameters<config extends Config = Config, context = unknown> = ConfigParameter<config> & {
|
|
@@ -9,5 +10,5 @@ export type UseWriteContractReturnType<config extends Config = Config, context =
|
|
|
9
10
|
writeContract: WriteContractMutate<config, context>;
|
|
10
11
|
writeContractAsync: WriteContractMutateAsync<config, context>;
|
|
11
12
|
};
|
|
12
|
-
export declare function useWriteContract<config extends Config =
|
|
13
|
+
export declare function useWriteContract<config extends Config = ResolvedRegister["config"], context = unknown>(params?: Accessor<UseWriteContractParameters<config, context>>): UseWriteContractReturnType<config, context>;
|
|
13
14
|
//# sourceMappingURL=useWriteContract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWriteContract.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWriteContract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useWriteContract.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWriteContract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,MAAM,EACN,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,MAAM,0BAA0B,CACpC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,OAAO,GAAG,OAAO,IACf,eAAe,CAAC,MAAM,CAAC,GAAG;IAC5B,QAAQ,CAAC,EACL,qBAAqB,CACnB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,CACpB,GAAG,EACH,MAAM,EACN,SAAS,OAAO,EAAE,EAClB,MAAM,EACN,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAC/B,EACD,OAAO,CACR,GACD,SAAS,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,0BAA0B,CACpC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,OAAO,GAAG,OAAO,IACf,qBAAqB,CACvB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,CACpB,GAAG,EACH,MAAM,EACN,SAAS,OAAO,EAAE,EAClB,MAAM,EACN,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAC/B,EACD,OAAO,CACR,GAAG;IACF,aAAa,EAAE,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpD,kBAAkB,EAAE,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/D,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,MAAM,SAAS,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,EAClD,OAAO,GAAG,OAAO,EAEjB,MAAM,GAAE,QAAQ,CAAC,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAc,GACzE,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAmB7C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DefaultError, QueryKey, SolidQueryOptions, UseInfiniteQueryOptions,
|
|
1
|
+
import type { DefaultError, QueryKey, SolidMutationOptions, SolidQueryOptions, UseInfiniteQueryOptions, UseMutationResult, UseQueryResult } from "@tanstack/solid-query";
|
|
2
2
|
import type { Config } from "@wagmi/core";
|
|
3
3
|
import type { Compute, ExactPartial, Omit, UnionStrictOmit } from "@wagmi/core/internal";
|
|
4
4
|
export type EnabledParameter = {
|
|
@@ -12,7 +12,7 @@ export type UseInfiniteQueryParameters<queryFnData = unknown, error = DefaultErr
|
|
|
12
12
|
initialData?: ReturnType<UseInfiniteQueryOptions<queryFnData, error, data, queryKey>>["initialData"] | undefined;
|
|
13
13
|
}>;
|
|
14
14
|
export type UseMutationReturnType<data = unknown, error = Error, variables = void, context = unknown> = Compute<UnionStrictOmit<UseMutationResult<data, error, variables, context>, "mutate" | "mutateAsync">>;
|
|
15
|
-
export type UseMutationParameters<data = unknown, error = Error, variables = void, context = unknown> = Compute<Omit<
|
|
15
|
+
export type UseMutationParameters<data = unknown, error = Error, variables = void, context = unknown> = Compute<Omit<SolidMutationOptions<data, error, Compute<variables>, context>, "mutationFn" | "mutationKey" | "throwOnError">>;
|
|
16
16
|
export type UseQueryParameters<queryFnData = unknown, error = DefaultError, data = queryFnData, queryKey extends QueryKey = QueryKey> = Compute<ExactPartial<Omit<SolidQueryOptions<queryFnData, error, data, queryKey>, "initialData">> & {
|
|
17
17
|
initialData?: SolidQueryOptions<queryFnData, error, data, queryKey>["initialData"] | undefined;
|
|
18
18
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA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,EAAE,SAAS,CAAC,EACzE,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,gBAAgB,GAAG,cAAc,CACzE,CAAC;CACH,CAAC"}
|
package/package.json
CHANGED
package/src/context.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
hydrate,
|
|
3
|
+
type Config,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
type State,
|
|
6
|
+
} from "@wagmi/core";
|
|
2
7
|
import {
|
|
3
8
|
createComponent,
|
|
4
9
|
createContext,
|
|
5
|
-
type JSX,
|
|
6
10
|
onMount,
|
|
7
11
|
splitProps,
|
|
12
|
+
type JSX,
|
|
8
13
|
} from "solid-js";
|
|
9
14
|
|
|
10
|
-
export
|
|
11
|
-
config
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const WagmiContext = createContext<WagmiCtx>();
|
|
15
|
+
export const WagmiContext = createContext<
|
|
16
|
+
ResolvedRegister["config"] | undefined
|
|
17
|
+
>(undefined);
|
|
16
18
|
|
|
17
19
|
export function WagmiProvider(props: {
|
|
18
20
|
config: Config;
|
|
@@ -35,7 +37,7 @@ export function WagmiProvider(props: {
|
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
return createComponent(WagmiContext.Provider, {
|
|
38
|
-
value:
|
|
40
|
+
value: config,
|
|
39
41
|
get children() {
|
|
40
42
|
return rest.children;
|
|
41
43
|
},
|
package/src/hooks/useAccount.ts
CHANGED
|
@@ -4,12 +4,12 @@ import { useConfig } from "./useConfig.js";
|
|
|
4
4
|
|
|
5
5
|
export function useAccount() {
|
|
6
6
|
const config = useConfig();
|
|
7
|
-
const [account, setAccount] = createSignal(getAccount(config));
|
|
7
|
+
const [account, setAccount] = createSignal(getAccount(config()));
|
|
8
8
|
|
|
9
9
|
// Watch account
|
|
10
10
|
let cleanup: VoidFunction;
|
|
11
11
|
onMount(() => {
|
|
12
|
-
cleanup = watchAccount(config, { onChange: setAccount });
|
|
12
|
+
cleanup = watchAccount(config(), { onChange: setAccount });
|
|
13
13
|
});
|
|
14
14
|
onCleanup(() => cleanup?.());
|
|
15
15
|
|
package/src/hooks/useBalance.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function useBalance(params: () => UseBalanceParameters) {
|
|
|
34
34
|
const chain = useChainId();
|
|
35
35
|
|
|
36
36
|
const options = () =>
|
|
37
|
-
getBalanceQueryOptions(config, { chainId: chain().id, ...params() });
|
|
37
|
+
getBalanceQueryOptions(config(), { chainId: chain().id, ...params() });
|
|
38
38
|
const enabled = () =>
|
|
39
39
|
Boolean(params().address && (params().query?.enabled ?? true));
|
|
40
40
|
|
package/src/hooks/useChainId.ts
CHANGED
|
@@ -6,17 +6,17 @@ import { useConfig } from "./useConfig.js";
|
|
|
6
6
|
|
|
7
7
|
export function useChainId() {
|
|
8
8
|
const config = useConfig();
|
|
9
|
-
const [chainId, setChainID] = createSignal(getChainId(config));
|
|
9
|
+
const [chainId, setChainID] = createSignal(getChainId(config()));
|
|
10
10
|
|
|
11
11
|
// Watch chain id
|
|
12
12
|
let cleanup: VoidFunction;
|
|
13
13
|
onMount(() => {
|
|
14
|
-
cleanup = watchChainId(config, { onChange: setChainID });
|
|
14
|
+
cleanup = watchChainId(config(), { onChange: setChainID });
|
|
15
15
|
});
|
|
16
16
|
onCleanup(() => cleanup?.());
|
|
17
17
|
|
|
18
18
|
const chain = createMemo(() =>
|
|
19
|
-
extractChain({ chains: config.chains, id: chainId() })
|
|
19
|
+
extractChain({ chains: config().chains, id: chainId() })
|
|
20
20
|
);
|
|
21
21
|
|
|
22
22
|
return chain;
|
package/src/hooks/useConfig.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Config, ResolvedRegister } from "@wagmi/core";
|
|
2
|
-
import { useContext, type Accessor } from "solid-js";
|
|
2
|
+
import { createMemo, useContext, type Accessor } from "solid-js";
|
|
3
3
|
import { WagmiContext } from "../context.js";
|
|
4
4
|
import { WagmiProviderNotFoundError } from "../errors/context.js";
|
|
5
5
|
import type { ConfigParameter } from "../types/index.js";
|
|
@@ -8,14 +8,16 @@ export type UseConfigParameters<config extends Config = Config> = Accessor<
|
|
|
8
8
|
ConfigParameter<config>
|
|
9
9
|
>;
|
|
10
10
|
|
|
11
|
-
export type UseConfigReturnType<config extends Config = Config> =
|
|
11
|
+
export type UseConfigReturnType<config extends Config = Config> =
|
|
12
|
+
Accessor<config>;
|
|
12
13
|
|
|
13
14
|
export function useConfig<config extends Config = ResolvedRegister["config"]>(
|
|
14
|
-
parameters
|
|
15
|
+
parameters: UseConfigParameters<config> = () => ({})
|
|
15
16
|
): UseConfigReturnType<config> {
|
|
16
|
-
|
|
17
|
+
return createMemo(() => {
|
|
18
|
+
const config = parameters().config ?? useContext(WagmiContext);
|
|
19
|
+
if (!config) throw new WagmiProviderNotFoundError();
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return config as UseConfigReturnType<config>;
|
|
21
|
+
return config as config;
|
|
22
|
+
});
|
|
21
23
|
}
|
package/src/hooks/useConnect.ts
CHANGED
|
@@ -6,14 +6,14 @@ import { useConfig } from "./useConfig.js";
|
|
|
6
6
|
export function useConnect() {
|
|
7
7
|
const config = useConfig();
|
|
8
8
|
|
|
9
|
-
const mutationOptions = connectMutationOptions(config);
|
|
9
|
+
const mutationOptions = connectMutationOptions(config());
|
|
10
10
|
const { mutate, mutateAsync, ...result } = useMutation(() => ({
|
|
11
11
|
...mutationOptions,
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
14
|
// Reset mutation back to an idle state when the connector disconnects.
|
|
15
15
|
createEffect(() => {
|
|
16
|
-
const unsub = config.subscribe(
|
|
16
|
+
const unsub = config().subscribe(
|
|
17
17
|
({ status }) => status,
|
|
18
18
|
(status, previousStatus) => {
|
|
19
19
|
if (previousStatus === "connected" && status === "disconnected")
|
|
@@ -4,11 +4,11 @@ import { useConfig } from "./useConfig.js";
|
|
|
4
4
|
|
|
5
5
|
export function useConnections() {
|
|
6
6
|
const config = useConfig();
|
|
7
|
-
const [connections, setConnections] = createSignal(getConnections(config));
|
|
7
|
+
const [connections, setConnections] = createSignal(getConnections(config()));
|
|
8
8
|
|
|
9
9
|
let cleanup: VoidFunction | undefined;
|
|
10
10
|
onMount(() => {
|
|
11
|
-
cleanup = watchConnections(config, { onChange: setConnections });
|
|
11
|
+
cleanup = watchConnections(config(), { onChange: setConnections });
|
|
12
12
|
});
|
|
13
13
|
onCleanup(() => cleanup?.());
|
|
14
14
|
|
|
@@ -8,7 +8,7 @@ export function useDisconnect() {
|
|
|
8
8
|
const config = useConfig();
|
|
9
9
|
|
|
10
10
|
const connections = useConnections();
|
|
11
|
-
const mutationOptions = disconnectMutationOptions(config);
|
|
11
|
+
const mutationOptions = disconnectMutationOptions(config());
|
|
12
12
|
const { mutate, mutateAsync, ...result } = useMutation(() => ({
|
|
13
13
|
...mutationOptions,
|
|
14
14
|
}));
|
|
@@ -91,7 +91,7 @@ export function useReadContracts<
|
|
|
91
91
|
const code = params().code as Hex | undefined;
|
|
92
92
|
|
|
93
93
|
const options = readContractsQueryOptions<Config, contracts, allowFailure>(
|
|
94
|
-
config,
|
|
94
|
+
config(),
|
|
95
95
|
{ ...params(), chainId: contractsChainId() ?? chainId().id }
|
|
96
96
|
);
|
|
97
97
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/solid-query";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Config,
|
|
4
|
+
ResolvedRegister,
|
|
5
|
+
WriteContractErrorType,
|
|
6
|
+
} from "@wagmi/core";
|
|
3
7
|
import {
|
|
4
8
|
writeContractMutationOptions,
|
|
5
9
|
type WriteContractData,
|
|
@@ -7,7 +11,7 @@ import {
|
|
|
7
11
|
type WriteContractMutateAsync,
|
|
8
12
|
type WriteContractVariables,
|
|
9
13
|
} from "@wagmi/core/query";
|
|
10
|
-
|
|
14
|
+
import type { Accessor } from "solid-js";
|
|
11
15
|
import type { Abi } from "viem";
|
|
12
16
|
import type {
|
|
13
17
|
ConfigParameter,
|
|
@@ -56,18 +60,22 @@ export type UseWriteContractReturnType<
|
|
|
56
60
|
};
|
|
57
61
|
|
|
58
62
|
export function useWriteContract<
|
|
59
|
-
config extends Config =
|
|
63
|
+
config extends Config = ResolvedRegister["config"],
|
|
60
64
|
context = unknown
|
|
61
65
|
>(
|
|
62
|
-
params
|
|
66
|
+
params: Accessor<UseWriteContractParameters<config, context>> = () => ({})
|
|
63
67
|
): UseWriteContractReturnType<config, context> {
|
|
64
68
|
const config = useConfig();
|
|
65
69
|
|
|
66
|
-
const mutationOptions = writeContractMutationOptions(config);
|
|
67
|
-
const { mutate, mutateAsync, ...result } = useMutation(() =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const mutationOptions = writeContractMutationOptions(config());
|
|
71
|
+
const { mutate, mutateAsync, ...result } = useMutation(() => {
|
|
72
|
+
const mutation = params?.().mutation;
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
...(mutation ?? {}),
|
|
76
|
+
...mutationOptions,
|
|
77
|
+
};
|
|
78
|
+
});
|
|
71
79
|
|
|
72
80
|
type Return = UseWriteContractReturnType<config, context>;
|
|
73
81
|
return {
|
package/src/types/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DefaultError,
|
|
3
3
|
QueryKey,
|
|
4
|
+
SolidMutationOptions,
|
|
4
5
|
SolidQueryOptions,
|
|
5
6
|
UseInfiniteQueryOptions,
|
|
6
|
-
UseMutationOptions,
|
|
7
7
|
UseMutationResult,
|
|
8
8
|
UseQueryResult,
|
|
9
9
|
} from "@tanstack/solid-query";
|
|
@@ -67,7 +67,7 @@ export type UseMutationParameters<
|
|
|
67
67
|
context = unknown
|
|
68
68
|
> = Compute<
|
|
69
69
|
Omit<
|
|
70
|
-
|
|
70
|
+
SolidMutationOptions<data, error, Compute<variables>, context>,
|
|
71
71
|
"mutationFn" | "mutationKey" | "throwOnError"
|
|
72
72
|
>
|
|
73
73
|
>;
|