@reef-knot/core-react 6.1.0 → 6.2.0-alpha.2

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.
@@ -1,14 +1,7 @@
1
- import type { WalletAdapterData } from '@reef-knot/types';
1
+ import type { ReefKnotContextValue } from '@reef-knot/types';
2
+ export type { ReefKnotConfig, ReefKnotProviderConfig, ReefKnotContextValue, } from '@reef-knot/types';
2
3
  /**
3
4
  * Context definition is in separated file to avoid circular dependencies
4
5
  */
5
- export type ReefKnotProviderConfig = {
6
- autoConnect: boolean;
7
- walletDataList: WalletAdapterData[];
8
- };
9
- export type ReefKnotContextValue = ReefKnotProviderConfig & {
10
- loadingWalletId: string | null;
11
- setLoadingWalletId: React.Dispatch<React.SetStateAction<string | null>>;
12
- };
13
6
  export declare const ReefKnotContext: import("react").Context<ReefKnotContextValue>;
14
7
  //# sourceMappingURL=reefKnotContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reefKnotContext.d.ts","sourceRoot":"","sources":["../../src/context/reefKnotContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D;;GAEG;AAEH,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,iBAAiB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,sBAAsB,GAAG;IAC1D,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kBAAkB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CACzE,CAAC;AAEF,eAAO,MAAM,eAAe,+CAA4C,CAAC"}
