@reef-knot/core-react 2.1.0 → 3.0.0

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.
Files changed (41) hide show
  1. package/dist/_virtual/_tslib.js +13 -1
  2. package/dist/components/AutoConnect.d.ts +2 -4
  3. package/dist/components/AutoConnect.d.ts.map +1 -1
  4. package/dist/components/AutoConnect.js +1 -3
  5. package/dist/context/index.d.ts +2 -1
  6. package/dist/context/index.d.ts.map +1 -1
  7. package/dist/context/reefKnot.d.ts.map +1 -1
  8. package/dist/context/reefKnot.js +3 -3
  9. package/dist/context/reefKnotModalContext.d.ts +43 -0
  10. package/dist/context/reefKnotModalContext.d.ts.map +1 -0
  11. package/dist/context/reefKnotModalContext.js +69 -0
  12. package/dist/helpers/index.d.ts +1 -0
  13. package/dist/helpers/index.d.ts.map +1 -1
  14. package/dist/helpers/useLocalStorage.d.ts +2 -0
  15. package/dist/helpers/useLocalStorage.d.ts.map +1 -0
  16. package/dist/helpers/useLocalStorage.js +29 -0
  17. package/dist/hooks/index.d.ts +3 -0
  18. package/dist/hooks/index.d.ts.map +1 -1
  19. package/dist/hooks/useAutoConnect.js +2 -5
  20. package/dist/hooks/useAutoConnectCheck.d.ts +4 -0
  21. package/dist/hooks/useAutoConnectCheck.d.ts.map +1 -0
  22. package/dist/hooks/useAutoConnectCheck.js +19 -0
  23. package/dist/hooks/useConnect.d.ts +6 -0
  24. package/dist/hooks/useConnect.d.ts.map +1 -0
  25. package/dist/hooks/useConnect.js +34 -0
  26. package/dist/hooks/useConnectorInfo.d.ts +0 -1
  27. package/dist/hooks/useConnectorInfo.d.ts.map +1 -1
  28. package/dist/hooks/useConnectorInfo.js +2 -3
  29. package/dist/hooks/useDisconnect.d.ts.map +1 -1
  30. package/dist/hooks/useDisconnect.js +8 -10
  31. package/dist/hooks/useEagerConnect.d.ts +3 -9
  32. package/dist/hooks/useEagerConnect.d.ts.map +1 -1
  33. package/dist/hooks/useEagerConnect.js +44 -51
  34. package/dist/hooks/useReefKnotModal.d.ts +2 -0
  35. package/dist/hooks/useReefKnotModal.d.ts.map +1 -0
  36. package/dist/hooks/useReefKnotModal.js +10 -0
  37. package/dist/index.js +5 -1
  38. package/package.json +1 -1
  39. package/dist/context/acceptTermsModal.d.ts +0 -17
  40. package/dist/context/acceptTermsModal.d.ts.map +0 -1
  41. package/dist/context/acceptTermsModal.js +0 -32
@@ -13,6 +13,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
13
  PERFORMANCE OF THIS SOFTWARE.
14
14
  ***************************************************************************** */
15
15
 
16
+ function __rest(s, e) {
17
+ var t = {};
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
19
+ t[p] = s[p];
20
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
21
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
23
+ t[p[i]] = s[p[i]];
24
+ }
25
+ return t;
26
+ }
27
+
16
28
  function __awaiter(thisArg, _arguments, P, generator) {
17
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -28,4 +40,4 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
28
40
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
29
41
  };
30
42
 
31
- export { __awaiter };
43
+ export { __awaiter, __rest };
@@ -1,10 +1,8 @@
1
- import React from 'react';
2
1
  import { Chain } from 'wagmi';
3
2
  import type { WalletAdapterData } from '@reef-knot/types';
4
- export declare const AutoConnect: ({ children, autoConnect, }: {
5
- children: React.ReactNode;
3
+ export declare const AutoConnect: ({ autoConnect, }: {
6
4
  autoConnect: boolean;
7
5
  walletDataList: WalletAdapterData[];
8
6
  chains: Chain[];
9
- }) => React.JSX.Element;
7
+ }) => null;
10
8
  //# sourceMappingURL=AutoConnect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AutoConnect.d.ts","sourceRoot":"","sources":["../../src/components/AutoConnect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,eAAO,MAAM,WAAW;cAIZ,MAAM,SAAS;iBACZ,OAAO;oBACJ,iBAAiB,EAAE;YAC3B,KAAK,EAAE;uBAKhB,CAAC"}
