@ecency/sdk 1.3.3 → 1.3.4

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.
@@ -24,6 +24,7 @@ interface AccountProfile {
24
24
  website?: string;
25
25
  pinned?: string;
26
26
  reputation?: number;
27
+ version?: number;
27
28
  beneficiary?: {
28
29
  account: string;
29
30
  weight: number;
@@ -704,19 +704,27 @@ function sanitizeTokens(tokens) {
704
704
  return { ...rest, meta: safeMeta };
705
705
  });
706
706
  }
707
+ function getExistingProfile(data) {
708
+ try {
709
+ const parsed = JSON.parse(data?.posting_json_metadata || "{}");
710
+ if (parsed && typeof parsed === "object" && parsed.profile && typeof parsed.profile === "object") {
711
+ return parsed.profile;
712
+ }
713
+ } catch (e) {
714
+ }
715
+ return {};
716
+ }
707
717
  function getBuiltProfile({
708
718
  profile,
709
719
  tokens,
710
720
  data
711
721
  }) {
712
- const metadata = R.pipe(
713
- JSON.parse(data?.posting_json_metadata || "{}").profile,
714
- R.mergeDeep(profile ?? {})
715
- );
722
+ const metadata = R.mergeDeep(getExistingProfile(data), profile ?? {});
716
723
  if (tokens && tokens.length > 0) {
717
724
  metadata.tokens = tokens;
718
725
  }
719
726
  metadata.tokens = sanitizeTokens(metadata.tokens);
727
+ metadata.version = 2;
720
728
  return metadata;
721
729
  }
722
730
  function useAccountUpdate(username) {