@n1xyz/wallet-widget 0.0.15 → 0.0.17
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/Logic/utils.d.ts +3 -1
- package/dist/Logic/utils.js +16 -2
- package/dist/Logic/utils.js.map +1 -1
- package/dist/Modal/N1WalletModal.d.ts +1 -0
- package/dist/Modal/N1WalletModal.js +1 -0
- package/dist/Modal/N1WalletModal.js.map +1 -1
- package/dist/Modal/NTSFlow/views/CreateSessionView.js +1 -0
- package/dist/Modal/NTSFlow/views/CreateSessionView.js.map +1 -1
- package/dist/Modal/NordFlow/screens/04-AmountInputScreen.js +1 -1
- package/dist/Modal/NordFlow/screens/04-AmountInputScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.d.ts +1 -1
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.js +14 -12
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.js.map +1 -1
- package/dist/Provider/N1WalletProvider.d.ts +1 -1
- package/dist/Provider/N1WalletProvider.js +65 -37
- package/dist/Provider/N1WalletProvider.js.map +1 -1
- package/dist/Provider/hooks/useNordUserInitialization.js +33 -37
- package/dist/Provider/hooks/useNordUserInitialization.js.map +1 -1
- package/dist/Provider/types.d.ts +13 -0
- package/dist/Provider/types.js.map +1 -1
- package/dist/embedded-main-css.d.ts +2 -0
- package/dist/embedded-main-css.js +3 -0
- package/dist/embedded-main-css.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/main.css +1 -1
- package/package.json +7 -4
- package/dist/Modal/NordFlow/context/deposit/types.d.ts +0 -26
- package/dist/Modal/NordFlow/context/deposit/types.js +0 -2
- package/dist/Modal/NordFlow/context/deposit/types.js.map +0 -1
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.d.ts +0 -7
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.js +0 -113
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.js.map +0 -1
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.d.ts +0 -20
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.js +0 -235
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.js.map +0 -1
- package/dist/Modal/NordFlow/hooks/index.d.ts +0 -3
- package/dist/Modal/NordFlow/hooks/index.js +0 -4
- package/dist/Modal/NordFlow/hooks/index.js.map +0 -1
- package/dist/Modal/NordFlow/hooks/useDepositFlow.d.ts +0 -52
- package/dist/Modal/NordFlow/hooks/useDepositFlow.js +0 -385
- package/dist/Modal/NordFlow/hooks/useDepositFlow.js.map +0 -1
- package/dist/Modal/NordFlow/hooks/useFlowState.d.ts +0 -32
- package/dist/Modal/NordFlow/hooks/useFlowState.js +0 -189
- package/dist/Modal/NordFlow/hooks/useFlowState.js.map +0 -1
- package/dist/Modal/NordFlow/hooks/useInterruptHandler.d.ts +0 -24
- package/dist/Modal/NordFlow/hooks/useInterruptHandler.js +0 -59
- package/dist/Modal/NordFlow/hooks/useInterruptHandler.js.map +0 -1
- package/dist/Modal/NordFlow/hooks/useNordInstance.d.ts +0 -0
- package/dist/Modal/NordFlow/hooks/useNordInstance.js +0 -3
- package/dist/Modal/NordFlow/hooks/useNordInstance.js.map +0 -1
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.d.ts +0 -13
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.js +0 -259
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.js.map +0 -1
- package/dist/Modal/NordFlow/utils/persistence.d.ts +0 -24
- package/dist/Modal/NordFlow/utils/persistence.js +0 -84
- package/dist/Modal/NordFlow/utils/persistence.js.map +0 -1
- package/dist/Provider/useN1WalletProvider.d.ts +0 -37
- package/dist/Provider/useN1WalletProvider.js +0 -398
- package/dist/Provider/useN1WalletProvider.js.map +0 -1
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
38
|
-
import { FlowState } from '../types';
|
|
39
|
-
import { AVAILABLE_CHAINS } from '../constants';
|
|
40
|
-
import { getExplorerUrl, } from '../../../Logic/transactionManager';
|
|
41
|
-
import { useN1WalletContext, useN1WalletInternalContext, } from '../../../Provider/hooks';
|
|
42
|
-
import { N1SessionMode } from '../../../Provider/types';
|
|
43
|
-
import { isNordConfigured } from '../utils/nordUtils';
|
|
44
|
-
import { logger } from '../../../utils/logger';
|
|
45
|
-
/**
|
|
46
|
-
* Hook for handling the deposit flow
|
|
47
|
-
*
|
|
48
|
-
* @param options Configuration options
|
|
49
|
-
* @returns Deposit flow methods and state
|
|
50
|
-
*/
|
|
51
|
-
export var useDepositFlow = function (options) {
|
|
52
|
-
var _a = useState(null), txId = _a[0], setTxId = _a[1];
|
|
53
|
-
var state = options.state, context = options.context, transition = options.transition, handleError = options.handleError;
|
|
54
|
-
var _b = useN1WalletContext(), address = _b.address, nord = _b.nord, signMessageWithWalletKey = _b.signMessageWithWalletKey, signMessageWithSessionKey = _b.signMessageWithSessionKey, nordUser = _b.nordUser;
|
|
55
|
-
var sessionMode = useN1WalletInternalContext().sessionMode;
|
|
56
|
-
var _c = useState(context.selectedChain), selectedChain = _c[0], setSelectedChain = _c[1];
|
|
57
|
-
var _d = useState(context.amount), amount = _d[0], setAmount = _d[1];
|
|
58
|
-
var _e = useState(false), isDepositing = _e[0], setIsDepositing = _e[1];
|
|
59
|
-
var _f = useState(context.transactionId), transactionId = _f[0], setTransactionId = _f[1];
|
|
60
|
-
var _g = useState(null), transactionResult = _g[0], setTransactionResult = _g[1];
|
|
61
|
-
// Use refs to track previous values
|
|
62
|
-
var prevContextRef = useRef(context);
|
|
63
|
-
// Use the nordUser from context
|
|
64
|
-
var currentNordUser = nordUser;
|
|
65
|
-
// Handle transaction ID changes
|
|
66
|
-
useEffect(function () {
|
|
67
|
-
if (!txId)
|
|
68
|
-
return;
|
|
69
|
-
// Transition to the appropriate screen based on whether user has an active session
|
|
70
|
-
if (context.hasActiveSession) {
|
|
71
|
-
// If user has an active session, go directly to FINAL_SUCCESS
|
|
72
|
-
transition(FlowState.FINAL_SUCCESS, { transactionId: txId });
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
// Check if there's a sessionId stored in localStorage
|
|
76
|
-
var sessionIdKey = "n1_sessionId_".concat(address);
|
|
77
|
-
var storedSessionId = localStorage.getItem(sessionIdKey);
|
|
78
|
-
if (storedSessionId !== null) {
|
|
79
|
-
// If we have a sessionId in localStorage (even if it's 0), go directly to FINAL_SUCCESS
|
|
80
|
-
transition(FlowState.FINAL_SUCCESS, { transactionId: txId });
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
// If user doesn't have an active session and no sessionId in localStorage, go to DEPOSIT_SUCCESS first
|
|
84
|
-
transition(FlowState.DEPOSIT_SUCCESS, { transactionId: txId });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
setTxId(null);
|
|
88
|
-
}, [txId, transition, context.hasActiveSession, address]);
|
|
89
|
-
/**
|
|
90
|
-
* Select a chain for deposit
|
|
91
|
-
*/
|
|
92
|
-
var selectChain = useCallback(function (chainId) {
|
|
93
|
-
var validChain = AVAILABLE_CHAINS.find(function (chain) { return chain.id === chainId; });
|
|
94
|
-
if (!validChain) {
|
|
95
|
-
handleError(new Error("Invalid chain: ".concat(chainId)));
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
setSelectedChain(chainId);
|
|
99
|
-
transition(FlowState.AMOUNT_INPUT, { selectedChain: chainId });
|
|
100
|
-
}, [transition, handleError]);
|
|
101
|
-
/**
|
|
102
|
-
* Update amount for deposit
|
|
103
|
-
*/
|
|
104
|
-
var updateAmount = useCallback(function (newAmount) {
|
|
105
|
-
setAmount(newAmount);
|
|
106
|
-
// Only update the context without transitioning to the same state
|
|
107
|
-
// This prevents the "Transition from AMOUNT_INPUT to AMOUNT_INPUT is not allowed" error
|
|
108
|
-
if (state === FlowState.AMOUNT_INPUT) {
|
|
109
|
-
// Use updateContext function if available to update without state transition
|
|
110
|
-
if (options.updateContext) {
|
|
111
|
-
options.updateContext({ amount: newAmount });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
transition(state, { amount: newAmount });
|
|
116
|
-
}
|
|
117
|
-
}, [state, transition, options.updateContext]);
|
|
118
|
-
/**
|
|
119
|
-
* Start deposit process
|
|
120
|
-
*/
|
|
121
|
-
var startDeposit = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
122
|
-
var currentSessionMode, txId_1, usdcToken, accountInitialized, i, exists, result, depositError_1, errorMessage, error_1, error_2;
|
|
123
|
-
var _a;
|
|
124
|
-
return __generator(this, function (_b) {
|
|
125
|
-
switch (_b.label) {
|
|
126
|
-
case 0:
|
|
127
|
-
if (isDepositing)
|
|
128
|
-
return [2 /*return*/];
|
|
129
|
-
logger.debug('Starting deposit process');
|
|
130
|
-
// Validate input
|
|
131
|
-
if (!selectedChain) {
|
|
132
|
-
handleError(new Error('No chain selected'));
|
|
133
|
-
return [2 /*return*/];
|
|
134
|
-
}
|
|
135
|
-
if (!amount || parseFloat(amount) <= 0) {
|
|
136
|
-
handleError(new Error('Invalid amount'));
|
|
137
|
-
return [2 /*return*/];
|
|
138
|
-
}
|
|
139
|
-
if (!address) {
|
|
140
|
-
handleError(new Error('No wallet address found'));
|
|
141
|
-
return [2 /*return*/];
|
|
142
|
-
}
|
|
143
|
-
setIsDepositing(true);
|
|
144
|
-
transition(FlowState.DEPOSIT_PROGRESS);
|
|
145
|
-
_b.label = 1;
|
|
146
|
-
case 1:
|
|
147
|
-
_b.trys.push([1, 18, , 19]);
|
|
148
|
-
currentSessionMode = sessionMode !== null && sessionMode !== void 0 ? sessionMode : N1SessionMode.NTS;
|
|
149
|
-
txId_1 = '';
|
|
150
|
-
if (!(currentNordUser && nord && isNordConfigured(nord))) return [3 /*break*/, 16];
|
|
151
|
-
_b.label = 2;
|
|
152
|
-
case 2:
|
|
153
|
-
_b.trys.push([2, 14, , 15]);
|
|
154
|
-
usdcToken = nord.tokens.find(function (t) { return t.symbol === 'USDC'; });
|
|
155
|
-
if (!usdcToken) {
|
|
156
|
-
throw new Error('USDC token not found');
|
|
157
|
-
}
|
|
158
|
-
_b.label = 3;
|
|
159
|
-
case 3:
|
|
160
|
-
_b.trys.push([3, 12, , 13]);
|
|
161
|
-
if (!(typeof currentNordUser.depositSpl === 'function')) return [3 /*break*/, 10];
|
|
162
|
-
return [4 /*yield*/, currentNordUser.depositSpl(parseFloat(amount), usdcToken.tokenId)];
|
|
163
|
-
case 4:
|
|
164
|
-
txId_1 = _b.sent();
|
|
165
|
-
accountInitialized = false;
|
|
166
|
-
i = 0;
|
|
167
|
-
_b.label = 5;
|
|
168
|
-
case 5:
|
|
169
|
-
if (!(i < 70)) return [3 /*break*/, 9];
|
|
170
|
-
return [4 /*yield*/, (nord === null || nord === void 0 ? void 0 : nord.accountExists(address))];
|
|
171
|
-
case 6:
|
|
172
|
-
exists = _b.sent();
|
|
173
|
-
if (exists) {
|
|
174
|
-
accountInitialized = true;
|
|
175
|
-
return [3 /*break*/, 9];
|
|
176
|
-
}
|
|
177
|
-
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 5000); })];
|
|
178
|
-
case 7:
|
|
179
|
-
_b.sent();
|
|
180
|
-
_b.label = 8;
|
|
181
|
-
case 8:
|
|
182
|
-
i++;
|
|
183
|
-
return [3 /*break*/, 5];
|
|
184
|
-
case 9:
|
|
185
|
-
if (!accountInitialized) {
|
|
186
|
-
throw new Error('Account failed to intialize on N1.');
|
|
187
|
-
}
|
|
188
|
-
logger.debug('Deposit successful using Nord-TS', txId_1);
|
|
189
|
-
// Make sure we have a valid chain ID
|
|
190
|
-
if (selectedChain) {
|
|
191
|
-
result = {
|
|
192
|
-
success: true,
|
|
193
|
-
transactionId: txId_1,
|
|
194
|
-
amount: amount,
|
|
195
|
-
tokenSymbol: 'USDC', // Default to USDC for now
|
|
196
|
-
fromAddress: address || 'Your Wallet',
|
|
197
|
-
toAddress: currentSessionMode === N1SessionMode.Nord
|
|
198
|
-
? 'Exchange Account'
|
|
199
|
-
: 'NTS Account',
|
|
200
|
-
networkName: ((_a = AVAILABLE_CHAINS.find(function (chain) { return chain.id === selectedChain; })) === null || _a === void 0 ? void 0 : _a.name) || selectedChain,
|
|
201
|
-
status: 'Completed',
|
|
202
|
-
explorerUrl: getExplorerUrl(txId_1, selectedChain),
|
|
203
|
-
};
|
|
204
|
-
// Update state with transaction result
|
|
205
|
-
setTransactionId(txId_1);
|
|
206
|
-
setTransactionResult(result);
|
|
207
|
-
logger.debug('Transaction completed successfully');
|
|
208
|
-
setTxId(txId_1);
|
|
209
|
-
return [2 /*return*/]; // Exit the function early since we've handled everything
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
throw new Error('No chain selected for deposit');
|
|
213
|
-
}
|
|
214
|
-
return [3 /*break*/, 11];
|
|
215
|
-
case 10:
|
|
216
|
-
// If depositSpl doesn't exist, throw an error to fall back to mock implementation
|
|
217
|
-
throw new Error('depositSpl method not available');
|
|
218
|
-
case 11: return [3 /*break*/, 13];
|
|
219
|
-
case 12:
|
|
220
|
-
depositError_1 = _b.sent();
|
|
221
|
-
logger.warn('Error using depositSpl, falling back to mock implementation:', depositError_1);
|
|
222
|
-
setIsDepositing(false);
|
|
223
|
-
errorMessage = depositError_1 instanceof Error
|
|
224
|
-
? depositError_1.message
|
|
225
|
-
: 'Failed to process deposit';
|
|
226
|
-
transition(FlowState.AMOUNT_INPUT, {
|
|
227
|
-
depositError: errorMessage
|
|
228
|
-
});
|
|
229
|
-
return [2 /*return*/]; // Exit early
|
|
230
|
-
case 13: return [3 /*break*/, 15];
|
|
231
|
-
case 14:
|
|
232
|
-
error_1 = _b.sent();
|
|
233
|
-
logger.error('Error using Nord-TS for deposit:', error_1);
|
|
234
|
-
throw error_1;
|
|
235
|
-
case 15: return [3 /*break*/, 17];
|
|
236
|
-
case 16:
|
|
237
|
-
logger.debug('Nord configuration issue:', {
|
|
238
|
-
hasNord: !!nord,
|
|
239
|
-
isConfigured: nord ? isNordConfigured(nord) : false,
|
|
240
|
-
hasAddress: !!address,
|
|
241
|
-
hasWalletSignFn: !!signMessageWithWalletKey,
|
|
242
|
-
hasSessionSignFn: !!signMessageWithSessionKey,
|
|
243
|
-
});
|
|
244
|
-
throw new Error('Nord is not configured or user is not initialized');
|
|
245
|
-
case 17: return [3 /*break*/, 19];
|
|
246
|
-
case 18:
|
|
247
|
-
error_2 = _b.sent();
|
|
248
|
-
setIsDepositing(false);
|
|
249
|
-
handleError(error_2 instanceof Error ? error_2 : new Error('Failed to process deposit'));
|
|
250
|
-
return [3 /*break*/, 19];
|
|
251
|
-
case 19: return [2 /*return*/];
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}); }, [
|
|
255
|
-
isDepositing,
|
|
256
|
-
selectedChain,
|
|
257
|
-
amount,
|
|
258
|
-
address,
|
|
259
|
-
sessionMode,
|
|
260
|
-
transition,
|
|
261
|
-
handleError,
|
|
262
|
-
nord,
|
|
263
|
-
signMessageWithWalletKey,
|
|
264
|
-
signMessageWithSessionKey,
|
|
265
|
-
currentNordUser,
|
|
266
|
-
]);
|
|
267
|
-
/**
|
|
268
|
-
* Complete the deposit process and move to the next screen
|
|
269
|
-
*/
|
|
270
|
-
var completeDeposit = useCallback(function () {
|
|
271
|
-
// Check if user has an active session to determine the next state
|
|
272
|
-
if (context.hasActiveSession) {
|
|
273
|
-
// If user has an active session, go directly to FINAL_SUCCESS
|
|
274
|
-
transition(FlowState.FINAL_SUCCESS);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
// Check if there's a sessionId stored in localStorage
|
|
278
|
-
var sessionIdKey = "n1_sessionId_".concat(address);
|
|
279
|
-
var storedSessionId = localStorage.getItem(sessionIdKey);
|
|
280
|
-
if (storedSessionId !== null) {
|
|
281
|
-
// If we have a sessionId in localStorage (even if it's 0), go directly to FINAL_SUCCESS
|
|
282
|
-
transition(FlowState.FINAL_SUCCESS);
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
// If user doesn't have an active session and no sessionId in localStorage, go to NORD_AUTH
|
|
286
|
-
transition(FlowState.AUTH_LOADING);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}, [context.hasActiveSession, transition, address]);
|
|
290
|
-
/**
|
|
291
|
-
* Go back to chain selection
|
|
292
|
-
*/
|
|
293
|
-
var goBackToChainSelection = useCallback(function () {
|
|
294
|
-
setAmount('');
|
|
295
|
-
transition(FlowState.CHAIN_SELECTION, { amount: '' });
|
|
296
|
-
}, [transition]);
|
|
297
|
-
/**
|
|
298
|
-
* Update state based on context changes
|
|
299
|
-
*/
|
|
300
|
-
useEffect(function () {
|
|
301
|
-
var prevContext = prevContextRef.current;
|
|
302
|
-
// Only update state if the relevant context values have actually changed
|
|
303
|
-
if (context.selectedChain !== prevContext.selectedChain) {
|
|
304
|
-
setSelectedChain(context.selectedChain);
|
|
305
|
-
}
|
|
306
|
-
if (context.amount !== prevContext.amount) {
|
|
307
|
-
setAmount(context.amount);
|
|
308
|
-
}
|
|
309
|
-
if (context.transactionId !== prevContext.transactionId) {
|
|
310
|
-
setTransactionId(context.transactionId);
|
|
311
|
-
}
|
|
312
|
-
// Update the ref to the current context
|
|
313
|
-
prevContextRef.current = context;
|
|
314
|
-
}, [context]);
|
|
315
|
-
/**
|
|
316
|
-
* Auto-start deposit if in deposit progress state
|
|
317
|
-
*/
|
|
318
|
-
useEffect(function () {
|
|
319
|
-
if (state === FlowState.DEPOSIT_PROGRESS &&
|
|
320
|
-
!isDepositing &&
|
|
321
|
-
!transactionId) {
|
|
322
|
-
startDeposit();
|
|
323
|
-
}
|
|
324
|
-
}, [state, isDepositing, transactionId, startDeposit]);
|
|
325
|
-
/**
|
|
326
|
-
* Get transaction details for display
|
|
327
|
-
*/
|
|
328
|
-
var getTransactionDetails = useCallback(function () {
|
|
329
|
-
var _a;
|
|
330
|
-
// Ensure we have a valid session mode
|
|
331
|
-
var currentSessionMode = sessionMode !== null && sessionMode !== void 0 ? sessionMode : N1SessionMode.NTS;
|
|
332
|
-
// Determine account type based on session mode
|
|
333
|
-
var accountType = currentSessionMode === N1SessionMode.Nord
|
|
334
|
-
? 'Exchange Account'
|
|
335
|
-
: 'NTS Account';
|
|
336
|
-
if (!transactionResult) {
|
|
337
|
-
// If we don't have a transaction result yet, return default values
|
|
338
|
-
return {
|
|
339
|
-
amount: amount || '0',
|
|
340
|
-
tx: transactionId || 'Processing...',
|
|
341
|
-
from: address || 'Your Wallet',
|
|
342
|
-
to: accountType,
|
|
343
|
-
network: selectedChain
|
|
344
|
-
? ((_a = AVAILABLE_CHAINS.find(function (chain) { return chain.id === selectedChain; })) === null || _a === void 0 ? void 0 : _a.name) || selectedChain
|
|
345
|
-
: 'Unknown',
|
|
346
|
-
status: 'Processing',
|
|
347
|
-
explorerUrl: '',
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
// Return actual transaction details
|
|
351
|
-
return {
|
|
352
|
-
amount: "".concat(transactionResult.amount, " ").concat(transactionResult.tokenSymbol),
|
|
353
|
-
tx: transactionResult.transactionId,
|
|
354
|
-
from: transactionResult.fromAddress,
|
|
355
|
-
to: transactionResult.toAddress,
|
|
356
|
-
network: transactionResult.networkName,
|
|
357
|
-
status: transactionResult.status,
|
|
358
|
-
explorerUrl: transactionResult.explorerUrl ||
|
|
359
|
-
getExplorerUrl(transactionResult.transactionId, selectedChain || ''),
|
|
360
|
-
};
|
|
361
|
-
}, [
|
|
362
|
-
transactionResult,
|
|
363
|
-
amount,
|
|
364
|
-
transactionId,
|
|
365
|
-
address,
|
|
366
|
-
sessionMode,
|
|
367
|
-
selectedChain,
|
|
368
|
-
]);
|
|
369
|
-
return {
|
|
370
|
-
selectedChain: selectedChain,
|
|
371
|
-
setSelectedChain: setSelectedChain,
|
|
372
|
-
amount: amount,
|
|
373
|
-
setAmount: setAmount,
|
|
374
|
-
isDepositing: isDepositing,
|
|
375
|
-
transactionId: transactionId,
|
|
376
|
-
transactionResult: transactionResult,
|
|
377
|
-
selectChain: selectChain,
|
|
378
|
-
updateAmount: updateAmount,
|
|
379
|
-
startDeposit: startDeposit,
|
|
380
|
-
completeDeposit: completeDeposit,
|
|
381
|
-
goBackToChainSelection: goBackToChainSelection,
|
|
382
|
-
getTransactionDetails: getTransactionDetails,
|
|
383
|
-
};
|
|
384
|
-
};
|
|
385
|
-
//# sourceMappingURL=useDepositFlow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDepositFlow.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/hooks/useDepositFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAe,SAAS,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,cAAc,GAEf,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,yBAAyB,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AM;YAChC,WAAW,EACT,iBAAiB,CAAC,WAAW;gBAC7B,cAAc,CAAC,iBAAiB,CAAC,aAAa,EAAE,aAAa,IAAI,EAAE,CAAC;SACvE,CAAC;IACJ,CAAC,EAAE;QACD,iBAAiB;QACjB,MAAM;QACN,aAAa;QACb,OAAO;QACP,WAAW;QACX,aAAa;KACd,CAAC,CAAC;IAEH,OAAO;QACL,aAAa,eAAA;QACb,gBAAgB,kBAAA;QAChB,MAAM,QAAA;QACN,SAAS,WAAA;QACT,YAAY,cAAA;QACZ,aAAa,eAAA;QACb,iBAAiB,mBAAA;QACjB,WAAW,aAAA;QACX,YAAY,cAAA;QACZ,YAAY,cAAA;QACZ,eAAe,iBAAA;QACf,sBAAsB,wBAAA;QACtB,qBAAqB,uBAAA;KACtB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { FlowContext, FlowState } from '../types';\nimport { AVAILABLE_CHAINS } from '../constants';\nimport {\n getExplorerUrl,\n TransactionResult,\n} from '../../../Logic/transactionManager';\nimport {\n useN1WalletContext,\n useN1WalletInternalContext,\n} from '../../../Provider/hooks';\nimport { N1SessionMode } from '../../../Provider/types';\nimport { isNordConfigured } from '../utils/nordUtils';\nimport { logger } from '../../../utils/logger';\n\n/**\n * Hook for handling the deposit flow\n *\n * @param options Configuration options\n * @returns Deposit flow methods and state\n */\nexport const useDepositFlow = (options: {\n /**\n * Flow state\n */\n state: FlowState;\n /**\n * Flow context\n */\n context: FlowContext;\n /**\n * Transition to a new state\n */\n transition: (\n newState: FlowState,\n contextUpdates?: Partial<FlowContext>\n ) => boolean;\n /**\n * Handle errors\n */\n handleError: (error: Error) => void;\n /**\n * Update context\n */\n updateContext?: (contextUpdates: Partial<FlowContext>) => void;\n}) => {\n const [txId, setTxId] = useState<string | null>(null);\n const { state, context, transition, handleError } = options;\n const {\n address,\n nord,\n signMessageWithWalletKey,\n signMessageWithSessionKey,\n nordUser,\n } = useN1WalletContext();\n const { sessionMode } = useN1WalletInternalContext();\n\n const [selectedChain, setSelectedChain] = useState<string | null>(\n context.selectedChain\n );\n const [amount, setAmount] = useState(context.amount);\n const [isDepositing, setIsDepositing] = useState(false);\n const [transactionId, setTransactionId] = useState<string | null>(\n context.transactionId\n );\n const [transactionResult, setTransactionResult] =\n useState<TransactionResult | null>(null);\n\n // Use refs to track previous values\n const prevContextRef = useRef(context);\n \n // Use the nordUser from context\n const currentNordUser = nordUser;\n\n // Handle transaction ID changes\n useEffect(() => {\n if (!txId) return;\n \n // Transition to the appropriate screen based on whether user has an active session\n if (context.hasActiveSession) {\n // If user has an active session, go directly to FINAL_SUCCESS\n transition(FlowState.FINAL_SUCCESS, { transactionId: txId });\n } else {\n // Check if there's a sessionId stored in localStorage\n const sessionIdKey = `n1_sessionId_${address}`;\n const storedSessionId = localStorage.getItem(sessionIdKey);\n\n if (storedSessionId !== null) {\n // If we have a sessionId in localStorage (even if it's 0), go directly to FINAL_SUCCESS\n transition(FlowState.FINAL_SUCCESS, { transactionId: txId });\n } else {\n // If user doesn't have an active session and no sessionId in localStorage, go to DEPOSIT_SUCCESS first\n transition(FlowState.DEPOSIT_SUCCESS, { transactionId: txId });\n }\n }\n setTxId(null);\n }, [txId, transition, context.hasActiveSession, address]);\n\n /**\n * Select a chain for deposit\n */\n const selectChain = useCallback(\n (chainId: string) => {\n const validChain = AVAILABLE_CHAINS.find((chain) => chain.id === chainId);\n\n if (!validChain) {\n handleError(new Error(`Invalid chain: ${chainId}`));\n return;\n }\n\n setSelectedChain(chainId);\n transition(FlowState.AMOUNT_INPUT, { selectedChain: chainId });\n },\n [transition, handleError]\n );\n\n /**\n * Update amount for deposit\n */\n const updateAmount = useCallback(\n (newAmount: string) => {\n setAmount(newAmount);\n // Only update the context without transitioning to the same state\n // This prevents the \"Transition from AMOUNT_INPUT to AMOUNT_INPUT is not allowed\" error\n if (state === FlowState.AMOUNT_INPUT) {\n // Use updateContext function if available to update without state transition\n if (options.updateContext) {\n options.updateContext({ amount: newAmount });\n }\n } else {\n transition(state, { amount: newAmount });\n }\n },\n [state, transition, options.updateContext]\n );\n\n /**\n * Start deposit process\n */\n const startDeposit = useCallback(async () => {\n if (isDepositing) return;\n\n logger.debug('Starting deposit process');\n // Validate input\n if (!selectedChain) {\n handleError(new Error('No chain selected'));\n return;\n }\n\n if (!amount || parseFloat(amount) <= 0) {\n handleError(new Error('Invalid amount'));\n return;\n }\n\n if (!address) {\n handleError(new Error('No wallet address found'));\n return;\n }\n\n setIsDepositing(true);\n transition(FlowState.DEPOSIT_PROGRESS);\n\n try {\n // Ensure we have a valid session mode\n const currentSessionMode = sessionMode ?? N1SessionMode.NTS;\n\n // Use Nord-TS if available\n let txId = '';\n\n if (currentNordUser && nord && isNordConfigured(nord)) {\n try {\n // Find the USDC token\n const usdcToken = nord.tokens.find((t: any) => t.symbol === 'USDC');\n if (!usdcToken) {\n throw new Error('USDC token not found');\n }\n\n // Attempt to perform the deposit using Nord-TS\n // Since we don't know the exact API, we'll use a try-catch approach\n try {\n // Try depositSpl method if it exists\n if (typeof currentNordUser.depositSpl === 'function') {\n txId = await currentNordUser.depositSpl(\n parseFloat(amount),\n usdcToken.tokenId\n );\n\n let accountInitialized = false;\n for (let i = 0; i < 70; i++) {\n const exists = await nord?.accountExists(address);\n if (exists) {\n accountInitialized = true;\n break;\n }\n await new Promise((resolve) => setTimeout(resolve, 5000));\n }\n\n if (!accountInitialized) {\n throw new Error('Account failed to intialize on N1.');\n }\n\n logger.debug('Deposit successful using Nord-TS', txId);\n\n // Make sure we have a valid chain ID\n if (selectedChain) {\n // Create transaction result object immediately after successful deposit\n const result: TransactionResult = {\n success: true,\n transactionId: txId,\n amount,\n tokenSymbol: 'USDC', // Default to USDC for now\n fromAddress: address || 'Your Wallet',\n toAddress:\n currentSessionMode === N1SessionMode.Nord\n ? 'Exchange Account'\n : 'NTS Account',\n networkName:\n AVAILABLE_CHAINS.find((chain) => chain.id === selectedChain)\n ?.name || selectedChain,\n status: 'Completed',\n explorerUrl: getExplorerUrl(txId, selectedChain),\n };\n\n // Update state with transaction result\n setTransactionId(txId);\n setTransactionResult(result);\n\n logger.debug('Transaction completed successfully');\n setTxId(txId);\n return; // Exit the function early since we've handled everything\n } else {\n throw new Error('No chain selected for deposit');\n }\n } else {\n // If depositSpl doesn't exist, throw an error to fall back to mock implementation\n throw new Error('depositSpl method not available');\n }\n } catch (depositError) {\n logger.warn(\n 'Error using depositSpl, falling back to mock implementation:',\n depositError\n );\n setIsDepositing(false);\n \n // Transition back to AMOUNT_INPUT with the error message\n const errorMessage = depositError instanceof Error \n ? depositError.message \n : 'Failed to process deposit';\n \n transition(FlowState.AMOUNT_INPUT, { \n depositError: errorMessage \n });\n return; // Exit early\n }\n } catch (error) {\n logger.error('Error using Nord-TS for deposit:', error);\n throw error;\n }\n } else {\n logger.debug('Nord configuration issue:', {\n hasNord: !!nord,\n isConfigured: nord ? isNordConfigured(nord) : false,\n hasAddress: !!address,\n hasWalletSignFn: !!signMessageWithWalletKey,\n hasSessionSignFn: !!signMessageWithSessionKey,\n });\n\n throw new Error('Nord is not configured or user is not initialized');\n }\n } catch (error) {\n setIsDepositing(false);\n handleError(\n error instanceof Error ? error : new Error('Failed to process deposit')\n );\n }\n }, [\n isDepositing,\n selectedChain,\n amount,\n address,\n sessionMode,\n transition,\n handleError,\n nord,\n signMessageWithWalletKey,\n signMessageWithSessionKey,\n currentNordUser,\n ]);\n\n /**\n * Complete the deposit process and move to the next screen\n */\n const completeDeposit = useCallback(() => {\n // Check if user has an active session to determine the next state\n if (context.hasActiveSession) {\n // If user has an active session, go directly to FINAL_SUCCESS\n transition(FlowState.FINAL_SUCCESS);\n } else {\n // Check if there's a sessionId stored in localStorage\n const sessionIdKey = `n1_sessionId_${address}`;\n const storedSessionId = localStorage.getItem(sessionIdKey);\n\n if (storedSessionId !== null) {\n // If we have a sessionId in localStorage (even if it's 0), go directly to FINAL_SUCCESS\n transition(FlowState.FINAL_SUCCESS);\n } else {\n // If user doesn't have an active session and no sessionId in localStorage, go to NORD_AUTH\n transition(FlowState.AUTH_LOADING);\n }\n }\n }, [context.hasActiveSession, transition, address]);\n\n /**\n * Go back to chain selection\n */\n const goBackToChainSelection = useCallback(() => {\n setAmount('');\n transition(FlowState.CHAIN_SELECTION, { amount: '' });\n }, [transition]);\n\n /**\n * Update state based on context changes\n */\n useEffect(() => {\n const prevContext = prevContextRef.current;\n \n // Only update state if the relevant context values have actually changed\n if (context.selectedChain !== prevContext.selectedChain) {\n setSelectedChain(context.selectedChain);\n }\n\n if (context.amount !== prevContext.amount) {\n setAmount(context.amount);\n }\n\n if (context.transactionId !== prevContext.transactionId) {\n setTransactionId(context.transactionId);\n }\n \n // Update the ref to the current context\n prevContextRef.current = context;\n }, [context]);\n\n /**\n * Auto-start deposit if in deposit progress state\n */\n useEffect(() => {\n if (\n state === FlowState.DEPOSIT_PROGRESS &&\n !isDepositing &&\n !transactionId\n ) {\n startDeposit();\n }\n }, [state, isDepositing, transactionId, startDeposit]);\n\n /**\n * Get transaction details for display\n */\n const getTransactionDetails = useCallback(() => {\n // Ensure we have a valid session mode\n const currentSessionMode = sessionMode ?? N1SessionMode.NTS;\n\n // Determine account type based on session mode\n const accountType =\n currentSessionMode === N1SessionMode.Nord\n ? 'Exchange Account'\n : 'NTS Account';\n\n if (!transactionResult) {\n // If we don't have a transaction result yet, return default values\n return {\n amount: amount || '0',\n tx: transactionId || 'Processing...',\n from: address || 'Your Wallet',\n to: accountType,\n network: selectedChain\n ? AVAILABLE_CHAINS.find((chain) => chain.id === selectedChain)\n ?.name || selectedChain\n : 'Unknown',\n status: 'Processing',\n explorerUrl: '',\n };\n }\n\n // Return actual transaction details\n return {\n amount: `${transactionResult.amount} ${transactionResult.tokenSymbol}`,\n tx: transactionResult.transactionId,\n from: transactionResult.fromAddress,\n to: transactionResult.toAddress,\n network: transactionResult.networkName,\n status: transactionResult.status,\n explorerUrl:\n transactionResult.explorerUrl ||\n getExplorerUrl(transactionResult.transactionId, selectedChain || ''),\n };\n }, [\n transactionResult,\n amount,\n transactionId,\n address,\n sessionMode,\n selectedChain,\n ]);\n\n return {\n selectedChain,\n setSelectedChain,\n amount,\n setAmount,\n isDepositing,\n transactionId,\n transactionResult,\n selectChain,\n updateAmount,\n startDeposit,\n completeDeposit,\n goBackToChainSelection,\n getTransactionDetails,\n };\n};\n"]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { FlowContext, FlowState } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Custom hook for managing the wallet connection flow state machine
|
|
4
|
-
* @param options Configuration options
|
|
5
|
-
* @returns Flow state management methods and properties
|
|
6
|
-
*/
|
|
7
|
-
export declare const useFlowState: (options: {
|
|
8
|
-
/**
|
|
9
|
-
* Whether to automatically recover saved state on initialization
|
|
10
|
-
*/
|
|
11
|
-
autoRecover?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Callback when state changes
|
|
14
|
-
*/
|
|
15
|
-
onStateChange?: (newState: FlowState, prevState: FlowState | null) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Callback when an error occurs
|
|
18
|
-
*/
|
|
19
|
-
onError?: (error: Error) => void;
|
|
20
|
-
}) => {
|
|
21
|
-
state: FlowState;
|
|
22
|
-
prevState: FlowState | null;
|
|
23
|
-
context: FlowContext;
|
|
24
|
-
isTransitioning: boolean;
|
|
25
|
-
isRecoveryAvailable: boolean;
|
|
26
|
-
transition: (targetState: FlowState, contextUpdates?: Partial<FlowContext>) => boolean;
|
|
27
|
-
updateContext: (updates: Partial<FlowContext>) => void;
|
|
28
|
-
reset: () => void;
|
|
29
|
-
recover: () => boolean;
|
|
30
|
-
recordInterruption: () => void;
|
|
31
|
-
handleError: (error: Error) => void;
|
|
32
|
-
};
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
13
|
-
import { FlowState, initialFlowContext } from '../types';
|
|
14
|
-
import { STATE_TRANSITIONS } from '../constants';
|
|
15
|
-
import { clearStoredState, loadStateFromLocalStorage, saveStateToLocalStorage, } from '../utils/persistence';
|
|
16
|
-
import { logger } from '../../../utils/logger';
|
|
17
|
-
/**
|
|
18
|
-
* Custom hook for managing the wallet connection flow state machine
|
|
19
|
-
* @param options Configuration options
|
|
20
|
-
* @returns Flow state management methods and properties
|
|
21
|
-
*/
|
|
22
|
-
export var useFlowState = function (options) {
|
|
23
|
-
var onStateChange = options.onStateChange, onError = options.onError;
|
|
24
|
-
// Flow state
|
|
25
|
-
var _a = useState(FlowState.IDLE), state = _a[0], setState = _a[1];
|
|
26
|
-
var _b = useState(null), prevState = _b[0], setPrevState = _b[1];
|
|
27
|
-
var _c = useState(initialFlowContext), context = _c[0], setContext = _c[1];
|
|
28
|
-
var _d = useState(false), isTransitioning = _d[0], setIsTransitioning = _d[1];
|
|
29
|
-
var _e = useState(false), isRecoveryAvailable = _e[0], setIsRecoveryAvailable = _e[1];
|
|
30
|
-
// Use refs to track previous values
|
|
31
|
-
var prevStateRef = useRef(FlowState.IDLE);
|
|
32
|
-
var prevContextRef = useRef(initialFlowContext);
|
|
33
|
-
/**
|
|
34
|
-
* Check if a transition is allowed based on current state and context
|
|
35
|
-
*/
|
|
36
|
-
var canTransition = useCallback(function (targetState, contextData) {
|
|
37
|
-
return STATE_TRANSITIONS.some(function (transition) {
|
|
38
|
-
var fromMatches = Array.isArray(transition.from)
|
|
39
|
-
? transition.from.includes(state)
|
|
40
|
-
: transition.from === state;
|
|
41
|
-
if (!fromMatches || transition.to !== targetState) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
if (transition.condition) {
|
|
45
|
-
return transition.condition(contextData);
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
});
|
|
49
|
-
}, [state]);
|
|
50
|
-
/**
|
|
51
|
-
* Transition to a new state if allowed
|
|
52
|
-
*/
|
|
53
|
-
var transition = useCallback(function (targetState, contextUpdates) {
|
|
54
|
-
if (contextUpdates === void 0) { contextUpdates = {}; }
|
|
55
|
-
// Skip if we're already in the target state and no context updates
|
|
56
|
-
if (targetState === state && Object.keys(contextUpdates).length === 0) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
if (!canTransition(targetState, __assign(__assign({}, context), contextUpdates))) {
|
|
60
|
-
logger.warn("Transition from ".concat(state, " to ").concat(targetState, " is not allowed"));
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
setIsTransitioning(true);
|
|
64
|
-
// Update context first
|
|
65
|
-
setContext(function (prevContext) {
|
|
66
|
-
var newContext = __assign(__assign({}, prevContext), contextUpdates);
|
|
67
|
-
// Save new state and context to localStorage for recovery
|
|
68
|
-
saveStateToLocalStorage(targetState, newContext);
|
|
69
|
-
return newContext;
|
|
70
|
-
});
|
|
71
|
-
// Then update state
|
|
72
|
-
setPrevState(state);
|
|
73
|
-
prevStateRef.current = state;
|
|
74
|
-
logger.debug("Transitioning from ".concat(state, " to ").concat(targetState));
|
|
75
|
-
setState(targetState);
|
|
76
|
-
if (onStateChange) {
|
|
77
|
-
onStateChange(targetState, state);
|
|
78
|
-
}
|
|
79
|
-
setIsTransitioning(false);
|
|
80
|
-
return true;
|
|
81
|
-
}, [canTransition, state, context, onStateChange]);
|
|
82
|
-
/**
|
|
83
|
-
* Reset flow to initial state
|
|
84
|
-
*/
|
|
85
|
-
var reset = useCallback(function () {
|
|
86
|
-
clearStoredState();
|
|
87
|
-
setContext(initialFlowContext);
|
|
88
|
-
prevContextRef.current = initialFlowContext;
|
|
89
|
-
setPrevState(null);
|
|
90
|
-
logger.debug('Resetting flow state to IDLE');
|
|
91
|
-
setState(FlowState.IDLE);
|
|
92
|
-
prevStateRef.current = FlowState.IDLE;
|
|
93
|
-
if (onStateChange) {
|
|
94
|
-
onStateChange(FlowState.IDLE, state);
|
|
95
|
-
}
|
|
96
|
-
}, [state, onStateChange]);
|
|
97
|
-
/**
|
|
98
|
-
* Handle an error by transitioning to error state
|
|
99
|
-
*/
|
|
100
|
-
var handleError = useCallback(function (error) {
|
|
101
|
-
if (onError) {
|
|
102
|
-
onError(error);
|
|
103
|
-
}
|
|
104
|
-
transition(FlowState.ERROR, { error: error });
|
|
105
|
-
}, [transition, onError]);
|
|
106
|
-
/**
|
|
107
|
-
* Recover state from localStorage
|
|
108
|
-
*/
|
|
109
|
-
var recover = useCallback(function () {
|
|
110
|
-
var savedState = loadStateFromLocalStorage();
|
|
111
|
-
if (!savedState) {
|
|
112
|
-
setIsRecoveryAvailable(false);
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
setContext(savedState.context);
|
|
116
|
-
prevContextRef.current = savedState.context;
|
|
117
|
-
setPrevState(state);
|
|
118
|
-
prevStateRef.current = state;
|
|
119
|
-
logger.debug("Recovering state: ".concat(savedState.state));
|
|
120
|
-
setState(savedState.state);
|
|
121
|
-
if (onStateChange) {
|
|
122
|
-
onStateChange(savedState.state, state);
|
|
123
|
-
}
|
|
124
|
-
return true;
|
|
125
|
-
}, [state, onStateChange]);
|
|
126
|
-
/**
|
|
127
|
-
* Update context without state transition
|
|
128
|
-
*/
|
|
129
|
-
var updateContext = useCallback(function (updates) {
|
|
130
|
-
// Skip if no actual updates
|
|
131
|
-
if (Object.keys(updates).length === 0) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
setContext(function (prevContext) {
|
|
135
|
-
// Check if any values are actually changing
|
|
136
|
-
var hasChanges = false;
|
|
137
|
-
// Type-safe way to check for changes
|
|
138
|
-
Object.keys(updates).forEach(function (key) {
|
|
139
|
-
if (updates[key] !== prevContext[key]) {
|
|
140
|
-
hasChanges = true;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
// If nothing is changing, return the previous context
|
|
144
|
-
if (!hasChanges) {
|
|
145
|
-
return prevContext;
|
|
146
|
-
}
|
|
147
|
-
var newContext = __assign(__assign({}, prevContext), updates);
|
|
148
|
-
prevContextRef.current = newContext;
|
|
149
|
-
saveStateToLocalStorage(state, newContext);
|
|
150
|
-
return newContext;
|
|
151
|
-
});
|
|
152
|
-
}, [state]);
|
|
153
|
-
/**
|
|
154
|
-
* Record an interruption in the flow (e.g., modal close, page reload)
|
|
155
|
-
*/
|
|
156
|
-
var recordInterruption = useCallback(function () {
|
|
157
|
-
updateContext({
|
|
158
|
-
lastInterruption: {
|
|
159
|
-
timestamp: Date.now(),
|
|
160
|
-
state: state,
|
|
161
|
-
context: __assign({}, context),
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
}, [state, context, updateContext]);
|
|
165
|
-
// Register unload handler to record interruptions
|
|
166
|
-
useEffect(function () {
|
|
167
|
-
var handleBeforeUnload = function () {
|
|
168
|
-
recordInterruption();
|
|
169
|
-
};
|
|
170
|
-
window.addEventListener('beforeunload', handleBeforeUnload);
|
|
171
|
-
return function () {
|
|
172
|
-
window.removeEventListener('beforeunload', handleBeforeUnload);
|
|
173
|
-
};
|
|
174
|
-
}, [recordInterruption]);
|
|
175
|
-
return {
|
|
176
|
-
state: state,
|
|
177
|
-
prevState: prevState,
|
|
178
|
-
context: context,
|
|
179
|
-
isTransitioning: isTransitioning,
|
|
180
|
-
isRecoveryAvailable: isRecoveryAvailable,
|
|
181
|
-
transition: transition,
|
|
182
|
-
updateContext: updateContext,
|
|
183
|
-
reset: reset,
|
|
184
|
-
recover: recover,
|
|
185
|
-
recordInterruption: recordInterruption,
|
|
186
|
-
handleError: handleError,
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
//# sourceMappingURL=useFlowState.js.map
|