steamutils 1.4.33 → 1.4.35

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.
Files changed (3) hide show
  1. package/SteamClient.js +32 -23
  2. package/package.json +1 -1
  3. package/utils.js +605 -0
package/SteamClient.js CHANGED
@@ -76,7 +76,6 @@ export const LOCS = {
76
76
 
77
77
  const AppID = 730;
78
78
  export let CSGO_VER = 13960;
79
- export const FreeAppList = JSON.parse(fs.readFileSync(path.join(__dirname, "free_packages.json"))).packages;
80
79
 
81
80
  SteamUser.getAppVersion(AppID).then(function (ver) {
82
81
  CSGO_VER = ver;
@@ -92,7 +91,6 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
92
91
  let isLogOff = false;
93
92
  let playingBlocked = null;
94
93
  const richPresence = {};
95
- let sendMessageTimestamp = 0;
96
94
  let lastTimePartyRegister = 0;
97
95
  let lastTimePartySearch = 0;
98
96
  const ownedApps = [];
@@ -406,7 +404,7 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
406
404
  game_type: game_type === "Competitive" ? 8 : 10,
407
405
  }),
408
406
  );
409
- lastTimePartySearch = new Date().getTime();
407
+ lastTimePartySearch = Date.now();
410
408
  pushGCCallback("partySearch", resolve, timeout);
411
409
  });
412
410
  if (Array.isArray(players) && players.length) {
@@ -451,7 +449,7 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
451
449
  const result = protoDecode(Protos.csgo.CMsgClientMMSCreateLobbyResponse, payload.toBuffer());
452
450
  const steam_id_lobby = result.steam_id_lobby.toString();
453
451
  currentLobby.lobbyID = steam_id_lobby;
454
- currentLobby.timestamp = new Date().getTime();
452
+ currentLobby.timestamp = Date.now();
455
453
  resolve(steam_id_lobby);
456
454
  },
457
455
  );
@@ -524,7 +522,7 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
524
522
  const result = protoDecode(Protos.csgo.CMsgClientMMSSetLobbyDataResponse, payload.toBuffer());
525
523
  const steam_id_lobby = result.steam_id_lobby.toString();
526
524
  currentLobby.lobbyID = steam_id_lobby;
527
- currentLobby.timestamp = new Date().getTime();
525
+ currentLobby.timestamp = Date.now();
528
526
  resolve(steam_id_lobby);
529
527
  },
530
528
  );
@@ -579,7 +577,7 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
579
577
  }
580
578
 
581
579
  let lobbyID = null;
