Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit d8f04dc

Browse files
committed
Adjusted account profile updating
1 parent d4f2c21 commit d8f04dc

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ecency/sdk",
33
"private": false,
4-
"version": "1.0.55",
4+
"version": "1.0.56",
55
"type": "module",
66
"license": "MIT",
77
"main": "./dist/ecency-sdk.umd.js",

packages/core/src/modules/accounts/mutations/use-account-update.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { useBroadcastMutation } from "@/modules/core";
22
import { useQuery } from "@tanstack/react-query";
33
import { getAccountFullQueryOptions } from "../queries";
4+
import { AccountProfile } from "../types";
45

56
interface Payload {
6-
profile: Record<string, any>;
7+
profile: Partial<AccountProfile>;
78
tokens: { symbol: string; meta: { address: string } }[];
8-
beneficiary: {
9-
username: string;
10-
reward: number;
11-
};
129
}
1310

1411
export function useAccountUpdate(username: string) {
@@ -17,29 +14,22 @@ export function useAccountUpdate(username: string) {
1714
return useBroadcastMutation(
1815
["accounts", "update", data],
1916
username,
20-
({ profile, tokens, beneficiary }: Partial<Payload>) => {
17+
({ profile, tokens }: Partial<Payload>) => {
18+
const metadata = {
19+
...JSON.parse(data?.posting_json_metadata || "{}"),
20+
profile: { ...data?.profile, ...profile, version: 2 },
21+
};
22+
23+
if (tokens && tokens.length > 0) {
24+
metadata.tokens = tokens;
25+
}
26+
2127
return [
2228
[
2329
"account_update2",
2430
{
2531
account: username,
26-
json_metadata: "",
27-
posting_json_metadata: JSON.stringify({
28-
...JSON.parse(data?.posting_json_metadata || "{}"),
29-
profile: { ...profile, version: 2 },
30-
tokens,
31-
32-
// See https://docs.ecency.com/communities/default-beneficiary/
33-
...(beneficiary
34-
? {
35-
beneficiary: {
36-
account: beneficiary?.username,
37-
weight: beneficiary?.reward,
38-
},
39-
}
40-
: {}),
41-
}),
42-
extensions: [],
32+
posting_json_metadata: JSON.stringify(metadata),
4333
},
4434
],
4535
];

packages/core/src/modules/accounts/queries/get-account-full-query-options.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { CONFIG } from "@/modules/core/config";
2-
import { AccountFollowStats, AccountReputation } from "../types";
2+
import {
3+
AccountFollowStats,
4+
AccountProfile,
5+
AccountReputation,
6+
} from "../types";
37
import { queryOptions } from "@tanstack/react-query";
48

59
export function getAccountFullQueryOptions(username: string) {
@@ -15,7 +19,8 @@ export function getAccountFullQueryOptions(username: string) {
1519
throw new Error("[SDK] No account with given username");
1620
}
1721

18-
const profile = JSON.parse(response[0].posting_json_metadata!).profile;
22+
const profile = JSON.parse(response[0].posting_json_metadata!)
23+
.profile as AccountProfile;
1924

2025
let follow_stats: AccountFollowStats | undefined;
2126
try {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export interface AccountProfile {
2+
about?: string;
3+
cover_image?: string;
4+
location?: string;
5+
name?: string;
6+
profile_image?: string;
7+
website?: string;
8+
pinned?: string;
9+
10+
// Community's default beneficiary settings
11+
beneficiary?: {
12+
account: string;
13+
weight: number;
14+
};
15+
}

packages/core/src/modules/accounts/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./account-reputation";
33
export * from "./account-relationship";
44
export * from "./account-bookmark";
55
export * from "./account-favourite";
6+
export * from "./account-profile";

0 commit comments

Comments
 (0)