@n1xyz/wallet-widget 0.0.15 → 0.0.16
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/Modal/N1WalletModal.d.ts +1 -0
- package/dist/Modal/N1WalletModal.js +1 -0
- package/dist/Modal/N1WalletModal.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/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,113 +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, useState } from 'react';
|
|
38
|
-
import { useN1WalletContext } from '../../../../Provider/hooks';
|
|
39
|
-
import { logger } from '../../../../utils/logger';
|
|
40
|
-
import { FlowState } from '../../types';
|
|
41
|
-
export var useDepositAuth = function (updateContext, transition, address) {
|
|
42
|
-
// auth states
|
|
43
|
-
var _a = useState('loading'), authStatus = _a[0], setAuthStatus = _a[1];
|
|
44
|
-
var _b = useState(null), authErrorMessage = _b[0], setAuthErrorMessage = _b[1];
|
|
45
|
-
var _c = useState(null), authStatusMessage = _c[0], setAuthStatusMessage = _c[1];
|
|
46
|
-
var nordUser = useN1WalletContext().nordUser;
|
|
47
|
-
/**
|
|
48
|
-
* Authenticate session
|
|
49
|
-
*/
|
|
50
|
-
var performAuth = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
-
var sessionPubKey, sessionId, sessionIdKey, error_1;
|
|
52
|
-
return __generator(this, function (_a) {
|
|
53
|
-
switch (_a.label) {
|
|
54
|
-
case 0:
|
|
55
|
-
_a.trys.push([0, 3, , 4]);
|
|
56
|
-
// Step 1: Tell user to sign transaction
|
|
57
|
-
setAuthStatusMessage('Please sign the transaction to authenticate your session');
|
|
58
|
-
if (!nordUser) {
|
|
59
|
-
throw new Error('Nord user is not initialized');
|
|
60
|
-
}
|
|
61
|
-
// Step 2: Call nordUser.refreshSession and get sessionId
|
|
62
|
-
setAuthStatusMessage('Session is being authenticated...');
|
|
63
|
-
sessionPubKey = nordUser.sessionPubKey;
|
|
64
|
-
if (!sessionPubKey) {
|
|
65
|
-
throw new Error('Session public key is not available');
|
|
66
|
-
}
|
|
67
|
-
// Refresh the session
|
|
68
|
-
return [4 /*yield*/, nordUser.refreshSession(sessionPubKey)];
|
|
69
|
-
case 1:
|
|
70
|
-
// Refresh the session
|
|
71
|
-
_a.sent();
|
|
72
|
-
return [4 /*yield*/, nordUser.updateAccountId()];
|
|
73
|
-
case 2:
|
|
74
|
-
_a.sent();
|
|
75
|
-
sessionId = nordUser.sessionId;
|
|
76
|
-
if (!sessionId) {
|
|
77
|
-
throw new Error('Failed to get session ID after refresh');
|
|
78
|
-
}
|
|
79
|
-
logger.debug('Session refreshed successfully', {
|
|
80
|
-
sessionId: sessionId.toString(),
|
|
81
|
-
});
|
|
82
|
-
// Step 3: Store sessionId in localStorage
|
|
83
|
-
if (address) {
|
|
84
|
-
sessionIdKey = "n1_sessionId_".concat(address);
|
|
85
|
-
localStorage.setItem(sessionIdKey, sessionId.toString());
|
|
86
|
-
logger.debug('Stored sessionId in localStorage', { key: sessionIdKey });
|
|
87
|
-
}
|
|
88
|
-
// Step 4: Update status to success
|
|
89
|
-
setAuthStatus('success');
|
|
90
|
-
// Step 5: Update context and transition to success
|
|
91
|
-
updateContext({ hasActiveSession: true });
|
|
92
|
-
setTimeout(function () {
|
|
93
|
-
transition(FlowState.FINAL_SUCCESS, { hasActiveSession: true, hasNordAccount: true });
|
|
94
|
-
}, 100);
|
|
95
|
-
return [3 /*break*/, 4];
|
|
96
|
-
case 3:
|
|
97
|
-
error_1 = _a.sent();
|
|
98
|
-
console.error('Authentication error:', error_1);
|
|
99
|
-
setAuthStatus('error');
|
|
100
|
-
setAuthErrorMessage(error_1 instanceof Error ? error_1.message : 'Unknown error occurred');
|
|
101
|
-
return [3 /*break*/, 4];
|
|
102
|
-
case 4: return [2 /*return*/];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}); }, [updateContext, transition, address, nordUser]);
|
|
106
|
-
return {
|
|
107
|
-
authStatus: authStatus,
|
|
108
|
-
authErrorMessage: authErrorMessage,
|
|
109
|
-
authStatusMessage: authStatusMessage,
|
|
110
|
-
performAuth: performAuth
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
//# sourceMappingURL=useDepositAuth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEnD,OAAO;QACL,UAAU,YAAA;QACV,gBAAgB,kBAAA;QAChB,iBAAiB,mBAAA;QACjB,WAAW,aAAA;KACZ,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useCallback, useState } from 'react';\nimport { useN1WalletContext } from '../../../../Provider/hooks';\nimport { logger } from '../../../../utils/logger';\nimport { FlowState } from '../../types';\n\nexport const useDepositAuth = (\n updateContext: (context: any) => void,\n transition: (state: FlowState, context?: any) => void,\n address: string | null\n) => {\n // auth states\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 const { nordUser } = useN1WalletContext();\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 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 return {\n authStatus,\n authErrorMessage,\n authStatusMessage,\n performAuth\n };\n}; "]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { TransactionResult } from '../../../../Logic/transactionManager';
|
|
2
|
-
import { FlowState } from '../../types';
|
|
3
|
-
export declare const useDepositTransaction: (selectedChain: string | null, initialAmount: string, transition: (state: FlowState, context?: any) => void, updateContext: (context: any) => void) => {
|
|
4
|
-
amount: string;
|
|
5
|
-
isDepositing: boolean;
|
|
6
|
-
transactionId: string | null;
|
|
7
|
-
transactionResult: TransactionResult | null;
|
|
8
|
-
updateAmount: (newAmount: string) => void;
|
|
9
|
-
startDeposit: () => Promise<void>;
|
|
10
|
-
completeDeposit: () => void;
|
|
11
|
-
getTransactionDetails: () => {
|
|
12
|
-
amount: string;
|
|
13
|
-
tx: string;
|
|
14
|
-
from: string;
|
|
15
|
-
to: string;
|
|
16
|
-
network: string;
|
|
17
|
-
status: string;
|
|
18
|
-
explorerUrl: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
@@ -1,235 +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, useState } from 'react';
|
|
38
|
-
import { getExplorerUrl } from '../../../../Logic/transactionManager';
|
|
39
|
-
import { useN1WalletContext, useN1WalletInternalContext } from '../../../../Provider/hooks';
|
|
40
|
-
import { N1SessionMode } from '../../../../Provider/types';
|
|
41
|
-
import { logger } from '../../../../utils/logger';
|
|
42
|
-
import { AVAILABLE_CHAINS } from '../../constants';
|
|
43
|
-
import { FlowState } from '../../types';
|
|
44
|
-
export var useDepositTransaction = function (selectedChain, initialAmount, transition, updateContext) {
|
|
45
|
-
// transaction states
|
|
46
|
-
var _a = useState(initialAmount), amount = _a[0], setAmount = _a[1];
|
|
47
|
-
var _b = useState(false), isDepositing = _b[0], setIsDepositing = _b[1];
|
|
48
|
-
var _c = useState(null), transactionId = _c[0], setTransactionId = _c[1];
|
|
49
|
-
var _d = useState(null), transactionResult = _d[0], setTransactionResult = _d[1];
|
|
50
|
-
// Get wallet context
|
|
51
|
-
var _e = useN1WalletContext(), address = _e.address, nord = _e.nord, signMessageWithWalletKey = _e.signMessageWithWalletKey, signMessageWithSessionKey = _e.signMessageWithSessionKey, nordUser = _e.nordUser;
|
|
52
|
-
var sessionMode = useN1WalletInternalContext().sessionMode;
|
|
53
|
-
/**
|
|
54
|
-
* Handle an error by transitioning to error state
|
|
55
|
-
*/
|
|
56
|
-
var handleError = useCallback(function (error) {
|
|
57
|
-
logger.error('Flow error:', error);
|
|
58
|
-
transition(FlowState.ERROR, { error: error });
|
|
59
|
-
}, [transition]);
|
|
60
|
-
/**
|
|
61
|
-
* Update amount for deposit
|
|
62
|
-
*/
|
|
63
|
-
var updateAmount = useCallback(function (newAmount) {
|
|
64
|
-
setAmount(newAmount);
|
|
65
|
-
updateContext({ amount: newAmount });
|
|
66
|
-
}, [updateContext]);
|
|
67
|
-
/**
|
|
68
|
-
* Start deposit process
|
|
69
|
-
*/
|
|
70
|
-
var startDeposit = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
71
|
-
var usdcToken, txId, accountInitialized, i, exists, result, depositError_1, errorMessage;
|
|
72
|
-
return __generator(this, function (_a) {
|
|
73
|
-
switch (_a.label) {
|
|
74
|
-
case 0:
|
|
75
|
-
if (isDepositing)
|
|
76
|
-
return [2 /*return*/];
|
|
77
|
-
logger.debug('Starting deposit process');
|
|
78
|
-
if (!amount || parseFloat(amount) <= 0) {
|
|
79
|
-
handleError(new Error('Invalid amount'));
|
|
80
|
-
return [2 /*return*/];
|
|
81
|
-
}
|
|
82
|
-
setIsDepositing(true);
|
|
83
|
-
transition(FlowState.DEPOSIT_PROGRESS);
|
|
84
|
-
_a.label = 1;
|
|
85
|
-
case 1:
|
|
86
|
-
_a.trys.push([1, 8, , 9]);
|
|
87
|
-
usdcToken = nord.tokens.find(function (t) { return t.symbol === 'USDC'; });
|
|
88
|
-
return [4 /*yield*/, nordUser.depositSpl(parseFloat(amount), usdcToken.tokenId)];
|
|
89
|
-
case 2:
|
|
90
|
-
txId = _a.sent();
|
|
91
|
-
accountInitialized = false;
|
|
92
|
-
i = 0;
|
|
93
|
-
_a.label = 3;
|
|
94
|
-
case 3:
|
|
95
|
-
if (!(i < 70)) return [3 /*break*/, 7];
|
|
96
|
-
return [4 /*yield*/, (nord === null || nord === void 0 ? void 0 : nord.accountExists(address))];
|
|
97
|
-
case 4:
|
|
98
|
-
exists = _a.sent();
|
|
99
|
-
if (exists) {
|
|
100
|
-
accountInitialized = true;
|
|
101
|
-
return [3 /*break*/, 7];
|
|
102
|
-
}
|
|
103
|
-
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 5000); })];
|
|
104
|
-
case 5:
|
|
105
|
-
_a.sent();
|
|
106
|
-
_a.label = 6;
|
|
107
|
-
case 6:
|
|
108
|
-
i++;
|
|
109
|
-
return [3 /*break*/, 3];
|
|
110
|
-
case 7:
|
|
111
|
-
if (!accountInitialized) {
|
|
112
|
-
throw new Error('Account failed to intialize on N1.');
|
|
113
|
-
}
|
|
114
|
-
logger.debug('Deposit successful using Nord-TS', txId);
|
|
115
|
-
result = {
|
|
116
|
-
success: true,
|
|
117
|
-
transactionId: txId,
|
|
118
|
-
amount: amount,
|
|
119
|
-
tokenSymbol: 'USDC',
|
|
120
|
-
fromAddress: address || 'Your Wallet',
|
|
121
|
-
toAddress: 'Exchange Account',
|
|
122
|
-
networkName: selectedChain,
|
|
123
|
-
status: 'Completed',
|
|
124
|
-
explorerUrl: getExplorerUrl(txId, selectedChain),
|
|
125
|
-
};
|
|
126
|
-
// Update state with transaction result
|
|
127
|
-
setTransactionId(txId);
|
|
128
|
-
setTransactionResult(result);
|
|
129
|
-
logger.debug('Transaction completed successfully');
|
|
130
|
-
transition(FlowState.DEPOSIT_SUCCESS, { transactionId: txId, hasNordAccount: true });
|
|
131
|
-
return [3 /*break*/, 9];
|
|
132
|
-
case 8:
|
|
133
|
-
depositError_1 = _a.sent();
|
|
134
|
-
logger.warn('Error using depositSpl, falling back to mock implementation:', depositError_1);
|
|
135
|
-
setIsDepositing(false);
|
|
136
|
-
errorMessage = depositError_1 instanceof Error
|
|
137
|
-
? depositError_1.message
|
|
138
|
-
: 'Failed to process deposit';
|
|
139
|
-
transition(FlowState.AMOUNT_INPUT, {
|
|
140
|
-
depositError: errorMessage
|
|
141
|
-
});
|
|
142
|
-
return [2 /*return*/]; // Exit early
|
|
143
|
-
case 9: return [2 /*return*/];
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}); }, [
|
|
147
|
-
isDepositing,
|
|
148
|
-
selectedChain,
|
|
149
|
-
amount,
|
|
150
|
-
address,
|
|
151
|
-
nord,
|
|
152
|
-
nordUser,
|
|
153
|
-
transition,
|
|
154
|
-
handleError,
|
|
155
|
-
]);
|
|
156
|
-
/**
|
|
157
|
-
* Complete the deposit process and move to the next screen
|
|
158
|
-
*/
|
|
159
|
-
var completeDeposit = useCallback(function () {
|
|
160
|
-
// Check if user has an active session to determine the next state
|
|
161
|
-
var hasActiveSession = updateContext.hasActiveSession;
|
|
162
|
-
if (hasActiveSession) {
|
|
163
|
-
// If user has an active session, go directly to FINAL_SUCCESS
|
|
164
|
-
transition(FlowState.FINAL_SUCCESS, { hasNordAccount: true, hasActiveSession: true });
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
// Check if there's a sessionId stored in localStorage
|
|
168
|
-
var sessionIdKey = "n1_sessionId_".concat(address);
|
|
169
|
-
var storedSessionId = localStorage.getItem(sessionIdKey);
|
|
170
|
-
if (storedSessionId !== null) {
|
|
171
|
-
// If we have a sessionId in localStorage (even if it's 0), go directly to FINAL_SUCCESS
|
|
172
|
-
transition(FlowState.FINAL_SUCCESS, { hasNordAccount: true, hasActiveSession: true });
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
// If user doesn't have an active session and no sessionId in localStorage, go to NORD_AUTH
|
|
176
|
-
transition(FlowState.AUTH_LOADING, { hasNordAccount: true });
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}, [address, transition, updateContext]);
|
|
180
|
-
/**
|
|
181
|
-
* Get transaction details for display
|
|
182
|
-
*/
|
|
183
|
-
var getTransactionDetails = useCallback(function () {
|
|
184
|
-
var _a;
|
|
185
|
-
// Ensure we have a valid session mode
|
|
186
|
-
var currentSessionMode = sessionMode !== null && sessionMode !== void 0 ? sessionMode : N1SessionMode.NTS;
|
|
187
|
-
// Determine account type based on session mode
|
|
188
|
-
var accountType = currentSessionMode === N1SessionMode.Nord
|
|
189
|
-
? 'Exchange Account'
|
|
190
|
-
: 'NTS Account';
|
|
191
|
-
if (!transactionResult) {
|
|
192
|
-
// If we don't have a transaction result yet, return default values
|
|
193
|
-
return {
|
|
194
|
-
amount: amount || '0',
|
|
195
|
-
tx: transactionId || 'Processing...',
|
|
196
|
-
from: address || 'Your Wallet',
|
|
197
|
-
to: accountType,
|
|
198
|
-
network: selectedChain
|
|
199
|
-
? ((_a = AVAILABLE_CHAINS.find(function (chain) { return chain.id === selectedChain; })) === null || _a === void 0 ? void 0 : _a.name) || selectedChain
|
|
200
|
-
: 'Unknown',
|
|
201
|
-
status: 'Processing',
|
|
202
|
-
explorerUrl: '',
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
// Return actual transaction details
|
|
206
|
-
return {
|
|
207
|
-
amount: "".concat(transactionResult.amount, " ").concat(transactionResult.tokenSymbol),
|
|
208
|
-
tx: transactionResult.transactionId,
|
|
209
|
-
from: transactionResult.fromAddress,
|
|
210
|
-
to: transactionResult.toAddress,
|
|
211
|
-
network: transactionResult.networkName,
|
|
212
|
-
status: transactionResult.status,
|
|
213
|
-
explorerUrl: transactionResult.explorerUrl ||
|
|
214
|
-
getExplorerUrl(transactionResult.transactionId, selectedChain || ''),
|
|
215
|
-
};
|
|
216
|
-
}, [
|
|
217
|
-
transactionResult,
|
|
218
|
-
amount,
|
|
219
|
-
transactionId,
|
|
220
|
-
address,
|
|
221
|
-
sessionMode,
|
|
222
|
-
selectedChain,
|
|
223
|
-
]);
|
|
224
|
-
return {
|
|
225
|
-
amount: amount,
|
|
226
|
-
isDepositing: isDepositing,
|
|
227
|
-
transactionId: transactionId,
|
|
228
|
-
transactionResult: transactionResult,
|
|
229
|
-
updateAmount: updateAmount,
|
|
230
|
-
startDeposit: startDeposit,
|
|
231
|
-
completeDeposit: completeDeposit,
|
|
232
|
-
getTransactionDetails: getTransactionDetails
|
|
233
|
-
};
|
|
234
|
-
};
|
|
235
|
-
//# sourceMappingURL=useDepositTransaction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDepositTransaction.js","sourceRoot":"","sources":["../../../../../src/Modal/NordFlow/context/deposit/useDepositTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EACL,cAAc,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gBACL,MAAM,EAAE,MAAM,IAAI,GAAG;gBACrB,EAAE,EAAE,aAAa,IAAI,eAAe;gBACpC,IAAI,EAAE,OAAO,IAAI,aAAa;gBAC9B,EAAE,EAAE,WAAW;gBACf,OAAO,EAAE,aAAa;oBACpB,CAAC,CAAC,CAAA,MAAA,gBAAgB,CAAC,IAAI,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,EAAE,KAAK,aAAa,EAA1B,CAA0B,CAAC,0CAC1D,IAAI,KAAI,aAAa;oBACzB,CAAC,CAAC,SAAS;gBACb,MAAM,EAAE,YAAY;gBACpB,WAAW,EAAE,EAAE;aAChB,CAAC;QACJ,CAAC;QAED,oCAAoC;QACpC,OAAO;YACL,MAAM,EAAE,UAAG,iBAAiB,CAAC,MAAM,cAAI,iBAAiB,CAAC,WAAW,CAAE;YACtE,EAAE,EAAE,iBAAiB,CAAC,aAAa;YACnC,IAAI,EAAE,iBAAiB,CAAC,WAAW;YACnC,EAAE,EAAE,iBAAiB,CAAC,SAAS;YAC/B,OAAO,EAAE,iBAAiB,CAAC,WAAW;YACtC,MAAM,EAAE,iBAAiB,CAAC,MAAM;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,MAAM,QAAA;QACN,YAAY,cAAA;QACZ,aAAa,eAAA;QACb,iBAAiB,mBAAA;QACjB,YAAY,cAAA;QACZ,YAAY,cAAA;QACZ,eAAe,iBAAA;QACf,qBAAqB,uBAAA;KACtB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useCallback, 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';\n\nexport const useDepositTransaction = (\n selectedChain: string | null,\n initialAmount: string,\n transition: (state: FlowState, context?: any) => void,\n updateContext: (context: any) => void\n) => {\n // transaction states\n const [amount, setAmount] = useState(initialAmount);\n const [isDepositing, setIsDepositing] = useState(false);\n const [transactionId, setTransactionId] = useState<string | null>(null);\n const [transactionResult, setTransactionResult] = useState<TransactionResult | null>(null);\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 /**\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 * Update amount for deposit\n */\n const updateAmount = useCallback(\n (newAmount: string) => {\n setAmount(newAmount);\n updateContext({ amount: newAmount });\n },\n [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, selectedChain!),\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 nord,\n nordUser,\n transition,\n handleError,\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 const hasActiveSession = updateContext.hasActiveSession;\n \n if (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\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, { hasNordAccount: true });\n }\n }\n }, [address, transition, updateContext]);\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 amount,\n isDepositing,\n transactionId,\n transactionResult,\n updateAmount,\n startDeposit,\n completeDeposit,\n getTransactionDetails\n };\n}; "]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC","sourcesContent":["export * from '../context/FlowContext';\nexport * from '../context/WalletConnectContext';\nexport * from '../context/DepositContext';\n"]}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { FlowContext, FlowState } from '../types';
|
|
2
|
-
import { TransactionResult } from '../../../Logic/transactionManager';
|
|
3
|
-
/**
|
|
4
|
-
* Hook for handling the deposit flow
|
|
5
|
-
*
|
|
6
|
-
* @param options Configuration options
|
|
7
|
-
* @returns Deposit flow methods and state
|
|
8
|
-
*/
|
|
9
|
-
export declare const useDepositFlow: (options: {
|
|
10
|
-
/**
|
|
11
|
-
* Flow state
|
|
12
|
-
*/
|
|
13
|
-
state: FlowState;
|
|
14
|
-
/**
|
|
15
|
-
* Flow context
|
|
16
|
-
*/
|
|
17
|
-
context: FlowContext;
|
|
18
|
-
/**
|
|
19
|
-
* Transition to a new state
|
|
20
|
-
*/
|
|
21
|
-
transition: (newState: FlowState, contextUpdates?: Partial<FlowContext>) => boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Handle errors
|
|
24
|
-
*/
|
|
25
|
-
handleError: (error: Error) => void;
|
|
26
|
-
/**
|
|
27
|
-
* Update context
|
|
28
|
-
*/
|
|
29
|
-
updateContext?: (contextUpdates: Partial<FlowContext>) => void;
|
|
30
|
-
}) => {
|
|
31
|
-
selectedChain: string | null;
|
|
32
|
-
setSelectedChain: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
33
|
-
amount: string;
|
|
34
|
-
setAmount: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
35
|
-
isDepositing: boolean;
|
|
36
|
-
transactionId: string | null;
|
|
37
|
-
transactionResult: TransactionResult | null;
|
|
38
|
-
selectChain: (chainId: string) => void;
|
|
39
|
-
updateAmount: (newAmount: string) => void;
|
|
40
|
-
startDeposit: () => Promise<void>;
|
|
41
|
-
completeDeposit: () => void;
|
|
42
|
-
goBackToChainSelection: () => void;
|
|
43
|
-
getTransactionDetails: () => {
|
|
44
|
-
amount: string;
|
|
45
|
-
tx: string;
|
|
46
|
-
from: string;
|
|
47
|
-
to: string;
|
|
48
|
-
network: string;
|
|
49
|
-
status: string;
|
|
50
|
-
explorerUrl: string;
|
|
51
|
-
};
|
|
52
|
-
};
|