582
- if (currentLobby.lobbyID && currentLobby.timestamp > new Date().getTime() - 30000) {
580
+ if (currentLobby.lobbyID && currentLobby.timestamp > Date.now() - 30000) {
583
581
  //30 seconds
584
582
  lobbyID = currentLobby.lobbyID;
585
583
  } else {
@@ -1818,7 +1816,7 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
1818
1816
 
1819
1817
  function _partyRegister(prime) {
1820
1818
  log("partyRegister", prime);
1821
- lastTimePartyRegister = new Date().getTime();
1819
+ lastTimePartyRegister = Date.now();
1822
1820
  steamClient.sendToGC(
1823
1821
  730,
1824
1822
  Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Register,
@@ -1835,37 +1833,48 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
1835
1833
  );
1836
1834
  }
1837
1835
 
1838
- async function sendFriendMessage(steamId, message) {
1839
- while (sendMessageTimestamp && new Date().getTime() - sendMessageTimestamp < 2000) {
1840
- await sleep(1000);
1841
- }
1836
+ const MessageQueue = [];
1842
1837
 
1843
- while (isSendingFriendMessages) {
1844
- await sleep(5000);
1838
+ async function _execMessageQueue() {
1839
+ if (isSendingFriendMessages) {
1840
+ return;
1845
1841
  }
1842
+ while (MessageQueue.length) {
1843
+ isSendingFriendMessages = true;
1844
+ const item = MessageQueue.shift();
1845
+ const result = await _sendFriendMessage(item.steamId, item.message);
1846
+ item.callback(result);
1847
+ if (MessageQueue.length) {
1848
+ await sleep(1000);
1849
+ }
1850
+ }
1851
+ isSendingFriendMessages = false;
1852
+ }
1846
1853
 
1847
- isSendingFriendMessages = true;
1848
- const now = new Date().getTime();
1849
- while (new Date().getTime() - now < 2 * 60000) {
1850
- //2 minutes
1851
- const result = await new Promise((resolve) => {
1854
+ async function _sendFriendMessage(steamId, message) {
1855
+ let result = null;
1856
+ for (let i = 0; i < 10; i++) {
1857
+ result = await new Promise((resolve) => {
1852
1858
  steamClient.chat.sendFriendMessage(steamId, message, undefined, function (...arg) {
1853
- sendMessageTimestamp = new Date().getTime();
1854
1859
  resolve(arg);
1855
1860
  });
1856
1861
  });
1857
-
1858
1862
  if (result?.[1]?.server_timestamp) {
1859
- isSendingFriendMessages = false;
1860
1863
  return result?.[1];
1861
1864
  } else if (result?.[0]?.message?.includes?.("RateLimitExceeded")) {
1862
1865
  await sleep(5000);
1863
1866
  } else {
1864
- isSendingFriendMessages = false;
1865
1867
  return result;
1866
1868
  }
1867
1869
  }
1868
- isSendingFriendMessages = false;
1870
+ return result;
1871
+ }
1872
+
1873
+ async function sendFriendMessage(steamId, message) {
1874
+ return new Promise((resolve) => {
1875
+ MessageQueue.push({ steamId, message, callback: resolve });
1876
+ _execMessageQueue();
1877
+ });
1869
1878
  }
1870
1879
 
1871
1880
  async function autoRequestFreeLicense(shouldLog = false, max = 10) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.4.33",
3
+ "version": "1.4.35",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",
package/utils.js CHANGED
@@ -2,6 +2,514 @@ import { EAuthTokenPlatformType, LoginApprover, LoginSession } from "steam-sessi
2
2
  import moment from "moment";
3
3
 
4
4
  const isBrowser = typeof window !== "undefined";
5
+ const g_rgCurrencyData = {
6
+ USD: {
7
+ strCode: "USD",
8
+ eCurrencyCode: 1,
9
+ strSymbol: "$",
10
+ bSymbolIsPrefix: true,
11
+ bWholeUnitsOnly: false,
12
+ strDecimalSymbol: ".",
13
+ strThousandsSeparator: ",",
14
+ strSymbolAndNumberSeparator: "",
15
+ },
16
+ GBP: {
17
+ strCode: "GBP",
18
+ eCurrencyCode: 2,
19
+ strSymbol: "\u00a3",
20
+ bSymbolIsPrefix: true,
21
+ bWholeUnitsOnly: false,
22
+ strDecimalSymbol: ".",
23
+ strThousandsSeparator: ",",
24
+ strSymbolAndNumberSeparator: "",
25
+ },
26
+ EUR: {
27
+ strCode: "EUR",
28
+ eCurrencyCode: 3,
29
+ strSymbol: "\u20ac",
30
+ bSymbolIsPrefix: false,
31
+ bWholeUnitsOnly: false,
32
+ strDecimalSymbol: ",",
33
+ strThousandsSeparator: " ",
34
+ strSymbolAndNumberSeparator: "",
35
+ },
36
+ CHF: {
37
+ strCode: "CHF",
38
+ eCurrencyCode: 4,
39
+ strSymbol: "CHF",
40
+ bSymbolIsPrefix: true,
41
+ bWholeUnitsOnly: false,
42
+ strDecimalSymbol: ".",
43
+ strThousandsSeparator: " ",
44
+ strSymbolAndNumberSeparator: " ",
45
+ },
46
+ RUB: {
47
+ strCode: "RUB",
48
+ eCurrencyCode: 5,
49
+ strSymbol: "p\u0443\u0431.",
50
+ bSymbolIsPrefix: false,
51
+ bWholeUnitsOnly: true,
52
+ strDecimalSymbol: ",",
53
+ strThousandsSeparator: "",
54
+ strSymbolAndNumberSeparator: " ",
55
+ },
56
+ BRL: {
57
+ strCode: "BRL",
58
+ eCurrencyCode: 7,
59
+ strSymbol: "R$",
60
+ bSymbolIsPrefix: true,
61
+ bWholeUnitsOnly: false,
62
+ strDecimalSymbol: ",",
63
+ strThousandsSeparator: ".",
64
+ strSymbolAndNumberSeparator: " ",
65
+ },
66
+ JPY: {
67
+ strCode: "JPY",
68
+ eCurrencyCode: 8,
69
+ strSymbol: "\u00a5",
70
+ bSymbolIsPrefix: true,
71
+ bWholeUnitsOnly: true,
72
+ strDecimalSymbol: ".",
73
+ strThousandsSeparator: ",",
74
+ strSymbolAndNumberSeparator: " ",
75
+ },
76
+ NOK: {
77
+ strCode: "NOK",
78
+ eCurrencyCode: 9,
79
+ strSymbol: "kr",
80
+ bSymbolIsPrefix: false,
81
+ bWholeUnitsOnly: false,
82
+ strDecimalSymbol: ",",
83
+ strThousandsSeparator: ".",
84
+ strSymbolAndNumberSeparator: " ",
85
+ },
86
+ IDR: {
87
+ strCode: "IDR",
88
+ eCurrencyCode: 10,
89
+ strSymbol: "Rp",
90
+ bSymbolIsPrefix: true,
91
+ bWholeUnitsOnly: true,
92
+ strDecimalSymbol: ".",
93
+ strThousandsSeparator: " ",
94
+ strSymbolAndNumberSeparator: " ",
95
+ },
96
+ MYR: {
97
+ strCode: "MYR",
98
+ eCurrencyCode: 11,
99
+ strSymbol: "RM",
100
+ bSymbolIsPrefix: true,
101
+ bWholeUnitsOnly: false,
102
+ strDecimalSymbol: ".",
103
+ strThousandsSeparator: ",",
104
+ strSymbolAndNumberSeparator: "",
105
+ },
106
+ PHP: {
107
+ strCode: "PHP",
108
+ eCurrencyCode: 12,
109
+ strSymbol: "P",
110
+ bSymbolIsPrefix: true,
111
+ bWholeUnitsOnly: false,
112
+ strDecimalSymbol: ".",
113
+ strThousandsSeparator: ",",
114
+ strSymbolAndNumberSeparator: "",
115
+ },
116
+ SGD: {
117
+ strCode: "SGD",
118
+ eCurrencyCode: 13,
119
+ strSymbol: "S$",
120
+ bSymbolIsPrefix: true,
121
+ bWholeUnitsOnly: false,
122
+ strDecimalSymbol: ".",
123
+ strThousandsSeparator: ",",
124
+ strSymbolAndNumberSeparator: "",
125
+ },
126
+ THB: {
127
+ strCode: "THB",
128
+ eCurrencyCode: 14,
129
+ strSymbol: "\u0e3f",
130
+ bSymbolIsPrefix: true,
131
+ bWholeUnitsOnly: false,
132
+ strDecimalSymbol: ".",
133
+ strThousandsSeparator: ",",
134
+ strSymbolAndNumberSeparator: "",
135
+ },
136
+ VND: {
137
+ strCode: "VND",
138
+ eCurrencyCode: 15,
139
+ strSymbol: "\u20ab",
140
+ bSymbolIsPrefix: false,
141
+ bWholeUnitsOnly: true,
142
+ strDecimalSymbol: ",",
143
+ strThousandsSeparator: ".",
144
+ strSymbolAndNumberSeparator: "",
145
+ },
146
+ KRW: {
147
+ strCode: "KRW",
148
+ eCurrencyCode: 16,
149
+ strSymbol: "\u20a9",
150
+ bSymbolIsPrefix: true,
151
+ bWholeUnitsOnly: true,
152
+ strDecimalSymbol: ".",
153
+ strThousandsSeparator: ",",
154
+ strSymbolAndNumberSeparator: " ",
155
+ },
156
+ TRY: {
157
+ strCode: "TRY",
158
+ eCurrencyCode: 17,
159
+ strSymbol: "TL",
160
+ bSymbolIsPrefix: false,
161
+ bWholeUnitsOnly: false,
162
+ strDecimalSymbol: ",",
163
+ strThousandsSeparator: ".",
164
+ strSymbolAndNumberSeparator: " ",
165
+ },
166
+ UAH: {
167
+ strCode: "UAH",
168
+ eCurrencyCode: 18,
169
+ strSymbol: "\u20b4",
170
+ bSymbolIsPrefix: false,
171
+ bWholeUnitsOnly: true,
172
+ strDecimalSymbol: ",",
173
+ strThousandsSeparator: " ",
174
+ strSymbolAndNumberSeparator: "",
175
+ },
176
+ MXN: {
177
+ strCode: "MXN",
178
+ eCurrencyCode: 19,
179
+ strSymbol: "Mex$",
180
+ bSymbolIsPrefix: true,
181
+ bWholeUnitsOnly: false,
182
+ strDecimalSymbol: ".",
183
+ strThousandsSeparator: ",",
184
+ strSymbolAndNumberSeparator: " ",
185
+ },
186
+ CAD: {
187
+ strCode: "CAD",
188
+ eCurrencyCode: 20,
189
+ strSymbol: "CDN$",
190
+ bSymbolIsPrefix: true,
191
+ bWholeUnitsOnly: false,
192
+ strDecimalSymbol: ".",
193
+ strThousandsSeparator: ",",
194
+ strSymbolAndNumberSeparator: " ",
195
+ },
196
+ AUD: {
197
+ strCode: "AUD",
198
+ eCurrencyCode: 21,
199
+ strSymbol: "A$",
200
+ bSymbolIsPrefix: true,
201
+ bWholeUnitsOnly: false,
202
+ strDecimalSymbol: ".",
203
+ strThousandsSeparator: ",",
204
+ strSymbolAndNumberSeparator: " ",
205
+ },
206
+ NZD: {
207
+ strCode: "NZD",
208
+ eCurrencyCode: 22,
209
+ strSymbol: "NZ$",
210
+ bSymbolIsPrefix: true,
211
+ bWholeUnitsOnly: false,
212
+ strDecimalSymbol: ".",
213
+ strThousandsSeparator: ",",
214
+ strSymbolAndNumberSeparator: " ",
215
+ },
216
+ PLN: {
217
+ strCode: "PLN",
218
+ eCurrencyCode: 6,
219
+ strSymbol: "z\u0142",
220
+ bSymbolIsPrefix: false,
221
+ bWholeUnitsOnly: false,
222
+ strDecimalSymbol: ",",
223
+ strThousandsSeparator: " ",
224
+ strSymbolAndNumberSeparator: "",
225
+ },
226
+ CNY: {
227
+ strCode: "CNY",
228
+ eCurrencyCode: 23,
229
+ strSymbol: "\u00a5",
230
+ bSymbolIsPrefix: true,
231
+ bWholeUnitsOnly: false,
232
+ strDecimalSymbol: ".",
233
+ strThousandsSeparator: ",",
234
+ strSymbolAndNumberSeparator: " ",
235
+ },
236
+ INR: {
237
+ strCode: "INR",
238
+ eCurrencyCode: 24,
239
+ strSymbol: "\u20b9",
240
+ bSymbolIsPrefix: true,
241
+ bWholeUnitsOnly: true,
242
+ strDecimalSymbol: ".",
243
+ strThousandsSeparator: ",",
244
+ strSymbolAndNumberSeparator: " ",
245
+ },
246
+ CLP: {
247
+ strCode: "CLP",
248
+ eCurrencyCode: 25,
249
+ strSymbol: "CLP$",
250
+ bSymbolIsPrefix: true,
251
+ bWholeUnitsOnly: true,
252
+ strDecimalSymbol: ",",
253
+ strThousandsSeparator: ".",
254
+ strSymbolAndNumberSeparator: " ",
255
+ },
256
+ PEN: {
257
+ strCode: "PEN",
258
+ eCurrencyCode: 26,
259
+ strSymbol: "S/.",
260
+ bSymbolIsPrefix: true,
261
+ bWholeUnitsOnly: false,
262
+ strDecimalSymbol: ".",
263
+ strThousandsSeparator: ",",
264
+ strSymbolAndNumberSeparator: "",
265
+ },
266
+ COP: {
267
+ strCode: "COP",
268
+ eCurrencyCode: 27,
269
+ strSymbol: "COL$",
270
+ bSymbolIsPrefix: true,
271
+ bWholeUnitsOnly: true,
272
+ strDecimalSymbol: ",",
273
+ strThousandsSeparator: ".",
274
+ strSymbolAndNumberSeparator: " ",
275
+ },
276
+ ZAR: {
277
+ strCode: "ZAR",
278
+ eCurrencyCode: 28,
279
+ strSymbol: "R",
280
+ bSymbolIsPrefix: true,
281
+ bWholeUnitsOnly: false,
282
+ strDecimalSymbol: ".",
283
+ strThousandsSeparator: " ",
284
+ strSymbolAndNumberSeparator: " ",
285
+ },
286
+ HKD: {
287
+ strCode: "HKD",
288
+ eCurrencyCode: 29,
289
+ strSymbol: "HK$",
290
+ bSymbolIsPrefix: true,
291
+ bWholeUnitsOnly: false,
292
+ strDecimalSymbol: ".",
293
+ strThousandsSeparator: ",",
294
+ strSymbolAndNumberSeparator: " ",
295
+ },
296
+ TWD: {
297
+ strCode: "TWD",
298
+ eCurrencyCode: 30,
299
+ strSymbol: "NT$",
300
+ bSymbolIsPrefix: true,
301
+ bWholeUnitsOnly: true,
302
+ strDecimalSymbol: ".",
303
+ strThousandsSeparator: ",",
304
+ strSymbolAndNumberSeparator: " ",
305
+ },
306
+ SAR: {
307
+ strCode: "SAR",
308
+ eCurrencyCode: 31,
309
+ strSymbol: "SR",
310
+ bSymbolIsPrefix: false,
311
+ bWholeUnitsOnly: false,
312
+ strDecimalSymbol: ".",
313
+ strThousandsSeparator: ",",
314
+ strSymbolAndNumberSeparator: " ",
315
+ },
316
+ AED: {
317
+ strCode: "AED",
318
+ eCurrencyCode: 32,
319
+ strSymbol: "AED",
320
+ bSymbolIsPrefix: false,
321
+ bWholeUnitsOnly: false,
322
+ strDecimalSymbol: ".",
323
+ strThousandsSeparator: ",",
324
+ strSymbolAndNumberSeparator: " ",
325
+ },
326
+ SEK: {
327
+ strCode: "SEK",
328
+ eCurrencyCode: 33,
329
+ strSymbol: "kr",
330
+ bSymbolIsPrefix: false,
331
+ bWholeUnitsOnly: false,
332
+ strDecimalSymbol: ".",
333
+ strThousandsSeparator: ",",
334
+ strSymbolAndNumberSeparator: " ",
335
+ },
336
+ ARS: {
337
+ strCode: "ARS",
338
+ eCurrencyCode: 34,
339
+ strSymbol: "ARS$",
340
+ bSymbolIsPrefix: true,
341
+ bWholeUnitsOnly: false,
342
+ strDecimalSymbol: ",",
343
+ strThousandsSeparator: ".",
344
+ strSymbolAndNumberSeparator: " ",
345
+ },
346
+ ILS: {
347
+ strCode: "ILS",
348
+ eCurrencyCode: 35,
349
+ strSymbol: "\u20aa",
350
+ bSymbolIsPrefix: true,
351
+ bWholeUnitsOnly: false,
352
+ strDecimalSymbol: ".",
353
+ strThousandsSeparator: ",",
354
+ strSymbolAndNumberSeparator: "",
355
+ },
356
+ BYN: {
357
+ strCode: "BYN",
358
+ eCurrencyCode: 36,
359
+ strSymbol: "Br",
360
+ bSymbolIsPrefix: true,
361
+ bWholeUnitsOnly: false,
362
+ strDecimalSymbol: ".",
363
+ strThousandsSeparator: ",",
364
+ strSymbolAndNumberSeparator: "",
365
+ },
366
+ KZT: {
367
+ strCode: "KZT",
368
+ eCurrencyCode: 37,
369
+ strSymbol: "\u20b8",
370
+ bSymbolIsPrefix: false,
371
+ bWholeUnitsOnly: true,
372
+ strDecimalSymbol: ",",
373
+ strThousandsSeparator: " ",
374
+ strSymbolAndNumberSeparator: "",
375
+ },
376
+ KWD: {
377
+ strCode: "KWD",
378
+ eCurrencyCode: 38,
379
+ strSymbol: "KD",
380
+ bSymbolIsPrefix: false,
381
+ bWholeUnitsOnly: false,
382
+ strDecimalSymbol: ".",
383
+ strThousandsSeparator: ",",
384
+ strSymbolAndNumberSeparator: " ",
385
+ },
386
+ QAR: {
387
+ strCode: "QAR",
388
+ eCurrencyCode: 39,
389
+ strSymbol: "QR",
390
+ bSymbolIsPrefix: false,
391
+ bWholeUnitsOnly: false,
392
+ strDecimalSymbol: ".",
393
+ strThousandsSeparator: ",",
394
+ strSymbolAndNumberSeparator: " ",
395
+ },
396
+ CRC: {
397
+ strCode: "CRC",
398
+ eCurrencyCode: 40,
399
+ strSymbol: "\u20a1",
400
+ bSymbolIsPrefix: true,
401
+ bWholeUnitsOnly: true,
402
+ strDecimalSymbol: ",",
403
+ strThousandsSeparator: ".",
404
+ strSymbolAndNumberSeparator: "",
405
+ },
406
+ UYU: {
407
+ strCode: "UYU",
408
+ eCurrencyCode: 41,
409
+ strSymbol: "$U",
410
+ bSymbolIsPrefix: true,
411
+ bWholeUnitsOnly: true,
412
+ strDecimalSymbol: ",",
413
+ strThousandsSeparator: ".",
414
+ strSymbolAndNumberSeparator: "",
415
+ },
416
+ BGN: {
417
+ strCode: "BGN",
418
+ eCurrencyCode: 42,
419
+ strSymbol: "\u043b\u0432",
420
+ bSymbolIsPrefix: false,
421
+ bWholeUnitsOnly: false,
422
+ strDecimalSymbol: ".",
423
+ strThousandsSeparator: ",",
424
+ strSymbolAndNumberSeparator: " ",
425
+ },
426
+ HRK: {
427
+ strCode: "HRK",
428
+ eCurrencyCode: 43,
429
+ strSymbol: "kn",
430
+ bSymbolIsPrefix: false,
431
+ bWholeUnitsOnly: false,
432
+ strDecimalSymbol: ".",
433
+ strThousandsSeparator: ",",
434
+ strSymbolAndNumberSeparator: " ",
435
+ },
436
+ CZK: {
437
+ strCode: "CZK",
438
+ eCurrencyCode: 44,
439
+ strSymbol: "K\u010d",
440
+ bSymbolIsPrefix: false,
441
+ bWholeUnitsOnly: false,
442
+ strDecimalSymbol: ".",
443
+ strThousandsSeparator: ",",
444
+ strSymbolAndNumberSeparator: " ",
445
+ },
446
+ DKK: {
447
+ strCode: "DKK",
448
+ eCurrencyCode: 45,
449
+ strSymbol: "kr.",
450
+ bSymbolIsPrefix: false,
451
+ bWholeUnitsOnly: false,
452
+ strDecimalSymbol: ".",
453
+ strThousandsSeparator: ",",
454
+ strSymbolAndNumberSeparator: " ",
455
+ },
456
+ HUF: {
457
+ strCode: "HUF",
458
+ eCurrencyCode: 46,
459
+ strSymbol: "Ft",
460
+ bSymbolIsPrefix: false,
461
+ bWholeUnitsOnly: false,
462
+ strDecimalSymbol: ".",
463
+ strThousandsSeparator: ",",
464
+ strSymbolAndNumberSeparator: " ",
465
+ },
466
+ RON: {
467
+ strCode: "RON",
468
+ eCurrencyCode: 47,
469
+ strSymbol: "lei",
470
+ bSymbolIsPrefix: false,
471
+ bWholeUnitsOnly: false,
472
+ strDecimalSymbol: ".",
473
+ strThousandsSeparator: ",",
474
+ strSymbolAndNumberSeparator: " ",
475
+ },
476
+ RMB: {
477
+ strCode: "RMB",
478
+ eCurrencyCode: 9000,
479
+ strSymbol: "\u5200\u5e01",
480
+ bSymbolIsPrefix: false,
481
+ bWholeUnitsOnly: true,
482
+ strDecimalSymbol: ".",
483
+ strThousandsSeparator: "",
484
+ strSymbolAndNumberSeparator: " ",
485
+ },
486
+ NXP: {
487
+ strCode: "NXP",
488
+ eCurrencyCode: 9001,
489
+ strSymbol: "\uc6d0",
490
+ bSymbolIsPrefix: false,
491
+ bWholeUnitsOnly: true,
492
+ strDecimalSymbol: ".",
493
+ strThousandsSeparator: ",",
494
+ strSymbolAndNumberSeparator: "",
495
+ },
496
+ };
497
+ const g_rgWalletInfo = {
498
+ wallet_currency: 15,
499
+ wallet_country: "VN",
500
+ wallet_state: "",
501
+ wallet_fee: "1",
502
+ wallet_fee_minimum: "1",
503
+ wallet_fee_percent: "0.05",
504
+ wallet_publisher_fee_percent_default: "0.10",
505
+ wallet_fee_base: "0",
506
+ wallet_balance: "6540490",
507
+ wallet_delayed_balance: "0",
508
+ wallet_max_balance: "4500000000",
509
+ wallet_trade_max_balance: "4049999616",
510
+ success: 1,
511
+ rwgrsn: -2,
512
+ };
5
513
 
6
514
  export const sleep = (ms) => {
7
515
  return new Promise((resolve) => {
@@ -265,3 +773,100 @@ export function estimateNextXp(currentXp, xpEarned) {
265
773
  const nextXp = 30 * 13 * bonusTime;
266
774
  return nextXp + currentXp;
267
775
  }
776
+
777
+ export function formatMarketCurrency(valueInCents, currencyCode = getMarketCurrencyCode(g_rgWalletInfo.wallet_currency), countryCode) {
778
+ if (!valueInCents && valueInCents !== 0) {
779
+ return "";
780
+ }
781
+
782
+ let currencyFormat = (valueInCents / 100).toFixed(2);
783
+
784
+ if (g_rgCurrencyData[currencyCode]) {
785
+ const currencyData = g_rgCurrencyData[currencyCode];
786
+ if (isCurrencyWholeUnits(currencyCode)) {
787
+ currencyFormat = currencyFormat.replace(".00", "");
788
+ }
789
+
790
+ if (currencyData.strDecimalSymbol !== ".") {
791
+ currencyFormat = currencyFormat.replace(".", currencyData.strDecimalSymbol);
792
+ }
793
+
794
+ const currencySymbol = getMarketCurrencySymbol(currencyCode);
795
+ const currencyReturn = isCurrencySymbolBeforeValue(currencyCode) ? currencySymbol + currencyData.strSymbolAndNumberSeparator + currencyFormat : currencyFormat + currencyData.strSymbolAndNumberSeparator + currencySymbol;
796
+
797
+ if (currencyCode === "USD" && typeof countryCode != "undefined" && countryCode != "US") {
798
+ return `${currencyReturn} USD`;
799
+ } else if (currencyCode === "EUR") {
800
+ return currencyReturn.replace(",00", ",--");
801
+ } else {
802
+ return currencyReturn;
803
+ }
804
+ } else {
805
+ return `${currencyFormat} ${currencyCode}`;
806
+ }
807
+ }
808
+
809
+ export function getMarketPriceValueAsInt(strAmount) {
810
+ let nAmount;
811
+ if (!strAmount) {
812
+ return 0;
813
+ }
814
+
815
+ // Users may enter either comma or period for the decimal mark and digit group separators.
816
+ strAmount = strAmount.replace(/,/g, ".");
817
+
818
+ // strip the currency symbol, set .-- to .00
819
+ strAmount = strAmount.replace(getMarketCurrencySymbol(getMarketCurrencyCode(g_rgWalletInfo.wallet_currency)), "").replace(".--", ".00");
820
+
821
+ // strip spaces
822
+ strAmount = strAmount.replace(/ /g, "");
823
+
824
+ // Remove all but the last period so that entries like "1,147.6" work
825
+ if (strAmount.includes(".")) {
826
+ var splitAmount = strAmount.split(".");
827
+ var strLastSegment = splitAmount[splitAmount.length - 1];
828
+
829
+ if (!isNaN(strLastSegment) && strLastSegment.length == 3 && splitAmount[splitAmount.length - 2] != "0") {
830
+ // Looks like the user only entered thousands separators. Remove all commas and periods.
831
+ // Ensures an entry like "1,147" is not treated as "1.147"
832
+ //
833
+ // Users may be surprised to find that "1.147" is treated as "1,147". "1.147" is either an error or the user
834
+ // really did mean one thousand one hundred and forty seven since no currencies can be split into more than
835
+ // hundredths. If it was an error, the user should notice in the next step of the dialog and can go back and
836
+ // correct it. If they happen to not notice, it is better that we list the item at a higher price than
837
+ // intended instead of lower than intended (which we would have done if we accepted the 1.147 value as is).
838
+ strAmount = splitAmount.join("");
839
+ } else {
840
+ strAmount = `${splitAmount.slice(0, -1).join("")}.${strLastSegment}`;
841
+ }
842
+ }
843
+
844
+ let flAmount = parseFloat(strAmount) * 100;
845
+ nAmount = Math.floor(isNaN(flAmount) ? 0 : flAmount + 0.000001); // round down
846
+
847
+ nAmount = Math.max(nAmount, 0);
848
+ return nAmount;
849
+ }
850
+
851
+ export function isCurrencyWholeUnits(currencyCode) {
852
+ return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bWholeUnitsOnly && currencyCode !== "RUB";
853
+ }
854
+
855
+ export function isCurrencySymbolBeforeValue(currencyCode) {
856
+ return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bSymbolIsPrefix;
857
+ }
858
+
859
+ // Return the symbol to use for a currency
860
+ export function getMarketCurrencySymbol(currencyCode) {
861
+ return g_rgCurrencyData[currencyCode]?.strSymbol ?? currencyCode;
862
+ }
863
+
864
+ export function getMarketCurrencyCode(currencyId) {
865
+ currencyId = parseInt(currencyId);
866
+ for (const code in g_rgCurrencyData) {
867
+ if (g_rgCurrencyData[code].eCurrencyCode === currencyId) {
868
+ return code;
869
+ }
870
+ }
871
+ return "Unknown";
872
+ }