@dynamic-labs/sdk-react-core 0.18.0-beta.29 → 0.18.0-beta.31
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 +18 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +10 -9
- package/src/index.cjs +2 -0
- package/src/index.js +1 -0
- package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
- package/src/lib/data/api.cjs +16 -0
- package/src/lib/data/api.d.ts +1 -0
- package/src/lib/data/api.js +18 -3
- package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +10 -2
- package/src/lib/layout/DynamicAuthLayout/Header/header.js +10 -2
- package/src/lib/shared/assets/double-arrow-right.cjs +53 -0
- package/src/lib/shared/assets/double-arrow-right.js +29 -0
- package/src/lib/shared/assets/index.d.ts +1 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -1
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -1
- package/src/lib/utils/hooks/useWalletConnectorEvent/index.d.ts +1 -0
- package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.cjs +42 -0
- package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.d.ts +12 -0
- package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.js +38 -0
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +12 -0
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +12 -0
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +91 -142
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +92 -143
- package/src/lib/views/EmailVerification/EmailVerification.cjs +6 -0
- package/src/lib/views/EmailVerification/EmailVerification.js +7 -1
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.cjs +103 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.d.ts +2 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.js +99 -0
- package/src/lib/views/MergeUserAccountsView/index.d.ts +1 -0
- package/src/lib/views/viewToComponentMap.cjs +2 -0
- package/src/lib/views/viewToComponentMap.js +2 -0
|
@@ -16,12 +16,11 @@ require('../../constants/colors.cjs');
|
|
|
16
16
|
require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
17
17
|
require('ethers');
|
|
18
18
|
require('../../../shared/consts/index.cjs');
|
|
19
|
+
var useWalletConnectorEvent = require('../useWalletConnectorEvent/useWalletConnectorEvent.cjs');
|
|
19
20
|
|
|
20
|
-
const orderedSecondaryWalletAddresses = (wallets) => wallets.map((wallet) => wallet.address).sort();
|
|
21
21
|
const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnector, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, authMode, refreshConnectedWallet, }) => {
|
|
22
22
|
const [loadingNetwork, setLoadingNetwork] = React.useState(true);
|
|
23
23
|
const [network, setNetwork] = React.useState(undefined);
|
|
24
|
-
const seen = new Set();
|
|
25
24
|
React.useEffect(() => {
|
|
26
25
|
const fetchNetwork = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
27
26
|
try {
|
|
@@ -40,36 +39,100 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
40
39
|
});
|
|
41
40
|
fetchNetwork();
|
|
42
41
|
}, [primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.id]);
|
|
43
|
-
|
|
42
|
+
useWalletConnectorEvent.useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'disconnect', () => {
|
|
43
|
+
logger.logger.debug('primary wallet disconnect');
|
|
44
|
+
handleLogOut();
|
|
45
|
+
});
|
|
46
|
+
useWalletConnectorEvent.useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'chainChange', (_, { chain }) => {
|
|
47
|
+
logger.logger.debug('primary wallet chain change', { chain });
|
|
44
48
|
if (!primaryWallet) {
|
|
45
49
|
return;
|
|
46
50
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
|
|
52
|
+
// https://linear.app/dynamic-labs/issue/QNTM-84/breaking-change-rename-network-to-primarywalletnetwork
|
|
53
|
+
if (primaryWallet.chain === 'starknet') {
|
|
54
|
+
setNetwork(chain);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
setNetwork(parseInt(chain));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
useWalletConnectorEvent.useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'accountChange', (_, { accounts }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
logger.logger.debug('primary wallet account change', {
|
|
62
|
+
accounts,
|
|
63
|
+
});
|
|
64
|
+
// change the api here
|
|
65
|
+
if (!primaryWallet)
|
|
66
|
+
return;
|
|
67
|
+
const [newAddress] = accounts;
|
|
68
|
+
const newWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
69
|
+
if (authMode === 'connect-only') {
|
|
70
|
+
refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (walletConnectorCore.isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
|
|
74
|
+
setMultiWalletWidgetState('idle');
|
|
75
|
+
}
|
|
76
|
+
else if (!multiWallet) {
|
|
77
|
+
yield handleLogOut();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
else if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
81
|
+
handleAccountChangeWhenAwaitingAccountSwitch(true, newAddress);
|
|
82
|
+
}
|
|
83
|
+
else if (multiWalletWidgetState === 'idle' && newWallet) {
|
|
84
|
+
setPrimaryWalletId(newWallet.id);
|
|
85
|
+
}
|
|
86
|
+
else if (multiWalletWidgetState === 'idle' && !newWallet) {
|
|
87
|
+
if (user) {
|
|
88
|
+
setMultiWalletWidgetState('detected_new_wallet');
|
|
89
|
+
setSelectedWalletConnector(primaryWallet.connector);
|
|
90
|
+
yield computeConnectedStateForWallets();
|
|
91
|
+
return;
|
|
67
92
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
logger.logger.error(`Unexpected multiWalletWidgetState (${multiWalletWidgetState}) and onAccountChange combination. Resetting state to idle.`);
|
|
96
|
+
setMultiWalletWidgetState('idle');
|
|
97
|
+
}
|
|
98
|
+
yield computeConnectedStateForWallets();
|
|
99
|
+
}));
|
|
100
|
+
const uniqueNonPrimaryWallets = React.useMemo(() => {
|
|
101
|
+
const primaryConnector = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
|
|
102
|
+
const secondaryConnectors = secondaryWallets.map(({ connector }) => connector);
|
|
103
|
+
const allWalletConnectors = new Set([
|
|
104
|
+
...secondaryConnectors,
|
|
105
|
+
primaryConnector,
|
|
106
|
+
selectedWalletConnector,
|
|
107
|
+
].filter((connector) => Boolean(connector)));
|
|
108
|
+
if (primaryConnector) {
|
|
109
|
+
allWalletConnectors.delete(primaryConnector);
|
|
110
|
+
}
|
|
111
|
+
return Array.from(allWalletConnectors);
|
|
112
|
+
}, [secondaryWallets, selectedWalletConnector, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector]);
|
|
113
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
logger.logger.debug('secondary wallet account change');
|
|
115
|
+
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
116
|
+
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
120
|
+
handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
|
|
121
|
+
}
|
|
122
|
+
yield computeConnectedStateForWallets();
|
|
123
|
+
}));
|
|
124
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
logger.logger.debug('secondary wallet chain change');
|
|
126
|
+
// We should pass the proper walletId here
|
|
127
|
+
if (!secondaryWallets.length) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
131
|
+
}));
|
|
132
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', () => {
|
|
133
|
+
logger.logger.debug('secondary wallet disconnect');
|
|
134
|
+
computeConnectedStateForWallets();
|
|
135
|
+
});
|
|
73
136
|
const handleAccountChangeWhenAwaitingAccountSwitch = React.useCallback((isPrimaryWallet, newAddress) => {
|
|
74
137
|
const linkedSecondaryWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
75
138
|
// this means the user is linking a new account, so we need proof of ownership...
|
|
@@ -92,120 +155,6 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
92
155
|
setSelectedWalletWithAction,
|
|
93
156
|
setPrimaryWalletId,
|
|
94
157
|
]);
|
|
95
|
-
const addPrimaryWalletEventListeners = React.useCallback((seen) => {
|
|
96
|
-
if (!primaryWallet) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
seen.add(primaryWallet.connector.name);
|
|
100
|
-
primaryWallet.connector.setupEventListeners({
|
|
101
|
-
onAccountChange: (accounts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
-
const [newAddress] = accounts;
|
|
103
|
-
const newWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
104
|
-
if (authMode === 'connect-only') {
|
|
105
|
-
refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (walletConnectorCore.isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
|
|
109
|
-
setMultiWalletWidgetState('idle');
|
|
110
|
-
}
|
|
111
|
-
else if (!multiWallet) {
|
|
112
|
-
yield handleLogOut();
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
else if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
116
|
-
handleAccountChangeWhenAwaitingAccountSwitch(true, newAddress);
|
|
117
|
-
}
|
|
118
|
-
else if (multiWalletWidgetState === 'idle' && newWallet) {
|
|
119
|
-
setPrimaryWalletId(newWallet.id);
|
|
120
|
-
}
|
|
121
|
-
else if (multiWalletWidgetState === 'idle' && !newWallet) {
|
|
122
|
-
if (user) {
|
|
123
|
-
setMultiWalletWidgetState('detected_new_wallet');
|
|
124
|
-
setSelectedWalletConnector(primaryWallet.connector);
|
|
125
|
-
yield computeConnectedStateForWallets();
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
logger.logger.error(`Unexpected multiWalletWidgetState (${multiWalletWidgetState}) and onAccountChange combination. Resetting state to idle.`);
|
|
131
|
-
setMultiWalletWidgetState('idle');
|
|
132
|
-
}
|
|
133
|
-
yield computeConnectedStateForWallets();
|
|
134
|
-
}),
|
|
135
|
-
onChainChange: (chain) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
136
|
-
if (!primaryWallet) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
|
|
140
|
-
// https://linear.app/dynamic-labs/issue/QNTM-84/breaking-change-rename-network-to-primarywalletnetwork
|
|
141
|
-
if (primaryWallet.chain === 'starknet') {
|
|
142
|
-
setNetwork(chain);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
setNetwork(parseInt(chain));
|
|
146
|
-
}
|
|
147
|
-
}),
|
|
148
|
-
onDisconnect: handleLogOut,
|
|
149
|
-
});
|
|
150
|
-
}, [
|
|
151
|
-
authMode,
|
|
152
|
-
primaryWallet,
|
|
153
|
-
setMultiWalletWidgetState,
|
|
154
|
-
multiWallet,
|
|
155
|
-
user,
|
|
156
|
-
computeConnectedStateForWallets,
|
|
157
|
-
handleLogOut,
|
|
158
|
-
multiWalletWidgetState,
|
|
159
|
-
secondaryWallets,
|
|
160
|
-
setSelectedWalletConnector,
|
|
161
|
-
handleAccountChangeWhenAwaitingAccountSwitch,
|
|
162
|
-
setPrimaryWalletId,
|
|
163
|
-
refreshConnectedWallet,
|
|
164
|
-
]);
|
|
165
|
-
const addSecondaryWalletEventListeners = React.useCallback((seen) => {
|
|
166
|
-
const secondaryListeners = {
|
|
167
|
-
onAccountChange: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
168
|
-
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
169
|
-
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
173
|
-
handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
|
|
174
|
-
}
|
|
175
|
-
yield computeConnectedStateForWallets();
|
|
176
|
-
}),
|
|
177
|
-
onChainChange: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
-
// We should pass the proper walletId here
|
|
179
|
-
if (!secondaryWallets.length) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
183
|
-
}),
|
|
184
|
-
onDisconnect: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
-
yield computeConnectedStateForWallets();
|
|
186
|
-
}),
|
|
187
|
-
};
|
|
188
|
-
if (selectedWalletConnector && !seen.has(selectedWalletConnector.name)) {
|
|
189
|
-
seen.add(selectedWalletConnector.name);
|
|
190
|
-
selectedWalletConnector.setupEventListeners(secondaryListeners);
|
|
191
|
-
}
|
|
192
|
-
for (const wallet of secondaryWallets) {
|
|
193
|
-
if (seen.has(wallet.connector.name)) {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
seen.add(wallet.connector.name);
|
|
197
|
-
wallet.connector.setupEventListeners(secondaryListeners);
|
|
198
|
-
}
|
|
199
|
-
}, [
|
|
200
|
-
authMode,
|
|
201
|
-
computeConnectedStateForWallets,
|
|
202
|
-
selectedWalletConnector,
|
|
203
|
-
selectedWalletWithAction,
|
|
204
|
-
handleAccountChangeWhenAwaitingAccountSwitch,
|
|
205
|
-
multiWalletWidgetState,
|
|
206
|
-
secondaryWallets,
|
|
207
|
-
refreshConnectedWallet,
|
|
208
|
-
]);
|
|
209
158
|
return {
|
|
210
159
|
loadingNetwork,
|
|
211
160
|
network,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import { useState, useEffect, useMemo, useCallback } from 'react';
|
|
3
3
|
import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import '@dynamic-labs/sdk-api';
|
|
5
5
|
import { logger } from '../../../shared/logger.js';
|
|
@@ -12,12 +12,11 @@ import '../../constants/colors.js';
|
|
|
12
12
|
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
13
13
|
import 'ethers';
|
|
14
14
|
import '../../../shared/consts/index.js';
|
|
15
|
+
import { useWalletConnectorEvent } from '../useWalletConnectorEvent/useWalletConnectorEvent.js';
|
|
15
16
|
|
|
16
|
-
const orderedSecondaryWalletAddresses = (wallets) => wallets.map((wallet) => wallet.address).sort();
|
|
17
17
|
const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnector, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, authMode, refreshConnectedWallet, }) => {
|
|
18
18
|
const [loadingNetwork, setLoadingNetwork] = useState(true);
|
|
19
19
|
const [network, setNetwork] = useState(undefined);
|
|
20
|
-
const seen = new Set();
|
|
21
20
|
useEffect(() => {
|
|
22
21
|
const fetchNetwork = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
22
|
try {
|
|
@@ -36,36 +35,100 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
36
35
|
});
|
|
37
36
|
fetchNetwork();
|
|
38
37
|
}, [primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.id]);
|
|
39
|
-
|
|
38
|
+
useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'disconnect', () => {
|
|
39
|
+
logger.debug('primary wallet disconnect');
|
|
40
|
+
handleLogOut();
|
|
41
|
+
});
|
|
42
|
+
useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'chainChange', (_, { chain }) => {
|
|
43
|
+
logger.debug('primary wallet chain change', { chain });
|
|
40
44
|
if (!primaryWallet) {
|
|
41
45
|
return;
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
|
|
48
|
+
// https://linear.app/dynamic-labs/issue/QNTM-84/breaking-change-rename-network-to-primarywalletnetwork
|
|
49
|
+
if (primaryWallet.chain === 'starknet') {
|
|
50
|
+
setNetwork(chain);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
setNetwork(parseInt(chain));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'accountChange', (_, { accounts }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
logger.debug('primary wallet account change', {
|
|
58
|
+
accounts,
|
|
59
|
+
});
|
|
60
|
+
// change the api here
|
|
61
|
+
if (!primaryWallet)
|
|
62
|
+
return;
|
|
63
|
+
const [newAddress] = accounts;
|
|
64
|
+
const newWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
65
|
+
if (authMode === 'connect-only') {
|
|
66
|
+
refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
|
|
70
|
+
setMultiWalletWidgetState('idle');
|
|
71
|
+
}
|
|
72
|
+
else if (!multiWallet) {
|
|
73
|
+
yield handleLogOut();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
else if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
77
|
+
handleAccountChangeWhenAwaitingAccountSwitch(true, newAddress);
|
|
78
|
+
}
|
|
79
|
+
else if (multiWalletWidgetState === 'idle' && newWallet) {
|
|
80
|
+
setPrimaryWalletId(newWallet.id);
|
|
81
|
+
}
|
|
82
|
+
else if (multiWalletWidgetState === 'idle' && !newWallet) {
|
|
83
|
+
if (user) {
|
|
84
|
+
setMultiWalletWidgetState('detected_new_wallet');
|
|
85
|
+
setSelectedWalletConnector(primaryWallet.connector);
|
|
86
|
+
yield computeConnectedStateForWallets();
|
|
87
|
+
return;
|
|
63
88
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
logger.error(`Unexpected multiWalletWidgetState (${multiWalletWidgetState}) and onAccountChange combination. Resetting state to idle.`);
|
|
92
|
+
setMultiWalletWidgetState('idle');
|
|
93
|
+
}
|
|
94
|
+
yield computeConnectedStateForWallets();
|
|
95
|
+
}));
|
|
96
|
+
const uniqueNonPrimaryWallets = useMemo(() => {
|
|
97
|
+
const primaryConnector = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
|
|
98
|
+
const secondaryConnectors = secondaryWallets.map(({ connector }) => connector);
|
|
99
|
+
const allWalletConnectors = new Set([
|
|
100
|
+
...secondaryConnectors,
|
|
101
|
+
primaryConnector,
|
|
102
|
+
selectedWalletConnector,
|
|
103
|
+
].filter((connector) => Boolean(connector)));
|
|
104
|
+
if (primaryConnector) {
|
|
105
|
+
allWalletConnectors.delete(primaryConnector);
|
|
106
|
+
}
|
|
107
|
+
return Array.from(allWalletConnectors);
|
|
108
|
+
}, [secondaryWallets, selectedWalletConnector, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector]);
|
|
109
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
logger.debug('secondary wallet account change');
|
|
111
|
+
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
112
|
+
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
116
|
+
handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
|
|
117
|
+
}
|
|
118
|
+
yield computeConnectedStateForWallets();
|
|
119
|
+
}));
|
|
120
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
+
logger.debug('secondary wallet chain change');
|
|
122
|
+
// We should pass the proper walletId here
|
|
123
|
+
if (!secondaryWallets.length) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
127
|
+
}));
|
|
128
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', () => {
|
|
129
|
+
logger.debug('secondary wallet disconnect');
|
|
130
|
+
computeConnectedStateForWallets();
|
|
131
|
+
});
|
|
69
132
|
const handleAccountChangeWhenAwaitingAccountSwitch = useCallback((isPrimaryWallet, newAddress) => {
|
|
70
133
|
const linkedSecondaryWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
71
134
|
// this means the user is linking a new account, so we need proof of ownership...
|
|
@@ -88,120 +151,6 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
88
151
|
setSelectedWalletWithAction,
|
|
89
152
|
setPrimaryWalletId,
|
|
90
153
|
]);
|
|
91
|
-
const addPrimaryWalletEventListeners = useCallback((seen) => {
|
|
92
|
-
if (!primaryWallet) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
seen.add(primaryWallet.connector.name);
|
|
96
|
-
primaryWallet.connector.setupEventListeners({
|
|
97
|
-
onAccountChange: (accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
-
const [newAddress] = accounts;
|
|
99
|
-
const newWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
100
|
-
if (authMode === 'connect-only') {
|
|
101
|
-
refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
|
|
105
|
-
setMultiWalletWidgetState('idle');
|
|
106
|
-
}
|
|
107
|
-
else if (!multiWallet) {
|
|
108
|
-
yield handleLogOut();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
else if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
112
|
-
handleAccountChangeWhenAwaitingAccountSwitch(true, newAddress);
|
|
113
|
-
}
|
|
114
|
-
else if (multiWalletWidgetState === 'idle' && newWallet) {
|
|
115
|
-
setPrimaryWalletId(newWallet.id);
|
|
116
|
-
}
|
|
117
|
-
else if (multiWalletWidgetState === 'idle' && !newWallet) {
|
|
118
|
-
if (user) {
|
|
119
|
-
setMultiWalletWidgetState('detected_new_wallet');
|
|
120
|
-
setSelectedWalletConnector(primaryWallet.connector);
|
|
121
|
-
yield computeConnectedStateForWallets();
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
logger.error(`Unexpected multiWalletWidgetState (${multiWalletWidgetState}) and onAccountChange combination. Resetting state to idle.`);
|
|
127
|
-
setMultiWalletWidgetState('idle');
|
|
128
|
-
}
|
|
129
|
-
yield computeConnectedStateForWallets();
|
|
130
|
-
}),
|
|
131
|
-
onChainChange: (chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
-
if (!primaryWallet) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
|
|
136
|
-
// https://linear.app/dynamic-labs/issue/QNTM-84/breaking-change-rename-network-to-primarywalletnetwork
|
|
137
|
-
if (primaryWallet.chain === 'starknet') {
|
|
138
|
-
setNetwork(chain);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
setNetwork(parseInt(chain));
|
|
142
|
-
}
|
|
143
|
-
}),
|
|
144
|
-
onDisconnect: handleLogOut,
|
|
145
|
-
});
|
|
146
|
-
}, [
|
|
147
|
-
authMode,
|
|
148
|
-
primaryWallet,
|
|
149
|
-
setMultiWalletWidgetState,
|
|
150
|
-
multiWallet,
|
|
151
|
-
user,
|
|
152
|
-
computeConnectedStateForWallets,
|
|
153
|
-
handleLogOut,
|
|
154
|
-
multiWalletWidgetState,
|
|
155
|
-
secondaryWallets,
|
|
156
|
-
setSelectedWalletConnector,
|
|
157
|
-
handleAccountChangeWhenAwaitingAccountSwitch,
|
|
158
|
-
setPrimaryWalletId,
|
|
159
|
-
refreshConnectedWallet,
|
|
160
|
-
]);
|
|
161
|
-
const addSecondaryWalletEventListeners = useCallback((seen) => {
|
|
162
|
-
const secondaryListeners = {
|
|
163
|
-
onAccountChange: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
-
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
165
|
-
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
169
|
-
handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
|
|
170
|
-
}
|
|
171
|
-
yield computeConnectedStateForWallets();
|
|
172
|
-
}),
|
|
173
|
-
onChainChange: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
-
// We should pass the proper walletId here
|
|
175
|
-
if (!secondaryWallets.length) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
179
|
-
}),
|
|
180
|
-
onDisconnect: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
-
yield computeConnectedStateForWallets();
|
|
182
|
-
}),
|
|
183
|
-
};
|
|
184
|
-
if (selectedWalletConnector && !seen.has(selectedWalletConnector.name)) {
|
|
185
|
-
seen.add(selectedWalletConnector.name);
|
|
186
|
-
selectedWalletConnector.setupEventListeners(secondaryListeners);
|
|
187
|
-
}
|
|
188
|
-
for (const wallet of secondaryWallets) {
|
|
189
|
-
if (seen.has(wallet.connector.name)) {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
seen.add(wallet.connector.name);
|
|
193
|
-
wallet.connector.setupEventListeners(secondaryListeners);
|
|
194
|
-
}
|
|
195
|
-
}, [
|
|
196
|
-
authMode,
|
|
197
|
-
computeConnectedStateForWallets,
|
|
198
|
-
selectedWalletConnector,
|
|
199
|
-
selectedWalletWithAction,
|
|
200
|
-
handleAccountChangeWhenAwaitingAccountSwitch,
|
|
201
|
-
multiWalletWidgetState,
|
|
202
|
-
secondaryWallets,
|
|
203
|
-
refreshConnectedWallet,
|
|
204
|
-
]);
|
|
205
154
|
return {
|
|
206
155
|
loadingNetwork,
|
|
207
156
|
network,
|
|
@@ -101,6 +101,11 @@ const EmailVerification = () => {
|
|
|
101
101
|
}
|
|
102
102
|
catch (error) {
|
|
103
103
|
logger.logger.debug(error);
|
|
104
|
+
// Handle the case where the user has already an account with the email
|
|
105
|
+
if (error instanceof utils.UserHasAccountWithEmailError) {
|
|
106
|
+
setView('merge-user-accounts');
|
|
107
|
+
return; // Early return to not show the error message
|
|
108
|
+
}
|
|
104
109
|
setErrorMessage(error.code);
|
|
105
110
|
}
|
|
106
111
|
finally {
|
|
@@ -119,6 +124,7 @@ const EmailVerification = () => {
|
|
|
119
124
|
setOnboardingOnlyJwt,
|
|
120
125
|
setCallback,
|
|
121
126
|
setErrorMessage,
|
|
127
|
+
setView,
|
|
122
128
|
]);
|
|
123
129
|
const handleEmailLogin = React.useCallback((verificationToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
124
130
|
setError(undefined);
|
|
@@ -2,7 +2,7 @@ import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
|
2
2
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { useState, useCallback } from 'react';
|
|
4
4
|
import { SignInWithEmailIcon } from '@dynamic-labs/iconic';
|
|
5
|
-
import { NoAccessError, AccountExistsError } from '@dynamic-labs/utils';
|
|
5
|
+
import { UserHasAccountWithEmailError, NoAccessError, AccountExistsError } from '@dynamic-labs/utils';
|
|
6
6
|
import { Typography } from '../../components/Typography/Typography.js';
|
|
7
7
|
import { decodeJwt } from '../../shared/utils/functions/decodeJwt/decodeJwt.js';
|
|
8
8
|
import '@dynamic-labs/wallet-connector-core';
|
|
@@ -97,6 +97,11 @@ const EmailVerification = () => {
|
|
|
97
97
|
}
|
|
98
98
|
catch (error) {
|
|
99
99
|
logger.debug(error);
|
|
100
|
+
// Handle the case where the user has already an account with the email
|
|
101
|
+
if (error instanceof UserHasAccountWithEmailError) {
|
|
102
|
+
setView('merge-user-accounts');
|
|
103
|
+
return; // Early return to not show the error message
|
|
104
|
+
}
|
|
100
105
|
setErrorMessage(error.code);
|
|
101
106
|
}
|
|
102
107
|
finally {
|
|
@@ -115,6 +120,7 @@ const EmailVerification = () => {
|
|
|
115
120
|
setOnboardingOnlyJwt,
|
|
116
121
|
setCallback,
|
|
117
122
|
setErrorMessage,
|
|
123
|
+
setView,
|
|
118
124
|
]);
|
|
119
125
|
const handleEmailLogin = useCallback((verificationToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
126
|
setError(undefined);
|