hedgequantx 1.8.44 → 1.8.46

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/src/pages/user.js CHANGED
@@ -13,9 +13,9 @@ const { prompts } = require('../utils');
13
13
  * Show user info
14
14
  */
15
15
  const showUserInfo = async (service) => {
16
- const spinner = ora({ text: 'Fetching user info...', color: 'yellow' }).start();
17
16
  const boxWidth = getLogoWidth();
18
17
  const { col1, col2 } = getColWidths(boxWidth);
18
+ let spinner;
19
19
 
20
20
  const fmtRow = (label, value, colW) => {
21
21
  const labelStr = ' ' + label.padEnd(14);
@@ -24,54 +24,75 @@ const showUserInfo = async (service) => {
24
24
  return chalk.white(labelStr) + value + ' '.repeat(padding);
25
25
  };
26
26
 
27
- let userInfo = null;
28
- let accountCount = 0;
29
-
30
- if (service?.user) {
31
- userInfo = service.user;
32
- } else if (service) {
33
- const result = await service.getUser();
34
- if (result.success) userInfo = result.user;
35
- }
36
-
37
- if (connections.count() > 0) {
38
- const accounts = await connections.getAllAccounts();
39
- accountCount = accounts.length;
40
- } else if (service) {
41
- const result = await service.getTradingAccounts();
42
- if (result.success) accountCount = result.accounts.length;
43
- }
44
-
45
- spinner.succeed('User info loaded');
46
- console.log();
47
-
48
- drawBoxHeader('USER INFO', boxWidth);
49
-
50
- if (!userInfo) {
51
- console.log(chalk.cyan('║') + padText(chalk.gray(' No user info available'), boxWidth - 2) + chalk.cyan('║'));
52
- } else {
53
- draw2ColHeader('PROFILE', 'CONNECTIONS', boxWidth);
54
-
55
- const username = userInfo.userName || userInfo.username || 'Unknown';
56
- const connCount = connections.count() || 1;
57
- console.log(chalk.cyan('║') + fmtRow('Username:', chalk.cyan(username.toUpperCase()), col1) + chalk.cyan('│') + fmtRow('Connections:', chalk.cyan(connCount.toString()), col2) + chalk.cyan('║'));
58
-
59
- const email = userInfo.email || 'N/A';
60
- console.log(chalk.cyan('║') + fmtRow('Email:', chalk.white(email), col1) + chalk.cyan('│') + fmtRow('Accounts:', chalk.cyan(accountCount.toString()), col2) + chalk.cyan('║'));
61
-
62
- const userId = userInfo.userId || userInfo.id || 'N/A';
63
- const platform = service.propfirm?.name || 'ProjectX';
64
- console.log(chalk.cyan('║') + fmtRow('User ID:', chalk.gray(userId.toString()), col1) + chalk.cyan('│') + fmtRow('Platform:', chalk.magenta(platform), col2) + chalk.cyan('║'));
65
-
66
- const firstName = userInfo.firstName || '';
67
- const lastName = userInfo.lastName || '';
68
- const fullName = (firstName + ' ' + lastName).trim() || 'N/A';
69
- console.log(chalk.cyan('║') + fmtRow('Name:', chalk.white(fullName), col1) + chalk.cyan('│') + padText('', col2) + chalk.cyan('║'));
27
+ try {
28
+ // Step 1: Get user info
29
+ spinner = ora({ text: 'Loading user info...', color: 'yellow' }).start();
30
+
31
+ let userInfo = null;
32
+
33
+ if (service?.user) {
34
+ userInfo = service.user;
35
+ } else if (service && typeof service.getUser === 'function') {
36
+ try {
37
+ const result = await service.getUser();
38
+ if (result.success) userInfo = result.user;
39
+ } catch (e) {}
40
+ }
41
+
42
+ spinner.succeed('User info loaded');
43
+
44
+ // Step 2: Get account count
45
+ spinner = ora({ text: 'Counting accounts...', color: 'yellow' }).start();
46
+
47
+ let accountCount = 0;
48
+
49
+ if (connections.count() > 0) {
50
+ try {
51
+ const accounts = await connections.getAllAccounts();
52
+ accountCount = accounts.length;
53
+ } catch (e) {}
54
+ } else if (service && typeof service.getTradingAccounts === 'function') {
55
+ try {
56
+ const result = await service.getTradingAccounts();
57
+ if (result.success) accountCount = result.accounts.length;
58
+ } catch (e) {}
59
+ }
60
+
61
+ spinner.succeed(`Found ${accountCount} account(s)`);
62
+ console.log();
63
+
64
+ // Display
65
+ drawBoxHeader('USER INFO', boxWidth);
66
+
67
+ if (!userInfo) {
68
+ console.log(chalk.cyan('║') + padText(chalk.gray(' No user info available'), boxWidth - 2) + chalk.cyan(''));
69
+ } else {
70
+ draw2ColHeader('PROFILE', 'CONNECTIONS', boxWidth);
71
+
72
+ const username = userInfo.userName || userInfo.username || 'Unknown';
73
+ const connCount = connections.count() || 1;
74
+ console.log(chalk.cyan('║') + fmtRow('Username:', chalk.cyan(username.toUpperCase()), col1) + chalk.cyan('│') + fmtRow('Connections:', chalk.cyan(String(connCount)), col2) + chalk.cyan('║'));
75
+
76
+ const email = userInfo.email || 'N/A';
77
+ console.log(chalk.cyan('║') + fmtRow('Email:', chalk.white(email), col1) + chalk.cyan('│') + fmtRow('Accounts:', chalk.cyan(String(accountCount)), col2) + chalk.cyan('║'));
78
+
79
+ const userId = userInfo.userId || userInfo.id || 'N/A';
80
+ const platform = service?.propfirm?.name || 'ProjectX';
81
+ console.log(chalk.cyan('║') + fmtRow('User ID:', chalk.gray(String(userId)), col1) + chalk.cyan('│') + fmtRow('Platform:', chalk.magenta(platform), col2) + chalk.cyan('║'));
82
+
83
+ const firstName = userInfo.firstName || '';
84
+ const lastName = userInfo.lastName || '';
85
+ const fullName = (firstName + ' ' + lastName).trim() || 'N/A';
86
+ console.log(chalk.cyan('║') + fmtRow('Name:', chalk.white(fullName), col1) + chalk.cyan('│') + padText('', col2) + chalk.cyan('║'));
87
+ }
88
+
89
+ drawBoxFooter(boxWidth);
90
+ console.log();
91
+
92
+ } catch (error) {
93
+ if (spinner) spinner.fail('Error: ' + error.message);
70
94
  }
71
95
 
72
- drawBoxFooter(boxWidth);
73
- console.log();
74
-
75
96
  await prompts.waitForEnter();
76
97
  };
77
98