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

Commit d4f2c21

Browse files
committed
Added community beneficiaries
1 parent 8ed4530 commit d4f2c21

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
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.54",
4+
"version": "1.0.55",
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: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
import { useBroadcastMutation } from "@/modules/core";
2+
import { useQuery } from "@tanstack/react-query";
3+
import { getAccountFullQueryOptions } from "../queries";
4+
5+
interface Payload {
6+
profile: Record<string, any>;
7+
tokens: { symbol: string; meta: { address: string } }[];
8+
beneficiary: {
9+
username: string;
10+
reward: number;
11+
};
12+
}
213

314
export function useAccountUpdate(username: string) {
15+
const { data } = useQuery(getAccountFullQueryOptions(username));
16+
417
return useBroadcastMutation(
5-
["accounts", "update"],
18+
["accounts", "update", data],
619
username,
7-
({
8-
profile,
9-
tokens,
10-
}: {
11-
profile: Record<string, any>;
12-
tokens: { symbol: string; meta: { address: string } }[];
13-
}) => {
20+
({ profile, tokens, beneficiary }: Partial<Payload>) => {
1421
return [
1522
[
1623
"account_update2",
1724
{
1825
account: username,
1926
json_metadata: "",
2027
posting_json_metadata: JSON.stringify({
28+
...JSON.parse(data?.posting_json_metadata || "{}"),
2129
profile: { ...profile, version: 2 },
2230
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+
: {}),
2341
}),
2442
extensions: [],
2543
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ export function getAccountFullQueryOptions(username: string) {
3232
);
3333

3434
return {
35-
...response,
35+
...response[0],
3636
follow_stats,
3737
reputation: reputation[0].reputation,
3838
profile: {
3939
...profile,
4040
reputation: reputation[0].reputation,
4141
},
42-
};
42+
} as const;
4343
},
4444
enabled: !!username,
4545
staleTime: 60000,

0 commit comments

Comments
 (0)