@reef-knot/core-react 6.2.4 → 7.0.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.
- package/dist/components/AutoConnect.js +7 -7
- package/dist/constants/localStorage.js +5 -9
- package/dist/context/reefKnotContext.js +6 -4
- package/dist/context/reefKnotModalContext.d.ts +1 -1
- package/dist/context/reefKnotModalContext.d.ts.map +1 -1
- package/dist/context/reefKnotModalContext.js +60 -64
- package/dist/context/reefKnotProvider.d.ts +2 -2
- package/dist/context/reefKnotProvider.d.ts.map +1 -1
- package/dist/context/reefKnotProvider.js +20 -22
- package/dist/eip6963.js +4 -2
- package/dist/helpers/checkTermsAccepted.js +6 -7
- package/dist/helpers/getDefaultConfig.js +47 -79
- package/dist/helpers/getUnsupportedChainError.js +10 -16
- package/dist/helpers/getWalletsDataList.js +14 -23
- package/dist/helpers/index.js +6 -0
- package/dist/helpers/providerDetectors.js +7 -8
- package/dist/helpers/useLocalStorage.js +15 -25
- package/dist/helpers/withCallback.js +8 -9
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useAutoConnect.js +32 -60
- package/dist/hooks/useAutoConnectCheck.js +13 -19
- package/dist/hooks/useConnect.js +18 -30
- package/dist/hooks/useConnectorInfo.js +20 -25
- package/dist/hooks/useDisconnect.js +37 -47
- package/dist/hooks/useEagerConnect.js +50 -73
- package/dist/hooks/useReefKnotContext.js +5 -3
- package/dist/hooks/useReefKnotModal.js +8 -6
- package/dist/index.js +22 -18
- package/package.json +21 -19
- package/dist/_virtual/_tslib.js +0 -45
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useAutoConnect } from
|
|
1
|
+
import { useAutoConnect } from "../hooks/useAutoConnect.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return null;
|
|
3
|
+
//#region src/components/AutoConnect.tsx
|
|
4
|
+
const AutoConnect = ({ autoConnect }) => {
|
|
5
|
+
useAutoConnect(autoConnect);
|
|
6
|
+
return null;
|
|
8
7
|
};
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AutoConnect };
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
// Storage key for restoring connector after page refresh
|
|
5
|
-
// `/packages/core-react/src/hooks/useAutoConnect.ts`
|
|
6
|
-
// It keeps association with the reef-knot `WalletAdapterData['walletId']` metadata
|
|
7
|
-
// from the `ReefKnotContextValue['walletDataList']` instead of wagmi's `config.connectors` for better reliability
|
|
8
|
-
const LS_KEY_RECONNECT_WALLET_ID = 'reef-knot_reconnect-wallet-id';
|
|
1
|
+
//#region src/constants/localStorage.ts
|
|
2
|
+
const LS_KEY_TERMS_ACCEPTANCE = "reef-knot_accept-terms_n2";
|
|
3
|
+
const LS_KEY_RECONNECT_WALLET_ID = "reef-knot_reconnect-wallet-id";
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
//#endregion
|
|
6
|
+
export { LS_KEY_RECONNECT_WALLET_ID, LS_KEY_TERMS_ACCEPTANCE };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { createContext } from
|
|
1
|
+
import { createContext } from "react";
|
|
2
2
|
|
|
3
|
+
//#region src/context/reefKnotContext.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
* Context definition is in separated file to avoid circular dependencies
|
|
6
|
+
*/
|
|
6
7
|
const ReefKnotContext = createContext({});
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ReefKnotContext };
|
|
@@ -38,6 +38,6 @@ export type ReefKnotModalContextValue = {
|
|
|
38
38
|
setTermsChecked: (isChecked: boolean) => void;
|
|
39
39
|
};
|
|
40
40
|
export declare const ReefKnotModalContext: React.Context<ReefKnotModalContextValue | null>;
|
|
41
|
-
export declare const ReefKnotModalContextProvider: ({ children, }: React.PropsWithChildren) =>
|
|
41
|
+
export declare const ReefKnotModalContextProvider: ({ children, }: React.PropsWithChildren) => import("react/jsx-runtime").JSX.Element;
|
|
42
42
|
export {};
|
|
43
43
|
//# sourceMappingURL=reefKnotModalContext.d.ts.map
|
|
@@ -1 +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,KAAK,CAAC,iBAAiB,
|
|
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,KAAK,CAAC,iBAAiB,4CA0DzB,CAAC"}
|
|
@@ -1,69 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { useLocalStorage } from "../helpers/useLocalStorage.js";
|
|
2
|
+
import { LS_KEY_TERMS_ACCEPTANCE } from "../constants/localStorage.js";
|
|
3
|
+
import { createContext, useMemo, useState } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
|
|
6
|
+
//#region src/context/reefKnotModalContext.tsx
|
|
6
7
|
const NOOP = () => {};
|
|
7
8
|
const ReefKnotModalContext = createContext(null);
|
|
8
|
-
ReefKnotModalContext.displayName =
|
|
9
|
-
const ReefKnotModalContextProvider = ({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
termsChecked,
|
|
62
|
-
setTermsChecked
|
|
63
|
-
}, stableCallbacks), [stableCallbacks, termsChecked, modalStack, setTermsChecked]);
|
|
64
|
-
return React.createElement(ReefKnotModalContext.Provider, {
|
|
65
|
-
value: contextValue
|
|
66
|
-
}, children);
|
|
9
|
+
ReefKnotModalContext.displayName = "ReefKnotModalContext";
|
|
10
|
+
const ReefKnotModalContextProvider = ({ children }) => {
|
|
11
|
+
const [termsChecked, setTermsChecked] = useLocalStorage(LS_KEY_TERMS_ACCEPTANCE, false);
|
|
12
|
+
const [modalStack, updateModalStack] = useState([]);
|
|
13
|
+
const stableCallbacks = useMemo(() => ({
|
|
14
|
+
openModal: ({ onClose = NOOP, ...props }) => {
|
|
15
|
+
updateModalStack((old) => [...old, {
|
|
16
|
+
...props,
|
|
17
|
+
onClose
|
|
18
|
+
}]);
|
|
19
|
+
},
|
|
20
|
+
openModalAsync: async ({ type, props }) => {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
updateModalStack((old) => [...old, {
|
|
23
|
+
type,
|
|
24
|
+
props,
|
|
25
|
+
onClose: resolve
|
|
26
|
+
}]);
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
closeModal: (result) => {
|
|
30
|
+
updateModalStack((old) => {
|
|
31
|
+
old.pop()?.onClose(result);
|
|
32
|
+
return [...old];
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
forceCloseAllModals: () => {
|
|
36
|
+
updateModalStack((old) => {
|
|
37
|
+
let modal = old.pop();
|
|
38
|
+
while (modal) {
|
|
39
|
+
modal?.onClose({ success: false });
|
|
40
|
+
modal = old.pop();
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}), []);
|
|
46
|
+
const contextValue = useMemo(() => ({
|
|
47
|
+
modalStack,
|
|
48
|
+
currentModal: modalStack[modalStack.length - 1],
|
|
49
|
+
termsChecked,
|
|
50
|
+
setTermsChecked,
|
|
51
|
+
...stableCallbacks
|
|
52
|
+
}), [
|
|
53
|
+
stableCallbacks,
|
|
54
|
+
termsChecked,
|
|
55
|
+
modalStack,
|
|
56
|
+
setTermsChecked
|
|
57
|
+
]);
|
|
58
|
+
return /* @__PURE__ */ jsx(ReefKnotModalContext.Provider, {
|
|
59
|
+
value: contextValue,
|
|
60
|
+
children
|
|
61
|
+
});
|
|
67
62
|
};
|
|
68
63
|
|
|
69
|
-
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ReefKnotModalContext, ReefKnotModalContextProvider };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
import { ReefKnotProviderConfig } from './reefKnotContext';
|
|
3
3
|
export interface ReefKnotProviderProps {
|
|
4
4
|
config: ReefKnotProviderConfig;
|
|
5
5
|
children?: ReactNode;
|
|
6
6
|
}
|
|
7
|
-
export declare const ReefKnotProvider: ({ config, children, }: ReefKnotProviderProps) =>
|
|
7
|
+
export declare const ReefKnotProvider: ({ config, children, }: ReefKnotProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
//# sourceMappingURL=reefKnotProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reefKnotProvider.d.ts","sourceRoot":"","sources":["../../src/context/reefKnotProvider.tsx"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"reefKnotProvider.d.ts","sourceRoot":"","sources":["../../src/context/reefKnotProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAqB,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAmB,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAG5E,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,gBAAgB,0BAG1B,qBAAqB,4CAqBvB,CAAC"}
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ReefKnotModalContextProvider } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { ReefKnotContext } from "./reefKnotContext.js";
|
|
2
|
+
import { ReefKnotModalContextProvider } from "./reefKnotModalContext.js";
|
|
3
|
+
import { AutoConnect } from "../components/AutoConnect.js";
|
|
4
|
+
import { useMemo, useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
value: contextValue
|
|
20
|
-
}, React.createElement(ReefKnotModalContextProvider, null, autoConnect && React.createElement(AutoConnect, {
|
|
21
|
-
autoConnect: true
|
|
22
|
-
}), children));
|
|
7
|
+
//#region src/context/reefKnotProvider.tsx
|
|
8
|
+
const ReefKnotProvider = ({ config, children }) => {
|
|
9
|
+
const [loadingWalletId, setLoadingWalletId] = useState(null);
|
|
10
|
+
const { autoConnect } = config;
|
|
11
|
+
const contextValue = useMemo(() => ({
|
|
12
|
+
...config,
|
|
13
|
+
loadingWalletId,
|
|
14
|
+
setLoadingWalletId
|
|
15
|
+
}), [config, loadingWalletId]);
|
|
16
|
+
return /* @__PURE__ */ jsx(ReefKnotContext.Provider, {
|
|
17
|
+
value: contextValue,
|
|
18
|
+
children: /* @__PURE__ */ jsxs(ReefKnotModalContextProvider, { children: [autoConnect && /* @__PURE__ */ jsx(AutoConnect, { autoConnect: true }), children] })
|
|
19
|
+
});
|
|
23
20
|
};
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ReefKnotProvider };
|
package/dist/eip6963.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { LS_KEY_TERMS_ACCEPTANCE } from
|
|
1
|
+
import { LS_KEY_TERMS_ACCEPTANCE } from "../constants/localStorage.js";
|
|
2
2
|
|
|
3
|
+
//#region src/helpers/checkTermsAccepted.ts
|
|
3
4
|
const checkTermsAccepted = () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return ((_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(LS_KEY_TERMS_ACCEPTANCE)) === 'true';
|
|
7
|
-
}
|
|
8
|
-
return false;
|
|
5
|
+
if (typeof window !== "undefined") return window.localStorage?.getItem(LS_KEY_TERMS_ACCEPTANCE) === "true";
|
|
6
|
+
return false;
|
|
9
7
|
};
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
export { checkTermsAccepted };
|
|
@@ -1,83 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { getWalletsDataList } from './getWalletsDataList.js';
|
|
1
|
+
import { getWalletsDataList } from "./getWalletsDataList.js";
|
|
2
|
+
import { createConfig } from "wagmi";
|
|
3
|
+
import { http } from "viem";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
//#region src/helpers/getDefaultConfig.ts
|
|
6
|
+
const getDefaultTransports = (chains, rpc) => chains.reduce((result, chain) => ({
|
|
7
|
+
...result,
|
|
8
|
+
[chain.id]: http(rpc[chain.id], { batch: true })
|
|
10
9
|
}), {});
|
|
11
|
-
const getDefaultConfig =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const reefKnotConfig = {
|
|
50
|
-
autoConnect,
|
|
51
|
-
walletDataList: walletsDataList,
|
|
52
|
-
onAutoConnect,
|
|
53
|
-
onReconnect
|
|
54
|
-
};
|
|
55
|
-
const wagmiConfig = createConfig(Object.assign({
|
|
56
|
-
chains,
|
|
57
|
-
transports: transports || getDefaultTransports(chains, rpc),
|
|
58
|
-
multiInjectedProviderDiscovery: false
|
|
59
|
-
}, wagmiArgs));
|
|
60
|
-
// TODO: We could use `getDefaultWalletsModalConfig` here, but it cause package dependency cycle rn
|
|
61
|
-
const walletsModalConfig = {
|
|
62
|
-
buttonComponentsByConnectorId,
|
|
63
|
-
walletsShown,
|
|
64
|
-
walletsPinned,
|
|
65
|
-
walletsDisplayInitialCount,
|
|
66
|
-
linkTerms,
|
|
67
|
-
linkPrivacyNotice,
|
|
68
|
-
linkDontHaveWallet,
|
|
69
|
-
onClickTermsAccept,
|
|
70
|
-
onClickWalletsLess,
|
|
71
|
-
onClickWalletsMore,
|
|
72
|
-
onConnectStart,
|
|
73
|
-
onConnectSuccess
|
|
74
|
-
};
|
|
75
|
-
return {
|
|
76
|
-
wagmiConfig,
|
|
77
|
-
reefKnotConfig,
|
|
78
|
-
walletsDataList,
|
|
79
|
-
walletsModalConfig
|
|
80
|
-
};
|
|
10
|
+
const getDefaultConfig = ({ rpc, defaultChain, walletconnectProjectId, walletsList, safeAllowedDomains, chains, transports, autoConnect, onAutoConnect, onReconnect, buttonComponentsByConnectorId, walletsShown, walletsPinned, walletsDisplayInitialCount, linkTerms, linkPrivacyNotice, linkDontHaveWallet, onClickTermsAccept, onClickWalletsLess, onClickWalletsMore, onConnectStart, onConnectSuccess, ...wagmiArgs }) => {
|
|
11
|
+
const { walletsDataList } = getWalletsDataList({
|
|
12
|
+
rpc,
|
|
13
|
+
defaultChain,
|
|
14
|
+
walletsList,
|
|
15
|
+
walletconnectProjectId,
|
|
16
|
+
safeAllowedDomains
|
|
17
|
+
});
|
|
18
|
+
const reefKnotConfig = {
|
|
19
|
+
autoConnect,
|
|
20
|
+
walletDataList: walletsDataList,
|
|
21
|
+
onAutoConnect,
|
|
22
|
+
onReconnect
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
wagmiConfig: createConfig({
|
|
26
|
+
chains,
|
|
27
|
+
transports: transports || getDefaultTransports(chains, rpc),
|
|
28
|
+
multiInjectedProviderDiscovery: false,
|
|
29
|
+
...wagmiArgs
|
|
30
|
+
}),
|
|
31
|
+
reefKnotConfig,
|
|
32
|
+
walletsDataList,
|
|
33
|
+
walletsModalConfig: {
|
|
34
|
+
buttonComponentsByConnectorId,
|
|
35
|
+
walletsShown,
|
|
36
|
+
walletsPinned,
|
|
37
|
+
walletsDisplayInitialCount,
|
|
38
|
+
linkTerms,
|
|
39
|
+
linkPrivacyNotice,
|
|
40
|
+
linkDontHaveWallet,
|
|
41
|
+
onClickTermsAccept,
|
|
42
|
+
onClickWalletsLess,
|
|
43
|
+
onClickWalletsMore,
|
|
44
|
+
onConnectStart,
|
|
45
|
+
onConnectSuccess
|
|
46
|
+
}
|
|
47
|
+
};
|
|
81
48
|
};
|
|
82
49
|
|
|
83
|
-
|
|
50
|
+
//#endregion
|
|
51
|
+
export { getDefaultConfig };
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.filter(chain => chain.id !== 80001).map(({
|
|
10
|
-
name
|
|
11
|
-
}) => name).filter(chainName => chainName !== 'unknown');
|
|
12
|
-
const lastChain = chains.pop();
|
|
13
|
-
return [chains.join(', '), lastChain].filter(chain => chain).join(' or ');
|
|
14
|
-
})();
|
|
15
|
-
return new Error(`Unsupported chain. Please switch to ${supportedChainsNames} in your wallet.`);
|
|
1
|
+
//#region src/helpers/getUnsupportedChainError.ts
|
|
2
|
+
const getUnsupportedChainError = (supportedChains) => {
|
|
3
|
+
const supportedChainsNames = (() => {
|
|
4
|
+
const chains = supportedChains.filter((chain) => chain.id !== 80001).map(({ name }) => name).filter((chainName) => chainName !== "unknown");
|
|
5
|
+
const lastChain = chains.pop();
|
|
6
|
+
return [chains.join(", "), lastChain].filter((chain) => chain).join(" or ");
|
|
7
|
+
})();
|
|
8
|
+
return /* @__PURE__ */ new Error(`Unsupported chain. Please switch to ${supportedChainsNames} in your wallet.`);
|
|
16
9
|
};
|
|
17
10
|
|
|
18
|
-
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getUnsupportedChainError };
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
import { providersStore } from
|
|
1
|
+
import { providersStore } from "../eip6963.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const walletsDataList = walletAdapters.map(walletAdapter => walletAdapter({
|
|
15
|
-
rpc,
|
|
16
|
-
defaultChain,
|
|
17
|
-
walletconnectProjectId,
|
|
18
|
-
safeAllowedDomains,
|
|
19
|
-
providersStore
|
|
20
|
-
}));
|
|
21
|
-
return {
|
|
22
|
-
walletsDataList
|
|
23
|
-
};
|
|
3
|
+
//#region src/helpers/getWalletsDataList.ts
|
|
4
|
+
const getWalletsDataList = ({ walletsList, rpc, defaultChain, walletconnectProjectId, safeAllowedDomains }) => {
|
|
5
|
+
const walletAdapters = Object.values(walletsList);
|
|
6
|
+
if (!rpc[defaultChain.id]) throw "RPC for default chain must be provided";
|
|
7
|
+
return { walletsDataList: walletAdapters.map((walletAdapter) => walletAdapter({
|
|
8
|
+
rpc,
|
|
9
|
+
defaultChain,
|
|
10
|
+
walletconnectProjectId,
|
|
11
|
+
safeAllowedDomains,
|
|
12
|
+
providersStore
|
|
13
|
+
})) };
|
|
24
14
|
};
|
|
25
15
|
|
|
26
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getWalletsDataList };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useLocalStorage } from "./useLocalStorage.js";
|
|
2
|
+
import { checkTermsAccepted } from "./checkTermsAccepted.js";
|
|
3
|
+
import { hasInjected, isDappBrowserProvider } from "./providerDetectors.js";
|
|
4
|
+
import { getUnsupportedChainError } from "./getUnsupportedChainError.js";
|
|
5
|
+
import { getWalletsDataList } from "./getWalletsDataList.js";
|
|
6
|
+
import { getDefaultConfig } from "./getDefaultConfig.js";
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { isMobileOrTablet } from
|
|
2
|
-
import
|
|
1
|
+
import { isMobileOrTablet } from "@reef-knot/wallets-helpers";
|
|
2
|
+
import "viem/window";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return !!((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.ethereum);
|
|
7
|
-
};
|
|
4
|
+
//#region src/helpers/providerDetectors.ts
|
|
5
|
+
const hasInjected = () => !!globalThis.window?.ethereum;
|
|
8
6
|
const isDappBrowserProvider = () => {
|
|
9
|
-
|
|
7
|
+
return isMobileOrTablet && hasInjected();
|
|
10
8
|
};
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
//#endregion
|
|
11
|
+
export { hasInjected, isDappBrowserProvider };
|
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
import { useState } from
|
|
1
|
+
import { useState } from "react";
|
|
2
2
|
|
|
3
|
+
//#region src/helpers/useLocalStorage.ts
|
|
3
4
|
function useLocalStorage(key, initialValue) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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];
|
|
5
|
+
const [storedValue, setStoredValue] = useState(() => {
|
|
6
|
+
let item;
|
|
7
|
+
if (typeof window !== "undefined") item = window.localStorage?.getItem(key);
|
|
8
|
+
return item ? JSON.parse(item) : initialValue;
|
|
9
|
+
});
|
|
10
|
+
const setValue = (value) => {
|
|
11
|
+
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
12
|
+
setStoredValue(valueToStore);
|
|
13
|
+
if (typeof window !== "undefined") window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
14
|
+
};
|
|
15
|
+
return [storedValue, setValue];
|
|
27
16
|
}
|
|
28
17
|
|
|
29
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useLocalStorage };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// Utility to wrap a function and call a callback after the function call
|
|
1
|
+
//#region src/helpers/withCallback.ts
|
|
4
2
|
function withCallback(fn, callback) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
return async (...args) => {
|
|
4
|
+
const result = await fn(...args);
|
|
5
|
+
if (callback) callback();
|
|
6
|
+
return result;
|
|
7
|
+
};
|
|
10
8
|
}
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
//#endregion
|
|
11
|
+
export { withCallback };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useReefKnotContext } from "./useReefKnotContext.js";
|
|
2
|
+
import { useReefKnotModal } from "./useReefKnotModal.js";
|
|
3
|
+
import { connectEagerly, useEagerConnect } from "./useEagerConnect.js";
|
|
4
|
+
import { useAutoConnect } from "./useAutoConnect.js";
|
|
5
|
+
import { useAutoConnectCheck } from "./useAutoConnectCheck.js";
|
|
6
|
+
import { useDisconnect, useForceDisconnect } from "./useDisconnect.js";
|
|
7
|
+
import { useConnectorInfo } from "./useConnectorInfo.js";
|
|
8
|
+
import { useConnect } from "./useConnect.js";
|