@ecency/sdk 1.3.0 → 1.3.2

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.
@@ -402,7 +402,11 @@ function getAccountFullQueryOptions(username) {
402
402
  if (!response[0]) {
403
403
  throw new Error("[SDK] No account with given username");
404
404
  }
405
- const profile = JSON.parse(response[0].posting_json_metadata).profile;
405
+ let profile = {};
406
+ try {
407
+ profile = JSON.parse(response[0].posting_json_metadata).profile;
408
+ } catch (e) {
409
+ }
406
410
  let follow_stats;
407
411
  try {
408
412
  follow_stats = await CONFIG.hiveClient.database.call(
@@ -411,11 +415,16 @@ function getAccountFullQueryOptions(username) {
411
415
  );
412
416
  } catch (e) {
413
417
  }
414
- const reputation = await CONFIG.hiveClient.call(
415
- "condenser_api",
416
- "get_account_reputations",
417
- [username, 1]
418
- );
418
+ let reputationValue = 0;
419
+ try {
420
+ const reputation = await CONFIG.hiveClient.call(
421
+ "condenser_api",
422
+ "get_account_reputations",
423
+ [username, 1]
424
+ );
425
+ reputationValue = reputation[0]?.reputation ?? 0;
426
+ } catch (e) {
427
+ }
419
428
  return {
420
429
  name: response[0].name,
421
430
  owner: response[0].owner,
@@ -455,11 +464,8 @@ function getAccountFullQueryOptions(username) {
455
464
  voting_power: response[0].voting_power,
456
465
  downvote_manabar: response[0].downvote_manabar,
457
466
  follow_stats,
458
- reputation: reputation[0].reputation,
459
- profile: {
460
- ...profile,
461
- reputation: reputation[0].reputation
462
- }
467
+ reputation: reputationValue,
468
+ profile
463
469
  };
464
470
  },
465
471
  enabled: !!username,
@@ -481,26 +487,99 @@ function getSearchAccountsByUsernameQueryOptions(query, limit = 5, excludeList =
481
487
  }
482
488
  });
483
489
  }
484
- function checkUsernameWalletsPendingQueryOptions(username) {
490
+ var RESERVED_META_KEYS = /* @__PURE__ */ new Set([
491
+ "ownerPublicKey",
492
+ "activePublicKey",
493
+ "postingPublicKey",
494
+ "memoPublicKey"
495
+ ]);
496
+ function checkUsernameWalletsPendingQueryOptions(username, code) {
485
497
  return queryOptions({
486
- queryKey: ["accounts", "check-wallet-pending", username],
498
+ queryKey: [
499
+ "accounts",
500
+ "check-wallet-pending",
501
+ username,
502
+ code ?? null
503
+ ],
487
504
  queryFn: async () => {
505
+ if (!username || !code) {
506
+ return { exist: false };
507
+ }
488
508
  const fetchApi = getBoundFetch();
489
509
  const response = await fetchApi(
490
- CONFIG.privateApiHost + "/private-api/wallets-chkuser",
510
+ CONFIG.privateApiHost + "/private-api/wallets",
491
511
  {
492
512
  method: "POST",
493
513
  headers: {
494
514
  "Content-Type": "application/json"
495
515
  },
496
516
  body: JSON.stringify({
497
- username
517
+ username,
518
+ code
498
519
  })
499
520
  }
500
521
  );
501
- return await response.json();
522
+ if (!response.ok) {
523
+ return { exist: false };
524
+ }
525
+ const payload = await response.json();
526
+ const wallets = Array.isArray(payload) ? payload.flatMap((item) => {
527
+ if (!item || typeof item !== "object") {
528
+ return [];
529
+ }
530
+ const walletItem = item;
531
+ const symbol = typeof walletItem.token === "string" ? walletItem.token : void 0;
532
+ if (!symbol) {
533
+ return [];
534
+ }
535
+ const meta = walletItem.meta && typeof walletItem.meta === "object" ? { ...walletItem.meta } : {};
536
+ const sanitizedMeta = {};
537
+ const address = typeof walletItem.address === "string" && walletItem.address ? walletItem.address : void 0;
538
+ const statusShow = typeof walletItem.status === "number" ? walletItem.status === 3 : void 0;
539
+ const showFlag = statusShow ?? false;
540
+ if (address) {
541
+ sanitizedMeta.address = address;
542
+ }
543
+ sanitizedMeta.show = showFlag;
544
+ const baseCandidate = {
545
+ symbol,
546
+ currency: symbol,
547
+ address,
548
+ show: showFlag,
549
+ type: "CHAIN",
550
+ meta: sanitizedMeta
551
+ };
552
+ const metaTokenCandidates = [];
553
+ for (const [metaSymbol, metaValue] of Object.entries(meta)) {
554
+ if (typeof metaSymbol !== "string") {
555
+ continue;
556
+ }
557
+ if (RESERVED_META_KEYS.has(metaSymbol)) {
558
+ continue;
559
+ }
560
+ if (typeof metaValue !== "string" || !metaValue) {
561
+ continue;
562
+ }
563
+ if (!/^[A-Z0-9]{2,10}$/.test(metaSymbol)) {
564
+ continue;
565
+ }
566
+ metaTokenCandidates.push({
567
+ symbol: metaSymbol,
568
+ currency: metaSymbol,
569
+ address: metaValue,
570
+ show: showFlag,
571
+ type: "CHAIN",
572
+ meta: { address: metaValue, show: showFlag }
573
+ });
574
+ }
575
+ return [baseCandidate, ...metaTokenCandidates];
576
+ }) : [];
577
+ return {
578
+ exist: wallets.length > 0,
579
+ tokens: wallets.length ? wallets : void 0,
580
+ wallets: wallets.length ? wallets : void 0
581
+ };
502
582
  },
503
- enabled: !!username,
504
583
  refetchOnMount: true
505
584
  });
506
585
  }