@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.
@@ -427,7 +427,11 @@ function getAccountFullQueryOptions(username) {
427
427
  if (!response[0]) {
428
428
  throw new Error("[SDK] No account with given username");
429
429
  }
430
- const profile = JSON.parse(response[0].posting_json_metadata).profile;
430
+ let profile = {};
431
+ try {
432
+ profile = JSON.parse(response[0].posting_json_metadata).profile;
433
+ } catch (e) {
434
+ }
431
435
  let follow_stats;
432
436
  try {
433
437
  follow_stats = await CONFIG.hiveClient.database.call(
@@ -436,11 +440,16 @@ function getAccountFullQueryOptions(username) {
436
440
  );
437
441
  } catch (e) {
438
442
  }
439
- const reputation = await CONFIG.hiveClient.call(
440
- "condenser_api",
441
- "get_account_reputations",
442
- [username, 1]
443
- );
443
+ let reputationValue = 0;
444
+ try {
445
+ const reputation = await CONFIG.hiveClient.call(
446
+ "condenser_api",
447
+ "get_account_reputations",
448
+ [username, 1]
449
+ );
450
+ reputationValue = reputation[0]?.reputation ?? 0;
451
+ } catch (e) {
452
+ }
444
453
  return {
445
454
  name: response[0].name,
446
455
  owner: response[0].owner,
@@ -480,11 +489,8 @@ function getAccountFullQueryOptions(username) {
480
489
  voting_power: response[0].voting_power,
481
490
  downvote_manabar: response[0].downvote_manabar,
482
491
  follow_stats,
483
- reputation: reputation[0].reputation,
484
- profile: {
485
- ...profile,
486
- reputation: reputation[0].reputation
487
- }
492
+ reputation: reputationValue,
493
+ profile
488
494
  };
489
495
  },
490
496
  enabled: !!username,
@@ -506,26 +512,99 @@ function getSearchAccountsByUsernameQueryOptions(query, limit = 5, excludeList =
506
512
  }
507
513
  });
508
514
  }
509
- function checkUsernameWalletsPendingQueryOptions(username) {
515
+ var RESERVED_META_KEYS = /* @__PURE__ */ new Set([
516
+ "ownerPublicKey",
517
+ "activePublicKey",
518
+ "postingPublicKey",
519
+ "memoPublicKey"
520
+ ]);
521
+ function checkUsernameWalletsPendingQueryOptions(username, code) {
510
522
  return reactQuery.queryOptions({
511
- queryKey: ["accounts", "check-wallet-pending", username],
523
+ queryKey: [
524
+ "accounts",
525
+ "check-wallet-pending",
526
+ username,
527
+ code ?? null
528
+ ],
512
529
  queryFn: async () => {
530
+ if (!username || !code) {
531
+ return { exist: false };
532
+ }
513
533
  const fetchApi = getBoundFetch();
514
534
  const response = await fetchApi(
515
- CONFIG.privateApiHost + "/private-api/wallets-chkuser",
535
+ CONFIG.privateApiHost + "/private-api/wallets",
516
536
  {
517
537
  method: "POST",
518
538
  headers: {
519
539
  "Content-Type": "application/json"
520
540
  },
521
541
  body: JSON.stringify({
522
- username
542
+ username,
543
+ code
523
544
  })
524
545
  }
525
546
  );
526
- return await response.json();
547
+ if (!response.ok) {
548
+ return { exist: false };
549
+ }
550
+ const payload = await response.json();
551
+ const wallets = Array.isArray(payload) ? payload.flatMap((item) => {
552
+ if (!item || typeof item !== "object") {
553
+ return [];
554
+ }
555
+ const walletItem = item;
556
+ const symbol = typeof walletItem.token === "string" ? walletItem.token : void 0;
557
+ if (!symbol) {
558
+ return [];
559
+ }
560
+ const meta = walletItem.meta && typeof walletItem.meta === "object" ? { ...walletItem.meta } : {};
561
+ const sanitizedMeta = {};
562
+ const address = typeof walletItem.address === "string" && walletItem.address ? walletItem.address : void 0;
563
+ const statusShow = typeof walletItem.status === "number" ? walletItem.status === 3 : void 0;
564
+ const showFlag = statusShow ?? false;
565
+ if (address) {
566
+ sanitizedMeta.address = address;
567
+ }
568
+ sanitizedMeta.show = showFlag;
569
+ const baseCandidate = {
570
+ symbol,
571
+ currency: symbol,
572
+ address,
573
+ show: showFlag,
574
+ type: "CHAIN",
575
+ meta: sanitizedMeta
576
+ };
577
+ const metaTokenCandidates = [];
578
+ for (const [metaSymbol, metaValue] of Object.entries(meta)) {
579
+ if (typeof metaSymbol !== "string") {
580
+ continue;
581
+ }
582
+ if (RESERVED_META_KEYS.has(metaSymbol)) {
583
+ continue;
584
+ }
585
+ if (typeof metaValue !== "string" || !metaValue) {
586
+ continue;
587
+ }
588
+ if (!/^[A-Z0-9]{2,10}$/.test(metaSymbol)) {
589
+ continue;
590
+ }
591
+ metaTokenCandidates.push({
592
+ symbol: metaSymbol,
593
+ currency: metaSymbol,
594
+ address: metaValue,
595
+ show: showFlag,
596
+ type: "CHAIN",
597
+ meta: { address: metaValue, show: showFlag }
598
+ });
599
+ }
600
+ return [baseCandidate, ...metaTokenCandidates];
601
+ }) : [];
602
+ return {
603
+ exist: wallets.length > 0,
604
+ tokens: wallets.length ? wallets : void 0,
605
+ wallets: wallets.length ? wallets : void 0
606
+ };
527
607
  },
528
- enabled: !!username,
529
608
  refetchOnMount: true
530
609
  });
531
610
  }