@reef-knot/core-react 4.2.0 → 4.3.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.
- package/dist/context/reefKnot.d.ts +2 -0
- package/dist/context/reefKnot.d.ts.map +1 -1
- package/dist/context/reefKnot.js +6 -3
- package/dist/context/reefKnotModalContext.d.ts.map +1 -1
- package/dist/hooks/useEagerConnect.d.ts +1 -2
- package/dist/hooks/useEagerConnect.d.ts.map +1 -1
- package/dist/hooks/useEagerConnect.js +10 -45
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ export interface ReefKnotContextProps {
|
|
|
10
10
|
export type ReefKnotContextValue = {
|
|
11
11
|
rpc: Record<number, string>;
|
|
12
12
|
walletDataList: WalletAdapterData[];
|
|
13
|
+
loadingWalletId: string | null;
|
|
14
|
+
setLoadingWalletId: React.Dispatch<React.SetStateAction<string | null>>;
|
|
13
15
|
chains: readonly [Chain, ...Chain[]];
|
|
14
16
|
};
|
|
15
17
|
export declare const ReefKnotContext: React.Context<ReefKnotContextValue>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reefKnot.d.ts","sourceRoot":"","sources":["../../src/context/reefKnot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,SAAS,
|
|
1
|
+
{"version":3,"file":"reefKnot.d.ts","sourceRoot":"","sources":["../../src/context/reefKnot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,SAAS,EAAqB,MAAM,OAAO,CAAC;AAE3E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,iBAAiB,EAAE,CAAC;IACpC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;IACrC,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,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kBAAkB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IACxE,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,eAAe,qCAA4C,CAAC;AAEzE,eAAO,MAAM,QAAQ,+CAKlB,oBAAoB,sBAmBtB,CAAC"}
|
package/dist/context/reefKnot.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { createContext, useMemo } from 'react';
|
|
1
|
+
import React, { createContext, useState, useMemo } from 'react';
|
|
2
2
|
import { ReefKnotModalContextProvider } from './reefKnotModalContext.js';
|
|
3
3
|
|
|
4
4
|
const ReefKnotContext = createContext({});
|
|
@@ -8,11 +8,14 @@ const ReefKnot = ({
|
|
|
8
8
|
walletDataList,
|
|
9
9
|
children
|
|
10
10
|
}) => {
|
|
11
|
+
const [loadingWalletId, setLoadingWalletId] = useState(null);
|
|
11
12
|
const contextValue = useMemo(() => ({
|
|
12
13
|
rpc,
|
|
13
14
|
walletDataList,
|
|
14
|
-
chains
|
|
15
|
-
|
|
15
|
+
chains,
|
|
16
|
+
loadingWalletId,
|
|
17
|
+
setLoadingWalletId
|
|
18
|
+
}), [rpc, walletDataList, chains, loadingWalletId]);
|
|
16
19
|
return React.createElement(ReefKnotContext.Provider, {
|
|
17
20
|
value: contextValue
|
|
18
21
|
}, React.createElement(ReefKnotModalContextProvider, null, children));
|
|
@@ -1 +1 @@
|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AAG,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,sBA0DzB,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { WalletAdapterData } from '@reef-knot/types';
|
|
2
|
-
import type { Chain } from 'wagmi/chains';
|
|
3
2
|
import type { Config, ConnectReturnType } from '@wagmi/core';
|
|
4
3
|
import type { ReefKnotModalContextValue } from '../context';
|
|
5
4
|
type ConnectResult = ConnectReturnType;
|
|
6
|
-
export declare const connectEagerly: (config: Config, adapters: WalletAdapterData[], openModalAsync: ReefKnotModalContextValue[
|
|
5
|
+
export declare const connectEagerly: (config: Config, adapters: WalletAdapterData[], openModalAsync: ReefKnotModalContextValue["openModalAsync"]) => Promise<ConnectResult | null>;
|
|
7
6
|
export declare const useEagerConnect: () => {
|
|
8
7
|
eagerConnect: () => Promise<ConnectResult | null>;
|
|
9
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEagerConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useEagerConnect.ts"],"names":[],"mappings":"
|
|
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,YAAY,CAAC;AAE5D,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"}
|
|
@@ -3,53 +3,20 @@ import { useCallback } from 'react';
|
|
|
3
3
|
import { useConfig } from 'wagmi';
|
|
4
4
|
import { useReefKnotContext } from './useReefKnotContext.js';
|
|
5
5
|
import { useReefKnotModal } from './useReefKnotModal.js';
|
|
6
|
-
import { connect
|
|
7
|
-
import { getUnsupportedChainError } from '../helpers/getUnsupportedChainError.js';
|
|
6
|
+
import { connect } from 'wagmi/actions';
|
|
8
7
|
import { checkTermsAccepted } from '../helpers/checkTermsAccepted.js';
|
|
9
8
|
|
|
10
|
-
const
|
|
9
|
+
const connectEagerly = (config, adapters, openModalAsync) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
10
|
var _a;
|
|
12
|
-
const connectResult = yield connect(config, {
|
|
13
|
-
connector
|
|
14
|
-
});
|
|
15
|
-
if (connectResult && supportedChains.findIndex(({
|
|
16
|
-
id
|
|
17
|
-
}) => id === connectResult.chainId) === -1) {
|
|
18
|
-
// No errors during connection, but the chain is unsupported.
|
|
19
|
-
// This case is considered as error for now, and we explicitly call disconnect() here.
|
|
20
|
-
// This logic comes from previously used web3-react connection logic, which wasn't reworked yet after web3-react removal.
|
|
21
|
-
// web3-react logic was: if a chain is unsupported – break the connection, throw an error
|
|
22
|
-
// wagmi logic is: if a chain is unsupported – connect anyway, without errors.
|
|
23
|
-
// So, here we are trying to mimic the legacy logic, because we are not ready to rework it yet.
|
|
24
|
-
const connectError = getUnsupportedChainError(supportedChains);
|
|
25
|
-
yield disconnect(config);
|
|
26
|
-
// A user may change a chain in a wallet app, prepare for that event.
|
|
27
|
-
// There is a strong recommendation in the MetaMask documentation
|
|
28
|
-
// to reload the page upon chain changes, unless there is a good reason not to.
|
|
29
|
-
// This looks like a good general approach.
|
|
30
|
-
if (config.state.current) {
|
|
31
|
-
const activeConnector = (_a = config.state.connections.get(config.state.current)) === null || _a === void 0 ? void 0 : _a.connector;
|
|
32
|
-
if (activeConnector) {
|
|
33
|
-
const provider = yield activeConnector.getProvider();
|
|
34
|
-
provider.once('chainChanged', () => {
|
|
35
|
-
var _a;
|
|
36
|
-
return (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.location.reload();
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
throw connectError;
|
|
41
|
-
}
|
|
42
|
-
return connectResult;
|
|
43
|
-
});
|
|
44
|
-
const connectEagerly = (config, adapters, openModalAsync, supportedChains) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
var _b;
|
|
46
11
|
const isTermsAccepted = checkTermsAccepted();
|
|
47
12
|
for (const adapter of adapters) {
|
|
48
|
-
if (yield (
|
|
13
|
+
if (yield (_a = adapter.detector) === null || _a === void 0 ? void 0 : _a.call(adapter)) {
|
|
49
14
|
// wallet is detected
|
|
50
15
|
let connectionResult = null;
|
|
51
16
|
const tryConnection = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
-
const result = yield
|
|
17
|
+
const result = yield connect(config, {
|
|
18
|
+
connector: adapter.createConnectorFn
|
|
19
|
+
});
|
|
53
20
|
connectionResult = result;
|
|
54
21
|
return result;
|
|
55
22
|
});
|
|
@@ -68,7 +35,7 @@ const connectEagerly = (config, adapters, openModalAsync, supportedChains) => __
|
|
|
68
35
|
try {
|
|
69
36
|
yield tryConnection();
|
|
70
37
|
} catch (e) {
|
|
71
|
-
// when failed open terms modal,allow user to see error and retry
|
|
38
|
+
// when failed, open the terms modal, allow user to see the error and retry the connection
|
|
72
39
|
yield openModalAsync({
|
|
73
40
|
type: 'eager',
|
|
74
41
|
props: {
|
|
@@ -78,7 +45,6 @@ const connectEagerly = (config, adapters, openModalAsync, supportedChains) => __
|
|
|
78
45
|
});
|
|
79
46
|
}
|
|
80
47
|
}
|
|
81
|
-
// TS doesn't know we assigned in tryConnection
|
|
82
48
|
return connectionResult;
|
|
83
49
|
}
|
|
84
50
|
}
|
|
@@ -90,15 +56,14 @@ const useEagerConnect = () => {
|
|
|
90
56
|
openModalAsync
|
|
91
57
|
} = useReefKnotModal();
|
|
92
58
|
const {
|
|
93
|
-
walletDataList
|
|
94
|
-
chains
|
|
59
|
+
walletDataList
|
|
95
60
|
} = useReefKnotContext();
|
|
96
61
|
const eagerConnect = useCallback(() => {
|
|
97
62
|
const autoConnectOnlyAdapters = walletDataList.filter(({
|
|
98
63
|
autoConnectOnly
|
|
99
64
|
}) => autoConnectOnly);
|
|
100
|
-
return connectEagerly(config, autoConnectOnlyAdapters, openModalAsync
|
|
101
|
-
}, [openModalAsync, walletDataList,
|
|
65
|
+
return connectEagerly(config, autoConnectOnlyAdapters, openModalAsync);
|
|
66
|
+
}, [openModalAsync, walletDataList, config]);
|
|
102
67
|
return {
|
|
103
68
|
eagerConnect
|
|
104
69
|
};
|