1
+ {"version":3,"file":"AutoConnect.d.ts","sourceRoot":"","sources":["../../src/components/AutoConnect.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,eAAO,MAAM,WAAW;iBAGT,OAAO;oBACJ,iBAAiB,EAAE;YAC3B,KAAK,EAAE;UAIhB,CAAC"}
@@ -1,12 +1,10 @@
1
- import React from 'react';
2
1
  import { useAutoConnect } from '../hooks/useAutoConnect.js';
3
2
 
4
3
  const AutoConnect = ({
5
- children,
6
4
  autoConnect
7
5
  }) => {
8
6
  useAutoConnect(autoConnect);
9
- return React.createElement(React.Fragment, null, children);
7
+ return null;
10
8
  };
11
9
 
12
10
  export { AutoConnect };
@@ -1,3 +1,4 @@
1
1
  export * from './reefKnot';
2
- export * from './acceptTermsModal';
2
+ export { ReefKnotModalContextProvider } from './reefKnotModalContext';
3
+ export type { ReefKnotModalContextValue } from './reefKnotModalContext';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"reefKnot.d.ts","sourceRoot":"","sources":["../../src/context/reefKnot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,EAAE,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAMrC,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,YAAY,EAAE,KAAK,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,cAAc,EAAE,iBAAiB,EAAE,CAAC;IACpC,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,eAAe,qCAA4C,CAAC;AAEzE,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,oBAAoB,CAuC7C,CAAC"}
1
+ {"version":3,"file":"reefKnot.d.ts","sourceRoot":"","sources":["../../src/context/reefKnot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,EAAE,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAMrC,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,YAAY,EAAE,KAAK,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,cAAc,EAAE,iBAAiB,EAAE,CAAC;IACpC,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,eAAe,qCAA4C,CAAC;AAEzE,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,oBAAoB,CAsC7C,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import React, { createContext, useMemo } from 'react';
2
2
  import { WCWarnBannerContextProvider } from '@reef-knot/ui-react';
3
3
  import { getWalletDataList } from '../walletData/index.js';
4
- import { AcceptTermsModalContextProvider } from './acceptTermsModal.js';
5
4
  import { AutoConnect } from '../components/AutoConnect.js';
5
+ import { ReefKnotModalContextProvider } from './reefKnotModalContext.js';
6
6
 
7
7
  const ReefKnotContext = createContext({});
8
8
  const ReefKnot = ({
@@ -26,11 +26,11 @@ const ReefKnot = ({
26
26
  }), [rpc, walletDataList, chains]);
27
27
  return React.createElement(ReefKnotContext.Provider, {
28
28
  value: contextValue
29
- }, React.createElement(AcceptTermsModalContextProvider, null, React.createElement(WCWarnBannerContextProvider, null, React.createElement(AutoConnect, {
29
+ }, React.createElement(ReefKnotModalContextProvider, null, React.createElement(WCWarnBannerContextProvider, null, React.createElement(AutoConnect, {
30
30
  autoConnect: autoConnect,
31
31
  walletDataList: walletDataList,
32
32
  chains: chains
33
- }, children))));
33
+ }), children)));
34
34
  };
35
35
 
36
36
  export { ReefKnot, ReefKnotContext };
@@ -0,0 +1,43 @@
1
+ import React, { ReactNode } from 'react';
2
+ type RequirementsData = {
3
+ icon?: ReactNode;
4
+ title?: string;
5
+ text?: ReactNode;
6
+ };
7
+ type ModalTypes = {
8
+ type: 'wallet' | 'ledger';
9
+ props?: undefined;
10
+ } | {
11
+ type: 'eager';
12
+ props: {
13
+ tryConnection: () => Promise<any>;
14
+ initialError?: Error;
15
+ };
16
+ } | {
17
+ type: 'requirements';
18
+ props: RequirementsData;
19
+ };
20
+ type ModalResult = {
21
+ success: boolean;
22
+ };
23
+ type ModalStateEntry = {
24
+ onClose: (props: ModalResult) => void;
25
+ } & ModalTypes;
26
+ type ModalOpenParams = {
27
+ onClose?: (props: ModalResult) => void;
28
+ } & ModalTypes;
29
+ type AsyncModalOpenParams = Omit<ModalOpenParams, 'onClose'>;
30
+ export type ReefKnotModalContextValue = {
31
+ openModal: (params: ModalOpenParams) => void;
32
+ openModalAsync: (params: AsyncModalOpenParams) => Promise<ModalResult>;
33
+ forceCloseAllModals: () => void;
34
+ closeModal: (result: ModalResult) => void;
35
+ modalStack: ModalStateEntry[];
36
+ currentModal: ModalStateEntry | undefined;
37
+ termsChecked: boolean;
38
+ setTermsChecked: (isChecked: boolean) => void;
39
+ };
40
+ export declare const ReefKnotModalContext: React.Context<ReefKnotModalContextValue | null>;
41
+ export declare const ReefKnotModalContextProvider: ({ children, }: React.PropsWithChildren) => React.JSX.Element;
42
+ export {};
43
+ //# sourceMappingURL=reefKnotModalContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reefKnotModalContext.d.ts","sourceRoot":"","sources":["../../src/context/reefKnotModalContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAC;AAM3E,KAAK,gBAAgB,GAAG;IACtB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,KAAK,UAAU,GACX;IACE,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE;QACL,aAAa,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,YAAY,CAAC,EAAE,KAAK,CAAC;KACtB,CAAC;CACH,GACD;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEN,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CACvC,GAAG,UAAU,CAAC;AAEf,KAAK,eAAe,GAAG;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CACxC,GAAG,UAAU,CAAC;AAEf,KAAK,oBAAoB,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;AAE7D,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;IAC7C,cAAc,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IACvE,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IAC1C,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,YAAY,EAAE,eAAe,GAAG,SAAS,CAAC;IAC1C,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC/C,CAAC;AAIF,eAAO,MAAM,oBAAoB,iDACsB,CAAC;AAGxD,eAAO,MAAM,4BAA4B,kBAEtC,MAAM,iBAAiB,sBA0DzB,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { __rest, __awaiter } from '../_virtual/_tslib.js';
2
+ import React, { createContext, useState, useMemo } from 'react';
3
+ import { useLocalStorage } from '../helpers/useLocalStorage.js';
4
+ import { LS_KEY_TERMS_ACCEPTANCE } from '../constants/localStorage.js';
5
+
6
+ const NOOP = () => {};
7
+ const ReefKnotModalContext = createContext(null);
8
+ ReefKnotModalContext.displayName = 'ReefKnotModalContext';
9
+ const ReefKnotModalContextProvider = ({
10
+ children
11
+ }) => {
12
+ const [termsChecked, setTermsChecked] = useLocalStorage(LS_KEY_TERMS_ACCEPTANCE, false);
13
+ const [modalStack, updateModalStack] = useState([]);
14
+ const stableCallbacks = useMemo(() => ({
15
+ openModal: _a => {
16
+ var {
17
+ onClose = NOOP
18
+ } = _a,
19
+ props = __rest(_a, ["onClose"]);
20
+ updateModalStack(old => [...old, Object.assign(Object.assign({}, props), {
21
+ onClose
22
+ })]);
23
+ },
24
+ openModalAsync: ({
25
+ type,
26
+ props
27
+ }) => __awaiter(void 0, void 0, void 0, function* () {
28
+ return new Promise(resolve => {
29
+ updateModalStack(old => [
30
+ // for some reason TS cannot match type and props here
31
+ ...old, {
32
+ type,
33
+ props: props,
34
+ onClose: resolve
35
+ }]);
36
+ });
37
+ }),
38
+ closeModal: result => {
39
+ updateModalStack(old => {
40
+ const modal = old.pop();
41
+ modal === null || modal === void 0 ? void 0 : modal.onClose(result);
42
+ return [...old];
43
+ });
44
+ },
45
+ forceCloseAllModals: () => {
46
+ updateModalStack(old => {
47
+ let modal = old.pop();
48
+ while (modal) {
49
+ modal === null || modal === void 0 ? void 0 : modal.onClose({
50
+ success: false
51
+ });
52
+ modal = old.pop();
53
+ }
54
+ return [];
55
+ });
56
+ }
57
+ }), []);
58
+ const contextValue = useMemo(() => Object.assign({
59
+ modalStack,
60
+ currentModal: modalStack[modalStack.length - 1],
61
+ termsChecked,
62
+ setTermsChecked
63
+ }, stableCallbacks), [stableCallbacks, termsChecked, modalStack, setTermsChecked]);
64
+ return React.createElement(ReefKnotModalContext.Provider, {
65
+ value: contextValue
66
+ }, children);
67
+ };
68
+
69
+ export { ReefKnotModalContext, ReefKnotModalContextProvider };
@@ -1,4 +1,5 @@
1
1
  export * from './getUnsupportedChainError';
2
2
  export * from './checkTermsAccepted';
3
3
  export * from './userAgents';
4
+ export * from './useLocalStorage';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function useLocalStorage<T>(key: string, initialValue: T): readonly [T, (value: T) => void];
2
+ //# sourceMappingURL=useLocalStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocalStorage.d.ts","sourceRoot":"","sources":["../../src/helpers/useLocalStorage.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,wBAapC,CAAC,WAW3B"}
@@ -0,0 +1,29 @@
1
+ import { useState } from 'react';
2
+
3
+ function useLocalStorage(key, initialValue) {
4
+ // State to store our value
5
+ // Pass initial state function to useState so logic is only executed once
6
+ const [storedValue, setStoredValue] = useState(() => {
7
+ var _a;
8
+ let item;
9
+ if (typeof window !== 'undefined') {
10
+ item = (_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(key);
11
+ }
12
+ // Parse stored json or if none return initialValue
13
+ return item ? JSON.parse(item) : initialValue;
14
+ });
15
+ // Return a wrapped version of useState's setter function that persists the new value to localStorage.
16
+ const setValue = value => {
17
+ // Allow value to be a function, so we have same API as useState
18
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
19
+ // Save state
20
+ setStoredValue(valueToStore);
21
+ // Save to local storage
22
+ if (typeof window !== 'undefined') {
23
+ window.localStorage.setItem(key, JSON.stringify(valueToStore));
24
+ }
25
+ };
26
+ return [storedValue, setValue];
27
+ }
28
+
29
+ export { useLocalStorage };
@@ -1,6 +1,9 @@
1
1
  export * from './useReefKnotContext';
2
2
  export * from './useAutoConnect';
3
+ export * from './useAutoConnectCheck';
3
4
  export * from './useEagerConnect';
4
5
  export * from './useDisconnect';
5
6
  export * from './useConnectorInfo';
7
+ export * from './useConnect';
8
+ export * from './useReefKnotModal';
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
@@ -20,13 +20,10 @@ const useAutoConnect = autoConnectEnabled => {
20
20
  isAutoConnectCalled.current = true;
21
21
  // Try to eagerly connect wallets that are meant to be used only with auto-connection.
22
22
  // For example, wallets with dApp browsers, or using iframes to open dApps.
23
- const {
24
- connectResult,
25
- connectError
26
- } = yield eagerConnect();
23
+ const connectResult = yield eagerConnect();
27
24
  // If still not connected and there were no errors and the terms of service are accepted,
28
25
  // call the default wagmi autoConnect method, which attempts to connect to the last used connector.
29
- if (!connectResult && !connectError && checkTermsAccepted()) {
26
+ if (!connectResult && checkTermsAccepted()) {
30
27
  yield client.autoConnect();
31
28
  }
32
29
  }), [autoConnectEnabled, client, eagerConnect, isConnected]);
@@ -0,0 +1,4 @@
1
+ export declare const useAutoConnectCheck: () => {
2
+ isAutoConnectionSuitable: boolean;
3
+ };
4
+ //# sourceMappingURL=useAutoConnectCheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutoConnectCheck.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoConnectCheck.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;;CAY/B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { useReefKnotContext } from './useReefKnotContext.js';
2
+
3
+ const useAutoConnectCheck = () => {
4
+ const {
5
+ walletDataList
6
+ } = useReefKnotContext();
7
+ const autoConnectOnlyAdapters = walletDataList.filter(({
8
+ autoConnectOnly
9
+ }) => autoConnectOnly);
10
+ const isAutoConnectionSuitable = autoConnectOnlyAdapters.some(adapter => {
11
+ var _a;
12
+ return (_a = adapter.detector) === null || _a === void 0 ? void 0 : _a.call(adapter);
13
+ });
14
+ return {
15
+ isAutoConnectionSuitable
16
+ };
17
+ };
18
+
19
+ export { useAutoConnectCheck };
@@ -0,0 +1,6 @@
1
+ export declare const useConnect: () => {
2
+ connect: () => Promise<{
3
+ success: boolean;
4
+ }>;
5
+ };
6
+ //# sourceMappingURL=useConnect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnect.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU;;;;CActB,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { __awaiter } from '../_virtual/_tslib.js';
2
+ import { useCallback } from 'react';
3
+ import { useAutoConnectCheck } from './useAutoConnectCheck.js';
4
+ import { useEagerConnect } from './useEagerConnect.js';
5
+ import { useReefKnotModal } from './useReefKnotModal.js';
6
+
7
+ const useConnect = () => {
8
+ const {
9
+ openModalAsync
10
+ } = useReefKnotModal();
11
+ const {
12
+ isAutoConnectionSuitable
13
+ } = useAutoConnectCheck();
14
+ const {
15
+ eagerConnect
16
+ } = useEagerConnect();
17
+ const connect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
18
+ if (isAutoConnectionSuitable) {
19
+ const result = yield eagerConnect();
20
+ return {
21
+ success: !!result
22
+ };
23
+ } else {
24
+ return openModalAsync({
25
+ type: 'wallet'
26
+ });
27
+ }
28
+ }), [eagerConnect, openModalAsync, isAutoConnectionSuitable]);
29
+ return {
30
+ connect
31
+ };
32
+ };
33
+
34
+ export { useConnect };
@@ -4,7 +4,6 @@ type ConnectorInfo = {
4
4
  isLedger: boolean;
5
5
  isLedgerLive: boolean;
6
6
  isDappBrowser: boolean;
7
- isAutoConnectionSuitable: boolean;
8
7
  };
