@bosonprotocol/react-kit 0.34.0-alpha.20 → 0.34.0-alpha.22
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/cjs/components/config/ConfigContext.d.ts +2 -1
- package/dist/cjs/components/config/ConfigContext.d.ts.map +1 -1
- package/dist/cjs/components/config/ConfigContext.js.map +1 -1
- package/dist/cjs/components/config/ConfigProvider.d.ts.map +1 -1
- package/dist/cjs/components/config/ConfigProvider.js +4 -1
- package/dist/cjs/components/config/ConfigProvider.js.map +1 -1
- package/dist/cjs/components/magicLink/MagicProvider.js +1 -1
- package/dist/cjs/components/magicLink/MagicProvider.js.map +1 -1
- package/dist/cjs/components/magicLink/UserContext.d.ts.map +1 -1
- package/dist/cjs/components/magicLink/UserContext.js +10 -2
- package/dist/cjs/components/magicLink/UserContext.js.map +1 -1
- package/dist/cjs/components/wallet/ConnectButton.d.ts.map +1 -1
- package/dist/cjs/components/wallet/ConnectButton.js +3 -2
- package/dist/cjs/components/wallet/ConnectButton.js.map +1 -1
- package/dist/cjs/components/wallet2/walletModal/index.d.ts +7 -2
- package/dist/cjs/components/wallet2/walletModal/index.d.ts.map +1 -1
- package/dist/cjs/components/wallet2/walletModal/index.js +1 -1
- package/dist/cjs/components/wallet2/walletModal/index.js.map +1 -1
- package/dist/cjs/hooks/connection/connection.d.ts.map +1 -1
- package/dist/cjs/hooks/connection/connection.js +41 -12
- package/dist/cjs/hooks/connection/connection.js.map +1 -1
- package/dist/cjs/hooks/magic.d.ts +4 -4
- package/dist/cjs/hooks/magic.d.ts.map +1 -1
- package/dist/cjs/hooks/magic.js +9 -6
- package/dist/cjs/hooks/magic.js.map +1 -1
- package/dist/cjs/lib/config/config.d.ts.map +1 -1
- package/dist/cjs/lib/config/config.js +0 -3
- package/dist/cjs/lib/config/config.js.map +1 -1
- package/dist/esm/components/config/ConfigContext.d.ts +2 -1
- package/dist/esm/components/config/ConfigContext.d.ts.map +1 -1
- package/dist/esm/components/config/ConfigContext.js.map +1 -1
- package/dist/esm/components/config/ConfigProvider.d.ts.map +1 -1
- package/dist/esm/components/config/ConfigProvider.js +4 -1
- package/dist/esm/components/config/ConfigProvider.js.map +1 -1
- package/dist/esm/components/magicLink/MagicProvider.js +1 -1
- package/dist/esm/components/magicLink/MagicProvider.js.map +1 -1
- package/dist/esm/components/magicLink/UserContext.d.ts.map +1 -1
- package/dist/esm/components/magicLink/UserContext.js +10 -2
- package/dist/esm/components/magicLink/UserContext.js.map +1 -1
- package/dist/esm/components/wallet/ConnectButton.d.ts.map +1 -1
- package/dist/esm/components/wallet/ConnectButton.js +4 -3
- package/dist/esm/components/wallet/ConnectButton.js.map +1 -1
- package/dist/esm/components/wallet2/walletModal/index.d.ts +7 -2
- package/dist/esm/components/wallet2/walletModal/index.d.ts.map +1 -1
- package/dist/esm/components/wallet2/walletModal/index.js +1 -1
- package/dist/esm/components/wallet2/walletModal/index.js.map +1 -1
- package/dist/esm/hooks/connection/connection.d.ts.map +1 -1
- package/dist/esm/hooks/connection/connection.js +41 -12
- package/dist/esm/hooks/connection/connection.js.map +1 -1
- package/dist/esm/hooks/magic.d.ts +4 -4
- package/dist/esm/hooks/magic.d.ts.map +1 -1
- package/dist/esm/hooks/magic.js +9 -6
- package/dist/esm/hooks/magic.js.map +1 -1
- package/dist/esm/lib/config/config.d.ts.map +1 -1
- package/dist/esm/lib/config/config.js +0 -3
- package/dist/esm/lib/config/config.js.map +1 -1
- package/package.json +5 -5
- package/src/components/config/ConfigContext.ts +2 -1
- package/src/components/config/ConfigProvider.tsx +5 -2
- package/src/components/magicLink/MagicProvider.tsx +1 -1
- package/src/components/magicLink/UserContext.tsx +10 -3
- package/src/components/wallet/ConnectButton.tsx +12 -9
- package/src/components/wallet2/walletModal/index.tsx +7 -3
- package/src/hooks/connection/connection.ts +42 -12
- package/src/hooks/magic.ts +9 -6
- package/src/lib/config/config.ts +0 -5
- package/src/stories/widgets/Commit.stories.tsx +2 -1
|
@@ -67,26 +67,36 @@ export function useChainId(): number | undefined {
|
|
|
67
67
|
const {
|
|
68
68
|
withExternalConnectionProps,
|
|
69
69
|
externalConnectedChainId,
|
|
70
|
-
withWeb3React
|
|
70
|
+
withWeb3React,
|
|
71
|
+
withMagicLink
|
|
71
72
|
} = useConfigContext();
|
|
72
73
|
const externalSigner = useExternalSigner();
|
|
73
74
|
const { data: externalSignerChainId } = useExternalSignerChainId();
|
|
74
|
-
const magicChainId = useMagicChainId();
|
|
75
75
|
const isMagicLoggedIn = useIsMagicLoggedIn();
|
|
76
76
|
let networkChainId: number | undefined;
|
|
77
|
+
let magicChainId: number | undefined;
|
|
77
78
|
let error: unknown;
|
|
79
|
+
let magicError: unknown;
|
|
78
80
|
try {
|
|
79
81
|
networkChainId = useNetwork().chain?.id;
|
|
80
82
|
} catch (wagmiError) {
|
|
81
83
|
error = wagmiError; // error if the provider is not there
|
|
82
84
|
}
|
|
85
|
+
try {
|
|
86
|
+
magicChainId = useMagicChainId();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
magicError = error; // error if the provider is not there
|
|
89
|
+
}
|
|
90
|
+
if (!withExternalConnectionProps && magicError && withMagicLink) {
|
|
91
|
+
throw magicError;
|
|
92
|
+
}
|
|
83
93
|
if (externalConnectedChainId) {
|
|
84
94
|
return externalConnectedChainId;
|
|
85
95
|
}
|
|
86
96
|
if (externalSigner) {
|
|
87
97
|
return externalSignerChainId;
|
|
88
98
|
}
|
|
89
|
-
if (isMagicLoggedIn) {
|
|
99
|
+
if (isMagicLoggedIn && withMagicLink) {
|
|
90
100
|
return magicChainId;
|
|
91
101
|
}
|
|
92
102
|
if (web3ReactChainId) {
|
|
@@ -108,32 +118,43 @@ export function useIsConnectedToWrongChain(): boolean {
|
|
|
108
118
|
export function useProvider():
|
|
109
119
|
| providers.JsonRpcProvider
|
|
110
120
|
| providers.FallbackProvider {
|
|
111
|
-
const { withExternalConnectionProps, withWeb3React } =
|
|
121
|
+
const { withExternalConnectionProps, withWeb3React, withMagicLink } =
|
|
122
|
+
useConfigContext();
|
|
112
123
|
const { provider: web3Provider } = useWeb3ReactWrapper() || {};
|
|
113
|
-
let provider;
|
|
124
|
+
let provider, magicProvider;
|
|
114
125
|
let error: unknown;
|
|
115
126
|
try {
|
|
116
127
|
provider = useEthersProvider();
|
|
117
128
|
} catch (wagmiError) {
|
|
118
129
|
error = wagmiError; // error if the provider is not there
|
|
119
130
|
}
|
|
120
|
-
const magicProvider = useMagicProvider();
|
|
121
|
-
const isMagicLoggedIn = useIsMagicLoggedIn();
|
|
122
131
|
if (!withExternalConnectionProps && error && !withWeb3React) {
|
|
123
132
|
throw error;
|
|
124
133
|
}
|
|
134
|
+
try {
|
|
135
|
+
magicProvider = useMagicProvider();
|
|
136
|
+
} catch (magicError) {
|
|
137
|
+
error = magicError; // error if the provider is not there
|
|
138
|
+
}
|
|
139
|
+
if (!withExternalConnectionProps && error && withMagicLink) {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
143
|
+
const magicLinkProvider = magicProvider!; // it should always be not null at this point
|
|
144
|
+
const isMagicLoggedIn = useIsMagicLoggedIn();
|
|
125
145
|
return isMagicLoggedIn
|
|
126
|
-
?
|
|
146
|
+
? magicLinkProvider ?? web3Provider ?? provider
|
|
127
147
|
: withWeb3React
|
|
128
|
-
? web3Provider ??
|
|
129
|
-
: provider ??
|
|
148
|
+
? web3Provider ?? magicLinkProvider ?? provider
|
|
149
|
+
: provider ?? magicLinkProvider ?? web3Provider;
|
|
130
150
|
}
|
|
131
151
|
|
|
132
152
|
export function useSigner(): Signer | undefined {
|
|
133
153
|
const {
|
|
134
154
|
withExternalConnectionProps,
|
|
135
155
|
externalConnectedSigner,
|
|
136
|
-
withWeb3React
|
|
156
|
+
withWeb3React,
|
|
157
|
+
withMagicLink
|
|
137
158
|
} = useConfigContext();
|
|
138
159
|
let wagmiSigner: ReturnType<typeof useEthersSigner>, error: unknown;
|
|
139
160
|
try {
|
|
@@ -142,8 +163,14 @@ export function useSigner(): Signer | undefined {
|
|
|
142
163
|
} catch (wagmiError) {
|
|
143
164
|
error = wagmiError; // error if the provider is not there
|
|
144
165
|
}
|
|
166
|
+
let magicProvider: providers.Web3Provider | undefined, magicError: unknown;
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
magicProvider = useMagicProvider();
|
|
170
|
+
} catch (err) {
|
|
171
|
+
magicError = err; // error if the provider is not there
|
|
172
|
+
}
|
|
145
173
|
const { externalSigner } = useExternalSigner() ?? {};
|
|
146
|
-
const magicProvider = useMagicProvider();
|
|
147
174
|
const isMagicLoggedIn = useIsMagicLoggedIn();
|
|
148
175
|
const { provider: web3Provider } = useWeb3ReactWrapper() || {};
|
|
149
176
|
|
|
@@ -169,6 +196,9 @@ export function useSigner(): Signer | undefined {
|
|
|
169
196
|
if (!withExternalConnectionProps && error && !withWeb3React) {
|
|
170
197
|
throw error;
|
|
171
198
|
}
|
|
199
|
+
if (!withExternalConnectionProps && magicError && withMagicLink) {
|
|
200
|
+
throw magicError;
|
|
201
|
+
}
|
|
172
202
|
return signer;
|
|
173
203
|
}
|
|
174
204
|
|
package/src/hooks/magic.ts
CHANGED
|
@@ -2,13 +2,15 @@ import { useContext } from "react";
|
|
|
2
2
|
import { useQuery } from "react-query";
|
|
3
3
|
import { MagicContext } from "../components/magicLink/MagicContext";
|
|
4
4
|
import { useUser } from "../components/magicLink/UserContext";
|
|
5
|
+
import { useConfigContext } from "../components/config/ConfigContext";
|
|
5
6
|
|
|
6
7
|
export const useMagic = () => {
|
|
8
|
+
const { withMagicLink } = useConfigContext();
|
|
7
9
|
const context = useContext(MagicContext);
|
|
8
|
-
if (!context) {
|
|
10
|
+
if (!context && withMagicLink) {
|
|
9
11
|
throw new Error("useMagic must be used within MagicContext");
|
|
10
12
|
}
|
|
11
|
-
return context
|
|
13
|
+
return context?.magic;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
export const useWalletInfo = () => {
|
|
@@ -23,11 +25,12 @@ export const useWalletInfo = () => {
|
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export function useMagicProvider() {
|
|
28
|
+
const { withMagicLink } = useConfigContext();
|
|
26
29
|
const context = useContext(MagicContext);
|
|
27
|
-
if (!context) {
|
|
30
|
+
if (!context && withMagicLink) {
|
|
28
31
|
throw new Error("useMagic must be used within MagicContext");
|
|
29
32
|
}
|
|
30
|
-
return context
|
|
33
|
+
return context?.magicProvider;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
export function useMagicChainId() {
|
|
@@ -36,7 +39,7 @@ export function useMagicChainId() {
|
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
export function useIsMagicLoggedIn() {
|
|
39
|
-
const
|
|
40
|
-
const isMagicLoggedIn = !!user;
|
|
42
|
+
const userContext = useUser();
|
|
43
|
+
const isMagicLoggedIn = !!userContext?.user;
|
|
41
44
|
return isMagicLoggedIn;
|
|
42
45
|
}
|
package/src/lib/config/config.ts
CHANGED
|
@@ -7,11 +7,6 @@ const magicLinkKey =
|
|
|
7
7
|
import.meta?.env.STORYBOOK_REACT_APP_MAGIC_API_KEY ||
|
|
8
8
|
// @ts-expect-error import.meta.env only exists in vite environments
|
|
9
9
|
import.meta?.env.REACT_APP_MAGIC_API_KEY;
|
|
10
|
-
if (!magicLinkKey) {
|
|
11
|
-
throw new Error(
|
|
12
|
-
"STORYBOOK_REACT_APP_MAGIC_API_KEY/REACT_APP_MAGIC_API_KEY is not defined"
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
10
|
const infuraKey =
|
|
16
11
|
process.env.STORYBOOK_REACT_APP_INFURA_KEY ||
|
|
17
12
|
process.env.REACT_APP_INFURA_KEY ||
|
|
@@ -28,7 +28,8 @@ const BASE_ARGS = {
|
|
|
28
28
|
envName,
|
|
29
29
|
configId: envConfig[0].configId,
|
|
30
30
|
walletConnectProjectId: process.env.REACT_APP_WALLET_CONNECT_PROJECT_ID,
|
|
31
|
-
withCustomReduxContext: false
|
|
31
|
+
withCustomReduxContext: false,
|
|
32
|
+
withMagicLink: true
|
|
32
33
|
} as const;
|
|
33
34
|
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
|
34
35
|
Commit.args = {
|