@dynamic-labs/sdk-react-core 0.16.20 → 0.16.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/CHANGELOG.md +13 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +4 -4
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.cjs +17 -8
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.js +17 -8
- package/src/lib/context/DynamicContext/DynamicContext.cjs +4 -3
- package/src/lib/context/DynamicContext/DynamicContext.js +4 -3
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +9 -2
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +3 -3
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +9 -2
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +23 -68
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.d.ts +2 -1
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +24 -69
- package/src/lib/utils/hooks/useWalletConnectors/utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.cjs +52 -0
- package/src/lib/utils/hooks/useWalletConnectors/utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.d.ts +8 -0
- package/src/lib/utils/hooks/useWalletConnectors/utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.js +48 -0
- package/src/lib/utils/hooks/useWalletConnectors/utils/createLinkedWalletsFromWalletOptions/index.d.ts +1 -0
- package/src/lib/utils/hooks/useWalletConnectors/utils/index.d.ts +2 -0
- package/src/lib/utils/hooks/useWalletConnectors/utils/primaryWalletIdValidator/index.d.ts +1 -0
- package/src/lib/utils/hooks/useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.cjs +7 -0
- package/src/lib/utils/hooks/useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.d.ts +1 -0
- package/src/lib/utils/hooks/useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.js +3 -0
- package/src/lib/utils/hooks/useWallets/useWallets.cjs +25 -30
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +1 -2
- package/src/lib/utils/hooks/useWallets/useWallets.js +26 -31
- package/src/lib/utils/hooks/useWalletsConnectionState/index.d.ts +1 -0
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.cjs +38 -0
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.d.ts +11 -0
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.js +34 -0
- package/src/lib/views/WalletList/data.cjs +4 -5
- package/src/lib/views/WalletList/data.d.ts +2 -2
- package/src/lib/views/WalletList/data.js +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
|
|
2
|
+
### [0.16.22](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.21...v0.16.22) (2023-06-06)
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* load primary wallet on first render ([#2263](https://github.com/dynamic-labs/DynamicAuth/pull/2263)) ([8079097](https://github.com/dynamic-labs/DynamicAuth/commit/8079097ade98ab3e302d14dc971792531cd2286d))
|
|
7
|
+
*
|
|
8
|
+
### [0.16.21](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.20...v0.16.21) (2023-06-05)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* disable button on social unlink ([#2247](https://github.com/dynamic-labs/DynamicAuth/issues/2247)) ([e74a53c](https://github.com/dynamic-labs/DynamicAuth/commit/e74a53c947fdbeca66144b65dc6babdd449c9240))
|
|
14
|
+
|
|
2
15
|
### [0.16.20](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.19...v0.16.20) (2023-06-02)
|
|
3
16
|
|
|
4
17
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.22",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"formik": "^2.2.9",
|
|
18
18
|
"qrcode": "1.5.1",
|
|
19
19
|
"ethers": "^5.7.2",
|
|
20
|
-
"@dynamic-labs/logger": "0.16.
|
|
21
|
-
"@dynamic-labs/multi-wallet": "0.16.
|
|
22
|
-
"@dynamic-labs/wallet-connector-core": "0.16.
|
|
20
|
+
"@dynamic-labs/logger": "0.16.22",
|
|
21
|
+
"@dynamic-labs/multi-wallet": "0.16.22",
|
|
22
|
+
"@dynamic-labs/wallet-connector-core": "0.16.22"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"semver": "^7.3.8"
|
package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.cjs
CHANGED
|
@@ -8,7 +8,7 @@ var React = require('react');
|
|
|
8
8
|
var iconic = require('@dynamic-labs/iconic');
|
|
9
9
|
var Typography = require('../../../Typography/Typography.cjs');
|
|
10
10
|
require('@dynamic-labs/sdk-api');
|
|
11
|
-
require('../../../../shared/logger.cjs');
|
|
11
|
+
var logger = require('../../../../shared/logger.cjs');
|
|
12
12
|
require('@dynamic-labs/multi-wallet');
|
|
13
13
|
require('../../../../context/ViewContext/ViewContext.cjs');
|
|
14
14
|
var add = require('../../../../shared/assets/add.cjs');
|
|
@@ -71,14 +71,23 @@ const UserProfileSocialAccount = ({ provider, authorizationUrl, verifiedCredenti
|
|
|
71
71
|
};
|
|
72
72
|
const disconnectAccount = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
73
73
|
var _c;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
try {
|
|
75
|
+
setLoading(true);
|
|
76
|
+
const jwt = yield api.unlinkOAuth({
|
|
77
|
+
environmentId,
|
|
78
|
+
verifiedCrentialId: (_c = verifiedCredential === null || verifiedCredential === void 0 ? void 0 : verifiedCredential.id) !== null && _c !== void 0 ? _c : '',
|
|
79
|
+
}, String(authToken || onboardingOnlyJwt));
|
|
80
|
+
if (!jwt) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
updateUserProfileByJWT(jwt);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
logger.logger.error(err);
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
setLoading(false);
|
|
80
90
|
}
|
|
81
|
-
updateUserProfileByJWT(jwt);
|
|
82
91
|
});
|
|
83
92
|
if (!verifiedCredential && !authorizationUrl) {
|
|
84
93
|
return null;
|
package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.js
CHANGED
|
@@ -4,7 +4,7 @@ import { useState } from 'react';
|
|
|
4
4
|
import { SocialIcon } from '@dynamic-labs/iconic';
|
|
5
5
|
import { Typography } from '../../../Typography/Typography.js';
|
|
6
6
|
import '@dynamic-labs/sdk-api';
|
|
7
|
-
import '../../../../shared/logger.js';
|
|
7
|
+
import { logger } from '../../../../shared/logger.js';
|
|
8
8
|
import '@dynamic-labs/multi-wallet';
|
|
9
9
|
import '../../../../context/ViewContext/ViewContext.js';
|
|
10
10
|
import { ReactComponent as SvgAdd } from '../../../../shared/assets/add.js';
|
|
@@ -67,14 +67,23 @@ const UserProfileSocialAccount = ({ provider, authorizationUrl, verifiedCredenti
|
|
|
67
67
|
};
|
|
68
68
|
const disconnectAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
69
|
var _c;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
try {
|
|
71
|
+
setLoading(true);
|
|
72
|
+
const jwt = yield unlinkOAuth({
|
|
73
|
+
environmentId,
|
|
74
|
+
verifiedCrentialId: (_c = verifiedCredential === null || verifiedCredential === void 0 ? void 0 : verifiedCredential.id) !== null && _c !== void 0 ? _c : '',
|
|
75
|
+
}, String(authToken || onboardingOnlyJwt));
|
|
76
|
+
if (!jwt) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
updateUserProfileByJWT(jwt);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
logger.error(err);
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
setLoading(false);
|
|
76
86
|
}
|
|
77
|
-
updateUserProfileByJWT(jwt);
|
|
78
87
|
});
|
|
79
88
|
if (!verifiedCredential && !authorizationUrl) {
|
|
80
89
|
return null;
|
|
@@ -112,7 +112,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
|
|
|
112
112
|
localStorage.removeItem(localStorage$1.AUTH_TOKEN);
|
|
113
113
|
removeUser();
|
|
114
114
|
}, [removeUser]);
|
|
115
|
-
const {
|
|
115
|
+
const { clearPrimaryWalletId, computeConnectedStateForWallets, didConnectedStateLoad, walletConnectors, primaryWallet, primaryWalletId, showQrcodeModal, secondaryWallets, setPrimaryWallet, setPrimaryWalletId, setShowQrcodeModal, } = useWalletConnectors.useWalletConnectors({
|
|
116
116
|
authToken: getAuthToken.getAuthToken() || onboardingOnlyJwt,
|
|
117
117
|
multiWalletWidgetState,
|
|
118
118
|
setDesktopUri,
|
|
@@ -130,6 +130,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
|
|
|
130
130
|
});
|
|
131
131
|
const walletForUserFacingContext = authMode === 'connect-and-sign' || user ? primaryWallet : connectedWallet;
|
|
132
132
|
useSyncPrimaryWallet.useSyncPrimaryWallet({
|
|
133
|
+
canSync: didConnectedStateLoad,
|
|
133
134
|
multiWalletWidgetState,
|
|
134
135
|
primaryWallet,
|
|
135
136
|
setMultiWalletWidgetState,
|
|
@@ -159,7 +160,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
|
|
|
159
160
|
removeLsNetworks();
|
|
160
161
|
setOnboardingOnlyJwt(undefined);
|
|
161
162
|
removeConnectedInfo();
|
|
162
|
-
|
|
163
|
+
clearPrimaryWalletId();
|
|
163
164
|
(_f = eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onLogout) === null || _f === void 0 ? void 0 : _f.call(eventsCallbacks, user);
|
|
164
165
|
}), [
|
|
165
166
|
clearAllWalletConnectSessions,
|
|
@@ -170,7 +171,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
|
|
|
170
171
|
setConnectedWallet,
|
|
171
172
|
removeLsNetworks,
|
|
172
173
|
removeConnectedInfo,
|
|
173
|
-
|
|
174
|
+
clearPrimaryWalletId,
|
|
174
175
|
eventsCallbacks,
|
|
175
176
|
environmentId,
|
|
176
177
|
walletConnectors,
|
|
@@ -108,7 +108,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
|
|
|
108
108
|
localStorage.removeItem(AUTH_TOKEN);
|
|
109
109
|
removeUser();
|
|
110
110
|
}, [removeUser]);
|
|
111
|
-
const {
|
|
111
|
+
const { clearPrimaryWalletId, computeConnectedStateForWallets, didConnectedStateLoad, walletConnectors, primaryWallet, primaryWalletId, showQrcodeModal, secondaryWallets, setPrimaryWallet, setPrimaryWalletId, setShowQrcodeModal, } = useWalletConnectors({
|
|
112
112
|
authToken: getAuthToken() || onboardingOnlyJwt,
|
|
113
113
|
multiWalletWidgetState,
|
|
114
114
|
setDesktopUri,
|
|
@@ -126,6 +126,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
|
|
|
126
126
|
});
|
|
127
127
|
const walletForUserFacingContext = authMode === 'connect-and-sign' || user ? primaryWallet : connectedWallet;
|
|
128
128
|
useSyncPrimaryWallet({
|
|
129
|
+
canSync: didConnectedStateLoad,
|
|
129
130
|
multiWalletWidgetState,
|
|
130
131
|
primaryWallet,
|
|
131
132
|
setMultiWalletWidgetState,
|
|
@@ -155,7 +156,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
|
|
|
155
156
|
removeLsNetworks();
|
|
156
157
|
setOnboardingOnlyJwt(undefined);
|
|
157
158
|
removeConnectedInfo();
|
|
158
|
-
|
|
159
|
+
clearPrimaryWalletId();
|
|
159
160
|
(_f = eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onLogout) === null || _f === void 0 ? void 0 : _f.call(eventsCallbacks, user);
|
|
160
161
|
}), [
|
|
161
162
|
clearAllWalletConnectSessions,
|
|
@@ -166,7 +167,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
|
|
|
166
167
|
setConnectedWallet,
|
|
167
168
|
removeLsNetworks,
|
|
168
169
|
removeConnectedInfo,
|
|
169
|
-
|
|
170
|
+
clearPrimaryWalletId,
|
|
170
171
|
eventsCallbacks,
|
|
171
172
|
environmentId,
|
|
172
173
|
walletConnectors,
|
|
@@ -5,8 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var multiWallet = require('@dynamic-labs/multi-wallet');
|
|
7
7
|
|
|
8
|
-
const useSyncPrimaryWallet = ({ primaryWallet, setMultiWalletWidgetState, multiWalletWidgetState, }) => {
|
|
8
|
+
const useSyncPrimaryWallet = ({ primaryWallet, setMultiWalletWidgetState, multiWalletWidgetState, canSync = true, }) => {
|
|
9
9
|
React.useEffect(() => {
|
|
10
|
+
if (!canSync)
|
|
11
|
+
return;
|
|
10
12
|
if (!primaryWallet || multiWalletWidgetState !== 'idle')
|
|
11
13
|
return;
|
|
12
14
|
if (primaryWallet.connector.connectedChain === 'FLOW')
|
|
@@ -25,7 +27,12 @@ const useSyncPrimaryWallet = ({ primaryWallet, setMultiWalletWidgetState, multiW
|
|
|
25
27
|
.catch(() => {
|
|
26
28
|
setMultiWalletWidgetState('awaiting_account_switch', 'primary_not_connected');
|
|
27
29
|
});
|
|
28
|
-
}, [
|
|
30
|
+
}, [
|
|
31
|
+
primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.id,
|
|
32
|
+
setMultiWalletWidgetState,
|
|
33
|
+
multiWalletWidgetState,
|
|
34
|
+
canSync,
|
|
35
|
+
]);
|
|
29
36
|
};
|
|
30
37
|
|
|
31
38
|
exports.useSyncPrimaryWallet = useSyncPrimaryWallet;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MultiWalletWidgetState, Wallet } from '../../../../shared/types';
|
|
2
2
|
import { MultiWalletWidgetStateSetter } from '../useMultiWalletWidgetState';
|
|
3
|
-
type UseSyncPrimaryWalletArgs = {
|
|
3
|
+
export type UseSyncPrimaryWalletArgs = {
|
|
4
|
+
canSync?: boolean;
|
|
4
5
|
multiWalletWidgetState: MultiWalletWidgetState;
|
|
5
6
|
primaryWallet: Wallet | null;
|
|
6
7
|
setMultiWalletWidgetState: MultiWalletWidgetStateSetter;
|
|
7
8
|
};
|
|
8
|
-
export declare const useSyncPrimaryWallet: ({ primaryWallet, setMultiWalletWidgetState, multiWalletWidgetState, }: UseSyncPrimaryWalletArgs) => void;
|
|
9
|
-
export {};
|
|
9
|
+
export declare const useSyncPrimaryWallet: ({ primaryWallet, setMultiWalletWidgetState, multiWalletWidgetState, canSync, }: UseSyncPrimaryWalletArgs) => void;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { isSameAddress } from '@dynamic-labs/multi-wallet';
|
|
3
3
|
|
|
4
|
-
const useSyncPrimaryWallet = ({ primaryWallet, setMultiWalletWidgetState, multiWalletWidgetState, }) => {
|
|
4
|
+
const useSyncPrimaryWallet = ({ primaryWallet, setMultiWalletWidgetState, multiWalletWidgetState, canSync = true, }) => {
|
|
5
5
|
useEffect(() => {
|
|
6
|
+
if (!canSync)
|
|
7
|
+
return;
|
|
6
8
|
if (!primaryWallet || multiWalletWidgetState !== 'idle')
|
|
7
9
|
return;
|
|
8
10
|
if (primaryWallet.connector.connectedChain === 'FLOW')
|
|
@@ -21,7 +23,12 @@ const useSyncPrimaryWallet = ({ primaryWallet, setMultiWalletWidgetState, multiW
|
|
|
21
23
|
.catch(() => {
|
|
22
24
|
setMultiWalletWidgetState('awaiting_account_switch', 'primary_not_connected');
|
|
23
25
|
});
|
|
24
|
-
}, [
|
|
26
|
+
}, [
|
|
27
|
+
primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.id,
|
|
28
|
+
setMultiWalletWidgetState,
|
|
29
|
+
multiWalletWidgetState,
|
|
30
|
+
canSync,
|
|
31
|
+
]);
|
|
25
32
|
};
|
|
26
33
|
|
|
27
34
|
export { useSyncPrimaryWallet };
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var multiWallet = require('@dynamic-labs/multi-wallet');
|
|
8
|
-
|
|
8
|
+
require('@dynamic-labs/sdk-api');
|
|
9
9
|
var logger = require('../../../shared/logger.cjs');
|
|
10
10
|
require('@dynamic-labs/iconic');
|
|
11
11
|
require('react/jsx-runtime');
|
|
@@ -14,80 +14,34 @@ var localStorage$1 = require('../../constants/localStorage.cjs');
|
|
|
14
14
|
require('../../constants/colors.cjs');
|
|
15
15
|
var useLocalStorage = require('../../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
|
|
16
16
|
require('../../../shared/consts/index.cjs');
|
|
17
|
-
var isWalletConnected = require('../../functions/isWalletConnected/isWalletConnected.cjs');
|
|
18
17
|
var isSameWalletName = require('../../functions/isSameWalletName/isSameWalletName.cjs');
|
|
19
|
-
require('
|
|
20
|
-
var
|
|
18
|
+
var useWalletsConnectionState = require('../useWalletsConnectionState/useWalletsConnectionState.cjs');
|
|
19
|
+
var primaryWalletIdValidator = require('./utils/primaryWalletIdValidator/primaryWalletIdValidator.cjs');
|
|
20
|
+
var createLinkedWalletsFromWalletOptions = require('./utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.cjs');
|
|
21
21
|
|
|
22
22
|
const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, }) => {
|
|
23
23
|
const [showQrcodeModal, setShowQrcodeModal] = React.useState(false);
|
|
24
|
-
const [
|
|
25
|
-
const
|
|
24
|
+
const [primaryWalletId, setPrimaryWalletIdState, clearPrimaryWalletId] = useLocalStorage.useLocalStorage(localStorage$1.PRIMARY_WALLET_ID, undefined, primaryWalletIdValidator.primaryWalletIdValidator);
|
|
25
|
+
const linkedWallets = React.useMemo(() => {
|
|
26
|
+
if (!authToken) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
return createLinkedWalletsFromWalletOptions.createLinkedWalletsFromWalletOptions({
|
|
30
|
+
authToken,
|
|
31
|
+
primaryWalletId,
|
|
32
|
+
walletOptions: availableWallets,
|
|
33
|
+
});
|
|
34
|
+
}, [availableWallets, primaryWalletId, authToken]);
|
|
35
|
+
const { connectedWalletMap, computeConnectedStateForWallets, didConnectedStateLoad, } = useWalletsConnectionState.useWalletsConnectionState(linkedWallets);
|
|
36
|
+
const wallets = React.useMemo(() => linkedWallets.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, linkedWallets]);
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
computeConnectedStateForWallets();
|
|
39
|
+
}, [primaryWalletId, computeConnectedStateForWallets]);
|
|
26
40
|
const setPrimaryWalletId = React.useCallback((walletId) => {
|
|
27
41
|
setPrimaryWalletIdState(walletId);
|
|
28
42
|
}, [setPrimaryWalletIdState]);
|
|
29
|
-
const
|
|
30
|
-
setWallets([]);
|
|
31
|
-
clearPrimaryWalletId();
|
|
32
|
-
}, [clearPrimaryWalletId]);
|
|
33
|
-
const getPrimaryWallet = React.useCallback(() => {
|
|
34
|
-
const primaryWallet = wallets.find((wallet) => wallet.id === primaryWalletId);
|
|
35
|
-
if (!primaryWallet) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return primaryWallet;
|
|
39
|
-
}, [primaryWalletId, wallets]);
|
|
43
|
+
const getPrimaryWallet = React.useCallback(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
|
|
40
44
|
const getSecondaryWallets = React.useCallback(() => wallets.filter((wallet) => wallet.id !== primaryWalletId), [primaryWalletId, wallets]);
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
const decodedJwt = decodeJwt.decodeJwt(authToken);
|
|
43
|
-
// wallet state should be null while loading all the wallets or when there is no user
|
|
44
|
-
if (!availableWallets || !decodedJwt) {
|
|
45
|
-
setWallets([]);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
Promise.all(decodedJwt.verifiedCredentials.map((account) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
-
const wallet = availableWallets.find((wallet) => account.walletName &&
|
|
50
|
-
isSameWalletName.isSameWalletName(wallet.name, account.walletName));
|
|
51
|
-
// this probably shouldn't happen. this would mean that the user has an account linked
|
|
52
|
-
// with wallet W, but the customer has toggled off wallet W or the chain that
|
|
53
|
-
// supports wallet W
|
|
54
|
-
/* istanbul ignore next */
|
|
55
|
-
if (!wallet)
|
|
56
|
-
return null;
|
|
57
|
-
// this is here because phantom fires a disconnect event on page load,
|
|
58
|
-
// and other wallets and chains have similar issues
|
|
59
|
-
if (account.id === primaryWalletId &&
|
|
60
|
-
shouldManuallyReconnectOnRefresh.shouldManuallyReconnectOnRefresh(wallet.walletConnector)) {
|
|
61
|
-
yield wallet.walletConnector.connect();
|
|
62
|
-
}
|
|
63
|
-
if (account.address && account.chain) {
|
|
64
|
-
return {
|
|
65
|
-
address: account.address,
|
|
66
|
-
chain: account.chain,
|
|
67
|
-
connected: yield isWalletConnected.isWalletConnected({
|
|
68
|
-
address: account.address,
|
|
69
|
-
chain: account.chain,
|
|
70
|
-
connector: wallet.walletConnector,
|
|
71
|
-
}),
|
|
72
|
-
connector: wallet.walletConnector,
|
|
73
|
-
id: account.id,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
}))).then((result) => {
|
|
78
|
-
setWallets(result.filter((wc) => wc !== null));
|
|
79
|
-
return null;
|
|
80
|
-
});
|
|
81
|
-
}, [availableWallets, primaryWalletId, authToken]);
|
|
82
|
-
const computeConnectedStateForWallets = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
-
if (!primaryWalletId)
|
|
84
|
-
return;
|
|
85
|
-
const connectionMap = {};
|
|
86
|
-
for (const wallet of wallets) {
|
|
87
|
-
connectionMap[wallet.id] = yield isWalletConnected.isWalletConnected(wallet);
|
|
88
|
-
}
|
|
89
|
-
setWallets((currentWallets) => currentWallets.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: connectionMap[wallet.id] }))));
|
|
90
|
-
}), [primaryWalletId, wallets]);
|
|
91
45
|
const getSelectedWallet = React.useCallback((walletId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
92
46
|
const newWallet = wallets.find(({ id }) => id === walletId);
|
|
93
47
|
if (!newWallet) {
|
|
@@ -165,8 +119,9 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
165
119
|
]);
|
|
166
120
|
const walletConnectors = wallets.map((wallet) => wallet.connector);
|
|
167
121
|
return {
|
|
168
|
-
|
|
122
|
+
clearPrimaryWalletId,
|
|
169
123
|
computeConnectedStateForWallets,
|
|
124
|
+
didConnectedStateLoad,
|
|
170
125
|
getPrimaryWallet,
|
|
171
126
|
getSecondaryWallets,
|
|
172
127
|
primaryWallet: getPrimaryWallet(),
|
|
@@ -11,8 +11,9 @@ type Props = {
|
|
|
11
11
|
wallets: WalletOption[];
|
|
12
12
|
};
|
|
13
13
|
export interface UseWalletConnectors {
|
|
14
|
-
|
|
14
|
+
clearPrimaryWalletId: () => void;
|
|
15
15
|
computeConnectedStateForWallets: () => Promise<void>;
|
|
16
|
+
didConnectedStateLoad: boolean;
|
|
16
17
|
getPrimaryWallet: () => Wallet | null;
|
|
17
18
|
getSecondaryWallets: () => Wallet[];
|
|
18
19
|
primaryWallet: Wallet | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
-
import { useState,
|
|
2
|
+
import { useState, useMemo, useEffect, useCallback } from 'react';
|
|
3
3
|
import { DynamicError, isEmailWalletConnector } from '@dynamic-labs/multi-wallet';
|
|
4
|
-
import
|
|
4
|
+
import '@dynamic-labs/sdk-api';
|
|
5
5
|
import { logger } from '../../../shared/logger.js';
|
|
6
6
|
import '@dynamic-labs/iconic';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
@@ -10,80 +10,34 @@ import { PRIMARY_WALLET_ID } from '../../constants/localStorage.js';
|
|
|
10
10
|
import '../../constants/colors.js';
|
|
11
11
|
import { useLocalStorage } from '../../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
|
|
12
12
|
import '../../../shared/consts/index.js';
|
|
13
|
-
import { isWalletConnected } from '../../functions/isWalletConnected/isWalletConnected.js';
|
|
14
13
|
import { isSameWalletName } from '../../functions/isSameWalletName/isSameWalletName.js';
|
|
15
|
-
import '
|
|
16
|
-
import {
|
|
14
|
+
import { useWalletsConnectionState } from '../useWalletsConnectionState/useWalletsConnectionState.js';
|
|
15
|
+
import { primaryWalletIdValidator } from './utils/primaryWalletIdValidator/primaryWalletIdValidator.js';
|
|
16
|
+
import { createLinkedWalletsFromWalletOptions } from './utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.js';
|
|
17
17
|
|
|
18
18
|
const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, }) => {
|
|
19
19
|
const [showQrcodeModal, setShowQrcodeModal] = useState(false);
|
|
20
|
-
const [
|
|
21
|
-
const
|
|
20
|
+
const [primaryWalletId, setPrimaryWalletIdState, clearPrimaryWalletId] = useLocalStorage(PRIMARY_WALLET_ID, undefined, primaryWalletIdValidator);
|
|
21
|
+
const linkedWallets = useMemo(() => {
|
|
22
|
+
if (!authToken) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
return createLinkedWalletsFromWalletOptions({
|
|
26
|
+
authToken,
|
|
27
|
+
primaryWalletId,
|
|
28
|
+
walletOptions: availableWallets,
|
|
29
|
+
});
|
|
30
|
+
}, [availableWallets, primaryWalletId, authToken]);
|
|
31
|
+
const { connectedWalletMap, computeConnectedStateForWallets, didConnectedStateLoad, } = useWalletsConnectionState(linkedWallets);
|
|
32
|
+
const wallets = useMemo(() => linkedWallets.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, linkedWallets]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
computeConnectedStateForWallets();
|
|
35
|
+
}, [primaryWalletId, computeConnectedStateForWallets]);
|
|
22
36
|
const setPrimaryWalletId = useCallback((walletId) => {
|
|
23
37
|
setPrimaryWalletIdState(walletId);
|
|
24
38
|
}, [setPrimaryWalletIdState]);
|
|
25
|
-
const
|
|
26
|
-
setWallets([]);
|
|
27
|
-
clearPrimaryWalletId();
|
|
28
|
-
}, [clearPrimaryWalletId]);
|
|
29
|
-
const getPrimaryWallet = useCallback(() => {
|
|
30
|
-
const primaryWallet = wallets.find((wallet) => wallet.id === primaryWalletId);
|
|
31
|
-
if (!primaryWallet) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
return primaryWallet;
|
|
35
|
-
}, [primaryWalletId, wallets]);
|
|
39
|
+
const getPrimaryWallet = useCallback(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
|
|
36
40
|
const getSecondaryWallets = useCallback(() => wallets.filter((wallet) => wallet.id !== primaryWalletId), [primaryWalletId, wallets]);
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
const decodedJwt = decodeJwt(authToken);
|
|
39
|
-
// wallet state should be null while loading all the wallets or when there is no user
|
|
40
|
-
if (!availableWallets || !decodedJwt) {
|
|
41
|
-
setWallets([]);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
Promise.all(decodedJwt.verifiedCredentials.map((account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
const wallet = availableWallets.find((wallet) => account.walletName &&
|
|
46
|
-
isSameWalletName(wallet.name, account.walletName));
|
|
47
|
-
// this probably shouldn't happen. this would mean that the user has an account linked
|
|
48
|
-
// with wallet W, but the customer has toggled off wallet W or the chain that
|
|
49
|
-
// supports wallet W
|
|
50
|
-
/* istanbul ignore next */
|
|
51
|
-
if (!wallet)
|
|
52
|
-
return null;
|
|
53
|
-
// this is here because phantom fires a disconnect event on page load,
|
|
54
|
-
// and other wallets and chains have similar issues
|
|
55
|
-
if (account.id === primaryWalletId &&
|
|
56
|
-
shouldManuallyReconnectOnRefresh(wallet.walletConnector)) {
|
|
57
|
-
yield wallet.walletConnector.connect();
|
|
58
|
-
}
|
|
59
|
-
if (account.address && account.chain) {
|
|
60
|
-
return {
|
|
61
|
-
address: account.address,
|
|
62
|
-
chain: account.chain,
|
|
63
|
-
connected: yield isWalletConnected({
|
|
64
|
-
address: account.address,
|
|
65
|
-
chain: account.chain,
|
|
66
|
-
connector: wallet.walletConnector,
|
|
67
|
-
}),
|
|
68
|
-
connector: wallet.walletConnector,
|
|
69
|
-
id: account.id,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}))).then((result) => {
|
|
74
|
-
setWallets(result.filter((wc) => wc !== null));
|
|
75
|
-
return null;
|
|
76
|
-
});
|
|
77
|
-
}, [availableWallets, primaryWalletId, authToken]);
|
|
78
|
-
const computeConnectedStateForWallets = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
-
if (!primaryWalletId)
|
|
80
|
-
return;
|
|
81
|
-
const connectionMap = {};
|
|
82
|
-
for (const wallet of wallets) {
|
|
83
|
-
connectionMap[wallet.id] = yield isWalletConnected(wallet);
|
|
84
|
-
}
|
|
85
|
-
setWallets((currentWallets) => currentWallets.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: connectionMap[wallet.id] }))));
|
|
86
|
-
}), [primaryWalletId, wallets]);
|
|
87
41
|
const getSelectedWallet = useCallback((walletId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
42
|
const newWallet = wallets.find(({ id }) => id === walletId);
|
|
89
43
|
if (!newWallet) {
|
|
@@ -161,8 +115,9 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
161
115
|
]);
|
|
162
116
|
const walletConnectors = wallets.map((wallet) => wallet.connector);
|
|
163
117
|
return {
|
|
164
|
-
|
|
118
|
+
clearPrimaryWalletId,
|
|
165
119
|
computeConnectedStateForWallets,
|
|
120
|
+
didConnectedStateLoad,
|
|
166
121
|
getPrimaryWallet,
|
|
167
122
|
getSecondaryWallets,
|
|
168
123
|
primaryWallet: getPrimaryWallet(),
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var decodeJwt = require('../../../../../shared/utils/functions/decodeJwt/decodeJwt.cjs');
|
|
6
|
+
require('../../../../../shared/logger.cjs');
|
|
7
|
+
require('@dynamic-labs/iconic');
|
|
8
|
+
require('@dynamic-labs/multi-wallet');
|
|
9
|
+
require('react/jsx-runtime');
|
|
10
|
+
require('../../../../../context/ViewContext/ViewContext.cjs');
|
|
11
|
+
require('react');
|
|
12
|
+
require('../../../../constants/colors.cjs');
|
|
13
|
+
require('../../../../../shared/consts/index.cjs');
|
|
14
|
+
var isSameWalletName = require('../../../../functions/isSameWalletName/isSameWalletName.cjs');
|
|
15
|
+
require('@dynamic-labs/sdk-api');
|
|
16
|
+
var shouldManuallyReconnectOnRefresh = require('../../../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.cjs');
|
|
17
|
+
|
|
18
|
+
const createLinkedWalletsFromWalletOptions = ({ authToken, walletOptions, primaryWalletId, }) => {
|
|
19
|
+
const decodedJwt = decodeJwt.decodeJwt(authToken);
|
|
20
|
+
// wallet state should be null while loading all the wallets or when there is no user
|
|
21
|
+
if (!walletOptions || !decodedJwt) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
return decodedJwt.verifiedCredentials
|
|
25
|
+
.map((account) => {
|
|
26
|
+
const wallet = walletOptions.find((wallet) => account.walletName &&
|
|
27
|
+
isSameWalletName.isSameWalletName(wallet.name, account.walletName));
|
|
28
|
+
// this probably shouldn't happen. this would mean that the user has an account linked
|
|
29
|
+
// with wallet W, but the customer has toggled off wallet W or the chain that
|
|
30
|
+
// supports wallet W
|
|
31
|
+
/* istanbul ignore next */
|
|
32
|
+
if (!wallet)
|
|
33
|
+
return null;
|
|
34
|
+
if (account.id === primaryWalletId &&
|
|
35
|
+
shouldManuallyReconnectOnRefresh.shouldManuallyReconnectOnRefresh(wallet.walletConnector)) {
|
|
36
|
+
wallet.walletConnector.connect();
|
|
37
|
+
}
|
|
38
|
+
if (account.address && account.chain) {
|
|
39
|
+
return {
|
|
40
|
+
address: account.address,
|
|
41
|
+
chain: account.chain,
|
|
42
|
+
connected: false,
|
|
43
|
+
connector: wallet.walletConnector,
|
|
44
|
+
id: account.id,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
})
|
|
49
|
+
.filter((wc) => wc !== null);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.createLinkedWalletsFromWalletOptions = createLinkedWalletsFromWalletOptions;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Wallet, WalletOption } from '../../../../../shared';
|
|
2
|
+
type CreateWalletsFromWalletOptionsProps = {
|
|
3
|
+
authToken: string;
|
|
4
|
+
primaryWalletId: string | undefined;
|
|
5
|
+
walletOptions: WalletOption[] | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare const createLinkedWalletsFromWalletOptions: ({ authToken, walletOptions, primaryWalletId, }: CreateWalletsFromWalletOptionsProps) => Wallet[];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { decodeJwt } from '../../../../../shared/utils/functions/decodeJwt/decodeJwt.js';
|
|
2
|
+
import '../../../../../shared/logger.js';
|
|
3
|
+
import '@dynamic-labs/iconic';
|
|
4
|
+
import '@dynamic-labs/multi-wallet';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import '../../../../../context/ViewContext/ViewContext.js';
|
|
7
|
+
import 'react';
|
|
8
|
+
import '../../../../constants/colors.js';
|
|
9
|
+
import '../../../../../shared/consts/index.js';
|
|
10
|
+
import { isSameWalletName } from '../../../../functions/isSameWalletName/isSameWalletName.js';
|
|
11
|
+
import '@dynamic-labs/sdk-api';
|
|
12
|
+
import { shouldManuallyReconnectOnRefresh } from '../../../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.js';
|
|
13
|
+
|
|
14
|
+
const createLinkedWalletsFromWalletOptions = ({ authToken, walletOptions, primaryWalletId, }) => {
|
|
15
|
+
const decodedJwt = decodeJwt(authToken);
|
|
16
|
+
// wallet state should be null while loading all the wallets or when there is no user
|
|
17
|
+
if (!walletOptions || !decodedJwt) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
return decodedJwt.verifiedCredentials
|
|
21
|
+
.map((account) => {
|
|
22
|
+
const wallet = walletOptions.find((wallet) => account.walletName &&
|
|
23
|
+
isSameWalletName(wallet.name, account.walletName));
|
|
24
|
+
// this probably shouldn't happen. this would mean that the user has an account linked
|
|
25
|
+
// with wallet W, but the customer has toggled off wallet W or the chain that
|
|
26
|
+
// supports wallet W
|
|
27
|
+
/* istanbul ignore next */
|
|
28
|
+
if (!wallet)
|
|
29
|
+
return null;
|
|
30
|
+
if (account.id === primaryWalletId &&
|
|
31
|
+
shouldManuallyReconnectOnRefresh(wallet.walletConnector)) {
|
|
32
|
+
wallet.walletConnector.connect();
|
|
33
|
+
}
|
|
34
|
+
if (account.address && account.chain) {
|
|
35
|
+
return {
|
|
36
|
+
address: account.address,
|
|
37
|
+
chain: account.chain,
|
|
38
|
+
connected: false,
|
|
39
|
+
connector: wallet.walletConnector,
|
|
40
|
+
id: account.id,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
})
|
|
45
|
+
.filter((wc) => wc !== null);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { createLinkedWalletsFromWalletOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createLinkedWalletsFromWalletOptions } from './createLinkedWalletsFromWalletOptions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { primaryWalletIdValidator } from './primaryWalletIdValidator';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const primaryWalletIdValidator: (value: string | unknown) => value is string | undefined;
|
|
@@ -2,42 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
5
|
var React = require('react');
|
|
7
6
|
var data = require('../../../views/WalletList/data.cjs');
|
|
8
7
|
var getMagicLinkApiKeyFromProviders = require('./utils/getMagicLinkApiKeyFromProviders/getMagicLinkApiKeyFromProviders.cjs');
|
|
9
8
|
|
|
10
9
|
const useWallets = ({ projectSettings, appLogoUrl, appName, networkConfigurations, vendorCredentials, walletUiUtils, magicLinkConfig, }) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
walletUiUtils,
|
|
25
|
-
});
|
|
26
|
-
const notInstalledWallets = yield data.getNotInstalledWallets(projectSettings, {
|
|
27
|
-
appLogoUrl,
|
|
28
|
-
appName,
|
|
29
|
-
magicLinkApiKey,
|
|
30
|
-
magicLinkConfig,
|
|
31
|
-
networkConfigurations,
|
|
32
|
-
skipMemo: true,
|
|
33
|
-
vendorCredentials,
|
|
34
|
-
walletUiUtils,
|
|
35
|
-
});
|
|
36
|
-
const unfilteredWallets = [...installedWallets, ...notInstalledWallets];
|
|
37
|
-
setWallets(unfilteredWallets);
|
|
38
|
-
}
|
|
10
|
+
const wallets = React.useMemo(() => {
|
|
11
|
+
if (!projectSettings)
|
|
12
|
+
return [];
|
|
13
|
+
const magicLinkApiKey = getMagicLinkApiKeyFromProviders.getMagicLinkApiKeyFromProviders((projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) || []);
|
|
14
|
+
const installedWallets = data.getInstalledWallets(projectSettings, {
|
|
15
|
+
appLogoUrl,
|
|
16
|
+
appName,
|
|
17
|
+
magicLinkApiKey,
|
|
18
|
+
magicLinkConfig,
|
|
19
|
+
networkConfigurations,
|
|
20
|
+
skipMemo: true,
|
|
21
|
+
vendorCredentials,
|
|
22
|
+
walletUiUtils,
|
|
39
23
|
});
|
|
40
|
-
|
|
24
|
+
const notInstalledWallets = data.getNotInstalledWallets(projectSettings, {
|
|
25
|
+
appLogoUrl,
|
|
26
|
+
appName,
|
|
27
|
+
magicLinkApiKey,
|
|
28
|
+
magicLinkConfig,
|
|
29
|
+
networkConfigurations,
|
|
30
|
+
skipMemo: true,
|
|
31
|
+
vendorCredentials,
|
|
32
|
+
walletUiUtils,
|
|
33
|
+
});
|
|
34
|
+
const unfilteredWallets = [...installedWallets, ...notInstalledWallets];
|
|
35
|
+
return unfilteredWallets;
|
|
41
36
|
}, [
|
|
42
37
|
projectSettings,
|
|
43
38
|
appLogoUrl,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MagicLinkConfig, NetworkConfigurationMap, VendorCredentials, WalletUiUtils } from '@dynamic-labs/multi-wallet';
|
|
2
2
|
import { ProjectSettings } from '@dynamic-labs/sdk-api';
|
|
3
|
-
import { WalletOption } from '../../../shared';
|
|
4
3
|
type Props = {
|
|
5
4
|
appLogoUrl?: string;
|
|
6
5
|
appName?: string;
|
|
@@ -11,6 +10,6 @@ type Props = {
|
|
|
11
10
|
walletUiUtils: WalletUiUtils;
|
|
12
11
|
};
|
|
13
12
|
export declare const useWallets: ({ projectSettings, appLogoUrl, appName, networkConfigurations, vendorCredentials, walletUiUtils, magicLinkConfig, }: Props) => {
|
|
14
|
-
wallets: WalletOption[];
|
|
13
|
+
wallets: import("../../../shared").WalletOption[];
|
|
15
14
|
};
|
|
16
15
|
export {};
|
|
@@ -1,39 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useState, useEffect } from 'react';
|
|
1
|
+
import { useMemo } from 'react';
|
|
3
2
|
import { getInstalledWallets, getNotInstalledWallets } from '../../../views/WalletList/data.js';
|
|
4
3
|
import { getMagicLinkApiKeyFromProviders } from './utils/getMagicLinkApiKeyFromProviders/getMagicLinkApiKeyFromProviders.js';
|
|
5
4
|
|
|
6
5
|
const useWallets = ({ projectSettings, appLogoUrl, appName, networkConfigurations, vendorCredentials, walletUiUtils, magicLinkConfig, }) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
walletUiUtils,
|
|
21
|
-
});
|
|
22
|
-
const notInstalledWallets = yield getNotInstalledWallets(projectSettings, {
|
|
23
|
-
appLogoUrl,
|
|
24
|
-
appName,
|
|
25
|
-
magicLinkApiKey,
|
|
26
|
-
magicLinkConfig,
|
|
27
|
-
networkConfigurations,
|
|
28
|
-
skipMemo: true,
|
|
29
|
-
vendorCredentials,
|
|
30
|
-
walletUiUtils,
|
|
31
|
-
});
|
|
32
|
-
const unfilteredWallets = [...installedWallets, ...notInstalledWallets];
|
|
33
|
-
setWallets(unfilteredWallets);
|
|
34
|
-
}
|
|
6
|
+
const wallets = useMemo(() => {
|
|
7
|
+
if (!projectSettings)
|
|
8
|
+
return [];
|
|
9
|
+
const magicLinkApiKey = getMagicLinkApiKeyFromProviders((projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) || []);
|
|
10
|
+
const installedWallets = getInstalledWallets(projectSettings, {
|
|
11
|
+
appLogoUrl,
|
|
12
|
+
appName,
|
|
13
|
+
magicLinkApiKey,
|
|
14
|
+
magicLinkConfig,
|
|
15
|
+
networkConfigurations,
|
|
16
|
+
skipMemo: true,
|
|
17
|
+
vendorCredentials,
|
|
18
|
+
walletUiUtils,
|
|
35
19
|
});
|
|
36
|
-
|
|
20
|
+
const notInstalledWallets = getNotInstalledWallets(projectSettings, {
|
|
21
|
+
appLogoUrl,
|
|
22
|
+
appName,
|
|
23
|
+
magicLinkApiKey,
|
|
24
|
+
magicLinkConfig,
|
|
25
|
+
networkConfigurations,
|
|
26
|
+
skipMemo: true,
|
|
27
|
+
vendorCredentials,
|
|
28
|
+
walletUiUtils,
|
|
29
|
+
});
|
|
30
|
+
const unfilteredWallets = [...installedWallets, ...notInstalledWallets];
|
|
31
|
+
return unfilteredWallets;
|
|
37
32
|
}, [
|
|
38
33
|
projectSettings,
|
|
39
34
|
appLogoUrl,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useWalletsConnectionState } from './useWalletsConnectionState';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
require('../../constants/colors.cjs');
|
|
8
|
+
require('@dynamic-labs/multi-wallet');
|
|
9
|
+
require('@dynamic-labs/sdk-api');
|
|
10
|
+
require('../../../shared/logger.cjs');
|
|
11
|
+
require('@dynamic-labs/iconic');
|
|
12
|
+
require('react/jsx-runtime');
|
|
13
|
+
require('../../../context/ViewContext/ViewContext.cjs');
|
|
14
|
+
var isWalletConnected = require('../../functions/isWalletConnected/isWalletConnected.cjs');
|
|
15
|
+
|
|
16
|
+
const useWalletsConnectionState = (linkedWallets) => {
|
|
17
|
+
const [connectedWalletMap, setConnectedWalletMap] = React.useState();
|
|
18
|
+
const computeConnectedStateForWallets = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const connectedWalletIds = (yield Promise.all(linkedWallets.map((wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const isConnected = yield isWalletConnected.isWalletConnected(wallet);
|
|
21
|
+
if (isConnected) {
|
|
22
|
+
return wallet.id;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
})))).filter((connectedWalletId) => connectedWalletId !== undefined);
|
|
28
|
+
const newConnectedStateByWalletIdMap = connectedWalletIds.reduce((result, walletId) => (Object.assign(Object.assign({}, result), { [walletId]: true })), {});
|
|
29
|
+
setConnectedWalletMap(newConnectedStateByWalletIdMap);
|
|
30
|
+
}), [linkedWallets, setConnectedWalletMap]);
|
|
31
|
+
return {
|
|
32
|
+
computeConnectedStateForWallets,
|
|
33
|
+
connectedWalletMap: connectedWalletMap !== null && connectedWalletMap !== void 0 ? connectedWalletMap : {},
|
|
34
|
+
didConnectedStateLoad: Boolean(connectedWalletMap),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.useWalletsConnectionState = useWalletsConnectionState;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Wallet } from '../../../shared';
|
|
2
|
+
type ConnectedWalletsMap = {
|
|
3
|
+
[address: string]: boolean;
|
|
4
|
+
};
|
|
5
|
+
type WalletsConnectionStateHook = (wallets: Wallet[]) => {
|
|
6
|
+
computeConnectedStateForWallets: () => Promise<void>;
|
|
7
|
+
connectedWalletMap: ConnectedWalletsMap;
|
|
8
|
+
didConnectedStateLoad: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const useWalletsConnectionState: WalletsConnectionStateHook;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { useState, useCallback } from 'react';
|
|
3
|
+
import '../../constants/colors.js';
|
|
4
|
+
import '@dynamic-labs/multi-wallet';
|
|
5
|
+
import '@dynamic-labs/sdk-api';
|
|
6
|
+
import '../../../shared/logger.js';
|
|
7
|
+
import '@dynamic-labs/iconic';
|
|
8
|
+
import 'react/jsx-runtime';
|
|
9
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
10
|
+
import { isWalletConnected } from '../../functions/isWalletConnected/isWalletConnected.js';
|
|
11
|
+
|
|
12
|
+
const useWalletsConnectionState = (linkedWallets) => {
|
|
13
|
+
const [connectedWalletMap, setConnectedWalletMap] = useState();
|
|
14
|
+
const computeConnectedStateForWallets = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const connectedWalletIds = (yield Promise.all(linkedWallets.map((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const isConnected = yield isWalletConnected(wallet);
|
|
17
|
+
if (isConnected) {
|
|
18
|
+
return wallet.id;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
})))).filter((connectedWalletId) => connectedWalletId !== undefined);
|
|
24
|
+
const newConnectedStateByWalletIdMap = connectedWalletIds.reduce((result, walletId) => (Object.assign(Object.assign({}, result), { [walletId]: true })), {});
|
|
25
|
+
setConnectedWalletMap(newConnectedStateByWalletIdMap);
|
|
26
|
+
}), [linkedWallets, setConnectedWalletMap]);
|
|
27
|
+
return {
|
|
28
|
+
computeConnectedStateForWallets,
|
|
29
|
+
connectedWalletMap: connectedWalletMap !== null && connectedWalletMap !== void 0 ? connectedWalletMap : {},
|
|
30
|
+
didConnectedStateLoad: Boolean(connectedWalletMap),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { useWalletsConnectionState };
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
6
5
|
var multiWallet = require('@dynamic-labs/multi-wallet');
|
|
7
6
|
require('@dynamic-labs/sdk-api');
|
|
8
7
|
require('../../shared/logger.cjs');
|
|
@@ -22,9 +21,9 @@ const getEnabledCosmosNetworks = (chains) => {
|
|
|
22
21
|
var _a, _b, _c;
|
|
23
22
|
return ((_c = (_b = (_a = chains.find(({ enabled, name }) => enabled && name === 'cosmos')) === null || _a === void 0 ? void 0 : _a.networks) === null || _b === void 0 ? void 0 : _b.filter(({ enabled }) => enabled)) === null || _c === void 0 ? void 0 : _c.map(({ networkId }) => networkId)) || [];
|
|
24
23
|
};
|
|
25
|
-
const createWallets = (props) =>
|
|
24
|
+
const createWallets = (props) => {
|
|
26
25
|
var _a, _b, _c, _d;
|
|
27
|
-
return
|
|
26
|
+
return multiWallet.getEnabledWallets({
|
|
28
27
|
enabledChains: getEnabledChains(props.settings.chains),
|
|
29
28
|
enabledNetworks: getEnabledCosmosNetworks(props.settings.chains),
|
|
30
29
|
getSupportedWalletOpts: Object.assign(Object.assign({}, props.getSupportedWalletOpts), { isWalletConnectV2Enabled: ((_a = props.settings.sdk.walletConnect) === null || _a === void 0 ? void 0 : _a.v2Enabled) &&
|
|
@@ -32,8 +31,8 @@ const createWallets = (props) => _tslib.__awaiter(void 0, void 0, void 0, functi
|
|
|
32
31
|
? (_c = props.settings.sdk.walletConnect) === null || _c === void 0 ? void 0 : _c.v2Enabled
|
|
33
32
|
: false, walletConnectProjectId: (_d = props.settings.sdk.walletConnect) === null || _d === void 0 ? void 0 : _d.projectId }),
|
|
34
33
|
installed: props.installed,
|
|
35
|
-
})
|
|
36
|
-
}
|
|
34
|
+
}).map(createWallet.createWallet);
|
|
35
|
+
};
|
|
37
36
|
const getInstalledWallets = (settings, getSupportedWalletOpts) => createWallets({
|
|
38
37
|
getSupportedWalletOpts,
|
|
39
38
|
installed: true,
|
|
@@ -7,6 +7,6 @@ interface IChain {
|
|
|
7
7
|
export declare const getEnabledChains: (chains: IChain[]) => ("ETH" | "FLOW" | "SOL" | "EVM" | "ALGO" | "STARK" | "ATOM" | "COSMOS")[];
|
|
8
8
|
export declare const getEnabledCosmosNetworks: (chains: IChain[]) => number[];
|
|
9
9
|
type BaseGetSupportedWalletOpts = Omit<GetSupportedWalletsOpts, 'isWalletConnectV2Enabled' | 'walletConnectProjectId'>;
|
|
10
|
-
export declare const getInstalledWallets: (settings: ProjectSettings, getSupportedWalletOpts: BaseGetSupportedWalletOpts) =>
|
|
11
|
-
export declare const getNotInstalledWallets: (settings: ProjectSettings, getSupportedWalletOpts: BaseGetSupportedWalletOpts) =>
|
|
10
|
+
export declare const getInstalledWallets: (settings: ProjectSettings, getSupportedWalletOpts: BaseGetSupportedWalletOpts) => import("../../shared").WalletOption[];
|
|
11
|
+
export declare const getNotInstalledWallets: (settings: ProjectSettings, getSupportedWalletOpts: BaseGetSupportedWalletOpts) => import("../../shared").WalletOption[];
|
|
12
12
|
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
2
1
|
import { getEnabledWallets, getChainInfo } from '@dynamic-labs/multi-wallet';
|
|
3
2
|
import '@dynamic-labs/sdk-api';
|
|
4
3
|
import '../../shared/logger.js';
|
|
@@ -18,9 +17,9 @@ const getEnabledCosmosNetworks = (chains) => {
|
|
|
18
17
|
var _a, _b, _c;
|
|
19
18
|
return ((_c = (_b = (_a = chains.find(({ enabled, name }) => enabled && name === 'cosmos')) === null || _a === void 0 ? void 0 : _a.networks) === null || _b === void 0 ? void 0 : _b.filter(({ enabled }) => enabled)) === null || _c === void 0 ? void 0 : _c.map(({ networkId }) => networkId)) || [];
|
|
20
19
|
};
|
|
21
|
-
const createWallets = (props) =>
|
|
20
|
+
const createWallets = (props) => {
|
|
22
21
|
var _a, _b, _c, _d;
|
|
23
|
-
return
|
|
22
|
+
return getEnabledWallets({
|
|
24
23
|
enabledChains: getEnabledChains(props.settings.chains),
|
|
25
24
|
enabledNetworks: getEnabledCosmosNetworks(props.settings.chains),
|
|
26
25
|
getSupportedWalletOpts: Object.assign(Object.assign({}, props.getSupportedWalletOpts), { isWalletConnectV2Enabled: ((_a = props.settings.sdk.walletConnect) === null || _a === void 0 ? void 0 : _a.v2Enabled) &&
|
|
@@ -28,8 +27,8 @@ const createWallets = (props) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
28
27
|
? (_c = props.settings.sdk.walletConnect) === null || _c === void 0 ? void 0 : _c.v2Enabled
|
|
29
28
|
: false, walletConnectProjectId: (_d = props.settings.sdk.walletConnect) === null || _d === void 0 ? void 0 : _d.projectId }),
|
|
30
29
|
installed: props.installed,
|
|
31
|
-
})
|
|
32
|
-
}
|
|
30
|
+
}).map(createWallet);
|
|
31
|
+
};
|
|
33
32
|
const getInstalledWallets = (settings, getSupportedWalletOpts) => createWallets({
|
|
34
33
|
getSupportedWalletOpts,
|
|
35
34
|
installed: true,
|