9
8
  export declare const useConnectorInfo: () => ConnectorInfo;
10
9
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"useConnectorInfo.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnectorInfo.ts"],"names":[],"mappings":"AAQA,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,wBAAwB,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAO,aAwBnC,CAAC"}
1
+ {"version":3,"file":"useConnectorInfo.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnectorInfo.ts"],"names":[],"mappings":"AAQA,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAO,aAuBnC,CAAC"}
@@ -8,11 +8,11 @@ const useConnectorInfo = () => {
8
8
  const {
9
9
  connector
10
10
  } = useAccount();
11
+ // These checks are working only for connected wallets! There is no connector if a wallet is not connected yet.
11
12
  const isLedger = connector instanceof LedgerHIDConnector;
12
13
  const isLedgerLive = connector instanceof LedgerLiveConnector;
13
14
  const isGnosis = connector instanceof SafeConnector;
14
15
  const isDappBrowser = !!((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.ethereum) && isMobileOrTablet;
15
- const isAutoConnectionSuitable = isLedgerLive || isGnosis || isDappBrowser;
16
16
  let connectorName = connector === null || connector === void 0 ? void 0 : connector.name;
17
17
  // Do not set connector's name if the app is opened in a mobile wallet dapp browser,
18
18
  // because we use a generic injected connector for this case and proper detection is hard.
@@ -23,8 +23,7 @@ const useConnectorInfo = () => {
23
23
  isGnosis,
24
24
  isLedger,
25
25
  isLedgerLive,
26
- isDappBrowser,
27
- isAutoConnectionSuitable
26
+ isDappBrowser
28
27
  };
29
28
  };
30
29
 
@@ -1 +1 @@
1
- {"version":3,"file":"useDisconnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useDisconnect.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB;;CAY9B,CAAC;AAEF,eAAO,MAAM,aAAa;wBACL,IAAI;CAWxB,CAAC"}
1
+ {"version":3,"file":"useDisconnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useDisconnect.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB;;CAU9B,CAAC;AAEF,eAAO,MAAM,aAAa;wBACL,IAAI;CAWxB,CAAC"}
@@ -1,21 +1,19 @@
1
- import { useContext, useCallback } from 'react';
1
+ import { useCallback } from 'react';
2
2
  import { useDisconnect as useDisconnect$1, useAccount } from 'wagmi';
3
- import { useConnectorInfo } from './useConnectorInfo.js';
4
- import { AcceptTermsModalContext } from '../context/acceptTermsModal.js';
3
+ import { useAutoConnectCheck } from './useAutoConnectCheck.js';
4
+ import { useReefKnotModal } from './useReefKnotModal.js';
5
5
 
6
6
  const useForceDisconnect = () => {
7
7
  const {
8
8
  disconnect
9
9
  } = useDisconnect$1();
10
10
  const {
11
- acceptTermsModal: {
12
- setVisible
13
- }
14
- } = useContext(AcceptTermsModalContext);
11
+ forceCloseAllModals
12
+ } = useReefKnotModal();
15
13
  const forceDisconnect = useCallback(() => {
14
+ forceCloseAllModals();
16
15
  disconnect();
17
- setVisible(false);
18
- }, [disconnect, setVisible]);
16
+ }, [disconnect, forceCloseAllModals]);
19
17
  return {
20
18
  forceDisconnect
21
19
  };
