@bigmi/react 0.0.0-preview-aab0339
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/CHANGELOG.md +207 -0
- package/LICENSE.md +21 -0
- package/README.md +471 -0
- package/dist/cjs/context.d.ts +15 -0
- package/dist/cjs/context.js +16 -0
- package/dist/cjs/context.js.map +1 -0
- package/dist/cjs/errors/context.d.ts +13 -0
- package/dist/cjs/errors/context.js +13 -0
- package/dist/cjs/errors/context.js.map +1 -0
- package/dist/cjs/hooks/useAccount.d.ts +11 -0
- package/dist/cjs/hooks/useAccount.js +26 -0
- package/dist/cjs/hooks/useAccount.js.map +1 -0
- package/dist/cjs/hooks/useConfig.d.ts +13 -0
- package/dist/cjs/hooks/useConfig.js +15 -0
- package/dist/cjs/hooks/useConfig.js.map +1 -0
- package/dist/cjs/hooks/useConnect.d.ts +20 -0
- package/dist/cjs/hooks/useConnect.js +32 -0
- package/dist/cjs/hooks/useConnect.js.map +1 -0
- package/dist/cjs/hooks/useConnectors.d.ts +11 -0
- package/dist/cjs/hooks/useConnectors.js +15 -0
- package/dist/cjs/hooks/useConnectors.js.map +1 -0
- package/dist/cjs/hooks/useReconnect.d.ts +7 -0
- package/dist/cjs/hooks/useReconnect.js +14 -0
- package/dist/cjs/hooks/useReconnect.js.map +1 -0
- package/dist/cjs/hooks/useSyncExternalStoreWithTracked.d.ts +5 -0
- package/dist/cjs/hooks/useSyncExternalStoreWithTracked.js +41 -0
- package/dist/cjs/hooks/useSyncExternalStoreWithTracked.js.map +1 -0
- package/dist/cjs/hydrate.d.ts +21 -0
- package/dist/cjs/hydrate.js +45 -0
- package/dist/cjs/hydrate.js.map +1 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +12 -0
- package/dist/cjs/types.js +0 -0
- package/dist/cjs/utils/query.d.ts +9 -0
- package/dist/cjs/utils/query.js +1 -0
- package/dist/cjs/version.d.ts +6 -0
- package/dist/cjs/version.js +9 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/context.d.ts +15 -0
- package/dist/esm/context.d.ts.map +1 -0
- package/dist/esm/context.js +14 -0
- package/dist/esm/context.js.map +1 -0
- package/dist/esm/errors/context.d.ts +13 -0
- package/dist/esm/errors/context.d.ts.map +1 -0
- package/dist/esm/errors/context.js +12 -0
- package/dist/esm/errors/context.js.map +1 -0
- package/dist/esm/hooks/useAccount.d.ts +11 -0
- package/dist/esm/hooks/useAccount.d.ts.map +1 -0
- package/dist/esm/hooks/useAccount.js +25 -0
- package/dist/esm/hooks/useAccount.js.map +1 -0
- package/dist/esm/hooks/useConfig.d.ts +13 -0
- package/dist/esm/hooks/useConfig.d.ts.map +1 -0
- package/dist/esm/hooks/useConfig.js +14 -0
- package/dist/esm/hooks/useConfig.js.map +1 -0
- package/dist/esm/hooks/useConnect.d.ts +20 -0
- package/dist/esm/hooks/useConnect.d.ts.map +1 -0
- package/dist/esm/hooks/useConnect.js +31 -0
- package/dist/esm/hooks/useConnect.js.map +1 -0
- package/dist/esm/hooks/useConnectors.d.ts +11 -0
- package/dist/esm/hooks/useConnectors.d.ts.map +1 -0
- package/dist/esm/hooks/useConnectors.js +14 -0
- package/dist/esm/hooks/useConnectors.js.map +1 -0
- package/dist/esm/hooks/useReconnect.d.ts +7 -0
- package/dist/esm/hooks/useReconnect.d.ts.map +1 -0
- package/dist/esm/hooks/useReconnect.js +13 -0
- package/dist/esm/hooks/useReconnect.js.map +1 -0
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.d.ts +5 -0
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.d.ts.map +1 -0
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.js +40 -0
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.js.map +1 -0
- package/dist/esm/hydrate.d.ts +21 -0
- package/dist/esm/hydrate.d.ts.map +1 -0
- package/dist/esm/hydrate.js +43 -0
- package/dist/esm/hydrate.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.d.ts +12 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/query.d.ts +9 -0
- package/dist/esm/utils/query.d.ts.map +1 -0
- package/dist/esm/utils/query.js +2 -0
- package/dist/esm/version.d.ts +6 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +7 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +58 -0
- package/src/context.ts +33 -0
- package/src/errors/context.ts +11 -0
- package/src/hooks/useAccount.ts +43 -0
- package/src/hooks/useConfig.ts +27 -0
- package/src/hooks/useConnect.ts +90 -0
- package/src/hooks/useConnectors.ts +33 -0
- package/src/hooks/useReconnect.ts +11 -0
- package/src/hooks/useSyncExternalStoreWithTracked.ts +76 -0
- package/src/hydrate.ts +86 -0
- package/src/index.ts +6 -0
- package/src/types.ts +9 -0
- package/src/utils/query.ts +31 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAccount.js","names":[],"sources":["../../../src/hooks/useAccount.ts"],"sourcesContent":["'use client'\n\nimport {\n type Config,\n type GetAccountReturnType,\n getAccount,\n watchAccount,\n} from '@bigmi/client'\n\nimport type { ResolvedRegister } from '../types.js'\nimport { type ConfigParameter, useConfig } from './useConfig.js'\nimport { useSyncExternalStoreWithTracked } from './useSyncExternalStoreWithTracked.js'\n\nexport type UseAccountParameters<config extends Config = Config> =\n ConfigParameter<config>\n\nexport type UseAccountReturnType<config extends Config = Config> =\n GetAccountReturnType<config>\n\nconst DISCONNECTED_ACCOUNT: GetAccountReturnType = {\n account: undefined,\n accounts: undefined,\n chain: undefined,\n chainId: undefined,\n connector: undefined,\n isConnected: false,\n isConnecting: false,\n isDisconnected: true,\n isReconnecting: false,\n status: 'disconnected',\n}\n\nexport function useAccount<C extends Config = ResolvedRegister['config']>(\n parameters: UseAccountParameters<C> = {}\n): UseAccountReturnType<C> {\n const config = useConfig(parameters)\n\n return useSyncExternalStoreWithTracked(\n (onChange) => watchAccount(config, { onChange }),\n () => getAccount(config),\n () => DISCONNECTED_ACCOUNT as UseAccountReturnType<C>\n )\n}\n"],"mappings":";;;;;AAmBA,MAAM,uBAA6C;CACjD,SAAS,KAAA;CACT,UAAU,KAAA;CACV,OAAO,KAAA;CACP,SAAS,KAAA;CACT,WAAW,KAAA;CACX,aAAa;CACb,cAAc;CACd,gBAAgB;CAChB,gBAAgB;CAChB,QAAQ;AACV;AAEA,SAAgB,WACd,aAAsC,CAAC,GACd;CACzB,MAAM,SAAS,UAAU,UAAU;CAEnC,OAAO,iCACJ,aAAa,aAAa,QAAQ,EAAE,SAAS,CAAC,SACzC,WAAW,MAAM,SACjB,oBACR;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ResolvedRegister } from "../types.js";
|
|
2
|
+
import { Config } from "@bigmi/client";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/useConfig.d.ts
|
|
5
|
+
type ConfigParameter<config extends Config = Config> = {
|
|
6
|
+
config?: Config | config | undefined;
|
|
7
|
+
};
|
|
8
|
+
type UseConfigParameters<config extends Config = Config> = ConfigParameter<config>;
|
|
9
|
+
type UseConfigReturnType<config extends Config = Config> = config;
|
|
10
|
+
declare function useConfig<C extends Config = ResolvedRegister["config"]>(parameters?: UseConfigParameters<C>): UseConfigReturnType<C>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ConfigParameter, UseConfigParameters, UseConfigReturnType, useConfig };
|
|
13
|
+
//# sourceMappingURL=useConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConfig.d.ts","names":[],"sources":["../../../src/hooks/useConfig.ts"],"mappings":";;;;KAQY,eAAA,gBAA+B,MAAA,GAAS,MAAA;EAClD,MAAA,GAAS,MAAA,GAAS,MAAA;AAAA;AAAA,KAGR,mBAAA,gBAAmC,MAAA,GAAS,MAAA,IACtD,eAAA,CAAgB,MAAA;AAAA,KAEN,mBAAA,gBAAmC,MAAA,GAAS,MAAA,IAAU,MAAA;AAAA,iBAElD,SAAA,WAAoB,MAAA,GAAS,gBAAA,YAC3C,UAAA,GAAY,mBAAA,CAAoB,CAAA,IAC/B,mBAAA,CAAoB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { BigmiContext } from "../context.js";
|
|
3
|
+
import { BigmiProviderNotFoundError } from "../errors/context.js";
|
|
4
|
+
import { useContext } from "react";
|
|
5
|
+
//#region src/hooks/useConfig.ts
|
|
6
|
+
function useConfig(parameters = {}) {
|
|
7
|
+
const config = parameters.config ?? useContext(BigmiContext);
|
|
8
|
+
if (!config) throw new BigmiProviderNotFoundError();
|
|
9
|
+
return config;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useConfig };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=useConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConfig.js","names":[],"sources":["../../../src/hooks/useConfig.ts"],"sourcesContent":["'use client'\n\nimport type { Config } from '@bigmi/client'\nimport { useContext } from 'react'\nimport { BigmiContext } from '../context.js'\nimport { BigmiProviderNotFoundError } from '../errors/context.js'\nimport type { ResolvedRegister } from '../types.js'\n\nexport type ConfigParameter<config extends Config = Config> = {\n config?: Config | config | undefined\n}\n\nexport type UseConfigParameters<config extends Config = Config> =\n ConfigParameter<config>\n\nexport type UseConfigReturnType<config extends Config = Config> = config\n\nexport function useConfig<C extends Config = ResolvedRegister['config']>(\n parameters: UseConfigParameters<C> = {}\n): UseConfigReturnType<C> {\n // biome-ignore lint/correctness/useHookAtTopLevel: part of the hook\n const config = parameters.config ?? useContext(BigmiContext)\n if (!config) {\n throw new BigmiProviderNotFoundError()\n }\n return config as UseConfigReturnType<C>\n}\n"],"mappings":";;;;;AAiBA,SAAgB,UACd,aAAqC,CAAC,GACd;CAExB,MAAM,SAAS,WAAW,UAAU,WAAW,YAAY;CAC3D,IAAI,CAAC,QACH,MAAM,IAAI,2BAA2B;CAEvC,OAAO;AACT"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ResolvedRegister } from "../types.js";
|
|
2
|
+
import { ConfigParameter } from "./useConfig.js";
|
|
3
|
+
import { UseMutationParameters, UseMutationReturnType } from "../utils/query.js";
|
|
4
|
+
import { UseConnectorsReturnType } from "./useConnectors.js";
|
|
5
|
+
import { Config, ConnectData, ConnectErrorType, ConnectMutate, ConnectMutateAsync, ConnectVariables } from "@bigmi/client";
|
|
6
|
+
import { Compute } from "@bigmi/core";
|
|
7
|
+
|
|
8
|
+
//#region src/hooks/useConnect.d.ts
|
|
9
|
+
type UseConnectParameters<config extends Config = Config, context = unknown> = Compute<ConfigParameter<config> & {
|
|
10
|
+
mutation?: UseMutationParameters<ConnectData<config>, ConnectErrorType, ConnectVariables<config, config["connectors"][number]>, context> | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
type UseConnectReturnType<config extends Config = Config, context = unknown> = Compute<UseMutationReturnType<ConnectData<config>, ConnectErrorType, ConnectVariables<config, config["connectors"][number]>, context> & {
|
|
13
|
+
connect: ConnectMutate<config, context>;
|
|
14
|
+
connectAsync: ConnectMutateAsync<config, context>;
|
|
15
|
+
connectors: Compute<UseConnectorsReturnType> | config["connectors"];
|
|
16
|
+
}>;
|
|
17
|
+
declare function useConnect<config extends Config = ResolvedRegister["config"], context = unknown>(parameters?: UseConnectParameters<config, context>): UseConnectReturnType<config, context>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { UseConnectParameters, UseConnectReturnType, useConnect };
|
|
20
|
+
//# sourceMappingURL=useConnect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnect.d.ts","names":[],"sources":["../../../src/hooks/useConnect.ts"],"mappings":";;;;;;;;KAsBY,oBAAA,gBACK,MAAA,GAAS,MAAA,uBAEtB,OAAA,CACF,eAAA,CAAgB,MAAA;EACd,QAAA,GACI,qBAAA,CACE,WAAA,CAAY,MAAA,GACZ,gBAAA,EACA,gBAAA,CAAiB,MAAA,EAAQ,MAAA,yBACzB,OAAA;AAAA;AAAA,KAME,oBAAA,gBACK,MAAA,GAAS,MAAA,uBAEtB,OAAA,CACF,qBAAA,CACE,WAAA,CAAY,MAAA,GACZ,gBAAA,EACA,gBAAA,CAAiB,MAAA,EAAQ,MAAA,yBACzB,OAAA;EAEA,OAAA,EAAS,aAAA,CAAc,MAAA,EAAQ,OAAA;EAC/B,YAAA,EAAc,kBAAA,CAAmB,MAAA,EAAQ,OAAA;EACzC,UAAA,EAAY,OAAA,CAAQ,uBAAA,IAA2B,MAAA;AAAA;AAAA,iBAInC,UAAA,gBACC,MAAA,GAAS,gBAAA,+BAGxB,UAAA,GAAY,oBAAA,CAAqB,MAAA,EAAQ,OAAA,IACxC,oBAAA,CAAqB,MAAA,EAAQ,OAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useConfig } from "./useConfig.js";
|
|
3
|
+
import { useConnectors } from "./useConnectors.js";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
import { connectMutationOptions } from "@bigmi/client";
|
|
6
|
+
import { useMutation } from "@tanstack/react-query";
|
|
7
|
+
//#region src/hooks/useConnect.ts
|
|
8
|
+
function useConnect(parameters = {}) {
|
|
9
|
+
const { mutation } = parameters;
|
|
10
|
+
const config = useConfig(parameters);
|
|
11
|
+
const mutationOptions = connectMutationOptions(config);
|
|
12
|
+
const { mutate, mutateAsync, reset, ...result } = useMutation({
|
|
13
|
+
...mutation,
|
|
14
|
+
...mutationOptions
|
|
15
|
+
});
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
return config.subscribe(({ status }) => status, (status, previousStatus) => {
|
|
18
|
+
if (previousStatus === "connected" && status === "disconnected") reset();
|
|
19
|
+
});
|
|
20
|
+
}, [config, reset]);
|
|
21
|
+
return {
|
|
22
|
+
...result,
|
|
23
|
+
connect: mutate,
|
|
24
|
+
connectAsync: mutateAsync,
|
|
25
|
+
connectors: useConnectors({ config })
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useConnect };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=useConnect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnect.js","names":[],"sources":["../../../src/hooks/useConnect.ts"],"sourcesContent":["'use client'\n\nimport {\n type Config,\n type ConnectData,\n type ConnectErrorType,\n type ConnectMutate,\n type ConnectMutateAsync,\n type ConnectVariables,\n connectMutationOptions,\n} from '@bigmi/client'\nimport type { Compute } from '@bigmi/core'\nimport { useMutation } from '@tanstack/react-query'\nimport { useEffect } from 'react'\nimport type { ResolvedRegister } from '../types.js'\nimport type {\n UseMutationParameters,\n UseMutationReturnType,\n} from '../utils/query.js'\nimport { type ConfigParameter, useConfig } from './useConfig.js'\nimport { type UseConnectorsReturnType, useConnectors } from './useConnectors.js'\n\nexport type UseConnectParameters<\n config extends Config = Config,\n context = unknown,\n> = Compute<\n ConfigParameter<config> & {\n mutation?:\n | UseMutationParameters<\n ConnectData<config>,\n ConnectErrorType,\n ConnectVariables<config, config['connectors'][number]>,\n context\n >\n | undefined\n }\n>\n\nexport type UseConnectReturnType<\n config extends Config = Config,\n context = unknown,\n> = Compute<\n UseMutationReturnType<\n ConnectData<config>,\n ConnectErrorType,\n ConnectVariables<config, config['connectors'][number]>,\n context\n > & {\n connect: ConnectMutate<config, context>\n connectAsync: ConnectMutateAsync<config, context>\n connectors: Compute<UseConnectorsReturnType> | config['connectors']\n }\n>\n\nexport function useConnect<\n config extends Config = ResolvedRegister['config'],\n context = unknown,\n>(\n parameters: UseConnectParameters<config, context> = {}\n): UseConnectReturnType<config, context> {\n const { mutation } = parameters\n\n const config = useConfig(parameters)\n\n const mutationOptions = connectMutationOptions(config)\n const { mutate, mutateAsync, reset, ...result } = useMutation({\n ...mutation,\n ...mutationOptions,\n })\n\n // Reset mutation back to an idle state when the connector disconnects.\n useEffect(() => {\n return config.subscribe(\n ({ status }) => status,\n (status, previousStatus) => {\n if (previousStatus === 'connected' && status === 'disconnected') {\n reset()\n }\n }\n )\n }, [config, reset])\n\n type Return = UseConnectReturnType<config, context>\n return {\n ...(result as Return),\n connect: mutate as Return['connect'],\n connectAsync: mutateAsync as Return['connectAsync'],\n connectors: useConnectors({ config }),\n }\n}\n"],"mappings":";;;;;;;AAsDA,SAAgB,WAId,aAAoD,CAAC,GACd;CACvC,MAAM,EAAE,aAAa;CAErB,MAAM,SAAS,UAAU,UAAU;CAEnC,MAAM,kBAAkB,uBAAuB,MAAM;CACrD,MAAM,EAAE,QAAQ,aAAa,OAAO,GAAG,WAAW,YAAY;EAC5D,GAAG;EACH,GAAG;CACL,CAAC;CAGD,gBAAgB;EACd,OAAO,OAAO,WACX,EAAE,aAAa,SACf,QAAQ,mBAAmB;GAC1B,IAAI,mBAAmB,eAAe,WAAW,gBAC/C,MAAM;EAEV,CACF;CACF,GAAG,CAAC,QAAQ,KAAK,CAAC;CAGlB,OAAO;EACL,GAAI;EACJ,SAAS;EACT,cAAc;EACd,YAAY,cAAc,EAAE,OAAO,CAAC;CACtC;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ResolvedRegister } from "../types.js";
|
|
2
|
+
import { ConfigParameter } from "./useConfig.js";
|
|
3
|
+
import { Config, GetConnectorsReturnType } from "@bigmi/client";
|
|
4
|
+
|
|
5
|
+
//#region src/hooks/useConnectors.d.ts
|
|
6
|
+
type UseConnectorsParameters<config extends Config = Config> = ConfigParameter<config>;
|
|
7
|
+
type UseConnectorsReturnType<config extends Config = Config> = GetConnectorsReturnType<config>;
|
|
8
|
+
declare function useConnectors<config extends Config = ResolvedRegister["config"]>(parameters?: UseConnectorsParameters<config>): UseConnectorsReturnType<config>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { UseConnectorsParameters, UseConnectorsReturnType, useConnectors };
|
|
11
|
+
//# sourceMappingURL=useConnectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnectors.d.ts","names":[],"sources":["../../../src/hooks/useConnectors.ts"],"mappings":";;;;;KAYY,uBAAA,gBAAuC,MAAA,GAAS,MAAA,IAC1D,eAAA,CAAgB,MAAA;AAAA,KAEN,uBAAA,gBAAuC,MAAA,GAAS,MAAA,IAC1D,uBAAA,CAAwB,MAAA;AAAA,iBAIV,aAAA,gBACC,MAAA,GAAS,gBAAA,YAExB,UAAA,GAAY,uBAAA,CAAwB,MAAA,IACnC,uBAAA,CAAwB,MAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useConfig } from "./useConfig.js";
|
|
3
|
+
import { useSyncExternalStore } from "react";
|
|
4
|
+
import { getConnectors, watchConnectors } from "@bigmi/client";
|
|
5
|
+
//#region src/hooks/useConnectors.ts
|
|
6
|
+
const EMPTY_CONNECTORS = [];
|
|
7
|
+
function useConnectors(parameters = {}) {
|
|
8
|
+
const config = useConfig(parameters);
|
|
9
|
+
return useSyncExternalStore((onChange) => watchConnectors(config, { onChange }), () => getConnectors(config), () => EMPTY_CONNECTORS);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useConnectors };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=useConnectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnectors.js","names":[],"sources":["../../../src/hooks/useConnectors.ts"],"sourcesContent":["'use client'\n\nimport {\n type Config,\n type GetConnectorsReturnType,\n getConnectors,\n watchConnectors,\n} from '@bigmi/client'\nimport { useSyncExternalStore } from 'react'\nimport type { ResolvedRegister } from '../types.js'\nimport { type ConfigParameter, useConfig } from './useConfig.js'\n\nexport type UseConnectorsParameters<config extends Config = Config> =\n ConfigParameter<config>\n\nexport type UseConnectorsReturnType<config extends Config = Config> =\n GetConnectorsReturnType<config>\n\nconst EMPTY_CONNECTORS: readonly [] = []\n\nexport function useConnectors<\n config extends Config = ResolvedRegister['config'],\n>(\n parameters: UseConnectorsParameters<config> = {}\n): UseConnectorsReturnType<config> {\n const config = useConfig(parameters)\n\n return useSyncExternalStore(\n (onChange) => watchConnectors(config, { onChange }),\n () => getConnectors(config),\n () => EMPTY_CONNECTORS as UseConnectorsReturnType<config>\n )\n}\n"],"mappings":";;;;;AAkBA,MAAM,mBAAgC,CAAC;AAEvC,SAAgB,cAGd,aAA8C,CAAC,GACd;CACjC,MAAM,SAAS,UAAU,UAAU;CAEnC,OAAO,sBACJ,aAAa,gBAAgB,QAAQ,EAAE,SAAS,CAAC,SAC5C,cAAc,MAAM,SACpB,gBACR;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReconnect.d.ts","names":[],"sources":["../../../src/hooks/useReconnect.ts"],"mappings":";;;cAMa,YAAA,GAAgB,MAAQ,EAAA,MAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { reconnect } from "@bigmi/client";
|
|
4
|
+
//#region src/hooks/useReconnect.ts
|
|
5
|
+
const useReconnect = (config) => {
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
reconnect(config);
|
|
8
|
+
}, [config]);
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { useReconnect };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=useReconnect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReconnect.js","names":[],"sources":["../../../src/hooks/useReconnect.ts"],"sourcesContent":["'use client'\n\nimport { type Config, reconnect } from '@bigmi/client'\n\nimport { useEffect } from 'react'\n\nexport const useReconnect = (config: Config): void => {\n useEffect(() => {\n reconnect(config)\n }, [config])\n}\n"],"mappings":";;;;AAMA,MAAa,gBAAgB,WAAyB;CACpD,gBAAgB;EACd,UAAU,MAAM;CAClB,GAAG,CAAC,MAAM,CAAC;AACb"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
//#region src/hooks/useSyncExternalStoreWithTracked.d.ts
|
|
2
|
+
declare function useSyncExternalStoreWithTracked<Snapshot extends Selection, Selection = Snapshot>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => Snapshot, getServerSnapshot?: (() => Snapshot) | undefined, isEqual?: (a: Selection, b: Selection) => boolean): Selection;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { useSyncExternalStoreWithTracked };
|
|
5
|
+
//# sourceMappingURL=useSyncExternalStoreWithTracked.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncExternalStoreWithTracked.d.ts","names":[],"sources":["../../../src/hooks/useSyncExternalStoreWithTracked.ts"],"mappings":";iBAOgB,+BAAA,kBACG,SAAA,cACL,QAAA,EAEZ,SAAA,GAAY,aAAA,6BACZ,WAAA,QAAmB,QAAA,EACnB,iBAAA,UAA0B,QAAA,eAC1B,OAAA,IAAU,CAAA,EAAG,SAAA,EAAW,CAAA,EAAG,SAAA,eAC1B,SAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import { deepEqual } from "@bigmi/core";
|
|
4
|
+
//#region src/hooks/useSyncExternalStoreWithTracked.ts
|
|
5
|
+
const isPlainObject = (obj) => typeof obj === "object" && !Array.isArray(obj);
|
|
6
|
+
function useSyncExternalStoreWithTracked(subscribe, getSnapshot, getServerSnapshot = getSnapshot, isEqual = deepEqual) {
|
|
7
|
+
const trackedKeys = useRef(/* @__PURE__ */ new Set());
|
|
8
|
+
const previousResult = useRef(void 0);
|
|
9
|
+
const snapshotCache = useRef(getSnapshot());
|
|
10
|
+
const snapshot = useSyncExternalStore((onChange) => subscribe(() => {
|
|
11
|
+
snapshotCache.current = getSnapshot();
|
|
12
|
+
onChange();
|
|
13
|
+
}), () => snapshotCache.current, getServerSnapshot);
|
|
14
|
+
const result = useMemo(() => {
|
|
15
|
+
if (!isPlainObject(snapshot)) return snapshot;
|
|
16
|
+
const trackedResult = { ...snapshot };
|
|
17
|
+
Object.defineProperties(trackedResult, Object.fromEntries(Object.entries(trackedResult).map(([key, value]) => [key, {
|
|
18
|
+
configurable: false,
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => {
|
|
21
|
+
trackedKeys.current.add(key);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
}])));
|
|
25
|
+
return trackedResult;
|
|
26
|
+
}, [snapshot]);
|
|
27
|
+
return useMemo(() => {
|
|
28
|
+
if (!trackedKeys.current.size || !previousResult.current) {
|
|
29
|
+
previousResult.current = result;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
if (!Array.from(trackedKeys.current).some((key) => !isEqual(result[key], previousResult.current[key]))) return previousResult.current;
|
|
33
|
+
previousResult.current = result;
|
|
34
|
+
return result;
|
|
35
|
+
}, [result, isEqual]);
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useSyncExternalStoreWithTracked };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=useSyncExternalStoreWithTracked.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncExternalStoreWithTracked.js","names":[],"sources":["../../../src/hooks/useSyncExternalStoreWithTracked.ts"],"sourcesContent":["'use client'\nimport { deepEqual } from '@bigmi/core'\nimport { useMemo, useRef, useSyncExternalStore } from 'react'\n\nconst isPlainObject = (obj: unknown): obj is Record<string, any> =>\n typeof obj === 'object' && !Array.isArray(obj)\n\nexport function useSyncExternalStoreWithTracked<\n Snapshot extends Selection,\n Selection = Snapshot,\n>(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => Snapshot,\n getServerSnapshot: (() => Snapshot) | undefined = getSnapshot,\n isEqual: (a: Selection, b: Selection) => boolean = deepEqual\n): Selection {\n const trackedKeys = useRef<Set<string>>(new Set())\n const previousResult = useRef<Selection | undefined>(undefined)\n const snapshotCache = useRef(getSnapshot())\n\n const snapshot = useSyncExternalStore(\n (onChange) =>\n subscribe(() => {\n snapshotCache.current = getSnapshot()\n onChange()\n }),\n () => snapshotCache.current!,\n getServerSnapshot\n )\n\n const result = useMemo(() => {\n if (!isPlainObject(snapshot)) {\n return snapshot\n }\n\n const trackedResult = { ...snapshot }\n Object.defineProperties(\n trackedResult,\n Object.fromEntries(\n Object.entries(trackedResult).map(([key, value]) => [\n key,\n {\n configurable: false,\n enumerable: true,\n get: () => {\n trackedKeys.current.add(key)\n return value\n },\n },\n ])\n )\n )\n return trackedResult\n }, [snapshot])\n\n return useMemo(() => {\n if (!trackedKeys.current.size || !previousResult.current) {\n previousResult.current = result\n return result\n }\n\n const hasChanged = Array.from(trackedKeys.current).some(\n (key) =>\n !isEqual(\n (result as Record<string, Selection>)[key],\n (previousResult.current as Record<string, Selection>)[key]\n )\n )\n\n if (!hasChanged) {\n return previousResult.current\n }\n previousResult.current = result\n return result\n }, [result, isEqual])\n}\n"],"mappings":";;;;AAIA,MAAM,iBAAiB,QACrB,OAAO,QAAQ,YAAY,CAAC,MAAM,QAAQ,GAAG;AAE/C,SAAgB,gCAId,WACA,aACA,oBAAkD,aAClD,UAAmD,WACxC;CACX,MAAM,cAAc,uBAAoB,IAAI,IAAI,CAAC;CACjD,MAAM,iBAAiB,OAA8B,KAAA,CAAS;CAC9D,MAAM,gBAAgB,OAAO,YAAY,CAAC;CAE1C,MAAM,WAAW,sBACd,aACC,gBAAgB;EACd,cAAc,UAAU,YAAY;EACpC,SAAS;CACX,CAAC,SACG,cAAc,SACpB,iBACF;CAEA,MAAM,SAAS,cAAc;EAC3B,IAAI,CAAC,cAAc,QAAQ,GACzB,OAAO;EAGT,MAAM,gBAAgB,EAAE,GAAG,SAAS;EACpC,OAAO,iBACL,eACA,OAAO,YACL,OAAO,QAAQ,aAAa,EAAE,KAAK,CAAC,KAAK,WAAW,CAClD,KACA;GACE,cAAc;GACd,YAAY;GACZ,WAAW;IACT,YAAY,QAAQ,IAAI,GAAG;IAC3B,OAAO;GACT;EACF,CACF,CAAC,CACH,CACF;EACA,OAAO;CACT,GAAG,CAAC,QAAQ,CAAC;CAEb,OAAO,cAAc;EACnB,IAAI,CAAC,YAAY,QAAQ,QAAQ,CAAC,eAAe,SAAS;GACxD,eAAe,UAAU;GACzB,OAAO;EACT;EAUA,IAAI,CARe,MAAM,KAAK,YAAY,OAAO,EAAE,MAChD,QACC,CAAC,QACE,OAAqC,MACrC,eAAe,QAAsC,IACxD,CAGU,GACZ,OAAO,eAAe;EAExB,eAAe,UAAU;EACzB,OAAO;CACT,GAAG,CAAC,QAAQ,OAAO,CAAC;AACtB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ResolvedRegister } from "./types.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { Config, State } from "@bigmi/client";
|
|
4
|
+
|
|
5
|
+
//#region src/hydrate.d.ts
|
|
6
|
+
type HydrateProps = {
|
|
7
|
+
config: ResolvedRegister["config"];
|
|
8
|
+
initialState?: State | undefined;
|
|
9
|
+
reconnectOnMount?: boolean | undefined;
|
|
10
|
+
};
|
|
11
|
+
type HydrateParameters = {
|
|
12
|
+
initialState?: State | undefined;
|
|
13
|
+
reconnectOnMount?: boolean | undefined;
|
|
14
|
+
};
|
|
15
|
+
declare function hydrate(config: Config, parameters: HydrateParameters): {
|
|
16
|
+
onMount(): Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
declare function Hydrate(parameters: React.PropsWithChildren<HydrateProps>): ReactElement;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Hydrate, HydrateProps, hydrate };
|
|
21
|
+
//# sourceMappingURL=hydrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate.d.ts","names":[],"sources":["../../src/hydrate.ts"],"mappings":";;;;;KAQY,YAAA;EACV,MAAA,EAAQ,gBAAA;EACR,YAAA,GAAe,KAAA;EACf,gBAAA;AAAA;AAAA,KAGG,iBAAA;EACH,YAAA,GAAe,KAAA;EACf,gBAAA;AAAA;AAAA,iBAGc,OAAA,CACd,MAAA,EAAQ,MAAA,EACR,UAAA,EAAY,iBAAA;EACT,OAAA,IAAW,OAAA;AAAA;AAAA,iBAiCA,OAAA,CAAQ,UAAA,EAAY,KAAA,CAAM,iBAAA,CAAkB,YAAA,IA6BvC,YAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { reconnect } from "@bigmi/client";
|
|
4
|
+
//#region src/hydrate.ts
|
|
5
|
+
function hydrate(config, parameters) {
|
|
6
|
+
const { initialState, reconnectOnMount } = parameters;
|
|
7
|
+
if (initialState && !config._internal.store.persist.hasHydrated()) config.setState({
|
|
8
|
+
...initialState,
|
|
9
|
+
chainId: config.chains.some((x) => x.id === initialState.chainId) ? initialState.chainId : config.chains[0].id,
|
|
10
|
+
connections: reconnectOnMount ? initialState.connections : /* @__PURE__ */ new Map(),
|
|
11
|
+
status: reconnectOnMount ? "reconnecting" : "disconnected"
|
|
12
|
+
});
|
|
13
|
+
return { async onMount() {
|
|
14
|
+
if (config._internal.ssr) await config._internal.store.persist.rehydrate();
|
|
15
|
+
if (reconnectOnMount) reconnect(config);
|
|
16
|
+
else if (config.storage) config.setState((x) => ({
|
|
17
|
+
...x,
|
|
18
|
+
connections: /* @__PURE__ */ new Map()
|
|
19
|
+
}));
|
|
20
|
+
} };
|
|
21
|
+
}
|
|
22
|
+
function Hydrate(parameters) {
|
|
23
|
+
const { children, config, initialState, reconnectOnMount = true } = parameters;
|
|
24
|
+
const { onMount } = hydrate(config, {
|
|
25
|
+
initialState,
|
|
26
|
+
reconnectOnMount
|
|
27
|
+
});
|
|
28
|
+
if (!config._internal.ssr) onMount();
|
|
29
|
+
const active = useRef(true);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!active.current) return;
|
|
32
|
+
if (!config._internal.ssr) return;
|
|
33
|
+
onMount();
|
|
34
|
+
return () => {
|
|
35
|
+
active.current = false;
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
return children;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { Hydrate, hydrate };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=hydrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate.js","names":[],"sources":["../../src/hydrate.ts"],"sourcesContent":["'use client'\n\nimport { type Config, reconnect, type State } from '@bigmi/client'\n\nimport { type ReactElement, useEffect, useRef } from 'react'\n\nimport type { ResolvedRegister } from './types.js'\n\nexport type HydrateProps = {\n config: ResolvedRegister['config']\n initialState?: State | undefined\n reconnectOnMount?: boolean | undefined\n}\n\ntype HydrateParameters = {\n initialState?: State | undefined\n reconnectOnMount?: boolean | undefined\n}\n\nexport function hydrate(\n config: Config,\n parameters: HydrateParameters\n): { onMount(): Promise<void> } {\n const { initialState, reconnectOnMount } = parameters\n\n if (initialState && !config._internal.store.persist.hasHydrated()) {\n config.setState({\n ...initialState,\n chainId: config.chains.some((x) => x.id === initialState.chainId)\n ? initialState.chainId\n : config.chains[0].id,\n connections: reconnectOnMount ? initialState.connections : new Map(),\n status: reconnectOnMount ? 'reconnecting' : 'disconnected',\n })\n }\n\n return {\n async onMount(): Promise<void> {\n if (config._internal.ssr) {\n await config._internal.store.persist.rehydrate()\n }\n\n if (reconnectOnMount) {\n reconnect(config)\n } else if (config.storage) {\n // Reset connections that may have been hydrated from storage.\n config.setState((x) => ({\n ...x,\n connections: new Map(),\n }))\n }\n },\n }\n}\n\nexport function Hydrate(parameters: React.PropsWithChildren<HydrateProps>) {\n const { children, config, initialState, reconnectOnMount = true } = parameters\n\n const { onMount } = hydrate(config, {\n initialState,\n reconnectOnMount,\n })\n\n // Hydrate for non-SSR\n if (!config._internal.ssr) {\n onMount()\n }\n\n // Hydrate for SSR\n const active = useRef(true)\n // biome-ignore lint/correctness/useExhaustiveDependencies: `queryKey` not required\n useEffect(() => {\n if (!active.current) {\n return\n }\n if (!config._internal.ssr) {\n return\n }\n onMount()\n return () => {\n active.current = false\n }\n }, [])\n\n return children as ReactElement\n}\n"],"mappings":";;;;AAmBA,SAAgB,QACd,QACA,YAC8B;CAC9B,MAAM,EAAE,cAAc,qBAAqB;CAE3C,IAAI,gBAAgB,CAAC,OAAO,UAAU,MAAM,QAAQ,YAAY,GAC9D,OAAO,SAAS;EACd,GAAG;EACH,SAAS,OAAO,OAAO,MAAM,MAAM,EAAE,OAAO,aAAa,OAAO,IAC5D,aAAa,UACb,OAAO,OAAO,GAAG;EACrB,aAAa,mBAAmB,aAAa,8BAAc,IAAI,IAAI;EACnE,QAAQ,mBAAmB,iBAAiB;CAC9C,CAAC;CAGH,OAAO,EACL,MAAM,UAAyB;EAC7B,IAAI,OAAO,UAAU,KACnB,MAAM,OAAO,UAAU,MAAM,QAAQ,UAAU;EAGjD,IAAI,kBACF,UAAU,MAAM;OACX,IAAI,OAAO,SAEhB,OAAO,UAAU,OAAO;GACtB,GAAG;GACH,6BAAa,IAAI,IAAI;EACvB,EAAE;CAEN,EACF;AACF;AAEA,SAAgB,QAAQ,YAAmD;CACzE,MAAM,EAAE,UAAU,QAAQ,cAAc,mBAAmB,SAAS;CAEpE,MAAM,EAAE,YAAY,QAAQ,QAAQ;EAClC;EACA;CACF,CAAC;CAGD,IAAI,CAAC,OAAO,UAAU,KACpB,QAAQ;CAIV,MAAM,SAAS,OAAO,IAAI;CAE1B,gBAAgB;EACd,IAAI,CAAC,OAAO,SACV;EAEF,IAAI,CAAC,OAAO,UAAU,KACpB;EAEF,QAAQ;EACR,aAAa;GACX,OAAO,UAAU;EACnB;CACF,GAAG,CAAC,CAAC;CAEL,OAAO;AACT"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BigmiContext, BigmiProvider, BigmiProviderProps } from "./context.js";
|
|
2
|
+
import { useConfig } from "./hooks/useConfig.js";
|
|
3
|
+
import { useAccount } from "./hooks/useAccount.js";
|
|
4
|
+
import { useConnect } from "./hooks/useConnect.js";
|
|
5
|
+
import { useReconnect } from "./hooks/useReconnect.js";
|
|
6
|
+
export { BigmiContext, BigmiProvider, type BigmiProviderProps, useAccount, useConfig, useConnect, useReconnect };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BigmiContext, BigmiProvider } from "./context.js";
|
|
2
|
+
import { useConfig } from "./hooks/useConfig.js";
|
|
3
|
+
import { useAccount } from "./hooks/useAccount.js";
|
|
4
|
+
import { useConnect } from "./hooks/useConnect.js";
|
|
5
|
+
import { useReconnect } from "./hooks/useReconnect.js";
|
|
6
|
+
export { BigmiContext, BigmiProvider, useAccount, useConfig, useConnect, useReconnect };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module","sideEffects":false}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Config } from "@bigmi/client";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type Register = {};
|
|
5
|
+
type ResolvedRegister = {
|
|
6
|
+
config: Register extends {
|
|
7
|
+
config: infer config extends Config;
|
|
8
|
+
} ? config : Config;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Register, ResolvedRegister };
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;KAGY,QAAA;AAAA,KACA,gBAAA;EACV,MAAA,EAAQ,QAAA;IAAmB,MAAA,uBAA6B,MAAA;EAAA,IACpD,MAAA,GACA,MAAA;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Compute, UnionStrictOmit } from "@bigmi/core";
|
|
2
|
+
import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/query.d.ts
|
|
5
|
+
type UseMutationParameters<data = unknown, error = Error, variables = void, context = unknown> = Compute<Omit<UseMutationOptions<data, error, Compute<variables>, context>, "mutationFn" | "mutationKey" | "throwOnError">>;
|
|
6
|
+
type UseMutationReturnType<data = unknown, error = Error, variables = void, context = unknown> = Compute<UnionStrictOmit<UseMutationResult<data, error, variables, context>, "mutate" | "mutateAsync">>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { UseMutationParameters, UseMutationReturnType };
|
|
9
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","names":[],"sources":["../../../src/utils/query.ts"],"mappings":";;;;KAQY,qBAAA,yBAEF,KAAA,yCAGN,OAAA,CACF,IAAA,CACE,kBAAA,CAAmB,IAAA,EAAM,KAAA,EAAO,OAAA,CAAQ,SAAA,GAAY,OAAA;AAAA,KAK5C,qBAAA,yBAEF,KAAA,yCAGN,OAAA,CACF,eAAA,CACE,iBAAA,CAAkB,IAAA,EAAM,KAAA,EAAO,SAAA,EAAW,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","names":[],"sources":["../../src/version.ts"],"mappings":";cAAa,IAAA;AAAA,cACA,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@bigmi/react'\nexport const version = '0.0.0-preview-aab0339'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bigmi/react",
|
|
3
|
+
"version": "0.0.0-preview-aab0339",
|
|
4
|
+
"description": "React primitives for Bitcoin apps.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"author": "Eugene Chybisov <eugene@li.finance>",
|
|
10
|
+
"homepage": "https://github.com/lifinance/bigmi",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/lifinance/bigmi.git",
|
|
14
|
+
"directory": "packages/react"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/lifinance/bigmi/issues"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"bitcoin",
|
|
22
|
+
"bitcoinjs",
|
|
23
|
+
"btc",
|
|
24
|
+
"utxo",
|
|
25
|
+
"web3",
|
|
26
|
+
"dapp",
|
|
27
|
+
"typescript",
|
|
28
|
+
"react",
|
|
29
|
+
"hooks"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@bigmi/core": "0.8.1",
|
|
33
|
+
"@bigmi/client": "0.0.0-preview-aab0339"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@tanstack/react-query": ">=5.68.0",
|
|
37
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
38
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist/**",
|
|
42
|
+
"CHANGELOG.md",
|
|
43
|
+
"!dist/**/*.tsbuildinfo",
|
|
44
|
+
"src/**/*.ts",
|
|
45
|
+
"!src/**/*.spec.ts",
|
|
46
|
+
"!**/__mocks__/**",
|
|
47
|
+
"!*.tmp",
|
|
48
|
+
"!*.env",
|
|
49
|
+
"!tsconfig.json"
|
|
50
|
+
],
|
|
51
|
+
"exports": {
|
|
52
|
+
".": {
|
|
53
|
+
"types": "./dist/esm/index.d.ts",
|
|
54
|
+
"default": "./dist/esm/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./package.json": "./package.json"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import type { State } from '@bigmi/client'
|
|
3
|
+
import {
|
|
4
|
+
type Context,
|
|
5
|
+
createContext,
|
|
6
|
+
createElement,
|
|
7
|
+
type PropsWithChildren,
|
|
8
|
+
type ReactElement,
|
|
9
|
+
} from 'react'
|
|
10
|
+
import { Hydrate } from './hydrate.js'
|
|
11
|
+
import type { ResolvedRegister } from './types.js'
|
|
12
|
+
|
|
13
|
+
export const BigmiContext: Context<ResolvedRegister['config'] | undefined> =
|
|
14
|
+
createContext<ResolvedRegister['config'] | undefined>(undefined)
|
|
15
|
+
|
|
16
|
+
export type BigmiProviderProps = {
|
|
17
|
+
config: ResolvedRegister['config']
|
|
18
|
+
initialState?: State | undefined
|
|
19
|
+
reconnectOnMount?: boolean | undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function BigmiProvider(
|
|
23
|
+
parameters: PropsWithChildren<BigmiProviderProps>
|
|
24
|
+
): ReactElement {
|
|
25
|
+
const { children, config } = parameters
|
|
26
|
+
|
|
27
|
+
const props = { value: config }
|
|
28
|
+
return createElement(
|
|
29
|
+
Hydrate,
|
|
30
|
+
parameters,
|
|
31
|
+
createElement(BigmiContext.Provider, props, children)
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseError } from '@bigmi/core'
|
|
2
|
+
|
|
3
|
+
export type BigmiProviderNotFoundErrorType = BigmiProviderNotFoundError & {
|
|
4
|
+
name: 'BigmiProviderNotFoundError'
|
|
5
|
+
}
|
|
6
|
+
export class BigmiProviderNotFoundError extends BaseError {
|
|
7
|
+
override name = 'BigmiProviderNotFoundError'
|
|
8
|
+
constructor() {
|
|
9
|
+
super('`useConfig` must be used within `BigmiProvider`.')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type Config,
|
|
5
|
+
type GetAccountReturnType,
|
|
6
|
+
getAccount,
|
|
7
|
+
watchAccount,
|
|
8
|
+
} from '@bigmi/client'
|
|
9
|
+
|
|
10
|
+
import type { ResolvedRegister } from '../types.js'
|
|
11
|
+
import { type ConfigParameter, useConfig } from './useConfig.js'
|
|
12
|
+
import { useSyncExternalStoreWithTracked } from './useSyncExternalStoreWithTracked.js'
|
|
13
|
+
|
|
14
|
+
export type UseAccountParameters<config extends Config = Config> =
|
|
15
|
+
ConfigParameter<config>
|
|
16
|
+
|
|
17
|
+
export type UseAccountReturnType<config extends Config = Config> =
|
|
18
|
+
GetAccountReturnType<config>
|
|
19
|
+
|
|
20
|
+
const DISCONNECTED_ACCOUNT: GetAccountReturnType = {
|
|
21
|
+
account: undefined,
|
|
22
|
+
accounts: undefined,
|
|
23
|
+
chain: undefined,
|
|
24
|
+
chainId: undefined,
|
|
25
|
+
connector: undefined,
|
|
26
|
+
isConnected: false,
|
|
27
|
+
isConnecting: false,
|
|
28
|
+
isDisconnected: true,
|
|
29
|
+
isReconnecting: false,
|
|
30
|
+
status: 'disconnected',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useAccount<C extends Config = ResolvedRegister['config']>(
|
|
34
|
+
parameters: UseAccountParameters<C> = {}
|
|
35
|
+
): UseAccountReturnType<C> {
|
|
36
|
+
const config = useConfig(parameters)
|
|
37
|
+
|
|
38
|
+
return useSyncExternalStoreWithTracked(
|
|
39
|
+
(onChange) => watchAccount(config, { onChange }),
|
|
40
|
+
() => getAccount(config),
|
|
41
|
+
() => DISCONNECTED_ACCOUNT as UseAccountReturnType<C>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { Config } from '@bigmi/client'
|
|
4
|
+
import { useContext } from 'react'
|
|
5
|
+
import { BigmiContext } from '../context.js'
|
|
6
|
+
import { BigmiProviderNotFoundError } from '../errors/context.js'
|
|
7
|
+
import type { ResolvedRegister } from '../types.js'
|
|
8
|
+
|
|
9
|
+
export type ConfigParameter<config extends Config = Config> = {
|
|
10
|
+
config?: Config | config | undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type UseConfigParameters<config extends Config = Config> =
|
|
14
|
+
ConfigParameter<config>
|
|
15
|
+
|
|
16
|
+
export type UseConfigReturnType<config extends Config = Config> = config
|
|
17
|
+
|
|
18
|
+
export function useConfig<C extends Config = ResolvedRegister['config']>(
|
|
19
|
+
parameters: UseConfigParameters<C> = {}
|
|
20
|
+
): UseConfigReturnType<C> {
|
|
21
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: part of the hook
|
|
22
|
+
const config = parameters.config ?? useContext(BigmiContext)
|
|
23
|
+
if (!config) {
|
|
24
|
+
throw new BigmiProviderNotFoundError()
|
|
25
|
+
}
|
|
26
|
+
return config as UseConfigReturnType<C>
|
|
27
|
+
}
|