1
+ {"version":3,"file":"reefKnotContext.d.ts","sourceRoot":"","sources":["../../src/context/reefKnotContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,YAAY,EACV,cAAc,EACd,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AAEH,eAAO,MAAM,eAAe,+CAA4C,CAAC"}
@@ -1,5 +1,8 @@
1
1
  import { createContext } from 'react';
2
2
 
3
+ /**
4
+ * Context definition is in separated file to avoid circular dependencies
5
+ */
3
6
  const ReefKnotContext = createContext({});
4
7
 
5
8
  export { ReefKnotContext };
@@ -1,13 +1,10 @@
1
1
  import { Chain } from 'viem';
2
2
  import { createConfig } from 'wagmi';
3
- import type { ReefKnotWalletsModalConfig } from '@reef-knot/types';
3
+ import type { ReefKnotWalletsModalConfig, ReefKnotProviderConfig, ReefKnotConfig } from '@reef-knot/types';
4
4
  import { GetWalletsDataListArgs } from './getWalletsDataList';
5
- import type { ReefKnotProviderConfig } from '../context/reefKnotContext';
6
5
  type WagmiConfigArgs = Omit<Parameters<typeof createConfig>[0], 'connectors' | 'client'>;
7
- type DefaultConfigArgs<I extends string = string> = ReefKnotWalletsModalConfig<I> & GetWalletsDataListArgs & WagmiConfigArgs & {
8
- autoConnect: boolean;
9
- };
10
- export declare const getDefaultConfig: <I extends string = string>({ rpc, defaultChain, walletconnectProjectId, walletsList, safeAllowedDomains, chains, transports, autoConnect, buttonComponentsByConnectorId, walletsShown, walletsPinned, walletsDisplayInitialCount, linkTerms, linkPrivacyNotice, linkDontHaveWallet, onClickTermsAccept, onClickWalletsLess, onClickWalletsMore, onConnectStart, onConnectSuccess, ...wagmiArgs }: DefaultConfigArgs<I>) => {
6
+ type DefaultConfigArgs<I extends string = string> = ReefKnotConfig & ReefKnotWalletsModalConfig<I> & GetWalletsDataListArgs & WagmiConfigArgs;
7
+ export declare const getDefaultConfig: <I extends string = string>({ rpc, defaultChain, walletconnectProjectId, walletsList, safeAllowedDomains, chains, transports, autoConnect, onAutoConnect, onReconnect, buttonComponentsByConnectorId, walletsShown, walletsPinned, walletsDisplayInitialCount, linkTerms, linkPrivacyNotice, linkDontHaveWallet, onClickTermsAccept, onClickWalletsLess, onClickWalletsMore, onConnectStart, onConnectSuccess, ...wagmiArgs }: DefaultConfigArgs<I>) => {
11
8
  wagmiConfig: import("wagmi").Config<readonly [Chain, ...Chain[]], Record<number, import("wagmi").Transport<string, Record<string, any>, import("viem").EIP1193RequestFn>>, readonly import("wagmi").CreateConnectorFn[]>;
12
9
  reefKnotConfig: ReefKnotProviderConfig;
13
10
  walletsDataList: import("@reef-knot/types").WalletAdapterData[];
@@ -1 +1 @@
1
- {"version":3,"file":"getDefaultConfig.d.ts","sourceRoot":"","sources":["../../src/helpers/getDefaultConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAa,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAEL,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAMzE,KAAK,eAAe,GAAG,IAAI,CACzB,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EAKlC,YAAY,GAAG,QAAQ,CACxB,CAAC;AAEF,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAC9C,0BAA0B,CAAC,CAAC,CAAC,GAC3B,sBAAsB,GACtB,eAAe,GAAG;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAWN,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,kXA2B9C,iBAAiB,CAAC,CAAC,CAAC;;;;;CA2CtB,CAAC"}
1
+ {"version":3,"file":"getDefaultConfig.d.ts","sourceRoot":"","sources":["../../src/helpers/getDefaultConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAa,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,KAAK,EACV,0BAA0B,EAC1B,sBAAsB,EACtB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAM9B,KAAK,eAAe,GAAG,IAAI,CACzB,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EAKlC,YAAY,GAAG,QAAQ,CACxB,CAAC;AAEF,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,cAAc,GAChE,0BAA0B,CAAC,CAAC,CAAC,GAC7B,sBAAsB,GACtB,eAAe,CAAC;AAWlB,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,8YA6B9C,iBAAiB,CAAC,CAAC,CAAC;;;;;CA6CtB,CAAC"}
@@ -19,6 +19,8 @@ const getDefaultConfig = _a => {
19
19
  chains,
20
20
  transports,
21
21
  autoConnect,
22
+ onAutoConnect,
23
+ onReconnect,
22
24
  // Wallets config args
23
25
  buttonComponentsByConnectorId,
24
26
  walletsShown,
@@ -34,7 +36,7 @@ const getDefaultConfig = _a => {
34
36
  onConnectSuccess
35
37
  } = _a,
36
38
  // Wagmi config args
37
- wagmiArgs = __rest(_a, ["rpc", "defaultChain", "walletconnectProjectId", "walletsList", "safeAllowedDomains", "chains", "transports", "autoConnect", "buttonComponentsByConnectorId", "walletsShown", "walletsPinned", "walletsDisplayInitialCount", "linkTerms", "linkPrivacyNotice", "linkDontHaveWallet", "onClickTermsAccept", "onClickWalletsLess", "onClickWalletsMore", "onConnectStart", "onConnectSuccess"]);
39
+ wagmiArgs = __rest(_a, ["rpc", "defaultChain", "walletconnectProjectId", "walletsList", "safeAllowedDomains", "chains", "transports", "autoConnect", "onAutoConnect", "onReconnect", "buttonComponentsByConnectorId", "walletsShown", "walletsPinned", "walletsDisplayInitialCount", "linkTerms", "linkPrivacyNotice", "linkDontHaveWallet", "onClickTermsAccept", "onClickWalletsLess", "onClickWalletsMore", "onConnectStart", "onConnectSuccess"]);
38
40
  const {
39
41
  walletsDataList
40
42
  } = getWalletsDataList({
@@ -46,7 +48,9 @@ const getDefaultConfig = _a => {
46
48
  });
47
49
  const reefKnotConfig = {
48
50
  autoConnect,
49
- walletDataList: walletsDataList
51
+ walletDataList: walletsDataList,
52
+ onAutoConnect,
53
+ onReconnect
50
54
  };
51
55
  const wagmiConfig = createConfig(Object.assign({
52
56
  chains,
@@ -0,0 +1,2 @@
1
+ export declare function withCallback<T extends (...args: any[]) => any, C extends ((...args: any[]) => void) | undefined>(fn: T, callback: C): (...args: Parameters<T>) => ReturnType<T> | Promise<ReturnType<T>>;
2
+ //# sourceMappingURL=withCallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withCallback.d.ts","sourceRoot":"","sources":["../../src/helpers/withCallback.ts"],"names":[],"mappings":"AACA,wBAAgB,YAAY,CAC1B,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACjC,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,EAEhD,EAAE,EAAE,CAAC,EACL,QAAQ,EAAE,CAAC,GACV,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAMpE"}
@@ -0,0 +1,12 @@
1
+ import { __awaiter } from '../_virtual/_tslib.js';
2
+
3
+ // Utility to wrap a function and call a callback after the function call
4
+ function withCallback(fn, callback) {
5
+ return (...args) => __awaiter(this, void 0, void 0, function* () {
6
+ const result = yield fn(...args);
7
+ if (callback) callback();
8
+ return result;
9
+ });
10
+ }
11
+
12
+ export { withCallback };
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoConnect.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,cAAc,uBAAwB,OAAO,SAmDzD,CAAC"}
1
+ {"version":3,"file":"useAutoConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoConnect.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,uBAAwB,OAAO,SAwDzD,CAAC"}
@@ -5,6 +5,7 @@ import { useEagerConnect } from './useEagerConnect.js';
5
5
  import { checkTermsAccepted } from '../helpers/checkTermsAccepted.js';
6
6
  import { useReefKnotContext } from './useReefKnotContext.js';
7
7
  import { LS_KEY_RECONNECT_WALLET_ID } from '../constants/localStorage.js';
8
+ import { withCallback } from '../helpers/withCallback.js';
8
9
 
9
10
  const useAutoConnect = autoConnectEnabled => {
10
11
  const {
@@ -20,7 +21,8 @@ const useAutoConnect = autoConnectEnabled => {
20
21
  eagerConnect
21
22
  } = useEagerConnect();
22
23
  const {
23
- walletDataList
24
+ walletDataList,
25
+ onReconnect
24
26
  } = useReefKnotContext();
25
27
  useEffect(() => {
26
28
  const tryReconnect = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -45,7 +47,8 @@ const useAutoConnect = autoConnectEnabled => {
45
47
  // Wait for all EIP-6963 wallets to load their code and fire "eip6963:announceProvider" event
46
48
  // Without the delay, this code can be called from a browser's cache faster than wallet extension code
47
49
  yield new Promise(resolve => setTimeout(resolve, 100));
48
- yield reconnectAsync({
50
+ const reconnectWithCallback = withCallback(reconnectAsync, onReconnect);
51
+ yield reconnectWithCallback({
49
52
  connectors: [createConnectorFn]
50
53
  });
51
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useEagerConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useEagerConnect.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,KAAK,aAAa,GAAG,iBAAiB,CAAC;AAEvC,eAAO,MAAM,cAAc,WACjB,MAAM,YACJ,iBAAiB,EAAE,kBACb,yBAAyB,CAAC,gBAAgB,CAAC,KAC1D,OAAO,CAAC,aAAa,GAAG,IAAI,CA4C9B,CAAC;AAEF,eAAO,MAAM,eAAe;;CAc3B,CAAC"}
1
+ {"version":3,"file":"useEagerConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useEagerConnect.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,KAAK,aAAa,GAAG,iBAAiB,CAAC;AAEvC,eAAO,MAAM,cAAc,WACjB,MAAM,YACJ,iBAAiB,EAAE,kBACb,yBAAyB,CAAC,gBAAgB,CAAC,KAC1D,OAAO,CAAC,aAAa,GAAG,IAAI,CA4C9B,CAAC;AAEF,eAAO,MAAM,eAAe;;CAuB3B,CAAC"}
@@ -56,14 +56,19 @@ const useEagerConnect = () => {
56
56
  openModalAsync
57
57
  } = useReefKnotModal();
58
58
  const {
59
- walletDataList
59
+ walletDataList,
60
+ onAutoConnect
60
61
  } = useReefKnotContext();
61
- const eagerConnect = useCallback(() => {
62
+ const eagerConnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
62
63
  const autoConnectOnlyAdapters = walletDataList.filter(({
63
64
  autoConnectOnly
64
65
  }) => autoConnectOnly);
65
- return connectEagerly(config, autoConnectOnlyAdapters, openModalAsync);
66
- }, [openModalAsync, walletDataList, config]);
66
+ const connectionResult = yield connectEagerly(config, autoConnectOnlyAdapters, openModalAsync);
67
+ if (connectionResult && onAutoConnect) {
68
+ onAutoConnect();
69
+ }
70
+ return connectionResult;
71
+ }), [openModalAsync, walletDataList, config, onAutoConnect]);
67
72
  return {
68
73
  eagerConnect
69
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reef-knot/core-react",
3
- "version": "6.1.0",
3
+ "version": "6.2.0-alpha.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -37,26 +37,26 @@
37
37
  "lint": "eslint --ext ts,tsx,js,mjs ."
38
38
  },
39
39
  "devDependencies": {
40
- "@reef-knot/ledger-connector": "^4.3.0",
41
- "@reef-knot/wallets-list": "^4.1.2",
42
- "@reef-knot/types": "^4.1.0",
43
- "@reef-knot/ui-react": "^2.2.0",
44
- "@reef-knot/wallets-helpers": "^2.2.0",
40
+ "@reef-knot/ledger-connector": "4.4.0-alpha.2",
41
+ "@reef-knot/types": "4.2.0-alpha.1",
42
+ "@reef-knot/ui-react": "2.3.0-alpha.1",
43
+ "@reef-knot/wallets-helpers": "2.3.0-alpha.1",
44
+ "@reef-knot/wallets-list": "4.2.0-alpha.2",
45
45
  "eslint-config-custom": "*",
46
+ "mipd": "0.0.7",
46
47
  "react": "18.2.0",
47
48
  "viem": ">=2.23",
48
- "wagmi": ">=2.14",
49
- "mipd": "0.0.7"
49
+ "wagmi": ">=2.14"
50
50
  },
51
51
  "peerDependencies": {
52
- "@reef-knot/ledger-connector": "^4.1.0",
53
- "@reef-knot/wallets-list": "^4.0.0",
54
- "@reef-knot/types": "^4.0.0",
55
- "@reef-knot/ui-react": "^2.1.3",
56
- "@reef-knot/wallets-helpers": "^2.0.2",
52
+ "@reef-knot/ledger-connector": "4.4.0-alpha.2",
53
+ "@reef-knot/types": "4.2.0-alpha.1",
54
+ "@reef-knot/ui-react": "2.3.0-alpha.1",
55
+ "@reef-knot/wallets-helpers": "2.3.0-alpha.1",
56
+ "@reef-knot/wallets-list": "4.2.0-alpha.2",
57
+ "@tanstack/react-query": "^5.29.0",
57
58
  "react": ">=18",
58
59
  "viem": ">=2.23",
59
- "wagmi": ">=2.14",
60
- "@tanstack/react-query": "^5.29.0"
60
+ "wagmi": ">=2.14"
61
61
  }
62
62
  }