hive-react-kit 0.10.0 → 0.10.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.
@@ -1,6 +1,8 @@
1
1
  import { CommunityItem, CommunityDetailsResponse, CommunitySubscriber, CommunityActivity } from '../types/community';
2
2
  declare class CommunityService {
3
- private readonly HIVE_API_URL;
3
+ /** Always read the latest endpoint — `setHiveApiEndpoint()` may have been
4
+ * called after construction, and a stale instance field would miss it. */
5
+ private get HIVE_API_URL();
4
6
  getListOfCommunities(query?: string, limit?: number, last?: string): Promise<CommunityItem[]>;
5
7
  getCommunityDetails(communityId: string): Promise<CommunityDetailsResponse>;
6
8
  getCommunitySubscribers(communityId: string, limit?: number, last?: string): Promise<CommunitySubscriber[]>;
@@ -16,7 +16,9 @@ export declare const SNAP_SUBTYPE_PARENTS: {
16
16
  };
17
17
  export type SnapSubType = keyof typeof SNAP_SUBTYPE_PARENTS;
18
18
  declare class UserService {
19
- private readonly HIVE_API_URL;
19
+ /** Always read the latest endpoint — `setHiveApiEndpoint()` may have been
20
+ * called after construction, and a stale instance field would miss it. */
21
+ private get HIVE_API_URL();
20
22
  /** Central fetch wrapper — threads AbortSignal to every network request */
21
23
  private _fetch;
22
24
  getProfile(username: string, signal?: AbortSignal): Promise<UserProfileResponse>;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Beneficiary helpers used by PostComposer's BeneficiariesEditor and by
3
+ * apps that broadcast Hive `comment_options`. The composer emits the chosen
4
+ * list via `onBeneficiariesChange`; the consumer calls
5
+ * `buildBeneficiariesCommentOptions(...)` (or `mergeBeneficiariesIntoCommentOptions`)
6
+ * at broadcast time.
7
+ *
8
+ * In the UI we work in **whole percent** units (1–100). On the wire Hive uses
9
+ * basis points (1% = 100, 100% = 10_000). The conversion happens when we
10
+ * build the operation tuple.
11
+ */
12
+ import type { RewardOption } from './commentOptions';
13
+ /** 3Speak fund account that must receive 10% on any video post or video comment. */
14
+ export declare const THREESPEAK_FUND_ACCOUNT = "threespeakfund";
15
+ /** Locked weight for the 3Speak fund beneficiary, expressed in whole-percent UI units. */
16
+ export declare const THREESPEAK_FUND_PERCENT = 10;
17
+ export interface Beneficiary {
18
+ /** Hive account name (lowercase, no leading @). */
19
+ account: string;
20
+ /** Whole-percent weight in [1, 100]. Hive's basis-point weight is computed as `weight * 100`. */
21
+ weight: number;
22
+ }
23
+ /** Detect a 3Speak video embed in the body — matches the URLs the composer appends. */
24
+ export declare function bodyHasVideo(body: string): boolean;
25
+ /** Normalize an account name — lowercase, strip leading `@`, trim whitespace. */
26
+ export declare function normalizeBeneficiaryAccount(account: string): string;
27
+ /**
28
+ * Sanitize a beneficiary list:
29
+ * - normalize account names, drop empty/invalid entries
30
+ * - clamp weights to [1, 100] (whole percent)
31
+ * - dedupe by account (later entries override earlier)
32
+ */
33
+ export declare function sanitizeBeneficiaries(list: Beneficiary[] | undefined): Beneficiary[];
34
+ /** Sum of beneficiary weights in whole-percent units. */
35
+ export declare function totalBeneficiaryWeight(list: Beneficiary[] | undefined): number;
36
+ /**
37
+ * Enforce the 3Speak fund rule: when a post/comment has video content, the
38
+ * `threespeakfund` account must receive 10% and is non-removable, so the
39
+ * remaining user-controlled allocation is capped at 90%.
40
+ *
41
+ * Strategy:
42
+ * 1. Strip any existing `threespeakfund` entry from `userList`.
43
+ * 2. Scale the remaining entries proportionally so their sum ≤ 90%.
44
+ * 3. Prepend a locked `threespeakfund` 10% entry.
45
+ *
46
+ * If `hasVideo` is false, returns `sanitizeBeneficiaries(userList)` unchanged.
47
+ */
48
+ export declare function enforceVideoBeneficiaries(userList: Beneficiary[] | undefined, hasVideo: boolean): Beneficiary[];
49
+ type CommentOptionsOp = [
50
+ 'comment_options',
51
+ {
52
+ author: string;
53
+ permlink: string;
54
+ allow_votes: boolean;
55
+ allow_curation_rewards: boolean;
56
+ max_accepted_payout: string;
57
+ percent_hbd: number;
58
+ extensions: unknown[];
59
+ }
60
+ ];
61
+ /**
62
+ * Build a standalone `comment_options` op carrying the beneficiary list.
63
+ * Returns `null` when there are no beneficiaries.
64
+ *
65
+ * For most posts this is what consumers want when reward routing is `'default'`.
66
+ * To combine beneficiaries with non-default reward routing, use
67
+ * `mergeBeneficiariesIntoCommentOptions` instead.
68
+ */
69
+ export declare function buildBeneficiariesCommentOptions(author: string, permlink: string, beneficiaries: Beneficiary[] | undefined): CommentOptionsOp | null;
70
+ /**
71
+ * Combine reward routing (power_up / burn / decline / default) with a
72
+ * user-chosen beneficiary list into a single `comment_options` op.
73
+ *
74
+ * Notes:
75
+ * - For `'burn'`, all rewards already go to `null` — additional beneficiaries
76
+ * are ignored to keep the burn intent clean.
77
+ * - For all other options, the user's beneficiary list is included verbatim.
78
+ * - Returns `null` when there is nothing to broadcast (default reward + no
79
+ * beneficiaries).
80
+ */
81
+ export declare function mergeBeneficiariesIntoCommentOptions(author: string, permlink: string, reward: RewardOption, beneficiaries: Beneficiary[] | undefined): CommentOptionsOp | null;
82
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hive-react-kit",
3
3
  "private": false,
4
- "version": "0.10.0",
4
+ "version": "0.10.2",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs.js",
7
7
  "module": "./dist/index.esm.js",