@ecency/sdk 1.3.1 → 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.
@@ -512,26 +512,99 @@ function getSearchAccountsByUsernameQueryOptions(query, limit = 5, excludeList =
512
512
  }
513
513
  });
514
514
  }
515
- 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) {
516
522
  return reactQuery.queryOptions({
517
- queryKey: ["accounts", "check-wallet-pending", username],
523
+ queryKey: [
524
+ "accounts",
525
+ "check-wallet-pending",
526
+ username,
527
+ code ?? null
528
+ ],
518
529
  queryFn: async () => {
530
+ if (!username || !code) {
531
+ return { exist: false };
532
+ }
519
533
  const fetchApi = getBoundFetch();
520
534
  const response = await fetchApi(
521
- CONFIG.privateApiHost + "/private-api/wallets-chkuser",
535
+ CONFIG.privateApiHost + "/private-api/wallets",
522
536
  {
523
537
  method: "POST",
524
538
  headers: {
525
539
  "Content-Type": "application/json"
526
540
  },
527
541
  body: JSON.stringify({
528
- username
542
+ username,
543
+ code
529
544
  })
530
545
  }
531
546
  );
532
- 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
+ };
533
607
  },
534
- enabled: !!username,
535
608
  refetchOnMount: true
536
609
  });
537
610
  }