@ecency/sdk 1.3.4 → 1.3.5

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.
@@ -3,7 +3,7 @@
3
3
  var reactQuery = require('@tanstack/react-query');
4
4
  var dhive = require('@hiveio/dhive');
5
5
  var hs = require('hivesigner');
6
- var R = require('remeda');
6
+ var R4 = require('remeda');
7
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
@@ -26,7 +26,7 @@ function _interopNamespace(e) {
26
26
  }
27
27
 
28
28
  var hs__default = /*#__PURE__*/_interopDefault(hs);
29
- var R__namespace = /*#__PURE__*/_interopNamespace(R);
29
+ var R4__namespace = /*#__PURE__*/_interopNamespace(R4);
30
30
 
31
31
  var __defProp = Object.defineProperty;
32
32
  var __export = (target, all) => {
@@ -427,11 +427,7 @@ function getAccountFullQueryOptions(username) {
427
427
  if (!response[0]) {
428
428
  throw new Error("[SDK] No account with given username");
429
429
  }
430
- let profile = {};
431
- try {
432
- profile = JSON.parse(response[0].posting_json_metadata).profile;
433
- } catch (e) {
434
- }
430
+ const profile = parseProfileMetadata(response[0].posting_json_metadata);
435
431
  let follow_stats;
436
432
  try {
437
433
  follow_stats = await CONFIG.hiveClient.database.call(
@@ -725,29 +721,42 @@ function sanitizeTokens(tokens) {
725
721
  return { ...rest, meta: safeMeta };
726
722
  });
727
723
  }
728
- function getExistingProfile(data) {
724
+ function parseProfileMetadata(postingJsonMetadata) {
725
+ if (!postingJsonMetadata) {
726
+ return {};
727
+ }
729
728
  try {
730
- const parsed = JSON.parse(data?.posting_json_metadata || "{}");
729
+ const parsed = JSON.parse(postingJsonMetadata);
731
730
  if (parsed && typeof parsed === "object" && parsed.profile && typeof parsed.profile === "object") {
732
731
  return parsed.profile;
733
732
  }
734
- } catch (e) {
733
+ } catch (err) {
735
734
  }
736
735
  return {};
737
736
  }
738
- function getBuiltProfile({
737
+ function extractAccountProfile(data) {
738
+ return parseProfileMetadata(data?.posting_json_metadata);
739
+ }
740
+ function buildProfileMetadata({
741
+ existingProfile,
739
742
  profile,
740
- tokens,
741
- data
743
+ tokens
742
744
  }) {
743
- const metadata = R__namespace.mergeDeep(getExistingProfile(data), profile ?? {});
744
- if (tokens && tokens.length > 0) {
745
- metadata.tokens = tokens;
745
+ const { tokens: profileTokens, version: _ignoredVersion, ...profileRest } = profile ?? {};
746
+ const metadata = R4__namespace.mergeDeep(
747
+ existingProfile ?? {},
748
+ profileRest
749
+ );
750
+ const nextTokens = tokens ?? profileTokens;
751
+ if (nextTokens && nextTokens.length > 0) {
752
+ metadata.tokens = nextTokens;
746
753
  }
747
754
  metadata.tokens = sanitizeTokens(metadata.tokens);
748
755
  metadata.version = 2;
749
756
  return metadata;
750
757
  }
758
+
759
+ // src/modules/accounts/mutations/use-account-update.ts
751
760
  function useAccountUpdate(username) {
752
761
  const queryClient = reactQuery.useQueryClient();
753
762
  const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
@@ -758,6 +767,11 @@ function useAccountUpdate(username) {
758
767
  if (!data) {
759
768
  throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
760
769
  }
770
+ const profile = buildProfileMetadata({
771
+ existingProfile: extractAccountProfile(data),
772
+ profile: payload.profile,
773
+ tokens: payload.tokens
774
+ });
761
775
  return [
762
776
  [
763
777
  "account_update2",
@@ -766,7 +780,7 @@ function useAccountUpdate(username) {
766
780
  json_metadata: "",
767
781
  extensions: [],
768
782
  posting_json_metadata: JSON.stringify({
769
- profile: getBuiltProfile({ ...payload, data })
783
+ profile
770
784
  })
771
785
  }
772
786
  ]
@@ -778,8 +792,12 @@ function useAccountUpdate(username) {
778
792
  if (!data2) {
779
793
  return data2;
780
794
  }
781
- const obj = R__namespace.clone(data2);
782
- obj.profile = getBuiltProfile({ ...variables, data: data2 });
795
+ const obj = R4__namespace.clone(data2);
796
+ obj.profile = buildProfileMetadata({
797
+ existingProfile: extractAccountProfile(data2),
798
+ profile: variables.profile,
799
+ tokens: variables.tokens
800
+ });
783
801
  return obj;
784
802
  }
785
803
  )
@@ -974,7 +992,7 @@ function useAccountUpdateKeyAuths(username, options) {
974
992
  );
975
993
  }
976
994
  const prepareAuth = (keyName) => {
977
- const auth = R__namespace.clone(accountData[keyName]);
995
+ const auth = R4__namespace.clone(accountData[keyName]);
978
996
  auth.key_auths = dedupeAndSortKeyAuths(
979
997
  keepCurrent ? auth.key_auths : [],
980
998
  keys.map(
@@ -1045,9 +1063,9 @@ function useAccountRevokePosting(username, options) {
1045
1063
  "[SDK][Accounts] \u2013\xA0cannot revoke posting for anonymous user"
1046
1064
  );
1047
1065
  }
1048
- const posting = R__namespace.pipe(
1066
+ const posting = R4__namespace.pipe(
1049
1067
  {},
1050
- R__namespace.mergeDeep(data.posting)
1068
+ R4__namespace.mergeDeep(data.posting)
1051
1069
  );
1052
1070
  posting.account_auths = posting.account_auths.filter(
1053
1071
  ([account]) => account !== accountName
@@ -1164,7 +1182,7 @@ function useAccountRevokeKey(username, options) {
1164
1182
  );
1165
1183
  }
1166
1184
  const prepareAuth = (keyName) => {
1167
- const auth = R__namespace.clone(accountData[keyName]);
1185
+ const auth = R4__namespace.clone(accountData[keyName]);
1168
1186
  auth.key_auths = auth.key_auths.filter(
1169
1187
  ([key]) => key !== revokingKey.toString()
1170
1188
  );
@@ -1758,10 +1776,12 @@ exports.ROLES = ROLES;
1758
1776
  exports.Symbol = Symbol2;
1759
1777
  exports.ThreeSpeakIntegration = ThreeSpeakIntegration;
1760
1778
  exports.broadcastJson = broadcastJson;
1779
+ exports.buildProfileMetadata = buildProfileMetadata;
1761
1780
  exports.checkUsernameWalletsPendingQueryOptions = checkUsernameWalletsPendingQueryOptions;
1762
1781
  exports.decodeObj = decodeObj;
1763
1782
  exports.dedupeAndSortKeyAuths = dedupeAndSortKeyAuths;
1764
1783
  exports.encodeObj = encodeObj;
1784
+ exports.extractAccountProfile = extractAccountProfile;
1765
1785
  exports.getAccessToken = getAccessToken;
1766
1786
  exports.getAccountFullQueryOptions = getAccountFullQueryOptions;
1767
1787
  exports.getAccountPendingRecoveryQueryOptions = getAccountPendingRecoveryQueryOptions;
@@ -1793,6 +1813,7 @@ exports.getTrendingTagsQueryOptions = getTrendingTagsQueryOptions;
1793
1813
  exports.getUser = getUser;
1794
1814
  exports.makeQueryClient = makeQueryClient;
1795
1815
  exports.parseAsset = parseAsset;
1816
+ exports.parseProfileMetadata = parseProfileMetadata;
1796
1817
  exports.roleMap = roleMap;
1797
1818
  exports.useAccountFavouriteAdd = useAccountFavouriteAdd;
1798
1819
  exports.useAccountFavouriteDelete = useAccountFavouriteDelete;