@n1xyz/wallet-widget 0.0.9 → 0.0.11
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/transactionManager.d.ts +1 -1
- package/dist/Logic/transactionManager.js +1 -1
- package/dist/Logic/transactionManager.js.map +1 -1
- package/dist/Modal/LoadingFallback.js +1 -1
- package/dist/Modal/LoadingFallback.js.map +1 -1
- package/dist/Modal/NTSFlow/LoadingFallback.js +1 -1
- package/dist/Modal/NTSFlow/LoadingFallback.js.map +1 -1
- package/dist/Modal/NTSFlow/components/BackButton.js +2 -2
- package/dist/Modal/NTSFlow/components/BackButton.js.map +1 -1
- package/dist/Modal/NTSFlow/components/ModalHeader.js +1 -1
- package/dist/Modal/NTSFlow/components/ModalHeader.js.map +1 -1
- package/dist/Modal/NTSFlow/views/ConnectView.js +2 -2
- package/dist/Modal/NTSFlow/views/ConnectView.js.map +1 -1
- package/dist/Modal/NTSFlow/views/CreateSessionView.js +5 -5
- package/dist/Modal/NTSFlow/views/CreateSessionView.js.map +1 -1
- package/dist/Modal/NTSFlow/views/CreateUserView.js +1 -1
- package/dist/Modal/NTSFlow/views/CreateUserView.js.map +1 -1
- package/dist/Modal/NTSFlow/views/NoWhitelistView.js +3 -3
- package/dist/Modal/NTSFlow/views/NoWhitelistView.js.map +1 -1
- package/dist/Modal/NTSFlow/views/SigningView.js +1 -1
- package/dist/Modal/NTSFlow/views/SigningView.js.map +1 -1
- package/dist/Modal/NordFlow/NordFlow.js +22 -228
- package/dist/Modal/NordFlow/NordFlow.js.map +1 -1
- package/dist/Modal/NordFlow/components/ChainButton.js +5 -5
- package/dist/Modal/NordFlow/components/ChainButton.js.map +1 -1
- package/dist/Modal/NordFlow/components/EVMChainsButton.js +4 -4
- package/dist/Modal/NordFlow/components/EVMChainsButton.js.map +1 -1
- package/dist/Modal/NordFlow/components/Header.d.ts +10 -0
- package/dist/Modal/NordFlow/components/Header.js +11 -0
- package/dist/Modal/NordFlow/components/Header.js.map +1 -0
- package/dist/Modal/NordFlow/components/ImageWithFallback.js +1 -1
- package/dist/Modal/NordFlow/components/ImageWithFallback.js.map +1 -1
- package/dist/Modal/NordFlow/components/LoadingSquares.js +1 -1
- package/dist/Modal/NordFlow/components/LoadingSquares.js.map +1 -1
- package/dist/Modal/NordFlow/components/MoreButton.js +4 -4
- package/dist/Modal/NordFlow/components/MoreButton.js.map +1 -1
- package/dist/Modal/NordFlow/components/TransactionTable.js +7 -10
- package/dist/Modal/NordFlow/components/TransactionTable.js.map +1 -1
- package/dist/Modal/NordFlow/components/WaitingMessage.js +1 -1
- package/dist/Modal/NordFlow/components/WaitingMessage.js.map +1 -1
- package/dist/Modal/NordFlow/components/index.d.ts +1 -0
- package/dist/Modal/NordFlow/components/index.js +1 -0
- package/dist/Modal/NordFlow/components/index.js.map +1 -1
- package/dist/Modal/NordFlow/constants.js +116 -95
- package/dist/Modal/NordFlow/constants.js.map +1 -1
- package/dist/Modal/NordFlow/context/DepositContext.d.ts +27 -0
- package/dist/Modal/NordFlow/context/DepositContext.js +308 -0
- package/dist/Modal/NordFlow/context/DepositContext.js.map +1 -0
- package/dist/Modal/NordFlow/context/FlowContext.d.ts +23 -0
- package/dist/Modal/NordFlow/context/FlowContext.js +125 -0
- package/dist/Modal/NordFlow/context/FlowContext.js.map +1 -0
- package/dist/Modal/NordFlow/context/NordProvider.d.ts +10 -0
- package/dist/Modal/NordFlow/context/NordProvider.js +14 -0
- package/dist/Modal/NordFlow/context/NordProvider.js.map +1 -0
- package/dist/Modal/NordFlow/context/WalletConnectContext.d.ts +20 -0
- package/dist/Modal/NordFlow/context/WalletConnectContext.js +214 -0
- package/dist/Modal/NordFlow/context/WalletConnectContext.js.map +1 -0
- package/dist/Modal/NordFlow/context/deposit/types.d.ts +26 -0
- package/dist/Modal/NordFlow/context/deposit/types.js +2 -0
- package/dist/Modal/NordFlow/context/deposit/types.js.map +1 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.d.ts +7 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.js +113 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.js.map +1 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.d.ts +20 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.js +235 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.js.map +1 -0
- package/dist/Modal/NordFlow/context/index.d.ts +5 -0
- package/dist/Modal/NordFlow/context/index.js +8 -0
- package/dist/Modal/NordFlow/context/index.js.map +1 -0
- package/dist/Modal/NordFlow/hooks/index.d.ts +3 -5
- package/dist/Modal/NordFlow/hooks/index.js +3 -5
- package/dist/Modal/NordFlow/hooks/index.js.map +1 -1
- package/dist/Modal/NordFlow/hooks/useDepositFlow.js +2 -4
- package/dist/Modal/NordFlow/hooks/useDepositFlow.js.map +1 -1
- package/dist/Modal/NordFlow/hooks/useNordInstance.d.ts +0 -6
- package/dist/Modal/NordFlow/hooks/useNordInstance.js +2 -358
- package/dist/Modal/NordFlow/hooks/useNordInstance.js.map +1 -1
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.d.ts +0 -1
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.js +0 -1
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.js.map +1 -1
- package/dist/Modal/NordFlow/screens/00-IdleScreen.d.ts +6 -0
- package/dist/Modal/NordFlow/screens/00-IdleScreen.js +9 -0
- package/dist/Modal/NordFlow/screens/00-IdleScreen.js.map +1 -0
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.d.ts +1 -6
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.js +12 -6
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/02-EvmWalletAuthScreen.d.ts +1 -5
- package/dist/Modal/NordFlow/screens/02-EvmWalletAuthScreen.js +13 -16
- package/dist/Modal/NordFlow/screens/02-EvmWalletAuthScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/03-ChainSelectionScreen.d.ts +1 -7
- package/dist/Modal/NordFlow/screens/03-ChainSelectionScreen.js +11 -9
- package/dist/Modal/NordFlow/screens/03-ChainSelectionScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/04-AmountInputScreen.d.ts +1 -13
- package/dist/Modal/NordFlow/screens/04-AmountInputScreen.js +59 -31
- package/dist/Modal/NordFlow/screens/04-AmountInputScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/05-DepositProgressScreen.d.ts +1 -6
- package/dist/Modal/NordFlow/screens/05-DepositProgressScreen.js +9 -4
- package/dist/Modal/NordFlow/screens/05-DepositProgressScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/06-DepositSuccessScreen.d.ts +1 -8
- package/dist/Modal/NordFlow/screens/06-DepositSuccessScreen.js +18 -7
- package/dist/Modal/NordFlow/screens/06-DepositSuccessScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/07-AuthLoadingScreen.d.ts +1 -6
- package/dist/Modal/NordFlow/screens/07-AuthLoadingScreen.js +15 -121
- package/dist/Modal/NordFlow/screens/07-AuthLoadingScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.d.ts +1 -1
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.js +10 -5
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/09-ErrorScreen.d.ts +1 -7
- package/dist/Modal/NordFlow/screens/09-ErrorScreen.js +9 -9
- package/dist/Modal/NordFlow/screens/09-ErrorScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/index.d.ts +1 -0
- package/dist/Modal/NordFlow/screens/index.js +1 -0
- package/dist/Modal/NordFlow/screens/index.js.map +1 -1
- package/dist/Modal/NordFlow/types.d.ts +0 -5
- package/dist/Modal/NordFlow/types.js +0 -1
- package/dist/Modal/NordFlow/types.js.map +1 -1
- package/dist/Modal/NordFlow/utils/index.d.ts +0 -1
- package/dist/Modal/NordFlow/utils/index.js +0 -1
- package/dist/Modal/NordFlow/utils/index.js.map +1 -1
- package/dist/Modal/Sidebar/N1Sidebar.js +10 -10
- package/dist/Modal/Sidebar/N1Sidebar.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/MarketOverview/MarketSelector.js +5 -5
- package/dist/Modal/Sidebar/NordTradingView/MarketOverview/MarketSelector.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/MarketOverview/MarketStats.js +3 -3
- package/dist/Modal/Sidebar/NordTradingView/MarketOverview/MarketStats.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/NordTradingView.js +2 -2
- package/dist/Modal/Sidebar/NordTradingView/NordTradingView.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/OrderBook/OrderBook.js +2 -2
- package/dist/Modal/Sidebar/NordTradingView/OrderBook/OrderBook.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/OrderBook/OrderBookDepthVisualizer.js +1 -1
- package/dist/Modal/Sidebar/NordTradingView/OrderBook/OrderBookDepthVisualizer.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/OrderBook/OrderBookHeader.js +4 -4
- package/dist/Modal/Sidebar/NordTradingView/OrderBook/OrderBookHeader.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/OrderBook/OrderBookTable.js +6 -6
- package/dist/Modal/Sidebar/NordTradingView/OrderBook/OrderBookTable.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/AmountInput.js +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/AmountInput.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/BuySellTabs.js +3 -3
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/BuySellTabs.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/FillModeSelector.js +7 -7
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/FillModeSelector.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/OrderTypeSelector.js +13 -13
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/OrderTypeSelector.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/PriceInput.js +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/PriceInput.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/SubmitButton.js +2 -2
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/SubmitButton.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/TotalCalculator.js +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/TotalCalculator.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/TradeForm.js +5 -5
- package/dist/Modal/Sidebar/NordTradingView/TradeForm/TradeForm.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/UserBalances/UserBalances.js +1 -1
- package/dist/Modal/Sidebar/NordTradingView/UserBalances/UserBalances.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/UserOrders/UserOrders.js +5 -5
- package/dist/Modal/Sidebar/NordTradingView/UserOrders/UserOrders.js.map +1 -1
- package/dist/Modal/Sidebar/NordTradingView/UserPositions/UserPositions.js +4 -4
- package/dist/Modal/Sidebar/NordTradingView/UserPositions/UserPositions.js.map +1 -1
- package/dist/Provider/LazyWalletProvider.js +2 -0
- package/dist/Provider/LazyWalletProvider.js.map +1 -1
- package/dist/Provider/N1WalletProvider.js +48 -63
- package/dist/Provider/N1WalletProvider.js.map +1 -1
- package/dist/Provider/WalletErrorBoundary.d.ts +10 -0
- package/dist/Provider/WalletErrorBoundary.js +39 -0
- package/dist/Provider/WalletErrorBoundary.js.map +1 -0
- package/dist/Provider/hooks/useNordUserInitialization.d.ts +20 -0
- package/dist/Provider/hooks/useNordUserInitialization.js +293 -0
- package/dist/Provider/hooks/useNordUserInitialization.js.map +1 -0
- package/dist/Provider/types.d.ts +2 -0
- package/dist/Provider/types.js.map +1 -1
- package/dist/Provider/useN1WalletProvider.d.ts +37 -0
- package/dist/Provider/useN1WalletProvider.js +398 -0
- package/dist/Provider/useN1WalletProvider.js.map +1 -0
- package/dist/components/QRCodeLoader.js +1 -1
- package/dist/components/QRCodeLoader.js.map +1 -1
- package/dist/components/logos/EVMChainsGroup.js +1 -1
- package/dist/components/logos/EVMChainsGroup.js.map +1 -1
- package/dist/components/logos/MoreChainsGroup.js +1 -1
- package/dist/components/logos/MoreChainsGroup.js.map +1 -1
- package/dist/main.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,308 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
38
|
+
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
39
|
+
import { getExplorerUrl, } from '../../../Logic/transactionManager';
|
|
40
|
+
import { useN1WalletContext, useN1WalletInternalContext, } from '../../../Provider/hooks';
|
|
41
|
+
import { logger } from '../../../utils/logger';
|
|
42
|
+
import { FlowState } from '../types';
|
|
43
|
+
import { useFlowStateContext } from './FlowContext';
|
|
44
|
+
// Create the context with a default value
|
|
45
|
+
var DepositContext = createContext(undefined);
|
|
46
|
+
/**
|
|
47
|
+
* Provider component for the deposit context
|
|
48
|
+
*/
|
|
49
|
+
export var DepositProvider = function (_a) {
|
|
50
|
+
var children = _a.children;
|
|
51
|
+
// Get flow state context
|
|
52
|
+
var _b = useFlowStateContext(), state = _b.state, context = _b.context, transition = _b.transition, updateContext = _b.updateContext;
|
|
53
|
+
// Get wallet context
|
|
54
|
+
var _c = useN1WalletContext(), address = _c.address, nord = _c.nord, signMessageWithWalletKey = _c.signMessageWithWalletKey, signMessageWithSessionKey = _c.signMessageWithSessionKey, nordUser = _c.nordUser;
|
|
55
|
+
var sessionMode = useN1WalletInternalContext().sessionMode;
|
|
56
|
+
// chain
|
|
57
|
+
var _d = useState(context.selectedChain), selectedChain = _d[0], setSelectedChain = _d[1];
|
|
58
|
+
// transaction & deposit
|
|
59
|
+
var _e = useState(context.amount), amount = _e[0], setAmount = _e[1];
|
|
60
|
+
var _f = useState(false), isDepositing = _f[0], setIsDepositing = _f[1];
|
|
61
|
+
var _g = useState(context.transactionId), transactionId = _g[0], setTransactionId = _g[1];
|
|
62
|
+
var _h = useState(null), transactionResult = _h[0], setTransactionResult = _h[1];
|
|
63
|
+
// auth
|
|
64
|
+
var _j = useState('loading'), authStatus = _j[0], setAuthStatus = _j[1];
|
|
65
|
+
var _k = useState(null), authErrorMessage = _k[0], setAuthErrorMessage = _k[1];
|
|
66
|
+
var _l = useState(null), authStatusMessage = _l[0], setAuthStatusMessage = _l[1];
|
|
67
|
+
// Use refs to track previous values
|
|
68
|
+
var prevContextRef = useRef(context);
|
|
69
|
+
/**
|
|
70
|
+
* Handle an error by transitioning to error state
|
|
71
|
+
*/
|
|
72
|
+
var handleError = useCallback(function (error) {
|
|
73
|
+
logger.error('Flow error:', error);
|
|
74
|
+
transition(FlowState.ERROR, { error: error });
|
|
75
|
+
}, [transition]);
|
|
76
|
+
/**
|
|
77
|
+
* Authenticate session
|
|
78
|
+
*/
|
|
79
|
+
var performAuth = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var sessionPubKey, sessionId, sessionIdKey, error_1;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
_a.trys.push([0, 3, , 4]);
|
|
85
|
+
// Step 1: Tell user to sign transaction
|
|
86
|
+
setAuthStatusMessage('Please sign the transaction to authenticate your session');
|
|
87
|
+
if (!nordUser) {
|
|
88
|
+
throw new Error('Nord user is not initialized');
|
|
89
|
+
}
|
|
90
|
+
// Step 2: Call nordUser.refreshSession and get sessionId
|
|
91
|
+
setAuthStatusMessage('Session is being authenticated...');
|
|
92
|
+
sessionPubKey = nordUser.sessionPubKey;
|
|
93
|
+
if (!sessionPubKey) {
|
|
94
|
+
throw new Error('Session public key is not available');
|
|
95
|
+
}
|
|
96
|
+
// Refresh the session
|
|
97
|
+
return [4 /*yield*/, nordUser.refreshSession(sessionPubKey)];
|
|
98
|
+
case 1:
|
|
99
|
+
// Refresh the session
|
|
100
|
+
_a.sent();
|
|
101
|
+
return [4 /*yield*/, nordUser.updateAccountId()];
|
|
102
|
+
case 2:
|
|
103
|
+
_a.sent();
|
|
104
|
+
sessionId = nordUser.sessionId;
|
|
105
|
+
if (!sessionId) {
|
|
106
|
+
throw new Error('Failed to get session ID after refresh');
|
|
107
|
+
}
|
|
108
|
+
logger.debug('Session refreshed successfully', {
|
|
109
|
+
sessionId: sessionId.toString(),
|
|
110
|
+
});
|
|
111
|
+
// Step 3: Store sessionId in localStorage
|
|
112
|
+
if (address) {
|
|
113
|
+
sessionIdKey = "n1_sessionId_".concat(address);
|
|
114
|
+
localStorage.setItem(sessionIdKey, sessionId.toString());
|
|
115
|
+
logger.debug('Stored sessionId in localStorage', { key: sessionIdKey });
|
|
116
|
+
}
|
|
117
|
+
// Step 4: Update status to success
|
|
118
|
+
setAuthStatus('success');
|
|
119
|
+
// Step 5: Update context and transition to success
|
|
120
|
+
console.log('hasActiveSession', "asdasdsadsa");
|
|
121
|
+
// updateContext({ hasActiveSession: true });
|
|
122
|
+
setTimeout(function () {
|
|
123
|
+
transition(FlowState.FINAL_SUCCESS, { hasActiveSession: true, hasNordAccount: true });
|
|
124
|
+
}, 100);
|
|
125
|
+
return [3 /*break*/, 4];
|
|
126
|
+
case 3:
|
|
127
|
+
error_1 = _a.sent();
|
|
128
|
+
console.error('Authentication error:', error_1);
|
|
129
|
+
setAuthStatus('error');
|
|
130
|
+
setAuthErrorMessage(error_1 instanceof Error ? error_1.message : 'Unknown error occurred');
|
|
131
|
+
return [3 /*break*/, 4];
|
|
132
|
+
case 4: return [2 /*return*/];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}); }, [updateContext, transition, address, nordUser]);
|
|
136
|
+
/**
|
|
137
|
+
* Update amount for deposit
|
|
138
|
+
*/
|
|
139
|
+
var updateAmount = useCallback(function (newAmount) {
|
|
140
|
+
setAmount(newAmount);
|
|
141
|
+
if (state === FlowState.AMOUNT_INPUT) {
|
|
142
|
+
updateContext({ amount: newAmount });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
transition(state, { amount: newAmount });
|
|
146
|
+
}
|
|
147
|
+
}, [state, transition, updateContext]);
|
|
148
|
+
/**
|
|
149
|
+
* Start deposit process
|
|
150
|
+
*/
|
|
151
|
+
var startDeposit = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
152
|
+
var usdcToken, txId, accountInitialized, i, exists, result, depositError_1, errorMessage;
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
switch (_a.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
if (isDepositing)
|
|
157
|
+
return [2 /*return*/];
|
|
158
|
+
logger.debug('Starting deposit process');
|
|
159
|
+
if (!amount || parseFloat(amount) <= 0) {
|
|
160
|
+
handleError(new Error('Invalid amount'));
|
|
161
|
+
return [2 /*return*/];
|
|
162
|
+
}
|
|
163
|
+
setIsDepositing(true);
|
|
164
|
+
transition(FlowState.DEPOSIT_PROGRESS);
|
|
165
|
+
_a.label = 1;
|
|
166
|
+
case 1:
|
|
167
|
+
_a.trys.push([1, 8, , 9]);
|
|
168
|
+
usdcToken = nord.tokens.find(function (t) { return t.symbol === 'USDC'; });
|
|
169
|
+
return [4 /*yield*/, nordUser.depositSpl(parseFloat(amount), usdcToken.tokenId)];
|
|
170
|
+
case 2:
|
|
171
|
+
txId = _a.sent();
|
|
172
|
+
accountInitialized = false;
|
|
173
|
+
i = 0;
|
|
174
|
+
_a.label = 3;
|
|
175
|
+
case 3:
|
|
176
|
+
if (!(i < 70)) return [3 /*break*/, 7];
|
|
177
|
+
return [4 /*yield*/, (nord === null || nord === void 0 ? void 0 : nord.accountExists(address))];
|
|
178
|
+
case 4:
|
|
179
|
+
exists = _a.sent();
|
|
180
|
+
if (exists) {
|
|
181
|
+
accountInitialized = true;
|
|
182
|
+
return [3 /*break*/, 7];
|
|
183
|
+
}
|
|
184
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 5000); })];
|
|
185
|
+
case 5:
|
|
186
|
+
_a.sent();
|
|
187
|
+
_a.label = 6;
|
|
188
|
+
case 6:
|
|
189
|
+
i++;
|
|
190
|
+
return [3 /*break*/, 3];
|
|
191
|
+
case 7:
|
|
192
|
+
if (!accountInitialized) {
|
|
193
|
+
throw new Error('Account failed to intialize on N1.');
|
|
194
|
+
}
|
|
195
|
+
logger.debug('Deposit successful using Nord-TS', txId);
|
|
196
|
+
result = {
|
|
197
|
+
success: true,
|
|
198
|
+
transactionId: txId,
|
|
199
|
+
amount: amount,
|
|
200
|
+
tokenSymbol: 'USDC',
|
|
201
|
+
fromAddress: address || 'Your Wallet',
|
|
202
|
+
toAddress: 'Exchange Account',
|
|
203
|
+
networkName: selectedChain,
|
|
204
|
+
status: 'Completed',
|
|
205
|
+
explorerUrl: getExplorerUrl(txId),
|
|
206
|
+
};
|
|
207
|
+
// Update state with transaction result
|
|
208
|
+
setTransactionId(txId);
|
|
209
|
+
setTransactionResult(result);
|
|
210
|
+
logger.debug('Transaction completed successfully');
|
|
211
|
+
transition(FlowState.DEPOSIT_SUCCESS, { transactionId: txId, hasNordAccount: true });
|
|
212
|
+
return [3 /*break*/, 9];
|
|
213
|
+
case 8:
|
|
214
|
+
depositError_1 = _a.sent();
|
|
215
|
+
logger.warn('Error using depositSpl, falling back to mock implementation:', depositError_1);
|
|
216
|
+
setIsDepositing(false);
|
|
217
|
+
errorMessage = depositError_1 instanceof Error
|
|
218
|
+
? depositError_1.message
|
|
219
|
+
: 'Failed to process deposit';
|
|
220
|
+
transition(FlowState.AMOUNT_INPUT, {
|
|
221
|
+
depositError: errorMessage
|
|
222
|
+
});
|
|
223
|
+
return [2 /*return*/]; // Exit early
|
|
224
|
+
case 9: return [2 /*return*/];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}); }, [
|
|
228
|
+
isDepositing,
|
|
229
|
+
selectedChain,
|
|
230
|
+
amount,
|
|
231
|
+
address,
|
|
232
|
+
sessionMode,
|
|
233
|
+
transition,
|
|
234
|
+
handleError,
|
|
235
|
+
nord,
|
|
236
|
+
signMessageWithWalletKey,
|
|
237
|
+
signMessageWithSessionKey,
|
|
238
|
+
nordUser,
|
|
239
|
+
]);
|
|
240
|
+
/**
|
|
241
|
+
* Complete the deposit process and move to the next screen
|
|
242
|
+
*/
|
|
243
|
+
var completeDeposit = useCallback(function () {
|
|
244
|
+
// Check if user has an active session to determine the next state
|
|
245
|
+
if (context.hasActiveSession) {
|
|
246
|
+
// If user has an active session, go directly to FINAL_SUCCESS
|
|
247
|
+
transition(FlowState.FINAL_SUCCESS, { hasNordAccount: true, hasActiveSession: true });
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
// Check if there's a sessionId stored in localStorage
|
|
251
|
+
var sessionIdKey = "n1_sessionId_".concat(address);
|
|
252
|
+
var storedSessionId = localStorage.getItem(sessionIdKey);
|
|
253
|
+
console.log('storedSessionId', storedSessionId, sessionIdKey);
|
|
254
|
+
if (storedSessionId !== null) {
|
|
255
|
+
// If we have a sessionId in localStorage (even if it's 0), go directly to FINAL_SUCCESS
|
|
256
|
+
transition(FlowState.FINAL_SUCCESS, { hasNordAccount: true, hasActiveSession: true });
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
// If user doesn't have an active session and no sessionId in localStorage, go to NORD_AUTH
|
|
260
|
+
transition(FlowState.AUTH_LOADING, { hasActiveSession: true });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}, [context.hasActiveSession, transition, address]);
|
|
264
|
+
// Create the context value
|
|
265
|
+
var contextValue = {
|
|
266
|
+
amount: amount,
|
|
267
|
+
isDepositing: isDepositing,
|
|
268
|
+
transactionId: transactionId,
|
|
269
|
+
transactionResult: transactionResult,
|
|
270
|
+
authStatus: authStatus,
|
|
271
|
+
authErrorMessage: authErrorMessage,
|
|
272
|
+
authStatusMessage: authStatusMessage,
|
|
273
|
+
updateAmount: updateAmount,
|
|
274
|
+
startDeposit: startDeposit,
|
|
275
|
+
completeDeposit: completeDeposit,
|
|
276
|
+
performAuth: performAuth,
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Update state based on context changes
|
|
280
|
+
*/
|
|
281
|
+
useEffect(function () {
|
|
282
|
+
var prevContext = prevContextRef.current;
|
|
283
|
+
// Only update state if the relevant context values have actually changed
|
|
284
|
+
if (context.selectedChain !== prevContext.selectedChain) {
|
|
285
|
+
setSelectedChain(context.selectedChain);
|
|
286
|
+
}
|
|
287
|
+
if (context.amount !== prevContext.amount) {
|
|
288
|
+
setAmount(context.amount);
|
|
289
|
+
}
|
|
290
|
+
if (context.transactionId !== prevContext.transactionId) {
|
|
291
|
+
setTransactionId(context.transactionId);
|
|
292
|
+
}
|
|
293
|
+
// Update the ref to the current context
|
|
294
|
+
prevContextRef.current = context;
|
|
295
|
+
}, [context]);
|
|
296
|
+
return (_jsx(DepositContext.Provider, { value: contextValue, children: children }));
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Hook to use the deposit context
|
|
300
|
+
*/
|
|
301
|
+
export var useDepositContext = function () {
|
|
302
|
+
var context = useContext(DepositContext);
|
|
303
|
+
if (context === undefined) {
|
|
304
|
+
throw new Error('useDepositContext must be used within a DepositProvider');
|
|
305
|
+
}
|
|
306
|
+
return context;
|
|
307
|
+
};
|
|
308
|
+
//# sourceMappingURL=DepositContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DepositContext.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/DepositContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAc,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnG,OAAO,EACL,cAAc,GAEf,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAiBpD,0CAA0C;AAC1C,IAAM,cAAc,GAAG,aAAa,CAAkC,SAAS,CAAC,CAAC;AAOjF;;GAEG;AACH,MAAM,CAAC,IAAM,eAAe,GAAmC,UAAC,EAE/D;QADC,QAAQ,cAAA;IAER,yBAAyB;IACnB,IAAA,KAKF,mBAAmB,EAAE,EAJvB,KAAK,WAAA,EACL,OAAO,aAAA,EACP,UAAU,gBAAA,EACV,aAAa,mBACU,CAAC;IAE1B,qBAAqB;IACf,IAAA,KAMF,kBAAkB,EAAE,EALtB,OAAO,aAAA,EACP,IAAI,UAAA,EACJ,wBAAwB,8BAAA,EACxB,yBAAyB,+BAAA,EACzB,QAAQ,cACc,CAAC;IACjB,IAAA,WAAW,GAAK,0BAA0B,EAAE,YAAjC,CAAkC;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,IAAC,KAAK,EAAE,YAAY,YACzC,QAAQ,GACe,CAC3B,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAG;IAC/B,IAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport {\n getExplorerUrl,\n TransactionResult,\n} from '../../../Logic/transactionManager';\nimport {\n useN1WalletContext,\n useN1WalletInternalContext,\n} from '../../../Provider/hooks';\nimport { N1SessionMode } from '../../../Provider/types';\nimport { logger } from '../../../utils/logger';\nimport { AVAILABLE_CHAINS } from '../constants';\nimport { FlowState } from '../types';\nimport { isNordConfigured } from '../utils/nordUtils';\nimport { useFlowStateContext } from './FlowContext';\n\n// Define the shape of the deposit context value\nexport interface DepositContextValue {\n amount: string;\n isDepositing: boolean;\n transactionId: string | null;\n transactionResult: TransactionResult | null;\n authStatus: 'loading' | 'success' | 'error';\n authErrorMessage: string | null;\n authStatusMessage: string | null;\n updateAmount: (newAmount: string) => void;\n startDeposit: () => Promise<void>;\n completeDeposit: () => void;\n performAuth: () => Promise<void>;\n}\n\n// Create the context with a default value\nconst DepositContext = createContext<DepositContextValue | undefined>(undefined);\n\n// Props for the provider component\ninterface DepositProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Provider component for the deposit context\n */\nexport const DepositProvider: React.FC<DepositProviderProps> = ({\n children,\n}) => {\n // Get flow state context\n const {\n state,\n context,\n transition,\n updateContext,\n } = useFlowStateContext();\n\n // Get wallet context\n const {\n address,\n nord,\n signMessageWithWalletKey,\n signMessageWithSessionKey,\n nordUser,\n } = useN1WalletContext();\n const { sessionMode } = useN1WalletInternalContext();\n\n // chain\n const [selectedChain, setSelectedChain] = useState<string | null>(\n context.selectedChain\n );\n\n // transaction & deposit\n const [amount, setAmount] = useState(context.amount);\n const [isDepositing, setIsDepositing] = useState(false);\n const [transactionId, setTransactionId] = useState<string | null>(context.transactionId);\n const [transactionResult, setTransactionResult] = useState<TransactionResult | null>(null);\n\n\n // auth\n const [authStatus, setAuthStatus] = useState<'loading' | 'success' | 'error'>('loading');\n const [authErrorMessage, setAuthErrorMessage] = useState<string | null>(null);\n const [authStatusMessage, setAuthStatusMessage] = useState<string | null>(null);\n\n // Use refs to track previous values\n const prevContextRef = useRef(context);\n\n\n /**\n * Handle an error by transitioning to error state\n */\n const handleError = useCallback(\n (error: Error) => {\n logger.error('Flow error:', error);\n transition(FlowState.ERROR, { error });\n },\n [transition]\n );\n\n /**\n * Authenticate session\n */\n const performAuth = useCallback(async () => {\n try {\n // Step 1: Tell user to sign transaction\n setAuthStatusMessage(\n 'Please sign the transaction to authenticate your session'\n );\n\n if (!nordUser) {\n throw new Error('Nord user is not initialized');\n }\n\n // Step 2: Call nordUser.refreshSession and get sessionId\n setAuthStatusMessage('Session is being authenticated...');\n\n // Get the session public key from the nordUser\n const sessionPubKey = nordUser.sessionPubKey;\n if (!sessionPubKey) {\n throw new Error('Session public key is not available');\n }\n\n // Refresh the session\n await nordUser.refreshSession(sessionPubKey);\n await nordUser.updateAccountId();\n\n // Get the sessionId after refresh\n const sessionId = nordUser.sessionId;\n if (!sessionId) {\n throw new Error('Failed to get session ID after refresh');\n }\n\n logger.debug('Session refreshed successfully', {\n sessionId: sessionId.toString(),\n });\n\n // Step 3: Store sessionId in localStorage\n if (address) {\n const sessionIdKey = `n1_sessionId_${address}`;\n localStorage.setItem(sessionIdKey, sessionId.toString());\n logger.debug('Stored sessionId in localStorage', { key: sessionIdKey });\n }\n\n // Step 4: Update status to success\n setAuthStatus('success');\n\n // Step 5: Update context and transition to success\n console.log('hasActiveSession', \"asdasdsadsa\");\n // updateContext({ hasActiveSession: true });\n setTimeout(() => {\n transition(FlowState.FINAL_SUCCESS, { hasActiveSession: true, hasNordAccount: true });\n }, 100);\n\n } catch (error) {\n console.error('Authentication error:', error);\n setAuthStatus('error');\n setAuthErrorMessage(\n error instanceof Error ? error.message : 'Unknown error occurred'\n );\n }\n }, [updateContext, transition, address, nordUser]);\n\n /**\n * Update amount for deposit\n */\n const updateAmount = useCallback(\n (newAmount: string) => {\n setAmount(newAmount);\n if (state === FlowState.AMOUNT_INPUT) {\n updateContext({ amount: newAmount });\n } else {\n transition(state, { amount: newAmount });\n }\n },\n [state, transition, 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\n if (!amount || parseFloat(amount) <= 0) {\n handleError(new Error('Invalid amount'));\n return;\n }\n\n setIsDepositing(true);\n transition(FlowState.DEPOSIT_PROGRESS);\n\n try {\n const usdcToken = nord!.tokens.find((t: any) => t.symbol === 'USDC');\n\n const txId = await nordUser.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 // Create transaction result object immediately after successful deposit\n const result: TransactionResult = {\n success: true,\n transactionId: txId,\n amount,\n tokenSymbol: 'USDC',\n fromAddress: address || 'Your Wallet',\n toAddress: 'Exchange Account',\n networkName: selectedChain!,\n status: 'Completed',\n explorerUrl: getExplorerUrl(txId),\n };\n\n // Update state with transaction result\n setTransactionId(txId);\n setTransactionResult(result);\n logger.debug('Transaction completed successfully');\n transition(FlowState.DEPOSIT_SUCCESS, { transactionId: txId, hasNordAccount: true });\n } catch (depositError) {\n logger.warn('Error using depositSpl, falling back to mock implementation:', depositError);\n setIsDepositing(false);\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 }, [\n isDepositing,\n selectedChain,\n amount,\n address,\n sessionMode,\n transition,\n handleError,\n nord,\n signMessageWithWalletKey,\n signMessageWithSessionKey,\n nordUser,\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, { hasNordAccount: true, hasActiveSession: true });\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 console.log('storedSessionId', storedSessionId, 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, { hasNordAccount: true, hasActiveSession: true });\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, { hasActiveSession: true });\n }\n }\n }, [context.hasActiveSession, transition, address]);\n\n\n\n\n\n // Create the context value\n const contextValue: DepositContextValue = {\n amount,\n isDepositing,\n transactionId,\n transactionResult,\n authStatus,\n authErrorMessage,\n authStatusMessage,\n updateAmount,\n startDeposit,\n completeDeposit,\n performAuth,\n };\n\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\n return (\n <DepositContext.Provider value={contextValue}>\n {children}\n </DepositContext.Provider>\n );\n};\n\n/**\n * Hook to use the deposit context\n */\nexport const useDepositContext = (): DepositContextValue => {\n const context = useContext(DepositContext);\n if (context === undefined) {\n throw new Error('useDepositContext must be used within a DepositProvider');\n }\n return context;\n}; "]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FlowContext as FlowContextType, FlowState } from '../types';
|
|
3
|
+
export interface FlowStateContextValue {
|
|
4
|
+
state: FlowState;
|
|
5
|
+
context: FlowContextType;
|
|
6
|
+
isClosing: boolean;
|
|
7
|
+
transition: (targetState: FlowState, contextUpdates?: Partial<FlowContextType>) => boolean;
|
|
8
|
+
updateContext: (updates: Partial<FlowContextType>) => void;
|
|
9
|
+
}
|
|
10
|
+
interface FlowStateProviderProps {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Provider component for the flow state context
|
|
15
|
+
*/
|
|
16
|
+
export declare const FlowStateProvider: React.FC<FlowStateProviderProps>;
|
|
17
|
+
/**
|
|
18
|
+
* Custom hook to use the flow state context
|
|
19
|
+
* @returns The flow state context value
|
|
20
|
+
* @throws Error if used outside of a FlowStateProvider
|
|
21
|
+
*/
|
|
22
|
+
export declare const useFlowStateContext: () => FlowStateContextValue;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useCallback, useContext, useRef, useState } from 'react';
|
|
14
|
+
import { FlowState, initialFlowContext } from '../types';
|
|
15
|
+
import { STATE_TRANSITIONS } from '../constants';
|
|
16
|
+
import { logger } from '../../../utils/logger';
|
|
17
|
+
import { useN1WalletContext, useN1WalletInternalContext } from '../../../Provider';
|
|
18
|
+
// Create the context with a default value
|
|
19
|
+
var FlowStateContext = createContext(undefined);
|
|
20
|
+
/**
|
|
21
|
+
* Provider component for the flow state context
|
|
22
|
+
*/
|
|
23
|
+
export var FlowStateProvider = function (_a) {
|
|
24
|
+
var children = _a.children;
|
|
25
|
+
// Flow state
|
|
26
|
+
var _b = useState(FlowState.IDLE), state = _b[0], setState = _b[1];
|
|
27
|
+
var _c = useState(initialFlowContext), context = _c[0], setContext = _c[1];
|
|
28
|
+
var _d = useState(false), isClosing = _d[0], setIsClosing = _d[1];
|
|
29
|
+
var nordUser = useN1WalletContext().nordUser;
|
|
30
|
+
var dynamicSdkHasLoaded = useN1WalletInternalContext().dynamicSdkHasLoaded;
|
|
31
|
+
var prevContextRef = useRef(initialFlowContext);
|
|
32
|
+
// Default handlers
|
|
33
|
+
var handleStateChange = useCallback(function (newState, currState) {
|
|
34
|
+
logger.debug("State changed from ".concat(currState, " to ").concat(newState));
|
|
35
|
+
}, []);
|
|
36
|
+
/**
|
|
37
|
+
* Check if a transition is allowed based on current state and context
|
|
38
|
+
*/
|
|
39
|
+
var canTransition = useCallback(function (targetState, contextData) {
|
|
40
|
+
if (dynamicSdkHasLoaded)
|
|
41
|
+
return STATE_TRANSITIONS.some(function (transition) {
|
|
42
|
+
var fromMatches = Array.isArray(transition.from)
|
|
43
|
+
? transition.from.includes(state)
|
|
44
|
+
: transition.from === state;
|
|
45
|
+
if (!fromMatches || transition.to !== targetState) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (transition.condition) {
|
|
49
|
+
return transition.condition(contextData);
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
});
|
|
53
|
+
return false;
|
|
54
|
+
}, [state, nordUser, dynamicSdkHasLoaded]);
|
|
55
|
+
/**
|
|
56
|
+
* Transition to a new state if allowed
|
|
57
|
+
*/
|
|
58
|
+
var transition = useCallback(function (targetState, contextUpdates) {
|
|
59
|
+
if (contextUpdates === void 0) { contextUpdates = {}; }
|
|
60
|
+
// Skip if we're already in the target state and no context updates
|
|
61
|
+
if (targetState === state && Object.keys(contextUpdates).length === 0) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (!canTransition(targetState, __assign(__assign({}, context), contextUpdates))) {
|
|
65
|
+
logger.warn("Transition from ".concat(state, " to ").concat(targetState, " is not allowed"));
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
// Update context first
|
|
69
|
+
setContext(function (prevContext) {
|
|
70
|
+
return __assign(__assign({}, prevContext), contextUpdates);
|
|
71
|
+
});
|
|
72
|
+
logger.debug("Transitioning from ".concat(state, " to ").concat(targetState));
|
|
73
|
+
setState(targetState);
|
|
74
|
+
handleStateChange(targetState, state);
|
|
75
|
+
return true;
|
|
76
|
+
}, [canTransition, state, context, handleStateChange]);
|
|
77
|
+
/**
|
|
78
|
+
* Update context without state transition
|
|
79
|
+
*/
|
|
80
|
+
var updateContext = useCallback(function (updates) {
|
|
81
|
+
// Skip if no actual updates
|
|
82
|
+
if (Object.keys(updates).length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
setContext(function (prevContext) {
|
|
86
|
+
// Check if any values are actually changing
|
|
87
|
+
var hasChanges = false;
|
|
88
|
+
// Type-safe way to check for changes
|
|
89
|
+
Object.keys(updates).forEach(function (key) {
|
|
90
|
+
if (updates[key] !== prevContext[key]) {
|
|
91
|
+
hasChanges = true;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
// If nothing is changing, return the previous context
|
|
95
|
+
if (!hasChanges) {
|
|
96
|
+
return prevContext;
|
|
97
|
+
}
|
|
98
|
+
var newContext = __assign(__assign({}, prevContext), updates);
|
|
99
|
+
prevContextRef.current = newContext;
|
|
100
|
+
return newContext;
|
|
101
|
+
});
|
|
102
|
+
}, [state]);
|
|
103
|
+
// Create the context value
|
|
104
|
+
var contextValue = {
|
|
105
|
+
state: state,
|
|
106
|
+
context: context,
|
|
107
|
+
isClosing: isClosing,
|
|
108
|
+
transition: transition,
|
|
109
|
+
updateContext: updateContext,
|
|
110
|
+
};
|
|
111
|
+
return (_jsx(FlowStateContext.Provider, { value: contextValue, children: children }));
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Custom hook to use the flow state context
|
|
115
|
+
* @returns The flow state context value
|
|
116
|
+
* @throws Error if used outside of a FlowStateProvider
|
|
117
|
+
*/
|
|
118
|
+
export var useFlowStateContext = function () {
|
|
119
|
+
var context = useContext(FlowStateContext);
|
|
120
|
+
if (context === undefined) {
|
|
121
|
+
throw new Error('useFlowStateContext must be used within a FlowStateProvider');
|
|
122
|
+
}
|
|
123
|
+
return context;
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=FlowContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowContext.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/FlowContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAc,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAa,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnG,OAAO,EAAkC,SAAS,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAWnF,0CAA0C;AAC1C,IAAM,gBAAgB,GAAG,aAAa,CAAoC,SAAS,CAAC,CAAC;AAOrF;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAqC,UAAC,EA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,UAAU,GAAG,KAAK,CAAC;YAEvB,qCAAqC;YACpC,MAAM,CAAC,IAAI,CAAC,OAAO,CAA2C,CAAC,OAAO,CAAC,UAAA,GAAG;gBACzE,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;oBACtC,UAAU,GAAG,IAAI,CAAC;gBACpB,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,sDAAsD;YACtD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,IAAM,UAAU,yBAAQ,WAAW,GAAK,OAAO,CAAE,CAAC;YAClD,cAAc,CAAC,OAAO,GAAG,UAAU,CAAC;YACpC,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,KAAK,CAAC,CACR,CAAC;IAGF,2BAA2B;IAC3B,IAAM,YAAY,GAA0B;QAC1C,KAAK,OAAA;QACL,OAAO,SAAA;QACP,SAAS,WAAA;QACT,UAAU,YAAA;QACV,aAAa,eAAA;KACd,CAAC;IAIF,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAG;IACjC,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAE7C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport { FlowContext as FlowContextType, FlowState, initialFlowContext } from '../types';\nimport { STATE_TRANSITIONS } from '../constants';\nimport { logger } from '../../../utils/logger';\nimport { useN1WalletContext, useN1WalletInternalContext } from '../../../Provider';\n\n// Define the shape of the context value\nexport interface FlowStateContextValue {\n state: FlowState;\n context: FlowContextType;\n isClosing: boolean;\n transition: (targetState: FlowState, contextUpdates?: Partial<FlowContextType>) => boolean;\n updateContext: (updates: Partial<FlowContextType>) => void;\n}\n\n// Create the context with a default value\nconst FlowStateContext = createContext<FlowStateContextValue | undefined>(undefined);\n\n// Props for the provider component\ninterface FlowStateProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Provider component for the flow state context\n */\nexport const FlowStateProvider: React.FC<FlowStateProviderProps> = ({\n children,\n}) => {\n // Flow state\n const [state, setState] = useState<FlowState>(FlowState.IDLE);\n const [context, setContext] = useState<FlowContextType>(initialFlowContext);\n const [isClosing, setIsClosing] = useState(false);\n\n const { nordUser } = useN1WalletContext();\n const { dynamicSdkHasLoaded } = useN1WalletInternalContext();\n const prevContextRef = useRef<FlowContextType>(initialFlowContext);\n\n\n // Default handlers\n const handleStateChange = useCallback((newState: FlowState, currState: FlowState | null) => {\n logger.debug(`State changed from ${currState} to ${newState}`);\n }, []);\n /**\n * Check if a transition is allowed based on current state and context\n */\n const canTransition = useCallback(\n (targetState: FlowState, contextData: FlowContextType): boolean => {\n if (dynamicSdkHasLoaded)\n return STATE_TRANSITIONS.some((transition) => {\n const fromMatches = Array.isArray(transition.from)\n ? transition.from.includes(state)\n : transition.from === state;\n\n if (!fromMatches || transition.to !== targetState) {\n return false;\n }\n\n if (transition.condition) {\n return transition.condition(contextData);\n }\n\n return true;\n });\n return false;\n },\n [state, nordUser, dynamicSdkHasLoaded]\n );\n\n /**\n * Transition to a new state if allowed\n */\n const transition = useCallback(\n (\n targetState: FlowState,\n contextUpdates: Partial<FlowContextType> = {}\n ): boolean => {\n // Skip if we're already in the target state and no context updates\n if (targetState === state && Object.keys(contextUpdates).length === 0) {\n return true;\n }\n\n if (!canTransition(targetState, { ...context, ...contextUpdates })) {\n logger.warn(\n `Transition from ${state} to ${targetState} is not allowed`\n );\n return false;\n }\n\n\n // Update context first\n setContext((prevContext) => {\n return { ...prevContext, ...contextUpdates };\n });\n\n logger.debug(`Transitioning from ${state} to ${targetState}`);\n setState(targetState);\n\n handleStateChange(targetState, state);\n return true;\n },\n [canTransition, state, context, handleStateChange]\n );\n\n\n\n /**\n * Update context without state transition\n */\n const updateContext = useCallback(\n (updates: Partial<FlowContextType>) => {\n // Skip if no actual updates\n if (Object.keys(updates).length === 0) {\n return;\n }\n\n setContext((prevContext) => {\n // Check if any values are actually changing\n let hasChanges = false;\n\n // Type-safe way to check for changes\n (Object.keys(updates) as Array<keyof Partial<FlowContextType>>).forEach(key => {\n if (updates[key] !== prevContext[key]) {\n hasChanges = true;\n }\n });\n\n // If nothing is changing, return the previous context\n if (!hasChanges) {\n return prevContext;\n }\n\n const newContext = { ...prevContext, ...updates };\n prevContextRef.current = newContext;\n return newContext;\n });\n },\n [state]\n );\n\n\n // Create the context value\n const contextValue: FlowStateContextValue = {\n state,\n context,\n isClosing,\n transition,\n updateContext,\n };\n\n\n\n return (\n <FlowStateContext.Provider value={contextValue}>\n {children}\n </FlowStateContext.Provider>\n );\n};\n\n/**\n * Custom hook to use the flow state context\n * @returns The flow state context value\n * @throws Error if used outside of a FlowStateProvider\n */\nexport const useFlowStateContext = (): FlowStateContextValue => {\n const context = useContext(FlowStateContext);\n\n if (context === undefined) {\n throw new Error('useFlowStateContext must be used within a FlowStateProvider');\n }\n\n return context;\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface NordProviderProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A provider component that combines FlowStateProvider, WalletConnectProvider, and DepositProvider
|
|
7
|
+
* into a single wrapper component for easier implementation.
|
|
8
|
+
*/
|
|
9
|
+
export declare const NordProvider: React.FC<NordProviderProps>;
|
|
10
|
+
export default NordProvider;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FlowStateProvider } from './FlowContext';
|
|
3
|
+
import { WalletConnectProvider } from './WalletConnectContext';
|
|
4
|
+
import { DepositProvider } from './DepositContext';
|
|
5
|
+
/**
|
|
6
|
+
* A provider component that combines FlowStateProvider, WalletConnectProvider, and DepositProvider
|
|
7
|
+
* into a single wrapper component for easier implementation.
|
|
8
|
+
*/
|
|
9
|
+
export var NordProvider = function (_a) {
|
|
10
|
+
var children = _a.children;
|
|
11
|
+
return (_jsx(FlowStateProvider, { children: _jsx(WalletConnectProvider, { children: _jsx(DepositProvider, { children: children }) }) }));
|
|
12
|
+
};
|
|
13
|
+
export default NordProvider;
|
|
14
|
+
//# sourceMappingURL=NordProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NordProvider.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/NordProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMnD;;;GAGG;AACH,MAAM,CAAC,IAAM,YAAY,GAAgC,UAAC,EAAY;QAAV,QAAQ,cAAA;IAClE,OAAO,CACL,KAAC,iBAAiB,cAChB,KAAC,qBAAqB,cACpB,KAAC,eAAe,cACb,QAAQ,GACO,GACI,GACN,CACrB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import React from 'react';\nimport { FlowStateProvider } from './FlowContext';\nimport { WalletConnectProvider } from './WalletConnectContext';\nimport { DepositProvider } from './DepositContext';\n\ninterface NordProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * A provider component that combines FlowStateProvider, WalletConnectProvider, and DepositProvider\n * into a single wrapper component for easier implementation.\n */\nexport const NordProvider: React.FC<NordProviderProps> = ({ children }) => {\n return (\n <FlowStateProvider>\n <WalletConnectProvider>\n <DepositProvider>\n {children}\n </DepositProvider>\n </WalletConnectProvider>\n </FlowStateProvider>\n );\n};\n\nexport default NordProvider; "]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface WalletConnectContextValue {
|
|
3
|
+
isConnecting: boolean;
|
|
4
|
+
connectWallet: () => Promise<void>;
|
|
5
|
+
disconnectWallet: () => void;
|
|
6
|
+
}
|
|
7
|
+
interface WalletConnectProviderProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Provider component for the wallet connect context
|
|
12
|
+
*/
|
|
13
|
+
export declare const WalletConnectProvider: React.FC<WalletConnectProviderProps>;
|
|
14
|
+
/**
|
|
15
|
+
* Custom hook to use the wallet connect context
|
|
16
|
+
* @returns The wallet connect context value
|
|
17
|
+
* @throws Error if used outside of a WalletConnectProvider
|
|
18
|
+
*/
|
|
19
|
+
export declare const useWalletConnectContext: () => WalletConnectContextValue;
|
|
20
|
+
export {};
|