@ecency/sdk 1.3.1 → 1.3.3

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.
@@ -487,26 +487,99 @@ function getSearchAccountsByUsernameQueryOptions(query, limit = 5, excludeList =
487
487
  }
488
488
  });
489
489
  }
490
- 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) {
491
497
  return queryOptions({
492
- queryKey: ["accounts", "check-wallet-pending", username],
498
+ queryKey: [
499
+ "accounts",
500
+ "check-wallet-pending",
501
+ username,
502
+ code ?? null
503
+ ],
493
504
  queryFn: async () => {
505
+ if (!username || !code) {
506
+ return { exist: false };
507
+ }
494
508
  const fetchApi = getBoundFetch();
495
509
  const response = await fetchApi(
496
- CONFIG.privateApiHost + "/private-api/wallets-chkuser",
510
+ CONFIG.privateApiHost + "/private-api/wallets",
497
511
  {
498
512
  method: "POST",
499
513
  headers: {
500
514
  "Content-Type": "application/json"
501
515
  },
502
516
  body: JSON.stringify({
503
- username
517
+ username,
518
+ code
504
519
  })
505
520
  }
506
521
  );
507
- 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
+ };
508
582
  },
509
- enabled: !!username,
510
583
  refetchOnMount: true
511
584
  });
512
585
  }