@@ -29,7 +27,7 @@ const useDisconnect = () => {
29
27
  } = useDisconnect$1();
30
28
  const {
31
29
  isAutoConnectionSuitable
32
- } = useConnectorInfo();
30
+ } = useAutoConnectCheck();
33
31
  const available = isConnected && !isAutoConnectionSuitable;
34
32
  return {
35
33
  disconnect: available ? disconnect : undefined
@@ -1,15 +1,9 @@
1
1
  import { Chain } from 'wagmi';
2
2
  import type { ConnectResult } from '@wagmi/core';
3
3
  import { WalletAdapterData } from '@reef-knot/types';
4
- import { AcceptTermsModal } from '../context/acceptTermsModal';
5
- export declare const connectEagerly: (adapters: WalletAdapterData[], acceptTermsModal: AcceptTermsModal, supportedChains: Chain[]) => Promise<{
6
- connectResult: ConnectResult | null;
7
- connectError?: Error | undefined;
8
- }>;
4
+ import { ReefKnotModalContextValue } from '../context';
5
+ export declare const connectEagerly: (adapters: WalletAdapterData[], openModalAsync: ReefKnotModalContextValue['openModalAsync'], supportedChains: Chain[]) => Promise<ConnectResult | null>;
9
6
  export declare const useEagerConnect: () => {
10
- eagerConnect: () => Promise<{
11
- connectResult: ConnectResult | null;
12
- connectError?: Error | undefined;
13
- }>;
7
+ eagerConnect: () => Promise<ConnectResult<import("@wagmi/core/dist/index-35b6525c").P> | null>;
14
8
  };
15
9
  //# sourceMappingURL=useEagerConnect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useEagerConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useEagerConnect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EACL,gBAAgB,EAEjB,MAAM,6BAA6B,CAAC;AAqDrC,eAAO,MAAM,cAAc,aACf,iBAAiB,EAAE,oBACX,gBAAgB,mBACjB,KAAK,EAAE;mBAET,aAAa,GAAG,IAAI;;EAgCpC,CAAC;AAEF,eAAO,MAAM,eAAe;;uBAlCX,aAAa,GAAG,IAAI;;;CA8CpC,CAAC"}
1
+ {"version":3,"file":"useEagerConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useEagerConnect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAgCvD,eAAO,MAAM,cAAc,aACf,iBAAiB,EAAE,kBACb,yBAAyB,CAAC,gBAAgB,CAAC,mBAC1C,KAAK,EAAE,KACvB,QAAQ,aAAa,GAAG,IAAI,CA2C9B,CAAC;AAEF,eAAO,MAAM,eAAe;;CAY3B,CAAC"}
@@ -1,23 +1,15 @@
1
1
  import { __awaiter } from '../_virtual/_tslib.js';
2
2
  import { connect, disconnect } from 'wagmi/actions';
3
- import { useContext, useCallback } from 'react';
4
- import { AcceptTermsModalContext } from '../context/acceptTermsModal.js';
3
+ import { useCallback } from 'react';
5
4
  import { getUnsupportedChainError } from '../helpers/getUnsupportedChainError.js';
6
5
  import { checkTermsAccepted } from '../helpers/checkTermsAccepted.js';
7
6
  import { useReefKnotContext } from './useReefKnotContext.js';
7
+ import { useReefKnotModal } from './useReefKnotModal.js';
8
8
 
9
- const connectAndHandleErrors = (connector, supportedChains, acceptTermsModal) => __awaiter(void 0, void 0, void 0, function* () {
10
- var _a, _b, _c, _d;
11
- let connectResult = null;
12
- let connectError;
13
- try {
14
- connectResult = yield connect({
15
- connector
16
- });
17
- } catch (e) {
18
- connectResult = null; // ensure that connectResult is empty in case of an error
19
- connectError = e;
20
- }
9
+ const connectToAdapter = (connector, supportedChains) => __awaiter(void 0, void 0, void 0, function* () {
10
+ const connectResult = yield connect({
11
+ connector
12
+ });
21
13
  if (connectResult === null || connectResult === void 0 ? void 0 : connectResult.chain.unsupported) {
22
14
  // No errors during connection, but the chain is unsupported.
23
15
  // This case is considered as error for now, and we explicitly call disconnect() here.
@@ -25,8 +17,7 @@ const connectAndHandleErrors = (connector, supportedChains, acceptTermsModal) =>
25
17
  // web3-react logic was: if a chain is unsupported – break the connection, throw an error
26
18
  // wagmi logic is: if a chain is unsupported – connect anyway, without errors, set `chain.unsupported` flag to true.
27
19
  // So, here we are trying to mimic the legacy logic, because we are not ready to rework it yet.
28
- connectResult = null;
29
- connectError = getUnsupportedChainError(supportedChains);
20
+ const connectError = getUnsupportedChainError(supportedChains);
30
21
  yield disconnect();
31
22
  // A user may change a chain in a wallet app, prepare for that event.
32
23
  // There is a strong recommendation in the MetaMask documentation
@@ -37,62 +28,64 @@ const connectAndHandleErrors = (connector, supportedChains, acceptTermsModal) =>
37
28
  var _a;
38
29
  return (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.location.reload();
39
30
  });
31
+ throw connectError;
40
32
  }
41
- if (connectError) {
42
- (_a = acceptTermsModal.setError) === null || _a === void 0 ? void 0 : _a.call(acceptTermsModal, connectError);
43
- (_b = acceptTermsModal.setVisible) === null || _b === void 0 ? void 0 : _b.call(acceptTermsModal, true);
44
- } else {
45
- (_c = acceptTermsModal.setVisible) === null || _c === void 0 ? void 0 : _c.call(acceptTermsModal, false);
46
- (_d = acceptTermsModal.setError) === null || _d === void 0 ? void 0 : _d.call(acceptTermsModal, undefined);
47
- }
48
- return {
49
- connectResult,
50
- connectError
51
- };
33
+ return connectResult;
52
34
  });
53
- const connectEagerly = (adapters, acceptTermsModal, supportedChains) => __awaiter(void 0, void 0, void 0, function* () {
54
- var _e, _f, _g;
35
+ const connectEagerly = (adapters, openModalAsync, supportedChains) => __awaiter(void 0, void 0, void 0, function* () {
36
+ var _a;
55
37
  const isTermsAccepted = checkTermsAccepted();
56
- let connectResult = null;
57
- let connectError;
58
- const continueConnection = connector => __awaiter(void 0, void 0, void 0, function* () {
59
- ({
60
- connectResult,
61
- connectError
62
- } = yield connectAndHandleErrors(connector, supportedChains, acceptTermsModal));
63
- });
64
38
  for (const adapter of adapters) {
65
- if ((_e = adapter.detector) === null || _e === void 0 ? void 0 : _e.call(adapter)) {
39
+ if ((_a = adapter.detector) === null || _a === void 0 ? void 0 : _a.call(adapter)) {
66
40
  // wallet is detected
41
+ let connectionResult = null;
42
+ const tryConnection = () => connectToAdapter(adapter.connector, supportedChains).then(result => {
43
+ connectionResult = result;
44
+ return result;
45
+ });
46
+ // if terms are not accepted, show modal and wait for user to try connect from it
67
47
  if (!isTermsAccepted) {
68
48
  // Terms of service were not accepted previously.
69
49
  // So, for legal reasons, we must ask a user to accept the terms before connecting.
70
- const onContinue = () => void continueConnection(adapter.connector);
71
- (_f = acceptTermsModal.setOnContinue) === null || _f === void 0 ? void 0 : _f.call(acceptTermsModal, () => onContinue);
72
- (_g = acceptTermsModal.setVisible) === null || _g === void 0 ? void 0 : _g.call(acceptTermsModal, true);
50
+ yield openModalAsync({
51
+ type: 'eager',
52
+ props: {
53
+ tryConnection
54
+ }
55
+ });
73
56
  } else {
74
- yield continueConnection(adapter.connector);
57
+ // happy path - try connection
58
+ try {
59
+ yield tryConnection();
60
+ } catch (e) {
61
+ // when failed open terms modal,allow user to see error and retry from it
62
+ yield openModalAsync({
63
+ type: 'eager',
64
+ props: {
65
+ tryConnection,
66
+ initialError: e
67
+ }
68
+ });
69
+ }
75
70
  }
76
- break; // no need to iterate over all other adapters if at least one was detected
71
+ // TS doesn't know we assigned in tryConnection
72
+ return connectionResult;
77
73
  }
78
74
  }
79
- return {
80
- connectResult,
81
- connectError
82
- };
75
+ return null;
83
76
  });
84
77
  const useEagerConnect = () => {
85
78
  const {
86
- acceptTermsModal
87
- } = useContext(AcceptTermsModalContext);
79
+ openModalAsync
80
+ } = useReefKnotModal();
88
81
  const {
89
82
  walletDataList,
90
83
  chains
91
84
  } = useReefKnotContext();
92
85
  const autoConnectOnlyAdapters = walletDataList.filter(adapter => adapter.autoConnectOnly);
93
86
  const eagerConnect = useCallback(() => {
94
- return connectEagerly(autoConnectOnlyAdapters, acceptTermsModal, chains);
95
- }, [acceptTermsModal, autoConnectOnlyAdapters, chains]);
87
+ return connectEagerly(autoConnectOnlyAdapters, openModalAsync, chains);
88
+ }, [openModalAsync, autoConnectOnlyAdapters, chains]);
96
89
  return {
97
90
  eagerConnect
98
91
  };
@@ -0,0 +1,2 @@
1
+ export declare const useReefKnotModal: () => import("../context/reefKnotModalContext").ReefKnotModalContextValue;
2
+ //# sourceMappingURL=useReefKnotModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReefKnotModal.d.ts","sourceRoot":"","sources":["../../src/hooks/useReefKnotModal.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,2EAO5B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { useContext } from 'react';
2
+ import { ReefKnotModalContext } from '../context/reefKnotModalContext.js';
3
+
4
+ const useReefKnotModal = () => {
5
+ const value = useContext(ReefKnotModalContext);
6
+ if (!value) throw new Error('useReefKnotModal was called outside of the ReefKnotModalContext');
7
+ return value;
8
+ };
9
+
10
+ export { useReefKnotModal };
package/dist/index.js CHANGED
@@ -1,13 +1,17 @@
1
1
  export { getConnectors, getWalletDataList } from './walletData/index.js';
2
2
  export { useReefKnotContext } from './hooks/useReefKnotContext.js';
3
3
  export { useAutoConnect } from './hooks/useAutoConnect.js';
4
+ export { useAutoConnectCheck } from './hooks/useAutoConnectCheck.js';
4
5
  export { connectEagerly, useEagerConnect } from './hooks/useEagerConnect.js';
5
6
  export { useDisconnect, useForceDisconnect } from './hooks/useDisconnect.js';
6
7
  export { useConnectorInfo } from './hooks/useConnectorInfo.js';
8
+ export { useConnect } from './hooks/useConnect.js';
9
+ export { useReefKnotModal } from './hooks/useReefKnotModal.js';
7
10
  export { ReefKnot, ReefKnotContext } from './context/reefKnot.js';
8
- export { AcceptTermsModalContext, AcceptTermsModalContextProvider } from './context/acceptTermsModal.js';
11
+ export { ReefKnotModalContextProvider } from './context/reefKnotModalContext.js';
9
12
  export { LS_KEY_TERMS_ACCEPTANCE } from './constants/localStorage.js';
10
13
  export { holesky } from './chains/holesky.js';
11
14
  export { getUnsupportedChainError } from './helpers/getUnsupportedChainError.js';
12
15
  export { checkTermsAccepted } from './helpers/checkTermsAccepted.js';
13
16
  export { browser, device, isMobile, isMobileOrTablet, isTablet, os } from './helpers/userAgents.js';
17
+ export { useLocalStorage } from './helpers/useLocalStorage.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reef-knot/core-react",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -1,17 +0,0 @@
1
- import React from 'react';
2
- export type AcceptTermsModal = {
3
- isVisible: boolean;
4
- setVisible: React.Dispatch<React.SetStateAction<boolean>>;
5
- onContinue: () => void;
6
- setOnContinue: React.Dispatch<React.SetStateAction<() => void>>;
7
- error?: Error;
8
- setError: React.Dispatch<React.SetStateAction<Error | undefined>>;
9
- };
10
- export type AcceptTermsModalContextValue = {
11
- acceptTermsModal: AcceptTermsModal;
12
- };
13
- export declare const AcceptTermsModalContext: React.Context<AcceptTermsModalContextValue>;
14
- export declare const AcceptTermsModalContextProvider: ({ children, }: {
15
- children: React.ReactNode;
16
- }) => React.JSX.Element;
17
- //# sourceMappingURL=acceptTermsModal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"acceptTermsModal.d.ts","sourceRoot":"","sources":["../../src/context/acceptTermsModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IAChE,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;CACnE,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,CAAC;AAKF,eAAO,MAAM,uBAAuB,6CAKF,CAAC;AAEnC,eAAO,MAAM,+BAA+B;cAGhC,MAAM,SAAS;uBA+B1B,CAAC"}
@@ -1,32 +0,0 @@
1
- import React, { createContext, useState, useMemo } from 'react';
2
-
3
- const isVisibleDefaultValue = false;
4
- const onContinueDefaultValue = () => void 0;
5
- const AcceptTermsModalContext = createContext({
6
- acceptTermsModal: {
7
- isVisible: isVisibleDefaultValue,
8
- onContinue: onContinueDefaultValue
9
- }
10
- });
11
- const AcceptTermsModalContextProvider = ({
12
- children
13
- }) => {
14
- const [isAcceptTermsModalVisible, setIsAcceptTermsModalVisible] = useState(isVisibleDefaultValue);
15
- const [onAcceptTermsModalContinue, setOnAcceptTermsModalContinue] = useState(() => onContinueDefaultValue);
16
- const [error, setError] = useState(undefined);
17
- const contextValue = useMemo(() => ({
18
- acceptTermsModal: {
19
- isVisible: isAcceptTermsModalVisible,
20
- setVisible: setIsAcceptTermsModalVisible,
21
- onContinue: onAcceptTermsModalContinue,
22
- setOnContinue: setOnAcceptTermsModalContinue,
23
- error,
24
- setError
25
- }
26
- }), [error, isAcceptTermsModalVisible, onAcceptTermsModalContinue]);
27
- return React.createElement(AcceptTermsModalContext.Provider, {
28
- value: contextValue
29
- }, children);
30
- };
31
-
32
- export { AcceptTermsModalContext, AcceptTermsModalContextProvider };