@ecency/sdk 1.3.6 → 1.3.9
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.
- package/dist/browser/index.d.ts +1935 -25
- package/dist/browser/index.js +2969 -835
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +3049 -832
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +2969 -835
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { QueryClient, useQuery, useInfiniteQuery, useMutation, queryOptions,
|
|
2
|
-
import { Client, PrivateKey, cryptoUtils, RCAPI } from '@hiveio/dhive';
|
|
1
|
+
import { QueryClient, useQuery, useInfiniteQuery, useMutation, queryOptions, infiniteQueryOptions, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { Client, utils, PrivateKey, cryptoUtils, RCAPI } from '@hiveio/dhive';
|
|
3
3
|
import hs from 'hivesigner';
|
|
4
4
|
import * as R4 from 'remeda';
|
|
5
5
|
|
|
@@ -59,7 +59,16 @@ var CONFIG = {
|
|
|
59
59
|
heliusApiKey: process.env.VITE_HELIUS_API_KEY,
|
|
60
60
|
queryClient: new QueryClient(),
|
|
61
61
|
plausibleHost: "https://pl.ecency.com",
|
|
62
|
-
spkNode: "https://spk.good-karma.xyz"
|
|
62
|
+
spkNode: "https://spk.good-karma.xyz",
|
|
63
|
+
// DMCA filtering - can be configured by the app
|
|
64
|
+
dmcaAccounts: [],
|
|
65
|
+
dmcaTags: [],
|
|
66
|
+
dmcaPatterns: [],
|
|
67
|
+
// Pre-compiled regex patterns for performance and security
|
|
68
|
+
dmcaTagRegexes: [],
|
|
69
|
+
dmcaPatternRegexes: [],
|
|
70
|
+
// Track if DMCA has been initialized to avoid duplicate logs
|
|
71
|
+
_dmcaInitialized: false
|
|
63
72
|
};
|
|
64
73
|
var ConfigManager;
|
|
65
74
|
((ConfigManager2) => {
|
|
@@ -67,6 +76,115 @@ var ConfigManager;
|
|
|
67
76
|
CONFIG.queryClient = client;
|
|
68
77
|
}
|
|
69
78
|
ConfigManager2.setQueryClient = setQueryClient;
|
|
79
|
+
function setPrivateApiHost(host) {
|
|
80
|
+
CONFIG.privateApiHost = host;
|
|
81
|
+
}
|
|
82
|
+
ConfigManager2.setPrivateApiHost = setPrivateApiHost;
|
|
83
|
+
function analyzeRedosRisk(pattern) {
|
|
84
|
+
if (/(\([^)]*[*+{][^)]*\))[*+{]/.test(pattern)) {
|
|
85
|
+
return { safe: false, reason: "nested quantifiers detected" };
|
|
86
|
+
}
|
|
87
|
+
if (/\([^|)]*\|[^)]*\)[*+{]/.test(pattern)) {
|
|
88
|
+
return { safe: false, reason: "alternation with quantifier (potential overlap)" };
|
|
89
|
+
}
|
|
90
|
+
if (/\([^)]*[*+][^)]*\)[*+]/.test(pattern)) {
|
|
91
|
+
return { safe: false, reason: "repeated quantifiers (catastrophic backtracking risk)" };
|
|
92
|
+
}
|
|
93
|
+
if (/\.\*\.\*/.test(pattern) || /\.\+\.\+/.test(pattern)) {
|
|
94
|
+
return { safe: false, reason: "multiple greedy quantifiers on wildcards" };
|
|
95
|
+
}
|
|
96
|
+
const unboundedRange = /\.?\{(\d+),(\d+)\}/g;
|
|
97
|
+
let match;
|
|
98
|
+
while ((match = unboundedRange.exec(pattern)) !== null) {
|
|
99
|
+
const [, min, max] = match;
|
|
100
|
+
const range = parseInt(max, 10) - parseInt(min, 10);
|
|
101
|
+
if (range > 1e3) {
|
|
102
|
+
return { safe: false, reason: `excessive range: {${min},${max}}` };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { safe: true };
|
|
106
|
+
}
|
|
107
|
+
function testRegexPerformance(regex) {
|
|
108
|
+
const adversarialInputs = [
|
|
109
|
+
// Nested quantifier attack
|
|
110
|
+
"a".repeat(50) + "x",
|
|
111
|
+
// Alternation attack
|
|
112
|
+
"ab".repeat(50) + "x",
|
|
113
|
+
// Wildcard attack
|
|
114
|
+
"x".repeat(100),
|
|
115
|
+
// Mixed attack
|
|
116
|
+
"aaa".repeat(30) + "bbb".repeat(30) + "x"
|
|
117
|
+
];
|
|
118
|
+
const maxExecutionTime = 5;
|
|
119
|
+
for (const input of adversarialInputs) {
|
|
120
|
+
const start = Date.now();
|
|
121
|
+
try {
|
|
122
|
+
regex.test(input);
|
|
123
|
+
const duration = Date.now() - start;
|
|
124
|
+
if (duration > maxExecutionTime) {
|
|
125
|
+
return {
|
|
126
|
+
safe: false,
|
|
127
|
+
reason: `runtime test exceeded ${maxExecutionTime}ms (took ${duration}ms on input length ${input.length})`
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
} catch (err) {
|
|
131
|
+
return { safe: false, reason: `runtime test threw error: ${err}` };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { safe: true };
|
|
135
|
+
}
|
|
136
|
+
function safeCompileRegex(pattern, maxLength = 200) {
|
|
137
|
+
try {
|
|
138
|
+
if (!pattern) {
|
|
139
|
+
console.warn(`[SDK] DMCA pattern rejected: empty pattern`);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (pattern.length > maxLength) {
|
|
143
|
+
console.warn(`[SDK] DMCA pattern rejected: length ${pattern.length} exceeds max ${maxLength} - pattern: ${pattern.substring(0, 50)}...`);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const staticAnalysis = analyzeRedosRisk(pattern);
|
|
147
|
+
if (!staticAnalysis.safe) {
|
|
148
|
+
console.warn(`[SDK] DMCA pattern rejected: static analysis failed (${staticAnalysis.reason}) - pattern: ${pattern.substring(0, 50)}...`);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
let regex;
|
|
152
|
+
try {
|
|
153
|
+
regex = new RegExp(pattern);
|
|
154
|
+
} catch (compileErr) {
|
|
155
|
+
console.warn(`[SDK] DMCA pattern rejected: compilation failed - pattern: ${pattern.substring(0, 50)}...`, compileErr);
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const runtimeTest = testRegexPerformance(regex);
|
|
159
|
+
if (!runtimeTest.safe) {
|
|
160
|
+
console.warn(`[SDK] DMCA pattern rejected: runtime test failed (${runtimeTest.reason}) - pattern: ${pattern.substring(0, 50)}...`);
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
return regex;
|
|
164
|
+
} catch (err) {
|
|
165
|
+
console.warn(`[SDK] DMCA pattern rejected: unexpected error - pattern: ${pattern.substring(0, 50)}...`, err);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function setDmcaLists(accounts = [], tags = [], patterns = []) {
|
|
170
|
+
CONFIG.dmcaAccounts = accounts;
|
|
171
|
+
CONFIG.dmcaTags = tags;
|
|
172
|
+
CONFIG.dmcaPatterns = patterns;
|
|
173
|
+
CONFIG.dmcaTagRegexes = tags.map((pattern) => safeCompileRegex(pattern)).filter((r) => r !== null);
|
|
174
|
+
CONFIG.dmcaPatternRegexes = [];
|
|
175
|
+
const rejectedTagCount = tags.length - CONFIG.dmcaTagRegexes.length;
|
|
176
|
+
if (!CONFIG._dmcaInitialized) {
|
|
177
|
+
console.log(`[SDK] DMCA configuration loaded:`);
|
|
178
|
+
console.log(` - Accounts: ${accounts.length}`);
|
|
179
|
+
console.log(` - Tag patterns: ${CONFIG.dmcaTagRegexes.length}/${tags.length} compiled (${rejectedTagCount} rejected)`);
|
|
180
|
+
console.log(` - Post patterns: ${patterns.length} (using exact string matching)`);
|
|
181
|
+
if (rejectedTagCount > 0) {
|
|
182
|
+
console.warn(`[SDK] ${rejectedTagCount} DMCA tag patterns were rejected due to security validation. Check warnings above for details.`);
|
|
183
|
+
}
|
|
184
|
+
CONFIG._dmcaInitialized = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
ConfigManager2.setDmcaLists = setDmcaLists;
|
|
70
188
|
})(ConfigManager || (ConfigManager = {}));
|
|
71
189
|
|
|
72
190
|
// src/modules/core/utils/decoder-encoder.ts
|
|
@@ -472,6 +590,176 @@ function getAccountFullQueryOptions(username) {
|
|
|
472
590
|
staleTime: 6e4
|
|
473
591
|
});
|
|
474
592
|
}
|
|
593
|
+
function sanitizeTokens(tokens) {
|
|
594
|
+
return tokens?.map(({ meta, ...rest }) => {
|
|
595
|
+
if (!meta || typeof meta !== "object") {
|
|
596
|
+
return { ...rest, meta };
|
|
597
|
+
}
|
|
598
|
+
const { privateKey, username, ...safeMeta } = meta;
|
|
599
|
+
return { ...rest, meta: safeMeta };
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
function parseProfileMetadata(postingJsonMetadata) {
|
|
603
|
+
if (!postingJsonMetadata) {
|
|
604
|
+
return {};
|
|
605
|
+
}
|
|
606
|
+
try {
|
|
607
|
+
const parsed = JSON.parse(postingJsonMetadata);
|
|
608
|
+
if (parsed && typeof parsed === "object" && parsed.profile && typeof parsed.profile === "object") {
|
|
609
|
+
return parsed.profile;
|
|
610
|
+
}
|
|
611
|
+
} catch (err) {
|
|
612
|
+
}
|
|
613
|
+
return {};
|
|
614
|
+
}
|
|
615
|
+
function extractAccountProfile(data) {
|
|
616
|
+
return parseProfileMetadata(data?.posting_json_metadata);
|
|
617
|
+
}
|
|
618
|
+
function buildProfileMetadata({
|
|
619
|
+
existingProfile,
|
|
620
|
+
profile,
|
|
621
|
+
tokens
|
|
622
|
+
}) {
|
|
623
|
+
const { tokens: profileTokens, version: _ignoredVersion, ...profileRest } = profile ?? {};
|
|
624
|
+
const metadata = R4.mergeDeep(
|
|
625
|
+
existingProfile ?? {},
|
|
626
|
+
profileRest
|
|
627
|
+
);
|
|
628
|
+
const nextTokens = tokens ?? profileTokens;
|
|
629
|
+
if (nextTokens && nextTokens.length > 0) {
|
|
630
|
+
metadata.tokens = nextTokens;
|
|
631
|
+
}
|
|
632
|
+
metadata.tokens = sanitizeTokens(metadata.tokens);
|
|
633
|
+
metadata.version = 2;
|
|
634
|
+
return metadata;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// src/modules/accounts/utils/parse-accounts.ts
|
|
638
|
+
function parseAccounts(rawAccounts) {
|
|
639
|
+
return rawAccounts.map((x) => {
|
|
640
|
+
const account = {
|
|
641
|
+
name: x.name,
|
|
642
|
+
owner: x.owner,
|
|
643
|
+
active: x.active,
|
|
644
|
+
posting: x.posting,
|
|
645
|
+
memo_key: x.memo_key,
|
|
646
|
+
post_count: x.post_count,
|
|
647
|
+
created: x.created,
|
|
648
|
+
reputation: x.reputation,
|
|
649
|
+
posting_json_metadata: x.posting_json_metadata,
|
|
650
|
+
last_vote_time: x.last_vote_time,
|
|
651
|
+
last_post: x.last_post,
|
|
652
|
+
json_metadata: x.json_metadata,
|
|
653
|
+
reward_hive_balance: x.reward_hive_balance,
|
|
654
|
+
reward_hbd_balance: x.reward_hbd_balance,
|
|
655
|
+
reward_vesting_hive: x.reward_vesting_hive,
|
|
656
|
+
reward_vesting_balance: x.reward_vesting_balance,
|
|
657
|
+
balance: x.balance,
|
|
658
|
+
hbd_balance: x.hbd_balance,
|
|
659
|
+
savings_balance: x.savings_balance,
|
|
660
|
+
savings_hbd_balance: x.savings_hbd_balance,
|
|
661
|
+
savings_hbd_last_interest_payment: x.savings_hbd_last_interest_payment,
|
|
662
|
+
savings_hbd_seconds_last_update: x.savings_hbd_seconds_last_update,
|
|
663
|
+
savings_hbd_seconds: x.savings_hbd_seconds,
|
|
664
|
+
next_vesting_withdrawal: x.next_vesting_withdrawal,
|
|
665
|
+
pending_claimed_accounts: x.pending_claimed_accounts,
|
|
666
|
+
vesting_shares: x.vesting_shares,
|
|
667
|
+
delegated_vesting_shares: x.delegated_vesting_shares,
|
|
668
|
+
received_vesting_shares: x.received_vesting_shares,
|
|
669
|
+
vesting_withdraw_rate: x.vesting_withdraw_rate,
|
|
670
|
+
to_withdraw: x.to_withdraw,
|
|
671
|
+
withdrawn: x.withdrawn,
|
|
672
|
+
witness_votes: x.witness_votes,
|
|
673
|
+
proxy: x.proxy,
|
|
674
|
+
recovery_account: x.recovery_account,
|
|
675
|
+
proxied_vsf_votes: x.proxied_vsf_votes,
|
|
676
|
+
voting_manabar: x.voting_manabar,
|
|
677
|
+
voting_power: x.voting_power,
|
|
678
|
+
downvote_manabar: x.downvote_manabar
|
|
679
|
+
};
|
|
680
|
+
let profile = parseProfileMetadata(
|
|
681
|
+
x.posting_json_metadata
|
|
682
|
+
);
|
|
683
|
+
if (!profile || Object.keys(profile).length === 0) {
|
|
684
|
+
try {
|
|
685
|
+
const jsonMetadata = JSON.parse(x.json_metadata || "{}");
|
|
686
|
+
if (jsonMetadata.profile) {
|
|
687
|
+
profile = jsonMetadata.profile;
|
|
688
|
+
}
|
|
689
|
+
} catch (e) {
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (!profile || Object.keys(profile).length === 0) {
|
|
693
|
+
profile = {
|
|
694
|
+
about: "",
|
|
695
|
+
cover_image: "",
|
|
696
|
+
location: "",
|
|
697
|
+
name: "",
|
|
698
|
+
profile_image: "",
|
|
699
|
+
website: ""
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
return { ...account, profile };
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// src/modules/accounts/queries/get-accounts-query-options.ts
|
|
707
|
+
function getAccountsQueryOptions(usernames) {
|
|
708
|
+
return queryOptions({
|
|
709
|
+
queryKey: ["accounts", "get-accounts", usernames],
|
|
710
|
+
queryFn: async () => {
|
|
711
|
+
const response = await CONFIG.hiveClient.database.getAccounts(usernames);
|
|
712
|
+
return parseAccounts(response);
|
|
713
|
+
},
|
|
714
|
+
enabled: usernames.length > 0
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
function getFollowCountQueryOptions(username) {
|
|
718
|
+
return queryOptions({
|
|
719
|
+
queryKey: ["accounts", "follow-count", username],
|
|
720
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_follow_count", [
|
|
721
|
+
username
|
|
722
|
+
])
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
function getFollowingQueryOptions(follower, startFollowing, followType = "blog", limit = 100) {
|
|
726
|
+
return queryOptions({
|
|
727
|
+
queryKey: ["accounts", "following", follower, startFollowing, followType, limit],
|
|
728
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_following", [
|
|
729
|
+
follower,
|
|
730
|
+
startFollowing,
|
|
731
|
+
followType,
|
|
732
|
+
limit
|
|
733
|
+
]),
|
|
734
|
+
enabled: !!follower
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function getMutedUsersQueryOptions(username, limit = 100) {
|
|
738
|
+
return queryOptions({
|
|
739
|
+
queryKey: ["accounts", "muted-users", username],
|
|
740
|
+
queryFn: async () => {
|
|
741
|
+
const response = await CONFIG.hiveClient.database.call("get_following", [
|
|
742
|
+
username,
|
|
743
|
+
"",
|
|
744
|
+
"ignore",
|
|
745
|
+
limit
|
|
746
|
+
]);
|
|
747
|
+
return response.map((user) => user.following);
|
|
748
|
+
},
|
|
749
|
+
enabled: !!username
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
function lookupAccountsQueryOptions(query, limit = 50) {
|
|
753
|
+
return queryOptions({
|
|
754
|
+
queryKey: ["accounts", "lookup", query, limit],
|
|
755
|
+
queryFn: () => CONFIG.hiveClient.database.call("lookup_accounts", [
|
|
756
|
+
query,
|
|
757
|
+
limit
|
|
758
|
+
]),
|
|
759
|
+
enabled: !!query,
|
|
760
|
+
staleTime: Infinity
|
|
761
|
+
});
|
|
762
|
+
}
|
|
475
763
|
function getSearchAccountsByUsernameQueryOptions(query, limit = 5, excludeList = []) {
|
|
476
764
|
return queryOptions({
|
|
477
765
|
queryKey: ["accounts", "search", query, excludeList],
|
|
@@ -691,314 +979,1320 @@ function getAccountPendingRecoveryQueryOptions(username) {
|
|
|
691
979
|
)
|
|
692
980
|
});
|
|
693
981
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
982
|
+
var ops = utils.operationOrders;
|
|
983
|
+
var ACCOUNT_OPERATION_GROUPS = {
|
|
984
|
+
transfers: [
|
|
985
|
+
ops.transfer,
|
|
986
|
+
ops.transfer_to_savings,
|
|
987
|
+
ops.transfer_from_savings,
|
|
988
|
+
ops.cancel_transfer_from_savings,
|
|
989
|
+
ops.recurrent_transfer,
|
|
990
|
+
ops.fill_recurrent_transfer,
|
|
991
|
+
ops.escrow_transfer,
|
|
992
|
+
ops.fill_recurrent_transfer
|
|
993
|
+
],
|
|
994
|
+
"market-orders": [
|
|
995
|
+
ops.fill_convert_request,
|
|
996
|
+
ops.fill_order,
|
|
997
|
+
ops.fill_collateralized_convert_request,
|
|
998
|
+
ops.limit_order_create2,
|
|
999
|
+
ops.limit_order_create,
|
|
1000
|
+
ops.limit_order_cancel
|
|
1001
|
+
],
|
|
1002
|
+
interests: [ops.interest],
|
|
1003
|
+
"stake-operations": [
|
|
1004
|
+
ops.return_vesting_delegation,
|
|
1005
|
+
ops.withdraw_vesting,
|
|
1006
|
+
ops.transfer_to_vesting,
|
|
1007
|
+
ops.set_withdraw_vesting_route,
|
|
1008
|
+
ops.update_proposal_votes,
|
|
1009
|
+
ops.fill_vesting_withdraw,
|
|
1010
|
+
ops.account_witness_proxy,
|
|
1011
|
+
ops.delegate_vesting_shares
|
|
1012
|
+
],
|
|
1013
|
+
rewards: [
|
|
1014
|
+
ops.author_reward,
|
|
1015
|
+
ops.curation_reward,
|
|
1016
|
+
ops.producer_reward,
|
|
1017
|
+
ops.claim_reward_balance,
|
|
1018
|
+
ops.comment_benefactor_reward,
|
|
1019
|
+
ops.liquidity_reward,
|
|
1020
|
+
ops.proposal_pay
|
|
1021
|
+
]
|
|
1022
|
+
};
|
|
1023
|
+
var ALL_ACCOUNT_OPERATIONS = [...Object.values(ACCOUNT_OPERATION_GROUPS)].reduce(
|
|
1024
|
+
(acc, val) => acc.concat(val),
|
|
1025
|
+
[]
|
|
1026
|
+
);
|
|
1027
|
+
function getTransactionsInfiniteQueryOptions(username, limit = 20, group = "") {
|
|
1028
|
+
return infiniteQueryOptions({
|
|
1029
|
+
queryKey: ["accounts", "transactions", username ?? "", group, limit],
|
|
1030
|
+
initialPageParam: -1,
|
|
1031
|
+
queryFn: async ({ pageParam }) => {
|
|
1032
|
+
if (!username) {
|
|
1033
|
+
return [];
|
|
1034
|
+
}
|
|
1035
|
+
let filters;
|
|
1036
|
+
switch (group) {
|
|
1037
|
+
case "transfers":
|
|
1038
|
+
filters = utils.makeBitMaskFilter(ACCOUNT_OPERATION_GROUPS["transfers"]);
|
|
1039
|
+
break;
|
|
1040
|
+
case "market-orders":
|
|
1041
|
+
filters = utils.makeBitMaskFilter(ACCOUNT_OPERATION_GROUPS["market-orders"]);
|
|
1042
|
+
break;
|
|
1043
|
+
case "interests":
|
|
1044
|
+
filters = utils.makeBitMaskFilter(ACCOUNT_OPERATION_GROUPS["interests"]);
|
|
1045
|
+
break;
|
|
1046
|
+
case "stake-operations":
|
|
1047
|
+
filters = utils.makeBitMaskFilter(ACCOUNT_OPERATION_GROUPS["stake-operations"]);
|
|
1048
|
+
break;
|
|
1049
|
+
case "rewards":
|
|
1050
|
+
filters = utils.makeBitMaskFilter(ACCOUNT_OPERATION_GROUPS["rewards"]);
|
|
1051
|
+
break;
|
|
1052
|
+
default:
|
|
1053
|
+
filters = utils.makeBitMaskFilter(ALL_ACCOUNT_OPERATIONS);
|
|
1054
|
+
}
|
|
1055
|
+
const response = await (filters ? CONFIG.hiveClient.call("condenser_api", "get_account_history", [
|
|
1056
|
+
username,
|
|
1057
|
+
pageParam,
|
|
1058
|
+
limit,
|
|
1059
|
+
...filters
|
|
1060
|
+
]) : CONFIG.hiveClient.call("condenser_api", "get_account_history", [
|
|
1061
|
+
username,
|
|
1062
|
+
pageParam,
|
|
1063
|
+
limit
|
|
1064
|
+
]));
|
|
1065
|
+
const mapped = response.map(([num, operation]) => {
|
|
1066
|
+
const base = {
|
|
1067
|
+
num,
|
|
1068
|
+
type: operation.op[0],
|
|
1069
|
+
timestamp: operation.timestamp,
|
|
1070
|
+
trx_id: operation.trx_id
|
|
1071
|
+
};
|
|
1072
|
+
const payload = operation.op[1];
|
|
1073
|
+
return { ...base, ...payload };
|
|
1074
|
+
}).filter(Boolean).sort((a, b) => b.num - a.num);
|
|
1075
|
+
return mapped;
|
|
1076
|
+
},
|
|
1077
|
+
getNextPageParam: (lastPage) => lastPage?.length ? (lastPage[lastPage.length - 1]?.num ?? 0) - 1 : -1
|
|
701
1078
|
});
|
|
702
1079
|
}
|
|
703
|
-
function
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
profile,
|
|
722
|
-
tokens
|
|
723
|
-
}) {
|
|
724
|
-
const { tokens: profileTokens, version: _ignoredVersion, ...profileRest } = profile ?? {};
|
|
725
|
-
const metadata = R4.mergeDeep(
|
|
726
|
-
existingProfile ?? {},
|
|
727
|
-
profileRest
|
|
728
|
-
);
|
|
729
|
-
const nextTokens = tokens ?? profileTokens;
|
|
730
|
-
if (nextTokens && nextTokens.length > 0) {
|
|
731
|
-
metadata.tokens = nextTokens;
|
|
732
|
-
}
|
|
733
|
-
metadata.tokens = sanitizeTokens(metadata.tokens);
|
|
734
|
-
metadata.version = 2;
|
|
735
|
-
return metadata;
|
|
1080
|
+
function getBotsQueryOptions() {
|
|
1081
|
+
return queryOptions({
|
|
1082
|
+
queryKey: ["accounts", "bots"],
|
|
1083
|
+
queryFn: async () => {
|
|
1084
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/public/bots", {
|
|
1085
|
+
method: "GET",
|
|
1086
|
+
headers: {
|
|
1087
|
+
"Content-Type": "application/json"
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
if (!response.ok) {
|
|
1091
|
+
throw new Error(`Failed to fetch bots: ${response.status}`);
|
|
1092
|
+
}
|
|
1093
|
+
return response.json();
|
|
1094
|
+
},
|
|
1095
|
+
refetchOnMount: true,
|
|
1096
|
+
staleTime: Infinity
|
|
1097
|
+
});
|
|
736
1098
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
if (!data) {
|
|
747
|
-
throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
|
|
1099
|
+
function getReferralsInfiniteQueryOptions(username) {
|
|
1100
|
+
return infiniteQueryOptions({
|
|
1101
|
+
queryKey: ["accounts", "referrals", username],
|
|
1102
|
+
initialPageParam: { maxId: void 0 },
|
|
1103
|
+
queryFn: async ({ pageParam }) => {
|
|
1104
|
+
const { maxId } = pageParam ?? {};
|
|
1105
|
+
const url = new URL(CONFIG.privateApiHost + `/private-api/referrals/${username}`);
|
|
1106
|
+
if (maxId !== void 0) {
|
|
1107
|
+
url.searchParams.set("max_id", maxId.toString());
|
|
748
1108
|
}
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
1109
|
+
const response = await fetch(url.toString(), {
|
|
1110
|
+
method: "GET",
|
|
1111
|
+
headers: {
|
|
1112
|
+
"Content-Type": "application/json"
|
|
1113
|
+
}
|
|
753
1114
|
});
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
account: username,
|
|
759
|
-
json_metadata: "",
|
|
760
|
-
extensions: [],
|
|
761
|
-
posting_json_metadata: JSON.stringify({
|
|
762
|
-
profile
|
|
763
|
-
})
|
|
764
|
-
}
|
|
765
|
-
]
|
|
766
|
-
];
|
|
1115
|
+
if (!response.ok) {
|
|
1116
|
+
throw new Error(`Failed to fetch referrals: ${response.status}`);
|
|
1117
|
+
}
|
|
1118
|
+
return response.json();
|
|
767
1119
|
},
|
|
768
|
-
(
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
1120
|
+
getNextPageParam: (lastPage) => {
|
|
1121
|
+
const nextMaxId = lastPage?.[lastPage.length - 1]?.id;
|
|
1122
|
+
return typeof nextMaxId === "number" ? { maxId: nextMaxId } : void 0;
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
function getReferralsStatsQueryOptions(username) {
|
|
1127
|
+
return queryOptions({
|
|
1128
|
+
queryKey: ["accounts", "referrals-stats", username],
|
|
1129
|
+
queryFn: async () => {
|
|
1130
|
+
const response = await fetch(
|
|
1131
|
+
CONFIG.privateApiHost + `/private-api/referrals/${username}/stats`,
|
|
1132
|
+
{
|
|
1133
|
+
method: "GET",
|
|
1134
|
+
headers: {
|
|
1135
|
+
"Content-Type": "application/json"
|
|
1136
|
+
}
|
|
773
1137
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
profile: variables.profile,
|
|
778
|
-
tokens: variables.tokens
|
|
779
|
-
});
|
|
780
|
-
return obj;
|
|
1138
|
+
);
|
|
1139
|
+
if (!response.ok) {
|
|
1140
|
+
throw new Error(`Failed to fetch referral stats: ${response.status}`);
|
|
781
1141
|
}
|
|
782
|
-
|
|
783
|
-
|
|
1142
|
+
const data = await response.json();
|
|
1143
|
+
if (!data) {
|
|
1144
|
+
throw new Error("No Referrals for this user!");
|
|
1145
|
+
}
|
|
1146
|
+
return {
|
|
1147
|
+
total: data.total ?? 0,
|
|
1148
|
+
rewarded: data.rewarded ?? 0
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
784
1152
|
}
|
|
785
|
-
function
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
1153
|
+
function getFriendsInfiniteQueryOptions(following, mode, options) {
|
|
1154
|
+
const { followType = "blog", limit = 100, enabled = true } = options ?? {};
|
|
1155
|
+
return infiniteQueryOptions({
|
|
1156
|
+
queryKey: ["accounts", "friends", following, mode, followType, limit],
|
|
1157
|
+
initialPageParam: { startFollowing: "" },
|
|
1158
|
+
enabled,
|
|
1159
|
+
refetchOnMount: true,
|
|
1160
|
+
queryFn: async ({ pageParam }) => {
|
|
1161
|
+
const { startFollowing } = pageParam;
|
|
1162
|
+
const response = await CONFIG.hiveClient.database.call(
|
|
1163
|
+
mode === "following" ? "get_following" : "get_followers",
|
|
1164
|
+
[following, startFollowing === "" ? null : startFollowing, followType, limit]
|
|
792
1165
|
);
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
relationsQuery.queryKey
|
|
1166
|
+
const accountNames = response.map(
|
|
1167
|
+
(e) => mode === "following" ? e.following : e.follower
|
|
796
1168
|
);
|
|
797
|
-
await
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
return {
|
|
809
|
-
...actualRelation,
|
|
810
|
-
ignores: kind === "toggle-ignore" ? !actualRelation?.ignores : actualRelation?.ignores,
|
|
811
|
-
follows: kind === "toggle-follow" ? !actualRelation?.follows : actualRelation?.follows
|
|
812
|
-
};
|
|
1169
|
+
const accounts = await CONFIG.hiveClient.call("bridge", "get_profiles", {
|
|
1170
|
+
accounts: accountNames,
|
|
1171
|
+
observer: void 0
|
|
1172
|
+
});
|
|
1173
|
+
const rows = (accounts ?? []).map((a) => ({
|
|
1174
|
+
name: a.name,
|
|
1175
|
+
reputation: a.reputation,
|
|
1176
|
+
active: a.active
|
|
1177
|
+
// Return raw timestamp
|
|
1178
|
+
}));
|
|
1179
|
+
return rows;
|
|
813
1180
|
},
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1181
|
+
getNextPageParam: (lastPage) => lastPage && lastPage.length === limit ? { startFollowing: lastPage[lastPage.length - 1].name } : void 0
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
var SEARCH_LIMIT = 30;
|
|
1185
|
+
function getSearchFriendsQueryOptions(username, mode, query) {
|
|
1186
|
+
return queryOptions({
|
|
1187
|
+
queryKey: ["accounts", "friends", "search", username, mode, query],
|
|
1188
|
+
refetchOnMount: false,
|
|
1189
|
+
enabled: false,
|
|
1190
|
+
// Manual query via refetch
|
|
1191
|
+
queryFn: async () => {
|
|
1192
|
+
if (!query) return [];
|
|
1193
|
+
const start = query.slice(0, -1);
|
|
1194
|
+
const response = await CONFIG.hiveClient.database.call(
|
|
1195
|
+
mode === "following" ? "get_following" : "get_followers",
|
|
1196
|
+
[username, start, "blog", 1e3]
|
|
820
1197
|
);
|
|
1198
|
+
const accountNames = response.map((e) => mode === "following" ? e.following : e.follower).filter((name) => name.toLowerCase().includes(query.toLowerCase())).slice(0, SEARCH_LIMIT);
|
|
1199
|
+
const accounts = await CONFIG.hiveClient.call("bridge", "get_profiles", {
|
|
1200
|
+
accounts: accountNames,
|
|
1201
|
+
observer: void 0
|
|
1202
|
+
});
|
|
1203
|
+
return accounts?.map((a) => ({
|
|
1204
|
+
name: a.name,
|
|
1205
|
+
full_name: a.metadata.profile?.name || "",
|
|
1206
|
+
reputation: a.reputation,
|
|
1207
|
+
active: a.active
|
|
1208
|
+
// Return raw timestamp
|
|
1209
|
+
})) ?? [];
|
|
821
1210
|
}
|
|
822
1211
|
});
|
|
823
1212
|
}
|
|
824
|
-
function
|
|
825
|
-
return
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
1213
|
+
function getTrendingTagsQueryOptions(limit = 20) {
|
|
1214
|
+
return infiniteQueryOptions({
|
|
1215
|
+
queryKey: ["posts", "trending-tags"],
|
|
1216
|
+
queryFn: async ({ pageParam: { afterTag } }) => CONFIG.hiveClient.database.call("get_trending_tags", [afterTag, limit]).then(
|
|
1217
|
+
(tags) => tags.filter((x) => x.name !== "").filter((x) => !x.name.startsWith("hive-")).map((x) => x.name)
|
|
1218
|
+
),
|
|
1219
|
+
initialPageParam: { afterTag: "" },
|
|
1220
|
+
getNextPageParam: (lastPage) => ({
|
|
1221
|
+
afterTag: lastPage?.[lastPage?.length - 1]
|
|
1222
|
+
}),
|
|
1223
|
+
staleTime: Infinity,
|
|
1224
|
+
refetchOnMount: true
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
function getFragmentsQueryOptions(username) {
|
|
1228
|
+
return queryOptions({
|
|
1229
|
+
queryKey: ["posts", "fragments", username],
|
|
1230
|
+
queryFn: async () => {
|
|
831
1231
|
const fetchApi = getBoundFetch();
|
|
832
1232
|
const response = await fetchApi(
|
|
833
|
-
CONFIG.privateApiHost + "/private-api/
|
|
1233
|
+
CONFIG.privateApiHost + "/private-api/fragments",
|
|
834
1234
|
{
|
|
835
1235
|
method: "POST",
|
|
836
|
-
headers: {
|
|
837
|
-
"Content-Type": "application/json"
|
|
838
|
-
},
|
|
839
1236
|
body: JSON.stringify({
|
|
840
|
-
author,
|
|
841
|
-
permlink,
|
|
842
1237
|
code: getAccessToken(username)
|
|
843
|
-
})
|
|
1238
|
+
}),
|
|
1239
|
+
headers: {
|
|
1240
|
+
"Content-Type": "application/json"
|
|
1241
|
+
}
|
|
844
1242
|
}
|
|
845
1243
|
);
|
|
846
1244
|
return response.json();
|
|
847
1245
|
},
|
|
848
|
-
|
|
849
|
-
onSuccess();
|
|
850
|
-
getQueryClient().invalidateQueries({
|
|
851
|
-
queryKey: ["accounts", "bookmarks", username]
|
|
852
|
-
});
|
|
853
|
-
},
|
|
854
|
-
onError
|
|
1246
|
+
enabled: !!username
|
|
855
1247
|
});
|
|
856
1248
|
}
|
|
857
|
-
function
|
|
858
|
-
return
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1249
|
+
function getPromotedPostsQuery(type = "feed") {
|
|
1250
|
+
return queryOptions({
|
|
1251
|
+
queryKey: ["posts", "promoted", type],
|
|
1252
|
+
queryFn: async () => {
|
|
1253
|
+
const url = new URL(
|
|
1254
|
+
CONFIG.privateApiHost + "/private-api/promoted-entries"
|
|
1255
|
+
);
|
|
1256
|
+
if (type === "waves") {
|
|
1257
|
+
url.searchParams.append("short_content", "1");
|
|
863
1258
|
}
|
|
864
1259
|
const fetchApi = getBoundFetch();
|
|
865
|
-
const response = await fetchApi(
|
|
866
|
-
|
|
867
|
-
{
|
|
868
|
-
|
|
869
|
-
headers: {
|
|
870
|
-
"Content-Type": "application/json"
|
|
871
|
-
},
|
|
872
|
-
body: JSON.stringify({
|
|
873
|
-
id: bookmarkId,
|
|
874
|
-
code: getAccessToken(username)
|
|
875
|
-
})
|
|
1260
|
+
const response = await fetchApi(url.toString(), {
|
|
1261
|
+
method: "GET",
|
|
1262
|
+
headers: {
|
|
1263
|
+
"Content-Type": "application/json"
|
|
876
1264
|
}
|
|
877
|
-
);
|
|
878
|
-
|
|
1265
|
+
});
|
|
1266
|
+
const data = await response.json();
|
|
1267
|
+
return data;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
function getEntryActiveVotesQueryOptions(entry) {
|
|
1272
|
+
return queryOptions({
|
|
1273
|
+
queryKey: ["posts", "entry-active-votes", entry?.author, entry?.permlink],
|
|
1274
|
+
queryFn: async () => {
|
|
1275
|
+
return CONFIG.hiveClient.database.call("get_active_votes", [
|
|
1276
|
+
entry?.author,
|
|
1277
|
+
entry?.permlink
|
|
1278
|
+
]);
|
|
879
1279
|
},
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1280
|
+
enabled: !!entry
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
function getPostHeaderQueryOptions(author, permlink) {
|
|
1284
|
+
return queryOptions({
|
|
1285
|
+
queryKey: ["posts", "post-header", author, permlink],
|
|
1286
|
+
queryFn: async () => {
|
|
1287
|
+
return CONFIG.hiveClient.call("bridge", "get_post_header", {
|
|
1288
|
+
author,
|
|
1289
|
+
permlink
|
|
884
1290
|
});
|
|
885
1291
|
},
|
|
886
|
-
|
|
1292
|
+
initialData: null
|
|
887
1293
|
});
|
|
888
1294
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1295
|
+
|
|
1296
|
+
// src/modules/posts/utils/filter-dmca-entries.ts
|
|
1297
|
+
function filterDmcaEntry(entryOrEntries) {
|
|
1298
|
+
if (Array.isArray(entryOrEntries)) {
|
|
1299
|
+
return entryOrEntries.map((entry) => applyFilter(entry));
|
|
1300
|
+
}
|
|
1301
|
+
return applyFilter(entryOrEntries);
|
|
1302
|
+
}
|
|
1303
|
+
function applyFilter(entry) {
|
|
1304
|
+
if (!entry) return entry;
|
|
1305
|
+
const entryPath = `@${entry.author}/${entry.permlink}`;
|
|
1306
|
+
const isDmca = CONFIG.dmcaPatternRegexes.some((regex) => regex.test(entryPath));
|
|
1307
|
+
if (isDmca) {
|
|
1308
|
+
return {
|
|
1309
|
+
...entry,
|
|
1310
|
+
body: "This post is not available due to a copyright/fraudulent claim.",
|
|
1311
|
+
title: ""
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
return entry;
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// src/modules/posts/queries/get-post-query-options.ts
|
|
1318
|
+
function makeEntryPath(category, author, permlink) {
|
|
1319
|
+
return `${category}/@${author}/${permlink}`;
|
|
1320
|
+
}
|
|
1321
|
+
function getPostQueryOptions(author, permlink, observer = "", num) {
|
|
1322
|
+
const cleanPermlink = permlink?.trim();
|
|
1323
|
+
const entryPath = makeEntryPath("", author, cleanPermlink ?? "");
|
|
1324
|
+
return queryOptions({
|
|
1325
|
+
queryKey: ["posts", "entry", entryPath],
|
|
1326
|
+
queryFn: async () => {
|
|
1327
|
+
if (!cleanPermlink || cleanPermlink === "undefined") {
|
|
1328
|
+
return null;
|
|
895
1329
|
}
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
method: "POST",
|
|
901
|
-
headers: {
|
|
902
|
-
"Content-Type": "application/json"
|
|
903
|
-
},
|
|
904
|
-
body: JSON.stringify({
|
|
905
|
-
account,
|
|
906
|
-
code: getAccessToken(username)
|
|
907
|
-
})
|
|
908
|
-
}
|
|
909
|
-
);
|
|
910
|
-
return response.json();
|
|
911
|
-
},
|
|
912
|
-
onSuccess: () => {
|
|
913
|
-
onSuccess();
|
|
914
|
-
getQueryClient().invalidateQueries({
|
|
915
|
-
queryKey: ["accounts", "favourites", username]
|
|
1330
|
+
const response = await CONFIG.hiveClient.call("bridge", "get_post", {
|
|
1331
|
+
author,
|
|
1332
|
+
permlink: cleanPermlink,
|
|
1333
|
+
observer
|
|
916
1334
|
});
|
|
1335
|
+
if (!response) {
|
|
1336
|
+
return null;
|
|
1337
|
+
}
|
|
1338
|
+
const entry = num !== void 0 ? { ...response, num } : response;
|
|
1339
|
+
return filterDmcaEntry(entry);
|
|
917
1340
|
},
|
|
918
|
-
|
|
1341
|
+
enabled: !!author && !!permlink && permlink.trim() !== "" && permlink.trim() !== "undefined"
|
|
919
1342
|
});
|
|
920
1343
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1344
|
+
var SortOrder = /* @__PURE__ */ ((SortOrder2) => {
|
|
1345
|
+
SortOrder2["trending"] = "trending";
|
|
1346
|
+
SortOrder2["author_reputation"] = "author_reputation";
|
|
1347
|
+
SortOrder2["votes"] = "votes";
|
|
1348
|
+
SortOrder2["created"] = "created";
|
|
1349
|
+
return SortOrder2;
|
|
1350
|
+
})(SortOrder || {});
|
|
1351
|
+
function parseAsset2(value) {
|
|
1352
|
+
const match = value.match(/^(\d+\.?\d*)\s*([A-Z]+)$/);
|
|
1353
|
+
if (!match) return { amount: 0, symbol: "" };
|
|
1354
|
+
return {
|
|
1355
|
+
amount: parseFloat(match[1]),
|
|
1356
|
+
symbol: match[2]
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
function sortDiscussions(entry, discussion, order) {
|
|
1360
|
+
const allPayout = (c) => parseAsset2(c.pending_payout_value).amount + parseAsset2(c.author_payout_value).amount + parseAsset2(c.curator_payout_value).amount;
|
|
1361
|
+
const absNegative = (a) => a.net_rshares < 0;
|
|
1362
|
+
const isPinned = (a) => entry.json_metadata?.pinned_reply === `${a.author}/${a.permlink}`;
|
|
1363
|
+
const sortOrders = {
|
|
1364
|
+
trending: (a, b) => {
|
|
1365
|
+
if (absNegative(a)) {
|
|
1366
|
+
return 1;
|
|
927
1367
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
account,
|
|
938
|
-
code: getAccessToken(username)
|
|
939
|
-
})
|
|
940
|
-
}
|
|
941
|
-
);
|
|
942
|
-
return response.json();
|
|
1368
|
+
if (absNegative(b)) {
|
|
1369
|
+
return -1;
|
|
1370
|
+
}
|
|
1371
|
+
const _a = allPayout(a);
|
|
1372
|
+
const _b = allPayout(b);
|
|
1373
|
+
if (_a !== _b) {
|
|
1374
|
+
return _b - _a;
|
|
1375
|
+
}
|
|
1376
|
+
return 0;
|
|
943
1377
|
},
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1378
|
+
author_reputation: (a, b) => {
|
|
1379
|
+
const keyA = a.author_reputation;
|
|
1380
|
+
const keyB = b.author_reputation;
|
|
1381
|
+
if (keyA > keyB) return -1;
|
|
1382
|
+
if (keyA < keyB) return 1;
|
|
1383
|
+
return 0;
|
|
949
1384
|
},
|
|
950
|
-
|
|
951
|
-
|
|
1385
|
+
votes: (a, b) => {
|
|
1386
|
+
const keyA = a.children;
|
|
1387
|
+
const keyB = b.children;
|
|
1388
|
+
if (keyA > keyB) return -1;
|
|
1389
|
+
if (keyA < keyB) return 1;
|
|
1390
|
+
return 0;
|
|
1391
|
+
},
|
|
1392
|
+
created: (a, b) => {
|
|
1393
|
+
if (absNegative(a)) {
|
|
1394
|
+
return 1;
|
|
1395
|
+
}
|
|
1396
|
+
if (absNegative(b)) {
|
|
1397
|
+
return -1;
|
|
1398
|
+
}
|
|
1399
|
+
const keyA = Date.parse(a.created);
|
|
1400
|
+
const keyB = Date.parse(b.created);
|
|
1401
|
+
if (keyA > keyB) return -1;
|
|
1402
|
+
if (keyA < keyB) return 1;
|
|
1403
|
+
return 0;
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
const sorted = discussion.sort(sortOrders[order]);
|
|
1407
|
+
const pinnedIndex = sorted.findIndex((i) => isPinned(i));
|
|
1408
|
+
const pinned = sorted[pinnedIndex];
|
|
1409
|
+
if (pinnedIndex >= 0) {
|
|
1410
|
+
sorted.splice(pinnedIndex, 1);
|
|
1411
|
+
sorted.unshift(pinned);
|
|
1412
|
+
}
|
|
1413
|
+
return sorted;
|
|
952
1414
|
}
|
|
953
|
-
function
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1415
|
+
function getDiscussionsQueryOptions(entry, order = "created" /* created */, enabled = true, observer) {
|
|
1416
|
+
return queryOptions({
|
|
1417
|
+
queryKey: [
|
|
1418
|
+
"posts",
|
|
1419
|
+
"discussions",
|
|
1420
|
+
entry?.author,
|
|
1421
|
+
entry?.permlink,
|
|
1422
|
+
order,
|
|
1423
|
+
observer || entry?.author
|
|
1424
|
+
],
|
|
1425
|
+
queryFn: async () => {
|
|
1426
|
+
if (!entry) {
|
|
1427
|
+
return [];
|
|
1428
|
+
}
|
|
1429
|
+
const response = await CONFIG.hiveClient.call("bridge", "get_discussion", {
|
|
1430
|
+
author: entry.author,
|
|
1431
|
+
permlink: entry.permlink,
|
|
1432
|
+
observer: observer || entry.author
|
|
1433
|
+
});
|
|
1434
|
+
const results = response ? Array.from(Object.values(response)) : [];
|
|
1435
|
+
return filterDmcaEntry(results);
|
|
1436
|
+
},
|
|
1437
|
+
enabled: enabled && !!entry,
|
|
1438
|
+
select: (data) => sortDiscussions(entry, data, order)
|
|
960
1439
|
});
|
|
961
|
-
return Array.from(merged.entries()).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)).map(([key, weight]) => [key, weight]);
|
|
962
1440
|
}
|
|
963
|
-
function
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1441
|
+
function getAccountPostsInfiniteQueryOptions(username, filter = "posts", limit = 20, observer = "", enabled = true) {
|
|
1442
|
+
return infiniteQueryOptions({
|
|
1443
|
+
queryKey: ["posts", "account-posts", username ?? "", filter, limit, observer],
|
|
1444
|
+
enabled: !!username && enabled,
|
|
1445
|
+
initialPageParam: {
|
|
1446
|
+
author: void 0,
|
|
1447
|
+
permlink: void 0,
|
|
1448
|
+
hasNextPage: true
|
|
1449
|
+
},
|
|
1450
|
+
queryFn: async ({ pageParam }) => {
|
|
1451
|
+
if (!pageParam?.hasNextPage || !username) return [];
|
|
1452
|
+
const rpcParams = {
|
|
1453
|
+
sort: filter,
|
|
1454
|
+
account: username,
|
|
1455
|
+
limit,
|
|
1456
|
+
...observer && observer.length > 0 ? { observer } : {},
|
|
1457
|
+
...pageParam.author ? { start_author: pageParam.author } : {},
|
|
1458
|
+
...pageParam.permlink ? { start_permlink: pageParam.permlink } : {}
|
|
1459
|
+
};
|
|
1460
|
+
try {
|
|
1461
|
+
if (CONFIG.dmcaAccounts.includes(username)) return [];
|
|
1462
|
+
const resp = await CONFIG.hiveClient.call(
|
|
1463
|
+
"bridge",
|
|
1464
|
+
"get_account_posts",
|
|
1465
|
+
rpcParams
|
|
971
1466
|
);
|
|
1467
|
+
if (resp && Array.isArray(resp)) {
|
|
1468
|
+
return filterDmcaEntry(resp);
|
|
1469
|
+
}
|
|
1470
|
+
return [];
|
|
1471
|
+
} catch (err) {
|
|
1472
|
+
console.error("[SDK] get_account_posts error:", err);
|
|
1473
|
+
return [];
|
|
972
1474
|
}
|
|
973
|
-
const prepareAuth = (keyName) => {
|
|
974
|
-
const auth = R4.clone(accountData[keyName]);
|
|
975
|
-
auth.key_auths = dedupeAndSortKeyAuths(
|
|
976
|
-
keepCurrent ? auth.key_auths : [],
|
|
977
|
-
keys.map(
|
|
978
|
-
(values, i) => [values[keyName].createPublic().toString(), i + 1]
|
|
979
|
-
)
|
|
980
|
-
);
|
|
981
|
-
return auth;
|
|
982
|
-
};
|
|
983
|
-
return CONFIG.hiveClient.broadcast.updateAccount(
|
|
984
|
-
{
|
|
985
|
-
account: username,
|
|
986
|
-
json_metadata: accountData.json_metadata,
|
|
987
|
-
owner: prepareAuth("owner"),
|
|
988
|
-
active: prepareAuth("active"),
|
|
989
|
-
posting: prepareAuth("posting"),
|
|
990
|
-
memo_key: keepCurrent ? accountData.memo_key : keys[0].memo_key.createPublic().toString()
|
|
991
|
-
},
|
|
992
|
-
currentKey
|
|
993
|
-
);
|
|
994
1475
|
},
|
|
995
|
-
|
|
1476
|
+
getNextPageParam: (lastPage) => {
|
|
1477
|
+
const last = lastPage?.[lastPage.length - 1];
|
|
1478
|
+
const hasNextPage = (lastPage?.length ?? 0) === limit;
|
|
1479
|
+
if (!hasNextPage) {
|
|
1480
|
+
return void 0;
|
|
1481
|
+
}
|
|
1482
|
+
return {
|
|
1483
|
+
author: last?.author,
|
|
1484
|
+
permlink: last?.permlink,
|
|
1485
|
+
hasNextPage
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
996
1488
|
});
|
|
997
1489
|
}
|
|
998
|
-
function
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1490
|
+
function getPostsRankedInfiniteQueryOptions(sort, tag, limit = 20, observer = "", enabled = true, _options = {}) {
|
|
1491
|
+
return infiniteQueryOptions({
|
|
1492
|
+
queryKey: ["posts", "posts-ranked", sort, tag, limit, observer],
|
|
1493
|
+
queryFn: async ({ pageParam }) => {
|
|
1494
|
+
if (!pageParam.hasNextPage) {
|
|
1495
|
+
return [];
|
|
1496
|
+
}
|
|
1497
|
+
let sanitizedTag = tag;
|
|
1498
|
+
if (CONFIG.dmcaTagRegexes.some((regex) => regex.test(tag))) {
|
|
1499
|
+
sanitizedTag = "";
|
|
1500
|
+
}
|
|
1501
|
+
const response = await CONFIG.hiveClient.call("bridge", "get_ranked_posts", {
|
|
1502
|
+
sort,
|
|
1503
|
+
start_author: pageParam.author,
|
|
1504
|
+
start_permlink: pageParam.permlink,
|
|
1505
|
+
limit,
|
|
1506
|
+
tag: sanitizedTag,
|
|
1507
|
+
observer
|
|
1508
|
+
});
|
|
1509
|
+
if (response && Array.isArray(response)) {
|
|
1510
|
+
const data = response;
|
|
1511
|
+
const sorted = sort === "hot" ? data : data.sort(
|
|
1512
|
+
(a, b) => new Date(b.created).getTime() - new Date(a.created).getTime()
|
|
1513
|
+
);
|
|
1514
|
+
const pinnedEntry = sorted.find((s) => s.stats?.is_pinned);
|
|
1515
|
+
const nonPinnedEntries = sorted.filter((s) => !s.stats?.is_pinned);
|
|
1516
|
+
const combined = [pinnedEntry, ...nonPinnedEntries].filter((s) => !!s);
|
|
1517
|
+
return filterDmcaEntry(combined);
|
|
1518
|
+
}
|
|
1519
|
+
return [];
|
|
1520
|
+
},
|
|
1521
|
+
enabled,
|
|
1522
|
+
initialPageParam: {
|
|
1523
|
+
author: void 0,
|
|
1524
|
+
permlink: void 0,
|
|
1525
|
+
hasNextPage: true
|
|
1526
|
+
},
|
|
1527
|
+
getNextPageParam: (lastPage) => {
|
|
1528
|
+
const last = lastPage?.[lastPage.length - 1];
|
|
1529
|
+
return {
|
|
1530
|
+
author: last?.author,
|
|
1531
|
+
permlink: last?.permlink,
|
|
1532
|
+
hasNextPage: (lastPage?.length ?? 0) > 0
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
function getReblogsQueryOptions(username, activeUsername, limit = 200) {
|
|
1538
|
+
return queryOptions({
|
|
1539
|
+
queryKey: ["posts", "reblogs", username ?? "", limit],
|
|
1540
|
+
queryFn: async () => {
|
|
1541
|
+
const response = await CONFIG.hiveClient.call("condenser_api", "get_blog_entries", [
|
|
1542
|
+
username ?? activeUsername,
|
|
1543
|
+
0,
|
|
1544
|
+
limit
|
|
1545
|
+
]);
|
|
1546
|
+
return response.filter(
|
|
1547
|
+
(i) => i.author !== activeUsername && !i.reblogged_on.startsWith("1970-")
|
|
1548
|
+
).map((i) => ({ author: i.author, permlink: i.permlink }));
|
|
1549
|
+
},
|
|
1550
|
+
enabled: !!username
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
function getSchedulesQueryOptions(activeUsername) {
|
|
1554
|
+
return queryOptions({
|
|
1555
|
+
queryKey: ["posts", "schedules", activeUsername],
|
|
1556
|
+
queryFn: async () => {
|
|
1557
|
+
if (!activeUsername) {
|
|
1558
|
+
return [];
|
|
1559
|
+
}
|
|
1560
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/schedules", {
|
|
1561
|
+
method: "POST",
|
|
1562
|
+
headers: {
|
|
1563
|
+
"Content-Type": "application/json"
|
|
1564
|
+
},
|
|
1565
|
+
body: JSON.stringify({
|
|
1566
|
+
code: getAccessToken(activeUsername)
|
|
1567
|
+
})
|
|
1568
|
+
});
|
|
1569
|
+
if (!response.ok) {
|
|
1570
|
+
throw new Error(`Failed to fetch schedules: ${response.status}`);
|
|
1571
|
+
}
|
|
1572
|
+
return response.json();
|
|
1573
|
+
},
|
|
1574
|
+
enabled: !!activeUsername
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
function getDraftsQueryOptions(activeUsername) {
|
|
1578
|
+
return queryOptions({
|
|
1579
|
+
queryKey: ["posts", "drafts", activeUsername],
|
|
1580
|
+
queryFn: async () => {
|
|
1581
|
+
if (!activeUsername) {
|
|
1582
|
+
return [];
|
|
1583
|
+
}
|
|
1584
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/drafts", {
|
|
1585
|
+
method: "POST",
|
|
1586
|
+
headers: {
|
|
1587
|
+
"Content-Type": "application/json"
|
|
1588
|
+
},
|
|
1589
|
+
body: JSON.stringify({
|
|
1590
|
+
code: getAccessToken(activeUsername)
|
|
1591
|
+
})
|
|
1592
|
+
});
|
|
1593
|
+
if (!response.ok) {
|
|
1594
|
+
throw new Error(`Failed to fetch drafts: ${response.status}`);
|
|
1595
|
+
}
|
|
1596
|
+
return response.json();
|
|
1597
|
+
},
|
|
1598
|
+
enabled: !!activeUsername
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
async function fetchUserImages(username) {
|
|
1602
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/images", {
|
|
1603
|
+
method: "POST",
|
|
1604
|
+
headers: {
|
|
1605
|
+
"Content-Type": "application/json"
|
|
1606
|
+
},
|
|
1607
|
+
body: JSON.stringify({
|
|
1608
|
+
code: getAccessToken(username)
|
|
1609
|
+
})
|
|
1610
|
+
});
|
|
1611
|
+
if (!response.ok) {
|
|
1612
|
+
throw new Error(`Failed to fetch images: ${response.status}`);
|
|
1613
|
+
}
|
|
1614
|
+
return response.json();
|
|
1615
|
+
}
|
|
1616
|
+
function getImagesQueryOptions(username) {
|
|
1617
|
+
return queryOptions({
|
|
1618
|
+
queryKey: ["posts", "images", username],
|
|
1619
|
+
queryFn: async () => {
|
|
1620
|
+
if (!username) {
|
|
1621
|
+
return [];
|
|
1622
|
+
}
|
|
1623
|
+
return fetchUserImages(username);
|
|
1624
|
+
},
|
|
1625
|
+
enabled: !!username
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
function getGalleryImagesQueryOptions(activeUsername) {
|
|
1629
|
+
return queryOptions({
|
|
1630
|
+
queryKey: ["posts", "gallery-images", activeUsername],
|
|
1631
|
+
queryFn: async () => {
|
|
1632
|
+
if (!activeUsername) {
|
|
1633
|
+
return [];
|
|
1634
|
+
}
|
|
1635
|
+
return fetchUserImages(activeUsername);
|
|
1636
|
+
},
|
|
1637
|
+
enabled: !!activeUsername
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
function getCommentHistoryQueryOptions(author, permlink, onlyMeta = false) {
|
|
1641
|
+
return queryOptions({
|
|
1642
|
+
queryKey: ["posts", "comment-history", author, permlink, onlyMeta],
|
|
1643
|
+
queryFn: async ({ signal }) => {
|
|
1644
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/comment-history", {
|
|
1645
|
+
method: "POST",
|
|
1646
|
+
headers: {
|
|
1647
|
+
"Content-Type": "application/json"
|
|
1648
|
+
},
|
|
1649
|
+
body: JSON.stringify({
|
|
1650
|
+
author,
|
|
1651
|
+
permlink,
|
|
1652
|
+
onlyMeta: onlyMeta ? "1" : ""
|
|
1653
|
+
}),
|
|
1654
|
+
signal
|
|
1655
|
+
});
|
|
1656
|
+
if (!response.ok) {
|
|
1657
|
+
throw new Error(`Failed to fetch comment history: ${response.status}`);
|
|
1658
|
+
}
|
|
1659
|
+
return response.json();
|
|
1660
|
+
},
|
|
1661
|
+
enabled: !!author && !!permlink
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
function makeEntryPath2(author, permlink) {
|
|
1665
|
+
const cleanAuthor = author?.trim();
|
|
1666
|
+
const cleanPermlink = permlink?.trim();
|
|
1667
|
+
if (!cleanAuthor || !cleanPermlink) {
|
|
1668
|
+
throw new Error("Invalid entry path: author and permlink are required");
|
|
1669
|
+
}
|
|
1670
|
+
const normalizedAuthor = cleanAuthor.replace(/^@+/, "");
|
|
1671
|
+
const normalizedPermlink = cleanPermlink.replace(/^\/+/, "");
|
|
1672
|
+
if (!normalizedAuthor || !normalizedPermlink) {
|
|
1673
|
+
throw new Error("Invalid entry path: author and permlink cannot be empty after normalization");
|
|
1674
|
+
}
|
|
1675
|
+
return `@${normalizedAuthor}/${normalizedPermlink}`;
|
|
1676
|
+
}
|
|
1677
|
+
function getDeletedEntryQueryOptions(author, permlink) {
|
|
1678
|
+
const cleanPermlink = permlink?.trim();
|
|
1679
|
+
const cleanAuthor = author?.trim();
|
|
1680
|
+
const isValid = !!cleanAuthor && !!cleanPermlink && cleanPermlink !== "undefined";
|
|
1681
|
+
const entryPath = isValid ? makeEntryPath2(cleanAuthor, cleanPermlink) : "";
|
|
1682
|
+
return queryOptions({
|
|
1683
|
+
queryKey: ["posts", "deleted-entry", entryPath],
|
|
1684
|
+
queryFn: async ({ signal }) => {
|
|
1685
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/comment-history", {
|
|
1686
|
+
method: "POST",
|
|
1687
|
+
headers: {
|
|
1688
|
+
"Content-Type": "application/json"
|
|
1689
|
+
},
|
|
1690
|
+
body: JSON.stringify({
|
|
1691
|
+
author,
|
|
1692
|
+
permlink: cleanPermlink || ""
|
|
1693
|
+
}),
|
|
1694
|
+
signal
|
|
1695
|
+
});
|
|
1696
|
+
if (!response.ok) {
|
|
1697
|
+
throw new Error(`Failed to fetch comment history: ${response.status}`);
|
|
1698
|
+
}
|
|
1699
|
+
return response.json();
|
|
1700
|
+
},
|
|
1701
|
+
select: (history) => {
|
|
1702
|
+
if (!history?.list?.[0]) {
|
|
1703
|
+
return null;
|
|
1704
|
+
}
|
|
1705
|
+
const { body, title, tags } = history.list[0];
|
|
1706
|
+
return {
|
|
1707
|
+
body,
|
|
1708
|
+
title,
|
|
1709
|
+
tags
|
|
1710
|
+
};
|
|
1711
|
+
},
|
|
1712
|
+
enabled: isValid
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
function getPostTipsQueryOptions(author, permlink, isEnabled = true) {
|
|
1716
|
+
return queryOptions({
|
|
1717
|
+
queryKey: ["posts", "tips", author, permlink],
|
|
1718
|
+
queryFn: async () => {
|
|
1719
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/post-tips", {
|
|
1720
|
+
method: "POST",
|
|
1721
|
+
headers: {
|
|
1722
|
+
"Content-Type": "application/json"
|
|
1723
|
+
},
|
|
1724
|
+
body: JSON.stringify({
|
|
1725
|
+
author,
|
|
1726
|
+
permlink
|
|
1727
|
+
})
|
|
1728
|
+
});
|
|
1729
|
+
if (!response.ok) {
|
|
1730
|
+
throw new Error(`Failed to fetch post tips: ${response.status}`);
|
|
1731
|
+
}
|
|
1732
|
+
return response.json();
|
|
1733
|
+
},
|
|
1734
|
+
enabled: !!author && !!permlink && isEnabled
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
// src/modules/posts/utils/waves-helpers.ts
|
|
1739
|
+
function normalizeContainer(entry, host) {
|
|
1740
|
+
return {
|
|
1741
|
+
...entry,
|
|
1742
|
+
id: entry.id ?? entry.post_id,
|
|
1743
|
+
host
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
function normalizeParent(entry) {
|
|
1747
|
+
return {
|
|
1748
|
+
...entry,
|
|
1749
|
+
id: entry.id ?? entry.post_id
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
function normalizeWaveEntryFromApi(entry, host) {
|
|
1753
|
+
if (!entry) {
|
|
1754
|
+
return null;
|
|
1755
|
+
}
|
|
1756
|
+
const containerSource = entry.container ?? entry;
|
|
1757
|
+
const container = normalizeContainer(containerSource, host);
|
|
1758
|
+
const parent = entry.parent ? normalizeParent(entry.parent) : void 0;
|
|
1759
|
+
return {
|
|
1760
|
+
...entry,
|
|
1761
|
+
id: entry.id ?? entry.post_id,
|
|
1762
|
+
host,
|
|
1763
|
+
container,
|
|
1764
|
+
parent
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
function toEntryArray(x) {
|
|
1768
|
+
return Array.isArray(x) ? x : [];
|
|
1769
|
+
}
|
|
1770
|
+
async function getVisibleFirstLevelThreadItems(container) {
|
|
1771
|
+
const queryOptions76 = getDiscussionsQueryOptions(container, "created" /* created */, true);
|
|
1772
|
+
const discussionItemsRaw = await CONFIG.queryClient.fetchQuery(queryOptions76);
|
|
1773
|
+
const discussionItems = toEntryArray(discussionItemsRaw);
|
|
1774
|
+
if (discussionItems.length <= 1) {
|
|
1775
|
+
return [];
|
|
1776
|
+
}
|
|
1777
|
+
const firstLevelItems = discussionItems.filter(
|
|
1778
|
+
({ parent_author, parent_permlink }) => parent_author === container.author && parent_permlink === container.permlink
|
|
1779
|
+
);
|
|
1780
|
+
if (firstLevelItems.length === 0) {
|
|
1781
|
+
return [];
|
|
1782
|
+
}
|
|
1783
|
+
const visibleItems = firstLevelItems.filter((item) => !item.stats?.gray);
|
|
1784
|
+
return visibleItems;
|
|
1785
|
+
}
|
|
1786
|
+
function mapThreadItemsToWaveEntries(items, container, host) {
|
|
1787
|
+
if (items.length === 0) {
|
|
1788
|
+
return [];
|
|
1789
|
+
}
|
|
1790
|
+
return items.map((item) => {
|
|
1791
|
+
const parent = items.find(
|
|
1792
|
+
(i) => i.author === item.parent_author && i.permlink === item.parent_permlink && i.author !== host
|
|
1793
|
+
);
|
|
1794
|
+
return {
|
|
1795
|
+
...item,
|
|
1796
|
+
id: item.post_id,
|
|
1797
|
+
host,
|
|
1798
|
+
container,
|
|
1799
|
+
parent
|
|
1800
|
+
};
|
|
1801
|
+
}).filter((entry) => entry.container.post_id !== entry.post_id).sort(
|
|
1802
|
+
(a, b) => new Date(b.created).getTime() - new Date(a.created).getTime()
|
|
1803
|
+
);
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
// src/modules/posts/queries/get-waves-by-host-query-options.ts
|
|
1807
|
+
var THREAD_CONTAINER_BATCH_SIZE = 5;
|
|
1808
|
+
var MAX_CONTAINERS_TO_SCAN = 50;
|
|
1809
|
+
async function getThreads(host, pageParam) {
|
|
1810
|
+
let startAuthor = pageParam?.author;
|
|
1811
|
+
let startPermlink = pageParam?.permlink;
|
|
1812
|
+
let scannedContainers = 0;
|
|
1813
|
+
let skipContainerId = pageParam?.post_id;
|
|
1814
|
+
while (scannedContainers < MAX_CONTAINERS_TO_SCAN) {
|
|
1815
|
+
const rpcParams = {
|
|
1816
|
+
sort: "posts",
|
|
1817
|
+
// ProfileFilter.posts
|
|
1818
|
+
account: host,
|
|
1819
|
+
limit: THREAD_CONTAINER_BATCH_SIZE,
|
|
1820
|
+
...startAuthor ? { start_author: startAuthor } : {},
|
|
1821
|
+
...startPermlink ? { start_permlink: startPermlink } : {}
|
|
1822
|
+
};
|
|
1823
|
+
const containers = await CONFIG.hiveClient.call(
|
|
1824
|
+
"bridge",
|
|
1825
|
+
"get_account_posts",
|
|
1826
|
+
rpcParams
|
|
1827
|
+
);
|
|
1828
|
+
if (!containers || containers.length === 0) {
|
|
1829
|
+
return null;
|
|
1830
|
+
}
|
|
1831
|
+
const normalizedContainers = containers.map((container) => {
|
|
1832
|
+
container.id = container.post_id;
|
|
1833
|
+
container.host = host;
|
|
1834
|
+
return container;
|
|
1835
|
+
});
|
|
1836
|
+
for (const container of normalizedContainers) {
|
|
1837
|
+
if (skipContainerId && container.post_id === skipContainerId) {
|
|
1838
|
+
skipContainerId = void 0;
|
|
1839
|
+
continue;
|
|
1840
|
+
}
|
|
1841
|
+
scannedContainers += 1;
|
|
1842
|
+
if (container.stats?.gray) {
|
|
1843
|
+
startAuthor = container.author;
|
|
1844
|
+
startPermlink = container.permlink;
|
|
1845
|
+
continue;
|
|
1846
|
+
}
|
|
1847
|
+
const visibleItems = await getVisibleFirstLevelThreadItems(container);
|
|
1848
|
+
if (visibleItems.length === 0) {
|
|
1849
|
+
startAuthor = container.author;
|
|
1850
|
+
startPermlink = container.permlink;
|
|
1851
|
+
continue;
|
|
1852
|
+
}
|
|
1853
|
+
return {
|
|
1854
|
+
entries: mapThreadItemsToWaveEntries(visibleItems, container, host)
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
const lastContainer = normalizedContainers[normalizedContainers.length - 1];
|
|
1858
|
+
if (!lastContainer) {
|
|
1859
|
+
return null;
|
|
1860
|
+
}
|
|
1861
|
+
startAuthor = lastContainer.author;
|
|
1862
|
+
startPermlink = lastContainer.permlink;
|
|
1863
|
+
}
|
|
1864
|
+
return null;
|
|
1865
|
+
}
|
|
1866
|
+
function getWavesByHostQueryOptions(host) {
|
|
1867
|
+
return infiniteQueryOptions({
|
|
1868
|
+
queryKey: ["posts", "waves", "by-host", host],
|
|
1869
|
+
initialPageParam: void 0,
|
|
1870
|
+
queryFn: async ({ pageParam }) => {
|
|
1871
|
+
const result = await getThreads(host, pageParam);
|
|
1872
|
+
if (!result) return [];
|
|
1873
|
+
return result.entries;
|
|
1874
|
+
},
|
|
1875
|
+
getNextPageParam: (lastPage) => lastPage?.[0]?.container
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
var DEFAULT_TAG_FEED_LIMIT = 40;
|
|
1879
|
+
function getWavesByTagQueryOptions(host, tag, limit = DEFAULT_TAG_FEED_LIMIT) {
|
|
1880
|
+
return infiniteQueryOptions({
|
|
1881
|
+
queryKey: ["posts", "waves", "by-tag", host, tag],
|
|
1882
|
+
initialPageParam: void 0,
|
|
1883
|
+
queryFn: async ({ signal }) => {
|
|
1884
|
+
try {
|
|
1885
|
+
const url = new URL(CONFIG.privateApiHost + "/private-api/waves/tags");
|
|
1886
|
+
url.searchParams.set("container", host);
|
|
1887
|
+
url.searchParams.set("tag", tag);
|
|
1888
|
+
const response = await fetch(url.toString(), {
|
|
1889
|
+
method: "GET",
|
|
1890
|
+
headers: {
|
|
1891
|
+
"Content-Type": "application/json"
|
|
1892
|
+
},
|
|
1893
|
+
signal
|
|
1894
|
+
});
|
|
1895
|
+
if (!response.ok) {
|
|
1896
|
+
throw new Error(`Failed to fetch waves by tag: ${response.status}`);
|
|
1897
|
+
}
|
|
1898
|
+
const data = await response.json();
|
|
1899
|
+
const result = data.slice(0, limit).map((entry) => normalizeWaveEntryFromApi(entry, host)).filter((entry) => Boolean(entry));
|
|
1900
|
+
return result.sort(
|
|
1901
|
+
(a, b) => new Date(b.created).getTime() - new Date(a.created).getTime()
|
|
1902
|
+
);
|
|
1903
|
+
} catch (error) {
|
|
1904
|
+
console.error("[SDK] Failed to fetch waves by tag", error);
|
|
1905
|
+
return [];
|
|
1906
|
+
}
|
|
1907
|
+
},
|
|
1908
|
+
getNextPageParam: () => void 0
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
function getWavesFollowingQueryOptions(host, username) {
|
|
1912
|
+
const normalizedUsername = username?.trim().toLowerCase();
|
|
1913
|
+
return infiniteQueryOptions({
|
|
1914
|
+
queryKey: ["posts", "waves", "following", host, normalizedUsername ?? ""],
|
|
1915
|
+
enabled: Boolean(normalizedUsername),
|
|
1916
|
+
initialPageParam: void 0,
|
|
1917
|
+
queryFn: async ({ signal }) => {
|
|
1918
|
+
if (!normalizedUsername) {
|
|
1919
|
+
return [];
|
|
1920
|
+
}
|
|
1921
|
+
try {
|
|
1922
|
+
const url = new URL(CONFIG.privateApiHost + "/private-api/waves/following");
|
|
1923
|
+
url.searchParams.set("container", host);
|
|
1924
|
+
url.searchParams.set("username", normalizedUsername);
|
|
1925
|
+
const response = await fetch(url.toString(), {
|
|
1926
|
+
method: "GET",
|
|
1927
|
+
headers: {
|
|
1928
|
+
"Content-Type": "application/json"
|
|
1929
|
+
},
|
|
1930
|
+
signal
|
|
1931
|
+
});
|
|
1932
|
+
if (!response.ok) {
|
|
1933
|
+
throw new Error(`Failed to fetch waves following feed: ${response.status}`);
|
|
1934
|
+
}
|
|
1935
|
+
const data = await response.json();
|
|
1936
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
1937
|
+
return [];
|
|
1938
|
+
}
|
|
1939
|
+
const flattened = data.map((entry) => normalizeWaveEntryFromApi(entry, host)).filter((entry) => Boolean(entry));
|
|
1940
|
+
if (flattened.length === 0) {
|
|
1941
|
+
return [];
|
|
1942
|
+
}
|
|
1943
|
+
return flattened.sort(
|
|
1944
|
+
(a, b) => new Date(b.created).getTime() - new Date(a.created).getTime()
|
|
1945
|
+
);
|
|
1946
|
+
} catch (error) {
|
|
1947
|
+
console.error("[SDK] Failed to fetch waves following feed", error);
|
|
1948
|
+
return [];
|
|
1949
|
+
}
|
|
1950
|
+
},
|
|
1951
|
+
getNextPageParam: () => void 0
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
function getWavesTrendingTagsQueryOptions(host, hours = 24) {
|
|
1955
|
+
return queryOptions({
|
|
1956
|
+
queryKey: ["posts", "waves", "trending-tags", host, hours],
|
|
1957
|
+
queryFn: async ({ signal }) => {
|
|
1958
|
+
try {
|
|
1959
|
+
const url = new URL(CONFIG.privateApiHost + "/private-api/waves/trending/tags");
|
|
1960
|
+
url.searchParams.set("container", host);
|
|
1961
|
+
url.searchParams.set("hours", hours.toString());
|
|
1962
|
+
const response = await fetch(url.toString(), {
|
|
1963
|
+
method: "GET",
|
|
1964
|
+
headers: {
|
|
1965
|
+
"Content-Type": "application/json"
|
|
1966
|
+
},
|
|
1967
|
+
signal
|
|
1968
|
+
});
|
|
1969
|
+
if (!response.ok) {
|
|
1970
|
+
throw new Error(`Failed to fetch waves trending tags: ${response.status}`);
|
|
1971
|
+
}
|
|
1972
|
+
const data = await response.json();
|
|
1973
|
+
return data.map(({ tag, posts }) => ({ tag, posts }));
|
|
1974
|
+
} catch (error) {
|
|
1975
|
+
console.error("[SDK] Failed to fetch waves trending tags", error);
|
|
1976
|
+
return [];
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
// src/modules/accounts/queries/get-account-vote-history-infinite-query-options.ts
|
|
1983
|
+
function isEntry(x) {
|
|
1984
|
+
return !!x && typeof x === "object" && "author" in x && "permlink" in x && "active_votes" in x;
|
|
1985
|
+
}
|
|
1986
|
+
function getDays(createdDate) {
|
|
1987
|
+
const past = new Date(createdDate);
|
|
1988
|
+
const now = /* @__PURE__ */ new Date();
|
|
1989
|
+
const diffMs = now.getTime() - past.getTime();
|
|
1990
|
+
return diffMs / (1e3 * 60 * 60 * 24);
|
|
1991
|
+
}
|
|
1992
|
+
function getAccountVoteHistoryInfiniteQueryOptions(username, options) {
|
|
1993
|
+
const { limit = 20, filters = [], dayLimit = 7 } = options ?? {};
|
|
1994
|
+
return infiniteQueryOptions({
|
|
1995
|
+
queryKey: ["accounts", "vote-history", username, limit],
|
|
1996
|
+
initialPageParam: { start: -1 },
|
|
1997
|
+
queryFn: async ({ pageParam }) => {
|
|
1998
|
+
const { start } = pageParam;
|
|
1999
|
+
const response = await CONFIG.hiveClient.call(
|
|
2000
|
+
"condenser_api",
|
|
2001
|
+
"get_account_history",
|
|
2002
|
+
[username, start, limit, ...filters]
|
|
2003
|
+
);
|
|
2004
|
+
const mappedResults = response.map(([num, historyObj]) => ({
|
|
2005
|
+
...historyObj.op[1],
|
|
2006
|
+
num,
|
|
2007
|
+
timestamp: historyObj.timestamp
|
|
2008
|
+
}));
|
|
2009
|
+
const result = mappedResults.filter(
|
|
2010
|
+
(filtered) => filtered.voter === username && filtered.weight !== 0 && getDays(filtered.timestamp) <= dayLimit
|
|
2011
|
+
);
|
|
2012
|
+
const entries = [];
|
|
2013
|
+
for (const obj of result) {
|
|
2014
|
+
const post = await CONFIG.queryClient.fetchQuery(
|
|
2015
|
+
getPostQueryOptions(obj.author, obj.permlink)
|
|
2016
|
+
);
|
|
2017
|
+
if (isEntry(post)) entries.push(post);
|
|
2018
|
+
}
|
|
2019
|
+
const [firstHistory] = response;
|
|
2020
|
+
return {
|
|
2021
|
+
lastDate: firstHistory ? getDays(firstHistory[1].timestamp) : 0,
|
|
2022
|
+
lastItemFetched: firstHistory ? firstHistory[0] : start,
|
|
2023
|
+
entries
|
|
2024
|
+
};
|
|
2025
|
+
},
|
|
2026
|
+
getNextPageParam: (lastPage) => ({
|
|
2027
|
+
start: lastPage.lastItemFetched
|
|
2028
|
+
})
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
// src/modules/accounts/mutations/use-account-update.ts
|
|
2033
|
+
function useAccountUpdate(username) {
|
|
2034
|
+
const queryClient = useQueryClient();
|
|
2035
|
+
const { data } = useQuery(getAccountFullQueryOptions(username));
|
|
2036
|
+
return useBroadcastMutation(
|
|
2037
|
+
["accounts", "update"],
|
|
2038
|
+
username,
|
|
2039
|
+
(payload) => {
|
|
2040
|
+
if (!data) {
|
|
2041
|
+
throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
|
|
2042
|
+
}
|
|
2043
|
+
const profile = buildProfileMetadata({
|
|
2044
|
+
existingProfile: extractAccountProfile(data),
|
|
2045
|
+
profile: payload.profile,
|
|
2046
|
+
tokens: payload.tokens
|
|
2047
|
+
});
|
|
2048
|
+
return [
|
|
2049
|
+
[
|
|
2050
|
+
"account_update2",
|
|
2051
|
+
{
|
|
2052
|
+
account: username,
|
|
2053
|
+
json_metadata: "",
|
|
2054
|
+
extensions: [],
|
|
2055
|
+
posting_json_metadata: JSON.stringify({
|
|
2056
|
+
profile
|
|
2057
|
+
})
|
|
2058
|
+
}
|
|
2059
|
+
]
|
|
2060
|
+
];
|
|
2061
|
+
},
|
|
2062
|
+
(_, variables) => queryClient.setQueryData(
|
|
2063
|
+
getAccountFullQueryOptions(username).queryKey,
|
|
2064
|
+
(data2) => {
|
|
2065
|
+
if (!data2) {
|
|
2066
|
+
return data2;
|
|
2067
|
+
}
|
|
2068
|
+
const obj = R4.clone(data2);
|
|
2069
|
+
obj.profile = buildProfileMetadata({
|
|
2070
|
+
existingProfile: extractAccountProfile(data2),
|
|
2071
|
+
profile: variables.profile,
|
|
2072
|
+
tokens: variables.tokens
|
|
2073
|
+
});
|
|
2074
|
+
return obj;
|
|
2075
|
+
}
|
|
2076
|
+
)
|
|
2077
|
+
);
|
|
2078
|
+
}
|
|
2079
|
+
function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
|
|
2080
|
+
return useMutation({
|
|
2081
|
+
mutationKey: ["accounts", "relation", "update", reference, target],
|
|
2082
|
+
mutationFn: async (kind) => {
|
|
2083
|
+
const relationsQuery = getRelationshipBetweenAccountsQueryOptions(
|
|
2084
|
+
reference,
|
|
2085
|
+
target
|
|
2086
|
+
);
|
|
2087
|
+
await getQueryClient().prefetchQuery(relationsQuery);
|
|
2088
|
+
const actualRelation = getQueryClient().getQueryData(
|
|
2089
|
+
relationsQuery.queryKey
|
|
2090
|
+
);
|
|
2091
|
+
await broadcastJson(reference, "follow", [
|
|
2092
|
+
"follow",
|
|
2093
|
+
{
|
|
2094
|
+
follower: reference,
|
|
2095
|
+
following: target,
|
|
2096
|
+
what: [
|
|
2097
|
+
...kind === "toggle-ignore" && !actualRelation?.ignores ? ["ignore"] : [],
|
|
2098
|
+
...kind === "toggle-follow" && !actualRelation?.follows ? ["blog"] : []
|
|
2099
|
+
]
|
|
2100
|
+
}
|
|
2101
|
+
]);
|
|
2102
|
+
return {
|
|
2103
|
+
...actualRelation,
|
|
2104
|
+
ignores: kind === "toggle-ignore" ? !actualRelation?.ignores : actualRelation?.ignores,
|
|
2105
|
+
follows: kind === "toggle-follow" ? !actualRelation?.follows : actualRelation?.follows
|
|
2106
|
+
};
|
|
2107
|
+
},
|
|
2108
|
+
onError,
|
|
2109
|
+
onSuccess(data) {
|
|
2110
|
+
onSuccess(data);
|
|
2111
|
+
getQueryClient().setQueryData(
|
|
2112
|
+
["accounts", "relations", reference, target],
|
|
2113
|
+
data
|
|
2114
|
+
);
|
|
2115
|
+
}
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2118
|
+
function useBookmarkAdd(username, onSuccess, onError) {
|
|
2119
|
+
return useMutation({
|
|
2120
|
+
mutationKey: ["accounts", "bookmarks", "add", username],
|
|
2121
|
+
mutationFn: async ({ author, permlink }) => {
|
|
2122
|
+
if (!username) {
|
|
2123
|
+
throw new Error("[SDK][Account][Bookmarks] \u2013 no active user");
|
|
2124
|
+
}
|
|
2125
|
+
const fetchApi = getBoundFetch();
|
|
2126
|
+
const response = await fetchApi(
|
|
2127
|
+
CONFIG.privateApiHost + "/private-api/bookmarks-add",
|
|
2128
|
+
{
|
|
2129
|
+
method: "POST",
|
|
2130
|
+
headers: {
|
|
2131
|
+
"Content-Type": "application/json"
|
|
2132
|
+
},
|
|
2133
|
+
body: JSON.stringify({
|
|
2134
|
+
author,
|
|
2135
|
+
permlink,
|
|
2136
|
+
code: getAccessToken(username)
|
|
2137
|
+
})
|
|
2138
|
+
}
|
|
2139
|
+
);
|
|
2140
|
+
return response.json();
|
|
2141
|
+
},
|
|
2142
|
+
onSuccess: () => {
|
|
2143
|
+
onSuccess();
|
|
2144
|
+
getQueryClient().invalidateQueries({
|
|
2145
|
+
queryKey: ["accounts", "bookmarks", username]
|
|
2146
|
+
});
|
|
2147
|
+
},
|
|
2148
|
+
onError
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
function useBookmarkDelete(username, onSuccess, onError) {
|
|
2152
|
+
return useMutation({
|
|
2153
|
+
mutationKey: ["accounts", "bookmarks", "delete", username],
|
|
2154
|
+
mutationFn: async (bookmarkId) => {
|
|
2155
|
+
if (!username) {
|
|
2156
|
+
throw new Error("[SDK][Account][Bookmarks] \u2013 no active user");
|
|
2157
|
+
}
|
|
2158
|
+
const fetchApi = getBoundFetch();
|
|
2159
|
+
const response = await fetchApi(
|
|
2160
|
+
CONFIG.privateApiHost + "/private-api/bookmarks-delete",
|
|
2161
|
+
{
|
|
2162
|
+
method: "POST",
|
|
2163
|
+
headers: {
|
|
2164
|
+
"Content-Type": "application/json"
|
|
2165
|
+
},
|
|
2166
|
+
body: JSON.stringify({
|
|
2167
|
+
id: bookmarkId,
|
|
2168
|
+
code: getAccessToken(username)
|
|
2169
|
+
})
|
|
2170
|
+
}
|
|
2171
|
+
);
|
|
2172
|
+
return response.json();
|
|
2173
|
+
},
|
|
2174
|
+
onSuccess: () => {
|
|
2175
|
+
onSuccess();
|
|
2176
|
+
getQueryClient().invalidateQueries({
|
|
2177
|
+
queryKey: ["accounts", "bookmarks", username]
|
|
2178
|
+
});
|
|
2179
|
+
},
|
|
2180
|
+
onError
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
function useAccountFavouriteAdd(username, onSuccess, onError) {
|
|
2184
|
+
return useMutation({
|
|
2185
|
+
mutationKey: ["accounts", "favourites", "add", username],
|
|
2186
|
+
mutationFn: async (account) => {
|
|
2187
|
+
if (!username) {
|
|
2188
|
+
throw new Error("[SDK][Account][Bookmarks] \u2013 no active user");
|
|
2189
|
+
}
|
|
2190
|
+
const fetchApi = getBoundFetch();
|
|
2191
|
+
const response = await fetchApi(
|
|
2192
|
+
CONFIG.privateApiHost + "/private-api/favorites-add",
|
|
2193
|
+
{
|
|
2194
|
+
method: "POST",
|
|
2195
|
+
headers: {
|
|
2196
|
+
"Content-Type": "application/json"
|
|
2197
|
+
},
|
|
2198
|
+
body: JSON.stringify({
|
|
2199
|
+
account,
|
|
2200
|
+
code: getAccessToken(username)
|
|
2201
|
+
})
|
|
2202
|
+
}
|
|
2203
|
+
);
|
|
2204
|
+
return response.json();
|
|
2205
|
+
},
|
|
2206
|
+
onSuccess: () => {
|
|
2207
|
+
onSuccess();
|
|
2208
|
+
getQueryClient().invalidateQueries({
|
|
2209
|
+
queryKey: ["accounts", "favourites", username]
|
|
2210
|
+
});
|
|
2211
|
+
},
|
|
2212
|
+
onError
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
function useAccountFavouriteDelete(username, onSuccess, onError) {
|
|
2216
|
+
return useMutation({
|
|
2217
|
+
mutationKey: ["accounts", "favourites", "add", username],
|
|
2218
|
+
mutationFn: async (account) => {
|
|
2219
|
+
if (!username) {
|
|
2220
|
+
throw new Error("[SDK][Account][Bookmarks] \u2013 no active user");
|
|
2221
|
+
}
|
|
2222
|
+
const fetchApi = getBoundFetch();
|
|
2223
|
+
const response = await fetchApi(
|
|
2224
|
+
CONFIG.privateApiHost + "/private-api/favorites-delete",
|
|
2225
|
+
{
|
|
2226
|
+
method: "POST",
|
|
2227
|
+
headers: {
|
|
2228
|
+
"Content-Type": "application/json"
|
|
2229
|
+
},
|
|
2230
|
+
body: JSON.stringify({
|
|
2231
|
+
account,
|
|
2232
|
+
code: getAccessToken(username)
|
|
2233
|
+
})
|
|
2234
|
+
}
|
|
2235
|
+
);
|
|
2236
|
+
return response.json();
|
|
2237
|
+
},
|
|
2238
|
+
onSuccess: () => {
|
|
2239
|
+
onSuccess();
|
|
2240
|
+
getQueryClient().invalidateQueries({
|
|
2241
|
+
queryKey: ["accounts", "favourites", username]
|
|
2242
|
+
});
|
|
2243
|
+
},
|
|
2244
|
+
onError
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
function dedupeAndSortKeyAuths(existing, additions) {
|
|
2248
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2249
|
+
existing.forEach(([key, weight]) => {
|
|
2250
|
+
merged.set(key.toString(), weight);
|
|
2251
|
+
});
|
|
2252
|
+
additions.forEach(([key, weight]) => {
|
|
2253
|
+
merged.set(key.toString(), weight);
|
|
2254
|
+
});
|
|
2255
|
+
return Array.from(merged.entries()).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)).map(([key, weight]) => [key, weight]);
|
|
2256
|
+
}
|
|
2257
|
+
function useAccountUpdateKeyAuths(username, options) {
|
|
2258
|
+
const { data: accountData } = useQuery(getAccountFullQueryOptions(username));
|
|
2259
|
+
return useMutation({
|
|
2260
|
+
mutationKey: ["accounts", "keys-update", username],
|
|
2261
|
+
mutationFn: async ({ keys, keepCurrent = false, currentKey }) => {
|
|
2262
|
+
if (!accountData) {
|
|
2263
|
+
throw new Error(
|
|
2264
|
+
"[SDK][Update password] \u2013 cannot update keys for anon user"
|
|
2265
|
+
);
|
|
2266
|
+
}
|
|
2267
|
+
const prepareAuth = (keyName) => {
|
|
2268
|
+
const auth = R4.clone(accountData[keyName]);
|
|
2269
|
+
auth.key_auths = dedupeAndSortKeyAuths(
|
|
2270
|
+
keepCurrent ? auth.key_auths : [],
|
|
2271
|
+
keys.map(
|
|
2272
|
+
(values, i) => [values[keyName].createPublic().toString(), i + 1]
|
|
2273
|
+
)
|
|
2274
|
+
);
|
|
2275
|
+
return auth;
|
|
2276
|
+
};
|
|
2277
|
+
return CONFIG.hiveClient.broadcast.updateAccount(
|
|
2278
|
+
{
|
|
2279
|
+
account: username,
|
|
2280
|
+
json_metadata: accountData.json_metadata,
|
|
2281
|
+
owner: prepareAuth("owner"),
|
|
2282
|
+
active: prepareAuth("active"),
|
|
2283
|
+
posting: prepareAuth("posting"),
|
|
2284
|
+
memo_key: keepCurrent ? accountData.memo_key : keys[0].memo_key.createPublic().toString()
|
|
2285
|
+
},
|
|
2286
|
+
currentKey
|
|
2287
|
+
);
|
|
2288
|
+
},
|
|
2289
|
+
...options
|
|
2290
|
+
});
|
|
2291
|
+
}
|
|
2292
|
+
function useAccountUpdatePassword(username, options) {
|
|
2293
|
+
const { data: accountData } = useQuery(getAccountFullQueryOptions(username));
|
|
2294
|
+
const { mutateAsync: updateKeys } = useAccountUpdateKeyAuths(username);
|
|
2295
|
+
return useMutation({
|
|
1002
2296
|
mutationKey: ["accounts", "password-update", username],
|
|
1003
2297
|
mutationFn: async ({
|
|
1004
2298
|
newPassword,
|
|
@@ -1007,745 +2301,1585 @@ function useAccountUpdatePassword(username, options) {
|
|
|
1007
2301
|
}) => {
|
|
1008
2302
|
if (!accountData) {
|
|
1009
2303
|
throw new Error(
|
|
1010
|
-
"[SDK][Update password] \u2013 cannot update password for anon user"
|
|
2304
|
+
"[SDK][Update password] \u2013 cannot update password for anon user"
|
|
2305
|
+
);
|
|
2306
|
+
}
|
|
2307
|
+
const currentKey = PrivateKey.fromLogin(
|
|
2308
|
+
username,
|
|
2309
|
+
currentPassword,
|
|
2310
|
+
"owner"
|
|
2311
|
+
);
|
|
2312
|
+
return updateKeys({
|
|
2313
|
+
currentKey,
|
|
2314
|
+
keepCurrent,
|
|
2315
|
+
keys: [
|
|
2316
|
+
{
|
|
2317
|
+
owner: PrivateKey.fromLogin(username, newPassword, "owner"),
|
|
2318
|
+
active: PrivateKey.fromLogin(username, newPassword, "active"),
|
|
2319
|
+
posting: PrivateKey.fromLogin(username, newPassword, "posting"),
|
|
2320
|
+
memo_key: PrivateKey.fromLogin(username, newPassword, "memo")
|
|
2321
|
+
}
|
|
2322
|
+
]
|
|
2323
|
+
});
|
|
2324
|
+
},
|
|
2325
|
+
...options
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
function useAccountRevokePosting(username, options) {
|
|
2329
|
+
const queryClient = useQueryClient();
|
|
2330
|
+
const { data } = useQuery(getAccountFullQueryOptions(username));
|
|
2331
|
+
return useMutation({
|
|
2332
|
+
mutationKey: ["accounts", "revoke-posting", data?.name],
|
|
2333
|
+
mutationFn: async ({ accountName, type, key }) => {
|
|
2334
|
+
if (!data) {
|
|
2335
|
+
throw new Error(
|
|
2336
|
+
"[SDK][Accounts] \u2013\xA0cannot revoke posting for anonymous user"
|
|
2337
|
+
);
|
|
2338
|
+
}
|
|
2339
|
+
const posting = R4.pipe(
|
|
2340
|
+
{},
|
|
2341
|
+
R4.mergeDeep(data.posting)
|
|
2342
|
+
);
|
|
2343
|
+
posting.account_auths = posting.account_auths.filter(
|
|
2344
|
+
([account]) => account !== accountName
|
|
2345
|
+
);
|
|
2346
|
+
const operationBody = {
|
|
2347
|
+
account: data.name,
|
|
2348
|
+
posting,
|
|
2349
|
+
memo_key: data.memo_key,
|
|
2350
|
+
json_metadata: data.json_metadata
|
|
2351
|
+
};
|
|
2352
|
+
if (type === "key" && key) {
|
|
2353
|
+
return CONFIG.hiveClient.broadcast.updateAccount(operationBody, key);
|
|
2354
|
+
} else if (type === "keychain") {
|
|
2355
|
+
return keychain_exports.broadcast(
|
|
2356
|
+
data.name,
|
|
2357
|
+
[["account_update", operationBody]],
|
|
2358
|
+
"Active"
|
|
2359
|
+
);
|
|
2360
|
+
} else {
|
|
2361
|
+
const params = {
|
|
2362
|
+
callback: `https://ecency.com/@${data.name}/permissions`
|
|
2363
|
+
};
|
|
2364
|
+
return hs.sendOperation(
|
|
2365
|
+
["account_update", operationBody],
|
|
2366
|
+
params,
|
|
2367
|
+
() => {
|
|
2368
|
+
}
|
|
2369
|
+
);
|
|
2370
|
+
}
|
|
2371
|
+
},
|
|
2372
|
+
onError: options.onError,
|
|
2373
|
+
onSuccess: (resp, payload, ctx) => {
|
|
2374
|
+
options.onSuccess?.(resp, payload, ctx);
|
|
2375
|
+
queryClient.setQueryData(
|
|
2376
|
+
getAccountFullQueryOptions(username).queryKey,
|
|
2377
|
+
(data2) => ({
|
|
2378
|
+
...data2,
|
|
2379
|
+
posting: {
|
|
2380
|
+
...data2?.posting,
|
|
2381
|
+
account_auths: data2?.posting?.account_auths?.filter(
|
|
2382
|
+
([account]) => account !== payload.accountName
|
|
2383
|
+
) ?? []
|
|
2384
|
+
}
|
|
2385
|
+
})
|
|
2386
|
+
);
|
|
2387
|
+
}
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
function useAccountUpdateRecovery(username, options) {
|
|
2391
|
+
const { data } = useQuery(getAccountFullQueryOptions(username));
|
|
2392
|
+
return useMutation({
|
|
2393
|
+
mutationKey: ["accounts", "recovery", data?.name],
|
|
2394
|
+
mutationFn: async ({ accountName, type, key, email }) => {
|
|
2395
|
+
if (!data) {
|
|
2396
|
+
throw new Error(
|
|
2397
|
+
"[SDK][Accounts] \u2013\xA0cannot change recovery for anonymous user"
|
|
2398
|
+
);
|
|
2399
|
+
}
|
|
2400
|
+
const operationBody = {
|
|
2401
|
+
account_to_recover: data.name,
|
|
2402
|
+
new_recovery_account: accountName,
|
|
2403
|
+
extensions: []
|
|
2404
|
+
};
|
|
2405
|
+
if (type === "ecency") {
|
|
2406
|
+
const fetchApi = getBoundFetch();
|
|
2407
|
+
return fetchApi(CONFIG.privateApiHost + "/private-api/recoveries-add", {
|
|
2408
|
+
method: "POST",
|
|
2409
|
+
body: JSON.stringify({
|
|
2410
|
+
code: getAccessToken(data.name),
|
|
2411
|
+
email,
|
|
2412
|
+
publicKeys: [
|
|
2413
|
+
...data.owner.key_auths,
|
|
2414
|
+
...data.active.key_auths,
|
|
2415
|
+
...data.posting.key_auths,
|
|
2416
|
+
data.memo_key
|
|
2417
|
+
]
|
|
2418
|
+
})
|
|
2419
|
+
});
|
|
2420
|
+
} else if (type === "key" && key) {
|
|
2421
|
+
return CONFIG.hiveClient.broadcast.sendOperations(
|
|
2422
|
+
[["change_recovery_account", operationBody]],
|
|
2423
|
+
key
|
|
2424
|
+
);
|
|
2425
|
+
} else if (type === "keychain") {
|
|
2426
|
+
return keychain_exports.broadcast(
|
|
2427
|
+
data.name,
|
|
2428
|
+
[["change_recovery_account", operationBody]],
|
|
2429
|
+
"Active"
|
|
2430
|
+
);
|
|
2431
|
+
} else {
|
|
2432
|
+
const params = {
|
|
2433
|
+
callback: `https://ecency.com/@${data.name}/permissions`
|
|
2434
|
+
};
|
|
2435
|
+
return hs.sendOperation(
|
|
2436
|
+
["change_recovery_account", operationBody],
|
|
2437
|
+
params,
|
|
2438
|
+
() => {
|
|
2439
|
+
}
|
|
2440
|
+
);
|
|
2441
|
+
}
|
|
2442
|
+
},
|
|
2443
|
+
onError: options.onError,
|
|
2444
|
+
onSuccess: options.onSuccess
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
function useAccountRevokeKey(username, options) {
|
|
2448
|
+
const { data: accountData } = useQuery(getAccountFullQueryOptions(username));
|
|
2449
|
+
return useMutation({
|
|
2450
|
+
mutationKey: ["accounts", "revoke-key", accountData?.name],
|
|
2451
|
+
mutationFn: async ({ currentKey, revokingKey }) => {
|
|
2452
|
+
if (!accountData) {
|
|
2453
|
+
throw new Error(
|
|
2454
|
+
"[SDK][Update password] \u2013 cannot update keys for anon user"
|
|
2455
|
+
);
|
|
2456
|
+
}
|
|
2457
|
+
const prepareAuth = (keyName) => {
|
|
2458
|
+
const auth = R4.clone(accountData[keyName]);
|
|
2459
|
+
auth.key_auths = auth.key_auths.filter(
|
|
2460
|
+
([key]) => key !== revokingKey.toString()
|
|
2461
|
+
);
|
|
2462
|
+
return auth;
|
|
2463
|
+
};
|
|
2464
|
+
return CONFIG.hiveClient.broadcast.updateAccount(
|
|
2465
|
+
{
|
|
2466
|
+
account: accountData.name,
|
|
2467
|
+
json_metadata: accountData.json_metadata,
|
|
2468
|
+
owner: prepareAuth("owner"),
|
|
2469
|
+
active: prepareAuth("active"),
|
|
2470
|
+
posting: prepareAuth("posting"),
|
|
2471
|
+
memo_key: accountData.memo_key
|
|
2472
|
+
},
|
|
2473
|
+
currentKey
|
|
2474
|
+
);
|
|
2475
|
+
},
|
|
2476
|
+
...options
|
|
2477
|
+
});
|
|
2478
|
+
}
|
|
2479
|
+
function useSignOperationByKey(username) {
|
|
2480
|
+
return useMutation({
|
|
2481
|
+
mutationKey: ["operations", "sign", username],
|
|
2482
|
+
mutationFn: ({
|
|
2483
|
+
operation,
|
|
2484
|
+
keyOrSeed
|
|
2485
|
+
}) => {
|
|
2486
|
+
if (!username) {
|
|
2487
|
+
throw new Error("[Operations][Sign] \u2013 cannot sign op with anon user");
|
|
2488
|
+
}
|
|
2489
|
+
let privateKey;
|
|
2490
|
+
if (keyOrSeed.split(" ").length === 12) {
|
|
2491
|
+
privateKey = PrivateKey.fromLogin(username, keyOrSeed, "active");
|
|
2492
|
+
} else if (cryptoUtils.isWif(keyOrSeed)) {
|
|
2493
|
+
privateKey = PrivateKey.fromString(keyOrSeed);
|
|
2494
|
+
} else {
|
|
2495
|
+
privateKey = PrivateKey.from(keyOrSeed);
|
|
2496
|
+
}
|
|
2497
|
+
return CONFIG.hiveClient.broadcast.sendOperations(
|
|
2498
|
+
[operation],
|
|
2499
|
+
privateKey
|
|
2500
|
+
);
|
|
2501
|
+
}
|
|
2502
|
+
});
|
|
2503
|
+
}
|
|
2504
|
+
function useSignOperationByKeychain(username, keyType = "Active") {
|
|
2505
|
+
return useMutation({
|
|
2506
|
+
mutationKey: ["operations", "sign-keychain", username],
|
|
2507
|
+
mutationFn: ({ operation }) => {
|
|
2508
|
+
if (!username) {
|
|
2509
|
+
throw new Error(
|
|
2510
|
+
"[SDK][Keychain] \u2013\xA0cannot sign operation with anon user"
|
|
1011
2511
|
);
|
|
1012
2512
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
2513
|
+
return keychain_exports.broadcast(username, [operation], keyType);
|
|
2514
|
+
}
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
function useSignOperationByHivesigner(callbackUri = "/") {
|
|
2518
|
+
return useMutation({
|
|
2519
|
+
mutationKey: ["operations", "sign-hivesigner", callbackUri],
|
|
2520
|
+
mutationFn: async ({ operation }) => {
|
|
2521
|
+
return hs.sendOperation(operation, { callback: callbackUri }, () => {
|
|
2522
|
+
});
|
|
2523
|
+
}
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
function getChainPropertiesQueryOptions() {
|
|
2527
|
+
return queryOptions({
|
|
2528
|
+
queryKey: ["operations", "chain-properties"],
|
|
2529
|
+
queryFn: async () => {
|
|
2530
|
+
return await CONFIG.hiveClient.database.getChainProperties();
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
}
|
|
2534
|
+
function useAddFragment(username) {
|
|
2535
|
+
return useMutation({
|
|
2536
|
+
mutationKey: ["posts", "add-fragment", username],
|
|
2537
|
+
mutationFn: async ({ title, body }) => {
|
|
2538
|
+
const fetchApi = getBoundFetch();
|
|
2539
|
+
const response = await fetchApi(
|
|
2540
|
+
CONFIG.privateApiHost + "/private-api/fragments-add",
|
|
2541
|
+
{
|
|
2542
|
+
method: "POST",
|
|
2543
|
+
body: JSON.stringify({
|
|
2544
|
+
code: getAccessToken(username),
|
|
2545
|
+
title,
|
|
2546
|
+
body
|
|
2547
|
+
}),
|
|
2548
|
+
headers: {
|
|
2549
|
+
"Content-Type": "application/json"
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
1017
2552
|
);
|
|
1018
|
-
return
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
2553
|
+
return response.json();
|
|
2554
|
+
},
|
|
2555
|
+
onSuccess(response) {
|
|
2556
|
+
getQueryClient().setQueryData(
|
|
2557
|
+
getFragmentsQueryOptions(username).queryKey,
|
|
2558
|
+
(data) => [response, ...data ?? []]
|
|
2559
|
+
);
|
|
2560
|
+
}
|
|
2561
|
+
});
|
|
2562
|
+
}
|
|
2563
|
+
function useEditFragment(username, fragmentId) {
|
|
2564
|
+
return useMutation({
|
|
2565
|
+
mutationKey: ["posts", "edit-fragment", username, fragmentId],
|
|
2566
|
+
mutationFn: async ({ title, body }) => {
|
|
2567
|
+
const fetchApi = getBoundFetch();
|
|
2568
|
+
const response = await fetchApi(
|
|
2569
|
+
CONFIG.privateApiHost + "/private-api/fragments-update",
|
|
2570
|
+
{
|
|
2571
|
+
method: "POST",
|
|
2572
|
+
body: JSON.stringify({
|
|
2573
|
+
code: getAccessToken(username),
|
|
2574
|
+
id: fragmentId,
|
|
2575
|
+
title,
|
|
2576
|
+
body
|
|
2577
|
+
}),
|
|
2578
|
+
headers: {
|
|
2579
|
+
"Content-Type": "application/json"
|
|
1027
2580
|
}
|
|
1028
|
-
|
|
2581
|
+
}
|
|
2582
|
+
);
|
|
2583
|
+
return response.json();
|
|
2584
|
+
},
|
|
2585
|
+
onSuccess(response) {
|
|
2586
|
+
getQueryClient().setQueryData(
|
|
2587
|
+
getFragmentsQueryOptions(username).queryKey,
|
|
2588
|
+
(data) => {
|
|
2589
|
+
if (!data) {
|
|
2590
|
+
return [];
|
|
2591
|
+
}
|
|
2592
|
+
const index = data.findIndex(({ id }) => id === fragmentId);
|
|
2593
|
+
if (index >= 0) {
|
|
2594
|
+
data[index] = response;
|
|
2595
|
+
}
|
|
2596
|
+
return [...data];
|
|
2597
|
+
}
|
|
2598
|
+
);
|
|
2599
|
+
}
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
function useRemoveFragment(username, fragmentId) {
|
|
2603
|
+
return useMutation({
|
|
2604
|
+
mutationKey: ["posts", "remove-fragment", username],
|
|
2605
|
+
mutationFn: async () => {
|
|
2606
|
+
const fetchApi = getBoundFetch();
|
|
2607
|
+
return fetchApi(CONFIG.privateApiHost + "/private-api/fragments-delete", {
|
|
2608
|
+
method: "POST",
|
|
2609
|
+
body: JSON.stringify({
|
|
2610
|
+
code: getAccessToken(username),
|
|
2611
|
+
id: fragmentId
|
|
2612
|
+
}),
|
|
2613
|
+
headers: {
|
|
2614
|
+
"Content-Type": "application/json"
|
|
2615
|
+
}
|
|
1029
2616
|
});
|
|
1030
2617
|
},
|
|
1031
|
-
|
|
2618
|
+
onSuccess() {
|
|
2619
|
+
getQueryClient().setQueryData(
|
|
2620
|
+
getFragmentsQueryOptions(username).queryKey,
|
|
2621
|
+
(data) => [...data ?? []].filter(({ id }) => id !== fragmentId)
|
|
2622
|
+
);
|
|
2623
|
+
}
|
|
2624
|
+
});
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
// src/modules/analytics/mutations/index.ts
|
|
2628
|
+
var mutations_exports = {};
|
|
2629
|
+
__export(mutations_exports, {
|
|
2630
|
+
useRecordActivity: () => useRecordActivity
|
|
2631
|
+
});
|
|
2632
|
+
function useRecordActivity(username, activityType) {
|
|
2633
|
+
return useMutation({
|
|
2634
|
+
mutationKey: ["analytics", activityType],
|
|
2635
|
+
mutationFn: async () => {
|
|
2636
|
+
if (!activityType) {
|
|
2637
|
+
throw new Error("[SDK][Analytics] \u2013 no activity type provided");
|
|
2638
|
+
}
|
|
2639
|
+
const fetchApi = getBoundFetch();
|
|
2640
|
+
await fetchApi(CONFIG.plausibleHost + "/api/event", {
|
|
2641
|
+
method: "POST",
|
|
2642
|
+
headers: {
|
|
2643
|
+
"Content-Type": "application/json"
|
|
2644
|
+
},
|
|
2645
|
+
body: JSON.stringify({
|
|
2646
|
+
name: activityType,
|
|
2647
|
+
url: window.location.href,
|
|
2648
|
+
domain: window.location.host,
|
|
2649
|
+
props: {
|
|
2650
|
+
username
|
|
2651
|
+
}
|
|
2652
|
+
})
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
function getDiscoverLeaderboardQueryOptions(duration) {
|
|
2658
|
+
return queryOptions({
|
|
2659
|
+
queryKey: ["analytics", "discover-leaderboard", duration],
|
|
2660
|
+
queryFn: async ({ signal }) => {
|
|
2661
|
+
const response = await fetch(
|
|
2662
|
+
CONFIG.privateApiHost + `/private-api/leaderboard/${duration}`,
|
|
2663
|
+
{ signal }
|
|
2664
|
+
);
|
|
2665
|
+
if (!response.ok) {
|
|
2666
|
+
throw new Error(`Failed to fetch leaderboard: ${response.status}`);
|
|
2667
|
+
}
|
|
2668
|
+
return response.json();
|
|
2669
|
+
}
|
|
2670
|
+
});
|
|
2671
|
+
}
|
|
2672
|
+
function getDiscoverCurationQueryOptions(duration) {
|
|
2673
|
+
return queryOptions({
|
|
2674
|
+
queryKey: ["analytics", "discover-curation", duration],
|
|
2675
|
+
queryFn: async ({ signal }) => {
|
|
2676
|
+
const response = await fetch(
|
|
2677
|
+
CONFIG.privateApiHost + `/private-api/curation/${duration}`,
|
|
2678
|
+
{ signal }
|
|
2679
|
+
);
|
|
2680
|
+
if (!response.ok) {
|
|
2681
|
+
throw new Error(`Failed to fetch curation data: ${response.status}`);
|
|
2682
|
+
}
|
|
2683
|
+
const data = await response.json();
|
|
2684
|
+
const accounts = data.map((item) => item.account);
|
|
2685
|
+
const accountsResponse = await CONFIG.hiveClient.database.getAccounts(accounts);
|
|
2686
|
+
for (let index = 0; index < accountsResponse.length; index++) {
|
|
2687
|
+
const element = accountsResponse[index];
|
|
2688
|
+
const curator = data[index];
|
|
2689
|
+
const vestingShares = typeof element.vesting_shares === "string" ? element.vesting_shares : element.vesting_shares.toString();
|
|
2690
|
+
const receivedVestingShares = typeof element.received_vesting_shares === "string" ? element.received_vesting_shares : element.received_vesting_shares.toString();
|
|
2691
|
+
const delegatedVestingShares = typeof element.delegated_vesting_shares === "string" ? element.delegated_vesting_shares : element.delegated_vesting_shares.toString();
|
|
2692
|
+
const vestingWithdrawRate = typeof element.vesting_withdraw_rate === "string" ? element.vesting_withdraw_rate : element.vesting_withdraw_rate.toString();
|
|
2693
|
+
const effectiveVest = parseFloat(vestingShares) + parseFloat(receivedVestingShares) - parseFloat(delegatedVestingShares) - parseFloat(vestingWithdrawRate);
|
|
2694
|
+
curator.efficiency = curator.vests / effectiveVest;
|
|
2695
|
+
}
|
|
2696
|
+
data.sort((a, b) => b.efficiency - a.efficiency);
|
|
2697
|
+
return data;
|
|
2698
|
+
}
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
function getPageStatsQueryOptions(url, dimensions = [], metrics = ["visitors", "pageviews", "visit_duration"], dateRange) {
|
|
2702
|
+
return queryOptions({
|
|
2703
|
+
queryKey: ["analytics", "page-stats", url, dimensions, metrics, dateRange],
|
|
2704
|
+
queryFn: async ({ signal }) => {
|
|
2705
|
+
const response = await fetch(CONFIG.privateApiHost + "/api/stats", {
|
|
2706
|
+
method: "POST",
|
|
2707
|
+
headers: {
|
|
2708
|
+
"Content-Type": "application/json"
|
|
2709
|
+
},
|
|
2710
|
+
body: JSON.stringify({
|
|
2711
|
+
metrics,
|
|
2712
|
+
url: encodeURIComponent(url),
|
|
2713
|
+
dimensions,
|
|
2714
|
+
date_range: dateRange
|
|
2715
|
+
}),
|
|
2716
|
+
signal
|
|
2717
|
+
});
|
|
2718
|
+
if (!response.ok) {
|
|
2719
|
+
throw new Error(`Failed to fetch page stats: ${response.status}`);
|
|
2720
|
+
}
|
|
2721
|
+
return response.json();
|
|
2722
|
+
},
|
|
2723
|
+
enabled: !!url
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
// src/modules/integrations/3speak/queries/index.ts
|
|
2728
|
+
var queries_exports2 = {};
|
|
2729
|
+
__export(queries_exports2, {
|
|
2730
|
+
getAccountTokenQueryOptions: () => getAccountTokenQueryOptions,
|
|
2731
|
+
getAccountVideosQueryOptions: () => getAccountVideosQueryOptions
|
|
2732
|
+
});
|
|
2733
|
+
|
|
2734
|
+
// src/modules/integrations/hivesigner/queries/index.ts
|
|
2735
|
+
var queries_exports = {};
|
|
2736
|
+
__export(queries_exports, {
|
|
2737
|
+
getDecodeMemoQueryOptions: () => getDecodeMemoQueryOptions
|
|
2738
|
+
});
|
|
2739
|
+
function getDecodeMemoQueryOptions(username, memo) {
|
|
2740
|
+
return queryOptions({
|
|
2741
|
+
queryKey: ["integrations", "hivesigner", "decode-memo", username],
|
|
2742
|
+
queryFn: async () => {
|
|
2743
|
+
const accessToken = getAccessToken(username);
|
|
2744
|
+
if (accessToken) {
|
|
2745
|
+
const hsClient = new hs.Client({
|
|
2746
|
+
accessToken
|
|
2747
|
+
});
|
|
2748
|
+
return hsClient.decode(memo);
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
// src/modules/integrations/hivesigner/index.ts
|
|
2755
|
+
var HiveSignerIntegration = {
|
|
2756
|
+
queries: queries_exports
|
|
2757
|
+
};
|
|
2758
|
+
|
|
2759
|
+
// src/modules/integrations/3speak/queries/get-account-token-query-options.ts
|
|
2760
|
+
function getAccountTokenQueryOptions(username) {
|
|
2761
|
+
return queryOptions({
|
|
2762
|
+
queryKey: ["integrations", "3speak", "authenticate", username],
|
|
2763
|
+
enabled: !!username,
|
|
2764
|
+
queryFn: async () => {
|
|
2765
|
+
if (!username) {
|
|
2766
|
+
throw new Error("[SDK][Integrations][3Speak] \u2013\xA0anon user");
|
|
2767
|
+
}
|
|
2768
|
+
const fetchApi = getBoundFetch();
|
|
2769
|
+
const response = await fetchApi(
|
|
2770
|
+
`https://studio.3speak.tv/mobile/login?username=${username}&hivesigner=true`,
|
|
2771
|
+
{
|
|
2772
|
+
headers: {
|
|
2773
|
+
"Content-Type": "application/json"
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
);
|
|
2777
|
+
const memoQueryOptions = HiveSignerIntegration.queries.getDecodeMemoQueryOptions(
|
|
2778
|
+
username,
|
|
2779
|
+
(await response.json()).memo
|
|
2780
|
+
);
|
|
2781
|
+
await getQueryClient().prefetchQuery(memoQueryOptions);
|
|
2782
|
+
const { memoDecoded } = getQueryClient().getQueryData(
|
|
2783
|
+
memoQueryOptions.queryKey
|
|
2784
|
+
);
|
|
2785
|
+
return memoDecoded.replace("#", "");
|
|
2786
|
+
}
|
|
1032
2787
|
});
|
|
1033
2788
|
}
|
|
1034
|
-
function
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
throw new Error(
|
|
1042
|
-
"[SDK][Accounts] \u2013\xA0cannot revoke posting for anonymous user"
|
|
1043
|
-
);
|
|
1044
|
-
}
|
|
1045
|
-
const posting = R4.pipe(
|
|
1046
|
-
{},
|
|
1047
|
-
R4.mergeDeep(data.posting)
|
|
2789
|
+
function getAccountVideosQueryOptions(username) {
|
|
2790
|
+
return queryOptions({
|
|
2791
|
+
queryKey: ["integrations", "3speak", "videos", username],
|
|
2792
|
+
enabled: !!username,
|
|
2793
|
+
queryFn: async () => {
|
|
2794
|
+
await getQueryClient().prefetchQuery(
|
|
2795
|
+
getAccountTokenQueryOptions(username)
|
|
1048
2796
|
);
|
|
1049
|
-
|
|
1050
|
-
(
|
|
2797
|
+
const token = getQueryClient().getQueryData(
|
|
2798
|
+
getAccountTokenQueryOptions(username).queryKey
|
|
1051
2799
|
);
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
return CONFIG.hiveClient.broadcast.updateAccount(operationBody, key);
|
|
1060
|
-
} else if (type === "keychain") {
|
|
1061
|
-
return keychain_exports.broadcast(
|
|
1062
|
-
data.name,
|
|
1063
|
-
[["account_update", operationBody]],
|
|
1064
|
-
"Active"
|
|
1065
|
-
);
|
|
1066
|
-
} else {
|
|
1067
|
-
const params = {
|
|
1068
|
-
callback: `https://ecency.com/@${data.name}/permissions`
|
|
1069
|
-
};
|
|
1070
|
-
return hs.sendOperation(
|
|
1071
|
-
["account_update", operationBody],
|
|
1072
|
-
params,
|
|
1073
|
-
() => {
|
|
1074
|
-
}
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1077
|
-
},
|
|
1078
|
-
onError: options.onError,
|
|
1079
|
-
onSuccess: (resp, payload, ctx) => {
|
|
1080
|
-
options.onSuccess?.(resp, payload, ctx);
|
|
1081
|
-
queryClient.setQueryData(
|
|
1082
|
-
getAccountFullQueryOptions(username).queryKey,
|
|
1083
|
-
(data2) => ({
|
|
1084
|
-
...data2,
|
|
1085
|
-
posting: {
|
|
1086
|
-
...data2?.posting,
|
|
1087
|
-
account_auths: data2?.posting?.account_auths?.filter(
|
|
1088
|
-
([account]) => account !== payload.accountName
|
|
1089
|
-
) ?? []
|
|
2800
|
+
const fetchApi = getBoundFetch();
|
|
2801
|
+
const response = await fetchApi(
|
|
2802
|
+
`https://studio.3speak.tv/mobile/api/my-videos`,
|
|
2803
|
+
{
|
|
2804
|
+
headers: {
|
|
2805
|
+
"Content-Type": "application/json",
|
|
2806
|
+
Authorization: `Bearer ${token}`
|
|
1090
2807
|
}
|
|
1091
|
-
}
|
|
2808
|
+
}
|
|
1092
2809
|
);
|
|
2810
|
+
return await response.json();
|
|
1093
2811
|
}
|
|
1094
2812
|
});
|
|
1095
2813
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
new_recovery_account: accountName,
|
|
1109
|
-
extensions: []
|
|
1110
|
-
};
|
|
1111
|
-
if (type === "ecency") {
|
|
2814
|
+
|
|
2815
|
+
// src/modules/integrations/3speak/index.ts
|
|
2816
|
+
var ThreeSpeakIntegration = {
|
|
2817
|
+
queries: queries_exports2
|
|
2818
|
+
};
|
|
2819
|
+
function getHivePoshLinksQueryOptions(username) {
|
|
2820
|
+
return queryOptions({
|
|
2821
|
+
queryKey: ["integrations", "hiveposh", "links", username],
|
|
2822
|
+
retry: false,
|
|
2823
|
+
// Don't retry on user not found errors
|
|
2824
|
+
queryFn: async () => {
|
|
2825
|
+
try {
|
|
1112
2826
|
const fetchApi = getBoundFetch();
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
...data.owner.key_auths,
|
|
1120
|
-
...data.active.key_auths,
|
|
1121
|
-
...data.posting.key_auths,
|
|
1122
|
-
data.memo_key
|
|
1123
|
-
]
|
|
1124
|
-
})
|
|
1125
|
-
});
|
|
1126
|
-
} else if (type === "key" && key) {
|
|
1127
|
-
return CONFIG.hiveClient.broadcast.sendOperations(
|
|
1128
|
-
[["change_recovery_account", operationBody]],
|
|
1129
|
-
key
|
|
1130
|
-
);
|
|
1131
|
-
} else if (type === "keychain") {
|
|
1132
|
-
return keychain_exports.broadcast(
|
|
1133
|
-
data.name,
|
|
1134
|
-
[["change_recovery_account", operationBody]],
|
|
1135
|
-
"Active"
|
|
1136
|
-
);
|
|
1137
|
-
} else {
|
|
1138
|
-
const params = {
|
|
1139
|
-
callback: `https://ecency.com/@${data.name}/permissions`
|
|
1140
|
-
};
|
|
1141
|
-
return hs.sendOperation(
|
|
1142
|
-
["change_recovery_account", operationBody],
|
|
1143
|
-
params,
|
|
1144
|
-
() => {
|
|
2827
|
+
const response = await fetchApi(
|
|
2828
|
+
`https://hiveposh.com/api/v0/linked-accounts/${username}`,
|
|
2829
|
+
{
|
|
2830
|
+
headers: {
|
|
2831
|
+
"Content-Type": "application/json"
|
|
2832
|
+
}
|
|
1145
2833
|
}
|
|
1146
2834
|
);
|
|
2835
|
+
if (response.status === 400) {
|
|
2836
|
+
const errorData = await response.json().catch(() => ({}));
|
|
2837
|
+
if (errorData?.message === "User Not Connected") {
|
|
2838
|
+
return null;
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
if (!response.ok) {
|
|
2842
|
+
return null;
|
|
2843
|
+
}
|
|
2844
|
+
const data = await response.json();
|
|
2845
|
+
return {
|
|
2846
|
+
twitter: {
|
|
2847
|
+
username: data.twitter_username,
|
|
2848
|
+
profile: data.twitter_profile
|
|
2849
|
+
},
|
|
2850
|
+
reddit: {
|
|
2851
|
+
username: data.reddit_username,
|
|
2852
|
+
profile: data.reddit_profile
|
|
2853
|
+
}
|
|
2854
|
+
};
|
|
2855
|
+
} catch (err) {
|
|
2856
|
+
return null;
|
|
1147
2857
|
}
|
|
2858
|
+
}
|
|
2859
|
+
});
|
|
2860
|
+
}
|
|
2861
|
+
function getStatsQueryOptions({
|
|
2862
|
+
url,
|
|
2863
|
+
dimensions = [],
|
|
2864
|
+
metrics = ["visitors", "pageviews", "visit_duration"],
|
|
2865
|
+
enabled = true
|
|
2866
|
+
}) {
|
|
2867
|
+
return queryOptions({
|
|
2868
|
+
queryKey: ["integrations", "plausible", url, dimensions, metrics],
|
|
2869
|
+
queryFn: async () => {
|
|
2870
|
+
const fetchApi = getBoundFetch();
|
|
2871
|
+
const response = await fetchApi(`https://ecency.com/api/stats`, {
|
|
2872
|
+
method: "POST",
|
|
2873
|
+
body: JSON.stringify({
|
|
2874
|
+
metrics,
|
|
2875
|
+
url: encodeURIComponent(url),
|
|
2876
|
+
dimensions
|
|
2877
|
+
}),
|
|
2878
|
+
headers: {
|
|
2879
|
+
"Content-Type": "application/json"
|
|
2880
|
+
}
|
|
2881
|
+
});
|
|
2882
|
+
return await response.json();
|
|
1148
2883
|
},
|
|
1149
|
-
|
|
1150
|
-
onSuccess: options.onSuccess
|
|
2884
|
+
enabled: !!url && enabled
|
|
1151
2885
|
});
|
|
1152
2886
|
}
|
|
1153
|
-
function
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
const prepareAuth = (keyName) => {
|
|
1164
|
-
const auth = R4.clone(accountData[keyName]);
|
|
1165
|
-
auth.key_auths = auth.key_auths.filter(
|
|
1166
|
-
([key]) => key !== revokingKey.toString()
|
|
1167
|
-
);
|
|
1168
|
-
return auth;
|
|
1169
|
-
};
|
|
1170
|
-
return CONFIG.hiveClient.broadcast.updateAccount(
|
|
1171
|
-
{
|
|
1172
|
-
account: accountData.name,
|
|
1173
|
-
json_metadata: accountData.json_metadata,
|
|
1174
|
-
owner: prepareAuth("owner"),
|
|
1175
|
-
active: prepareAuth("active"),
|
|
1176
|
-
posting: prepareAuth("posting"),
|
|
1177
|
-
memo_key: accountData.memo_key
|
|
1178
|
-
},
|
|
1179
|
-
currentKey
|
|
2887
|
+
function getRcStatsQueryOptions() {
|
|
2888
|
+
return queryOptions({
|
|
2889
|
+
queryKey: ["resource-credits", "stats"],
|
|
2890
|
+
queryFn: async () => {
|
|
2891
|
+
const response = await CONFIG.hiveClient.call(
|
|
2892
|
+
"rc_api",
|
|
2893
|
+
"get_rc_stats",
|
|
2894
|
+
{}
|
|
1180
2895
|
);
|
|
2896
|
+
return response.rc_stats;
|
|
2897
|
+
}
|
|
2898
|
+
});
|
|
2899
|
+
}
|
|
2900
|
+
function getAccountRcQueryOptions(username) {
|
|
2901
|
+
return queryOptions({
|
|
2902
|
+
queryKey: ["resource-credits", "account", username],
|
|
2903
|
+
queryFn: async () => {
|
|
2904
|
+
const rcClient = new RCAPI(CONFIG.hiveClient);
|
|
2905
|
+
return rcClient.findRCAccounts([username]);
|
|
1181
2906
|
},
|
|
1182
|
-
|
|
2907
|
+
enabled: !!username
|
|
1183
2908
|
});
|
|
1184
2909
|
}
|
|
1185
|
-
function
|
|
1186
|
-
return
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
keyOrSeed
|
|
1191
|
-
}) => {
|
|
2910
|
+
function getGameStatusCheckQueryOptions(username, gameType) {
|
|
2911
|
+
return queryOptions({
|
|
2912
|
+
queryKey: ["games", "status-check", gameType, username],
|
|
2913
|
+
enabled: !!username,
|
|
2914
|
+
queryFn: async () => {
|
|
1192
2915
|
if (!username) {
|
|
1193
|
-
throw new Error("[
|
|
1194
|
-
}
|
|
1195
|
-
let privateKey;
|
|
1196
|
-
if (keyOrSeed.split(" ").length === 12) {
|
|
1197
|
-
privateKey = PrivateKey.fromLogin(username, keyOrSeed, "active");
|
|
1198
|
-
} else if (cryptoUtils.isWif(keyOrSeed)) {
|
|
1199
|
-
privateKey = PrivateKey.fromString(keyOrSeed);
|
|
1200
|
-
} else {
|
|
1201
|
-
privateKey = PrivateKey.from(keyOrSeed);
|
|
2916
|
+
throw new Error("[SDK][Games] \u2013 anon user in status check");
|
|
1202
2917
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
2918
|
+
const fetchApi = getBoundFetch();
|
|
2919
|
+
const response = await fetchApi(
|
|
2920
|
+
CONFIG.privateApiHost + "/private-api/get-game",
|
|
2921
|
+
{
|
|
2922
|
+
method: "POST",
|
|
2923
|
+
body: JSON.stringify({
|
|
2924
|
+
game_type: gameType,
|
|
2925
|
+
code: getAccessToken(username)
|
|
2926
|
+
}),
|
|
2927
|
+
headers: {
|
|
2928
|
+
"Content-Type": "application/json"
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
1206
2931
|
);
|
|
2932
|
+
return await response.json();
|
|
1207
2933
|
}
|
|
1208
2934
|
});
|
|
1209
2935
|
}
|
|
1210
|
-
function
|
|
2936
|
+
function useGameClaim(username, gameType, key) {
|
|
2937
|
+
const { mutateAsync: recordActivity } = useRecordActivity(
|
|
2938
|
+
username,
|
|
2939
|
+
"spin-rolled"
|
|
2940
|
+
);
|
|
1211
2941
|
return useMutation({
|
|
1212
|
-
mutationKey: ["
|
|
1213
|
-
mutationFn: (
|
|
2942
|
+
mutationKey: ["games", "post", gameType, username],
|
|
2943
|
+
mutationFn: async () => {
|
|
1214
2944
|
if (!username) {
|
|
1215
|
-
throw new Error(
|
|
1216
|
-
"[SDK][Keychain] \u2013\xA0cannot sign operation with anon user"
|
|
1217
|
-
);
|
|
2945
|
+
throw new Error("[SDK][Games] \u2013 anon user in game post");
|
|
1218
2946
|
}
|
|
1219
|
-
|
|
2947
|
+
const fetchApi = getBoundFetch();
|
|
2948
|
+
const response = await fetchApi(
|
|
2949
|
+
CONFIG.privateApiHost + "/private-api/post-game",
|
|
2950
|
+
{
|
|
2951
|
+
method: "POST",
|
|
2952
|
+
body: JSON.stringify({
|
|
2953
|
+
game_type: gameType,
|
|
2954
|
+
code: getAccessToken(username),
|
|
2955
|
+
key
|
|
2956
|
+
}),
|
|
2957
|
+
headers: {
|
|
2958
|
+
"Content-Type": "application/json"
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
);
|
|
2962
|
+
return await response.json();
|
|
2963
|
+
},
|
|
2964
|
+
onSuccess() {
|
|
2965
|
+
recordActivity();
|
|
1220
2966
|
}
|
|
1221
2967
|
});
|
|
1222
2968
|
}
|
|
1223
|
-
function
|
|
1224
|
-
return
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
2969
|
+
function getCommunitiesQueryOptions(sort, query, limit = 100, observer = void 0, enabled = true) {
|
|
2970
|
+
return queryOptions({
|
|
2971
|
+
queryKey: ["communities", "list", sort, query, limit],
|
|
2972
|
+
enabled,
|
|
2973
|
+
queryFn: async () => {
|
|
2974
|
+
const response = await CONFIG.hiveClient.call(
|
|
2975
|
+
"bridge",
|
|
2976
|
+
"list_communities",
|
|
2977
|
+
{
|
|
2978
|
+
last: "",
|
|
2979
|
+
limit,
|
|
2980
|
+
sort: sort === "hot" ? "rank" : sort,
|
|
2981
|
+
query: query ? query : null,
|
|
2982
|
+
observer
|
|
2983
|
+
}
|
|
2984
|
+
);
|
|
2985
|
+
return response ? sort === "hot" ? response.sort(() => Math.random() - 0.5) : response : [];
|
|
1229
2986
|
}
|
|
1230
2987
|
});
|
|
1231
2988
|
}
|
|
1232
|
-
function
|
|
2989
|
+
function getCommunityContextQueryOptions(username, communityName) {
|
|
1233
2990
|
return queryOptions({
|
|
1234
|
-
queryKey: ["
|
|
2991
|
+
queryKey: ["community", "context", username, communityName],
|
|
2992
|
+
enabled: !!username && !!communityName,
|
|
1235
2993
|
queryFn: async () => {
|
|
1236
|
-
|
|
2994
|
+
const response = await CONFIG.hiveClient.call(
|
|
2995
|
+
"bridge",
|
|
2996
|
+
"get_community_context",
|
|
2997
|
+
{
|
|
2998
|
+
account: username,
|
|
2999
|
+
name: communityName
|
|
3000
|
+
}
|
|
3001
|
+
);
|
|
3002
|
+
return {
|
|
3003
|
+
role: response?.role ?? "guest",
|
|
3004
|
+
subscribed: response?.subscribed ?? false
|
|
3005
|
+
};
|
|
1237
3006
|
}
|
|
1238
3007
|
});
|
|
1239
3008
|
}
|
|
1240
|
-
function
|
|
3009
|
+
function getCommunitySubscribersQueryOptions(communityName) {
|
|
3010
|
+
return queryOptions({
|
|
3011
|
+
queryKey: ["communities", "subscribers", communityName],
|
|
3012
|
+
queryFn: async () => {
|
|
3013
|
+
const response = await CONFIG.hiveClient.call("bridge", "list_subscribers", {
|
|
3014
|
+
community: communityName
|
|
3015
|
+
});
|
|
3016
|
+
return response ?? [];
|
|
3017
|
+
},
|
|
3018
|
+
staleTime: 6e4
|
|
3019
|
+
});
|
|
3020
|
+
}
|
|
3021
|
+
function getAccountNotificationsInfiniteQueryOptions(account, limit) {
|
|
1241
3022
|
return infiniteQueryOptions({
|
|
1242
|
-
queryKey: ["
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
3023
|
+
queryKey: ["communities", "account-notifications", account, limit],
|
|
3024
|
+
initialPageParam: null,
|
|
3025
|
+
queryFn: async ({ pageParam }) => {
|
|
3026
|
+
try {
|
|
3027
|
+
const response = await CONFIG.hiveClient.call("bridge", "account_notifications", {
|
|
3028
|
+
account,
|
|
3029
|
+
limit,
|
|
3030
|
+
last_id: pageParam ?? void 0
|
|
3031
|
+
});
|
|
3032
|
+
return response ?? [];
|
|
3033
|
+
} catch {
|
|
3034
|
+
return [];
|
|
3035
|
+
}
|
|
3036
|
+
},
|
|
3037
|
+
getNextPageParam: (lastPage) => lastPage?.length > 0 ? lastPage[lastPage.length - 1].id : null
|
|
1252
3038
|
});
|
|
1253
3039
|
}
|
|
1254
|
-
function
|
|
3040
|
+
function getRewardedCommunitiesQueryOptions() {
|
|
1255
3041
|
return queryOptions({
|
|
1256
|
-
queryKey: ["
|
|
3042
|
+
queryKey: ["communities", "rewarded"],
|
|
1257
3043
|
queryFn: async () => {
|
|
1258
|
-
const
|
|
1259
|
-
|
|
1260
|
-
CONFIG.privateApiHost + "/private-api/fragments",
|
|
3044
|
+
const response = await fetch(
|
|
3045
|
+
CONFIG.privateApiHost + "/private-api/rewarded-communities",
|
|
1261
3046
|
{
|
|
1262
|
-
method: "
|
|
1263
|
-
body: JSON.stringify({
|
|
1264
|
-
code: getAccessToken(username)
|
|
1265
|
-
}),
|
|
3047
|
+
method: "GET",
|
|
1266
3048
|
headers: {
|
|
1267
3049
|
"Content-Type": "application/json"
|
|
1268
3050
|
}
|
|
1269
3051
|
}
|
|
1270
3052
|
);
|
|
3053
|
+
if (!response.ok) {
|
|
3054
|
+
throw new Error(`Failed to fetch rewarded communities: ${response.status}`);
|
|
3055
|
+
}
|
|
1271
3056
|
return response.json();
|
|
1272
|
-
}
|
|
1273
|
-
enabled: !!username
|
|
3057
|
+
}
|
|
1274
3058
|
});
|
|
1275
3059
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
3060
|
+
|
|
3061
|
+
// src/modules/communities/types/community.ts
|
|
3062
|
+
var ROLES = /* @__PURE__ */ ((ROLES2) => {
|
|
3063
|
+
ROLES2["OWNER"] = "owner";
|
|
3064
|
+
ROLES2["ADMIN"] = "admin";
|
|
3065
|
+
ROLES2["MOD"] = "mod";
|
|
3066
|
+
ROLES2["MEMBER"] = "member";
|
|
3067
|
+
ROLES2["GUEST"] = "guest";
|
|
3068
|
+
ROLES2["MUTED"] = "muted";
|
|
3069
|
+
return ROLES2;
|
|
3070
|
+
})(ROLES || {});
|
|
3071
|
+
var roleMap = {
|
|
3072
|
+
["owner" /* OWNER */]: [
|
|
3073
|
+
"admin" /* ADMIN */,
|
|
3074
|
+
"mod" /* MOD */,
|
|
3075
|
+
"member" /* MEMBER */,
|
|
3076
|
+
"guest" /* GUEST */,
|
|
3077
|
+
"muted" /* MUTED */
|
|
3078
|
+
],
|
|
3079
|
+
["admin" /* ADMIN */]: ["mod" /* MOD */, "member" /* MEMBER */, "guest" /* GUEST */, "muted" /* MUTED */],
|
|
3080
|
+
["mod" /* MOD */]: ["member" /* MEMBER */, "guest" /* GUEST */, "muted" /* MUTED */]
|
|
3081
|
+
};
|
|
3082
|
+
|
|
3083
|
+
// src/modules/communities/utils/index.ts
|
|
3084
|
+
function getCommunityType(name, type_id) {
|
|
3085
|
+
if (name.startsWith("hive-3") || type_id === 3) return "Council";
|
|
3086
|
+
if (name.startsWith("hive-2") || type_id === 2) return "Journal";
|
|
3087
|
+
return "Topic";
|
|
3088
|
+
}
|
|
3089
|
+
function getCommunityPermissions({
|
|
3090
|
+
communityType,
|
|
3091
|
+
userRole,
|
|
3092
|
+
subscribed
|
|
3093
|
+
}) {
|
|
3094
|
+
const canPost = (() => {
|
|
3095
|
+
if (userRole === "muted" /* MUTED */) return false;
|
|
3096
|
+
if (communityType === "Topic") return true;
|
|
3097
|
+
return ["owner" /* OWNER */, "admin" /* ADMIN */, "mod" /* MOD */, "member" /* MEMBER */].includes(
|
|
3098
|
+
userRole
|
|
3099
|
+
);
|
|
3100
|
+
})();
|
|
3101
|
+
const canComment = (() => {
|
|
3102
|
+
if (userRole === "muted" /* MUTED */) return false;
|
|
3103
|
+
switch (communityType) {
|
|
3104
|
+
case "Topic":
|
|
3105
|
+
return true;
|
|
3106
|
+
case "Journal":
|
|
3107
|
+
return userRole !== "guest" /* GUEST */ || subscribed;
|
|
3108
|
+
case "Council":
|
|
3109
|
+
return canPost;
|
|
1295
3110
|
}
|
|
1296
|
-
});
|
|
3111
|
+
})();
|
|
3112
|
+
const isModerator = ["owner" /* OWNER */, "admin" /* ADMIN */, "mod" /* MOD */].includes(userRole);
|
|
3113
|
+
return {
|
|
3114
|
+
canPost,
|
|
3115
|
+
canComment,
|
|
3116
|
+
isModerator
|
|
3117
|
+
};
|
|
1297
3118
|
}
|
|
1298
|
-
function
|
|
1299
|
-
return
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
const
|
|
1303
|
-
|
|
1304
|
-
CONFIG.privateApiHost + "/private-api/fragments-add",
|
|
3119
|
+
function getNotificationsUnreadCountQueryOptions(activeUsername) {
|
|
3120
|
+
return queryOptions({
|
|
3121
|
+
queryKey: ["notifications", "unread", activeUsername],
|
|
3122
|
+
queryFn: async () => {
|
|
3123
|
+
const response = await fetch(
|
|
3124
|
+
`${CONFIG.privateApiHost}/private-api/notifications/unread`,
|
|
1305
3125
|
{
|
|
1306
3126
|
method: "POST",
|
|
1307
|
-
body: JSON.stringify({
|
|
1308
|
-
code: getAccessToken(username),
|
|
1309
|
-
title,
|
|
1310
|
-
body
|
|
1311
|
-
}),
|
|
3127
|
+
body: JSON.stringify({ code: getAccessToken(activeUsername) }),
|
|
1312
3128
|
headers: {
|
|
1313
3129
|
"Content-Type": "application/json"
|
|
1314
3130
|
}
|
|
1315
3131
|
}
|
|
1316
3132
|
);
|
|
1317
|
-
|
|
3133
|
+
const data = await response.json();
|
|
3134
|
+
return data.count;
|
|
1318
3135
|
},
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
(data) => [response, ...data ?? []]
|
|
1323
|
-
);
|
|
1324
|
-
}
|
|
3136
|
+
enabled: !!activeUsername,
|
|
3137
|
+
initialData: 0,
|
|
3138
|
+
refetchInterval: 6e4
|
|
1325
3139
|
});
|
|
1326
3140
|
}
|
|
1327
|
-
function
|
|
1328
|
-
return
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
const
|
|
1332
|
-
|
|
1333
|
-
|
|
3141
|
+
function getNotificationsInfiniteQueryOptions(activeUsername, filter = void 0) {
|
|
3142
|
+
return infiniteQueryOptions({
|
|
3143
|
+
queryKey: ["notifications", activeUsername, filter],
|
|
3144
|
+
queryFn: async ({ pageParam }) => {
|
|
3145
|
+
const data = {
|
|
3146
|
+
code: getAccessToken(activeUsername),
|
|
3147
|
+
filter,
|
|
3148
|
+
since: pageParam,
|
|
3149
|
+
user: void 0
|
|
3150
|
+
};
|
|
3151
|
+
const response = await fetch(
|
|
3152
|
+
CONFIG.privateApiHost + "/private-api/notifications",
|
|
1334
3153
|
{
|
|
1335
3154
|
method: "POST",
|
|
1336
|
-
body: JSON.stringify({
|
|
1337
|
-
code: getAccessToken(username),
|
|
1338
|
-
id: fragmentId,
|
|
1339
|
-
title,
|
|
1340
|
-
body
|
|
1341
|
-
}),
|
|
1342
3155
|
headers: {
|
|
1343
3156
|
"Content-Type": "application/json"
|
|
1344
|
-
}
|
|
3157
|
+
},
|
|
3158
|
+
body: JSON.stringify(data)
|
|
1345
3159
|
}
|
|
1346
3160
|
);
|
|
1347
3161
|
return response.json();
|
|
1348
3162
|
},
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
3163
|
+
enabled: !!activeUsername,
|
|
3164
|
+
initialData: { pages: [], pageParams: [] },
|
|
3165
|
+
initialPageParam: "",
|
|
3166
|
+
getNextPageParam: (lastPage) => lastPage?.[lastPage.length - 1]?.id ?? "",
|
|
3167
|
+
refetchOnMount: true
|
|
3168
|
+
});
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
// src/modules/notifications/enums/notification-filter.ts
|
|
3172
|
+
var NotificationFilter = /* @__PURE__ */ ((NotificationFilter2) => {
|
|
3173
|
+
NotificationFilter2["VOTES"] = "rvotes";
|
|
3174
|
+
NotificationFilter2["MENTIONS"] = "mentions";
|
|
3175
|
+
NotificationFilter2["FAVORITES"] = "nfavorites";
|
|
3176
|
+
NotificationFilter2["BOOKMARKS"] = "nbookmarks";
|
|
3177
|
+
NotificationFilter2["FOLLOWS"] = "follows";
|
|
3178
|
+
NotificationFilter2["REPLIES"] = "replies";
|
|
3179
|
+
NotificationFilter2["REBLOGS"] = "reblogs";
|
|
3180
|
+
NotificationFilter2["TRANSFERS"] = "transfers";
|
|
3181
|
+
NotificationFilter2["DELEGATIONS"] = "delegations";
|
|
3182
|
+
return NotificationFilter2;
|
|
3183
|
+
})(NotificationFilter || {});
|
|
3184
|
+
|
|
3185
|
+
// src/modules/notifications/enums/notify-types.ts
|
|
3186
|
+
var NotifyTypes = /* @__PURE__ */ ((NotifyTypes2) => {
|
|
3187
|
+
NotifyTypes2[NotifyTypes2["VOTE"] = 1] = "VOTE";
|
|
3188
|
+
NotifyTypes2[NotifyTypes2["MENTION"] = 2] = "MENTION";
|
|
3189
|
+
NotifyTypes2[NotifyTypes2["FOLLOW"] = 3] = "FOLLOW";
|
|
3190
|
+
NotifyTypes2[NotifyTypes2["COMMENT"] = 4] = "COMMENT";
|
|
3191
|
+
NotifyTypes2[NotifyTypes2["RE_BLOG"] = 5] = "RE_BLOG";
|
|
3192
|
+
NotifyTypes2[NotifyTypes2["TRANSFERS"] = 6] = "TRANSFERS";
|
|
3193
|
+
NotifyTypes2[NotifyTypes2["FAVORITES"] = 13] = "FAVORITES";
|
|
3194
|
+
NotifyTypes2[NotifyTypes2["BOOKMARKS"] = 15] = "BOOKMARKS";
|
|
3195
|
+
NotifyTypes2["ALLOW_NOTIFY"] = "ALLOW_NOTIFY";
|
|
3196
|
+
return NotifyTypes2;
|
|
3197
|
+
})(NotifyTypes || {});
|
|
3198
|
+
var ALL_NOTIFY_TYPES = [
|
|
3199
|
+
1 /* VOTE */,
|
|
3200
|
+
2 /* MENTION */,
|
|
3201
|
+
3 /* FOLLOW */,
|
|
3202
|
+
4 /* COMMENT */,
|
|
3203
|
+
5 /* RE_BLOG */,
|
|
3204
|
+
6 /* TRANSFERS */,
|
|
3205
|
+
13 /* FAVORITES */,
|
|
3206
|
+
15 /* BOOKMARKS */
|
|
3207
|
+
];
|
|
3208
|
+
var NotificationViewType = /* @__PURE__ */ ((NotificationViewType2) => {
|
|
3209
|
+
NotificationViewType2["ALL"] = "All";
|
|
3210
|
+
NotificationViewType2["UNREAD"] = "Unread";
|
|
3211
|
+
NotificationViewType2["READ"] = "Read";
|
|
3212
|
+
return NotificationViewType2;
|
|
3213
|
+
})(NotificationViewType || {});
|
|
3214
|
+
|
|
3215
|
+
// src/modules/notifications/queries/get-notifications-settings-query-options.ts
|
|
3216
|
+
function getNotificationsSettingsQueryOptions(activeUsername) {
|
|
3217
|
+
return queryOptions({
|
|
3218
|
+
queryKey: ["notifications", "settings", activeUsername],
|
|
3219
|
+
queryFn: async () => {
|
|
3220
|
+
let token = activeUsername + "-web";
|
|
3221
|
+
const response = await fetch(
|
|
3222
|
+
CONFIG.privateApiHost + "/private-api/detail-device",
|
|
3223
|
+
{
|
|
3224
|
+
body: JSON.stringify({
|
|
3225
|
+
code: getAccessToken(activeUsername),
|
|
3226
|
+
username: activeUsername,
|
|
3227
|
+
token
|
|
3228
|
+
}),
|
|
3229
|
+
method: "POST",
|
|
3230
|
+
headers: {
|
|
3231
|
+
"Content-Type": "application/json"
|
|
1359
3232
|
}
|
|
1360
|
-
return [...data];
|
|
1361
3233
|
}
|
|
1362
3234
|
);
|
|
3235
|
+
if (!response.ok) {
|
|
3236
|
+
throw new Error(`Failed to fetch notification settings: ${response.status}`);
|
|
3237
|
+
}
|
|
3238
|
+
return response.json();
|
|
3239
|
+
},
|
|
3240
|
+
enabled: !!activeUsername,
|
|
3241
|
+
refetchOnMount: false,
|
|
3242
|
+
initialData: () => {
|
|
3243
|
+
const wasMutedPreviously = typeof window !== "undefined" ? localStorage.getItem("notifications") !== "true" : false;
|
|
3244
|
+
return {
|
|
3245
|
+
status: 0,
|
|
3246
|
+
system: "web",
|
|
3247
|
+
allows_notify: 0,
|
|
3248
|
+
notify_types: wasMutedPreviously ? [] : [
|
|
3249
|
+
4 /* COMMENT */,
|
|
3250
|
+
3 /* FOLLOW */,
|
|
3251
|
+
2 /* MENTION */,
|
|
3252
|
+
13 /* FAVORITES */,
|
|
3253
|
+
15 /* BOOKMARKS */,
|
|
3254
|
+
1 /* VOTE */,
|
|
3255
|
+
5 /* RE_BLOG */,
|
|
3256
|
+
6 /* TRANSFERS */
|
|
3257
|
+
]
|
|
3258
|
+
};
|
|
1363
3259
|
}
|
|
1364
3260
|
});
|
|
1365
3261
|
}
|
|
1366
|
-
function
|
|
1367
|
-
return
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1372
|
-
method: "POST",
|
|
1373
|
-
body: JSON.stringify({
|
|
1374
|
-
code: getAccessToken(username),
|
|
1375
|
-
id: fragmentId
|
|
1376
|
-
}),
|
|
3262
|
+
function getAnnouncementsQueryOptions() {
|
|
3263
|
+
return queryOptions({
|
|
3264
|
+
queryKey: ["notifications", "announcements"],
|
|
3265
|
+
queryFn: async () => {
|
|
3266
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/announcements", {
|
|
3267
|
+
method: "GET",
|
|
1377
3268
|
headers: {
|
|
1378
3269
|
"Content-Type": "application/json"
|
|
1379
3270
|
}
|
|
1380
3271
|
});
|
|
3272
|
+
if (!response.ok) {
|
|
3273
|
+
throw new Error(`Failed to fetch announcements: ${response.status}`);
|
|
3274
|
+
}
|
|
3275
|
+
const data = await response.json();
|
|
3276
|
+
return data || [];
|
|
1381
3277
|
},
|
|
1382
|
-
|
|
1383
|
-
getQueryClient().setQueryData(
|
|
1384
|
-
getFragmentsQueryOptions(username).queryKey,
|
|
1385
|
-
(data) => [...data ?? []].filter(({ id }) => id !== fragmentId)
|
|
1386
|
-
);
|
|
1387
|
-
}
|
|
3278
|
+
staleTime: 36e5
|
|
1388
3279
|
});
|
|
1389
3280
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
3281
|
+
function getProposalQueryOptions(id) {
|
|
3282
|
+
return queryOptions({
|
|
3283
|
+
queryKey: ["proposals", "proposal", id],
|
|
3284
|
+
queryFn: async () => {
|
|
3285
|
+
const r = await CONFIG.hiveClient.call("condenser_api", "find_proposals", [[id]]);
|
|
3286
|
+
const proposal = r[0];
|
|
3287
|
+
if (new Date(proposal.start_date) < /* @__PURE__ */ new Date() && new Date(proposal.end_date) >= /* @__PURE__ */ new Date()) {
|
|
3288
|
+
proposal.status = "active";
|
|
3289
|
+
} else if (new Date(proposal.end_date) < /* @__PURE__ */ new Date()) {
|
|
3290
|
+
proposal.status = "expired";
|
|
3291
|
+
} else {
|
|
3292
|
+
proposal.status = "inactive";
|
|
1402
3293
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
3294
|
+
return proposal;
|
|
3295
|
+
}
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3298
|
+
function getProposalsQueryOptions() {
|
|
3299
|
+
return queryOptions({
|
|
3300
|
+
queryKey: ["proposals", "list"],
|
|
3301
|
+
queryFn: async () => {
|
|
3302
|
+
const response = await CONFIG.hiveClient.call("database_api", "list_proposals", {
|
|
3303
|
+
start: [-1],
|
|
3304
|
+
limit: 500,
|
|
3305
|
+
order: "by_total_votes",
|
|
3306
|
+
order_direction: "descending",
|
|
3307
|
+
status: "all"
|
|
1417
3308
|
});
|
|
3309
|
+
const proposals = response.proposals;
|
|
3310
|
+
const expired = proposals.filter((x) => x.status === "expired");
|
|
3311
|
+
const others = proposals.filter((x) => x.status !== "expired");
|
|
3312
|
+
return [...others, ...expired];
|
|
1418
3313
|
}
|
|
1419
3314
|
});
|
|
1420
3315
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
3316
|
+
function getProposalVotesInfiniteQueryOptions(proposalId, voter, limit) {
|
|
3317
|
+
return infiniteQueryOptions({
|
|
3318
|
+
queryKey: ["proposals", "votes", proposalId, voter, limit],
|
|
3319
|
+
initialPageParam: voter,
|
|
3320
|
+
refetchOnMount: true,
|
|
3321
|
+
staleTime: 0,
|
|
3322
|
+
// Always refetch on mount
|
|
3323
|
+
queryFn: async ({ pageParam }) => {
|
|
3324
|
+
const startParam = pageParam ?? voter;
|
|
3325
|
+
const response = await CONFIG.hiveClient.call("condenser_api", "list_proposal_votes", [
|
|
3326
|
+
[proposalId, startParam],
|
|
3327
|
+
limit,
|
|
3328
|
+
"by_proposal_voter"
|
|
3329
|
+
]);
|
|
3330
|
+
const list = response.filter((x) => x.proposal?.proposal_id === proposalId).map((x) => ({ id: x.id, voter: x.voter }));
|
|
3331
|
+
const rawAccounts = await CONFIG.hiveClient.database.getAccounts(list.map((l) => l.voter));
|
|
3332
|
+
const accounts = parseAccounts(rawAccounts);
|
|
3333
|
+
const page = list.map((i) => ({
|
|
3334
|
+
...i,
|
|
3335
|
+
voterAccount: accounts.find((a) => i.voter === a.name)
|
|
3336
|
+
}));
|
|
3337
|
+
return page;
|
|
3338
|
+
},
|
|
3339
|
+
getNextPageParam: (lastPage) => {
|
|
3340
|
+
const last = lastPage?.[lastPage.length - 1];
|
|
3341
|
+
return last?.voter ?? void 0;
|
|
3342
|
+
}
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
function getUserProposalVotesQueryOptions(voter) {
|
|
1435
3346
|
return queryOptions({
|
|
1436
|
-
queryKey: ["
|
|
3347
|
+
queryKey: ["proposals", "votes", "by-user", voter],
|
|
3348
|
+
enabled: !!voter && voter !== "",
|
|
3349
|
+
staleTime: 60 * 1e3,
|
|
3350
|
+
// Cache for 1 minute
|
|
1437
3351
|
queryFn: async () => {
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
const hsClient = new hs.Client({
|
|
1441
|
-
accessToken
|
|
1442
|
-
});
|
|
1443
|
-
return hsClient.decode(memo);
|
|
3352
|
+
if (!voter || voter === "") {
|
|
3353
|
+
return [];
|
|
1444
3354
|
}
|
|
3355
|
+
const response = await CONFIG.hiveClient.call("database_api", "list_proposal_votes", {
|
|
3356
|
+
start: [voter],
|
|
3357
|
+
limit: 1e3,
|
|
3358
|
+
order: "by_voter_proposal",
|
|
3359
|
+
order_direction: "ascending",
|
|
3360
|
+
status: "votable"
|
|
3361
|
+
});
|
|
3362
|
+
const userVotes = (response.proposal_votes || []).filter((vote) => vote.voter === voter);
|
|
3363
|
+
return userVotes;
|
|
1445
3364
|
}
|
|
1446
3365
|
});
|
|
1447
3366
|
}
|
|
1448
|
-
|
|
1449
|
-
// src/modules/integrations/hivesigner/index.ts
|
|
1450
|
-
var HiveSignerIntegration = {
|
|
1451
|
-
queries: queries_exports
|
|
1452
|
-
};
|
|
1453
|
-
|
|
1454
|
-
// src/modules/integrations/3speak/queries/get-account-token-query-options.ts
|
|
1455
|
-
function getAccountTokenQueryOptions(username) {
|
|
3367
|
+
function getVestingDelegationsQueryOptions(username, from, limit = 50) {
|
|
1456
3368
|
return queryOptions({
|
|
1457
|
-
queryKey: ["
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
3369
|
+
queryKey: ["wallet", "vesting-delegations", username, from, limit],
|
|
3370
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_vesting_delegations", [
|
|
3371
|
+
username,
|
|
3372
|
+
from,
|
|
3373
|
+
limit
|
|
3374
|
+
]),
|
|
3375
|
+
enabled: !!username
|
|
3376
|
+
});
|
|
3377
|
+
}
|
|
3378
|
+
function getConversionRequestsQueryOptions(account) {
|
|
3379
|
+
return queryOptions({
|
|
3380
|
+
queryKey: ["wallet", "conversion-requests", account],
|
|
3381
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_conversion_requests", [
|
|
3382
|
+
account
|
|
3383
|
+
]),
|
|
3384
|
+
select: (data) => data.sort((a, b) => a.requestid - b.requestid)
|
|
3385
|
+
});
|
|
3386
|
+
}
|
|
3387
|
+
function getCollateralizedConversionRequestsQueryOptions(account) {
|
|
3388
|
+
return queryOptions({
|
|
3389
|
+
queryKey: ["wallet", "collateralized-conversion-requests", account],
|
|
3390
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_collateralized_conversion_requests", [
|
|
3391
|
+
account
|
|
3392
|
+
]),
|
|
3393
|
+
select: (data) => data.sort((a, b) => a.requestid - b.requestid)
|
|
3394
|
+
});
|
|
3395
|
+
}
|
|
3396
|
+
function getSavingsWithdrawFromQueryOptions(account) {
|
|
3397
|
+
return queryOptions({
|
|
3398
|
+
queryKey: ["wallet", "savings-withdraw", account],
|
|
3399
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_savings_withdraw_from", [
|
|
3400
|
+
account
|
|
3401
|
+
]),
|
|
3402
|
+
select: (data) => data.sort((a, b) => a.request_id - b.request_id)
|
|
3403
|
+
});
|
|
3404
|
+
}
|
|
3405
|
+
function getWithdrawRoutesQueryOptions(account) {
|
|
3406
|
+
return queryOptions({
|
|
3407
|
+
queryKey: ["wallet", "withdraw-routes", account],
|
|
3408
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_withdraw_routes", [
|
|
3409
|
+
account,
|
|
3410
|
+
"outgoing"
|
|
3411
|
+
])
|
|
3412
|
+
});
|
|
3413
|
+
}
|
|
3414
|
+
function getOpenOrdersQueryOptions(user) {
|
|
3415
|
+
return queryOptions({
|
|
3416
|
+
queryKey: ["wallet", "open-orders", user],
|
|
3417
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_open_orders", [
|
|
3418
|
+
user
|
|
3419
|
+
]),
|
|
3420
|
+
select: (data) => data.sort((a, b) => a.orderid - b.orderid),
|
|
3421
|
+
enabled: !!user
|
|
3422
|
+
});
|
|
3423
|
+
}
|
|
3424
|
+
function getOutgoingRcDelegationsInfiniteQueryOptions(username, limit = 100) {
|
|
3425
|
+
return infiniteQueryOptions({
|
|
3426
|
+
queryKey: ["wallet", "outgoing-rc-delegations", username, limit],
|
|
3427
|
+
initialPageParam: null,
|
|
3428
|
+
queryFn: async ({ pageParam }) => {
|
|
3429
|
+
const response = await CONFIG.hiveClient.call("rc_api", "list_rc_direct_delegations", {
|
|
3430
|
+
start: [username, pageParam ?? ""],
|
|
3431
|
+
limit
|
|
3432
|
+
}).then((r) => r);
|
|
3433
|
+
let delegations = response.rc_direct_delegations || [];
|
|
3434
|
+
if (pageParam) {
|
|
3435
|
+
delegations = delegations.filter((delegation) => delegation.to !== pageParam);
|
|
1462
3436
|
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
const
|
|
1473
|
-
username
|
|
1474
|
-
(await response.json()).memo
|
|
1475
|
-
);
|
|
1476
|
-
await getQueryClient().prefetchQuery(memoQueryOptions);
|
|
1477
|
-
const { memoDecoded } = getQueryClient().getQueryData(
|
|
1478
|
-
memoQueryOptions.queryKey
|
|
3437
|
+
return delegations;
|
|
3438
|
+
},
|
|
3439
|
+
getNextPageParam: (lastPage) => lastPage.length === limit ? lastPage[lastPage.length - 1].to : null
|
|
3440
|
+
});
|
|
3441
|
+
}
|
|
3442
|
+
function getReceivedVestingSharesQueryOptions(username) {
|
|
3443
|
+
return queryOptions({
|
|
3444
|
+
queryKey: ["wallet", "received-vesting-shares", username],
|
|
3445
|
+
queryFn: async () => {
|
|
3446
|
+
const response = await fetch(
|
|
3447
|
+
CONFIG.privateApiHost + `/private-api/received-vesting/${username}`
|
|
1479
3448
|
);
|
|
1480
|
-
|
|
3449
|
+
if (!response.ok) {
|
|
3450
|
+
throw new Error(`Failed to fetch received vesting shares: ${response.status}`);
|
|
3451
|
+
}
|
|
3452
|
+
const data = await response.json();
|
|
3453
|
+
return data.list;
|
|
1481
3454
|
}
|
|
1482
3455
|
});
|
|
1483
3456
|
}
|
|
1484
|
-
function
|
|
3457
|
+
function getWitnessesInfiniteQueryOptions(limit) {
|
|
3458
|
+
return infiniteQueryOptions({
|
|
3459
|
+
queryKey: ["witnesses", "list", limit],
|
|
3460
|
+
initialPageParam: "",
|
|
3461
|
+
queryFn: async ({ pageParam }) => CONFIG.hiveClient.call("condenser_api", "get_witnesses_by_vote", [
|
|
3462
|
+
pageParam,
|
|
3463
|
+
limit
|
|
3464
|
+
]),
|
|
3465
|
+
getNextPageParam: (lastPage) => {
|
|
3466
|
+
const last = lastPage?.[lastPage.length - 1];
|
|
3467
|
+
return last ? last.owner : void 0;
|
|
3468
|
+
}
|
|
3469
|
+
});
|
|
3470
|
+
}
|
|
3471
|
+
function getOrderBookQueryOptions(limit = 500) {
|
|
1485
3472
|
return queryOptions({
|
|
1486
|
-
queryKey: ["
|
|
1487
|
-
|
|
3473
|
+
queryKey: ["market", "order-book", limit],
|
|
3474
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_order_book", [
|
|
3475
|
+
limit
|
|
3476
|
+
])
|
|
3477
|
+
});
|
|
3478
|
+
}
|
|
3479
|
+
function getMarketStatisticsQueryOptions() {
|
|
3480
|
+
return queryOptions({
|
|
3481
|
+
queryKey: ["market", "statistics"],
|
|
3482
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_ticker", [])
|
|
3483
|
+
});
|
|
3484
|
+
}
|
|
3485
|
+
function getMarketHistoryQueryOptions(seconds, startDate, endDate) {
|
|
3486
|
+
const formatDate = (date) => {
|
|
3487
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
3488
|
+
};
|
|
3489
|
+
return queryOptions({
|
|
3490
|
+
queryKey: ["market", "history", seconds, startDate.getTime(), endDate.getTime()],
|
|
3491
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_market_history", [
|
|
3492
|
+
seconds,
|
|
3493
|
+
formatDate(startDate),
|
|
3494
|
+
formatDate(endDate)
|
|
3495
|
+
])
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
function getHiveHbdStatsQueryOptions() {
|
|
3499
|
+
return queryOptions({
|
|
3500
|
+
queryKey: ["market", "hive-hbd-stats"],
|
|
1488
3501
|
queryFn: async () => {
|
|
1489
|
-
await
|
|
1490
|
-
|
|
3502
|
+
const stats = await CONFIG.hiveClient.call(
|
|
3503
|
+
"condenser_api",
|
|
3504
|
+
"get_ticker",
|
|
3505
|
+
[]
|
|
1491
3506
|
);
|
|
1492
|
-
const
|
|
1493
|
-
|
|
3507
|
+
const now = /* @__PURE__ */ new Date();
|
|
3508
|
+
const oneDayAgo = new Date(now.getTime() - 864e5);
|
|
3509
|
+
const formatDate = (date) => {
|
|
3510
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
3511
|
+
};
|
|
3512
|
+
const dayChange = await CONFIG.hiveClient.call(
|
|
3513
|
+
"condenser_api",
|
|
3514
|
+
"get_market_history",
|
|
3515
|
+
[86400, formatDate(oneDayAgo), formatDate(now)]
|
|
1494
3516
|
);
|
|
1495
|
-
const
|
|
1496
|
-
|
|
1497
|
-
|
|
3517
|
+
const result = {
|
|
3518
|
+
price: +stats.latest,
|
|
3519
|
+
close: dayChange[0] ? dayChange[0].non_hive.open / dayChange[0].hive.open : 0,
|
|
3520
|
+
high: dayChange[0] ? dayChange[0].non_hive.high / dayChange[0].hive.high : 0,
|
|
3521
|
+
low: dayChange[0] ? dayChange[0].non_hive.low / dayChange[0].hive.low : 0,
|
|
3522
|
+
percent: dayChange[0] ? 100 - dayChange[0].non_hive.open / dayChange[0].hive.open * 100 / +stats.latest : 0,
|
|
3523
|
+
totalFromAsset: stats.hive_volume.split(" ")[0],
|
|
3524
|
+
totalToAsset: stats.hbd_volume.split(" ")[0]
|
|
3525
|
+
};
|
|
3526
|
+
return result;
|
|
3527
|
+
}
|
|
3528
|
+
});
|
|
3529
|
+
}
|
|
3530
|
+
function getMarketDataQueryOptions(coin, vsCurrency, fromTs, toTs) {
|
|
3531
|
+
return queryOptions({
|
|
3532
|
+
queryKey: ["market", "data", coin, vsCurrency, fromTs, toTs],
|
|
3533
|
+
queryFn: async ({ signal }) => {
|
|
3534
|
+
const url = `https://api.coingecko.com/api/v3/coins/${coin}/market_chart/range?vs_currency=${vsCurrency}&from=${fromTs}&to=${toTs}`;
|
|
3535
|
+
const response = await fetch(url, { signal });
|
|
3536
|
+
if (!response.ok) {
|
|
3537
|
+
throw new Error(`Failed to fetch market data: ${response.status}`);
|
|
3538
|
+
}
|
|
3539
|
+
return response.json();
|
|
3540
|
+
}
|
|
3541
|
+
});
|
|
3542
|
+
}
|
|
3543
|
+
function getPointsQueryOptions(username, filter = 0) {
|
|
3544
|
+
return queryOptions({
|
|
3545
|
+
queryKey: ["points", username, filter],
|
|
3546
|
+
queryFn: async () => {
|
|
3547
|
+
if (!username) {
|
|
3548
|
+
throw new Error("Get points query \u2013 username wasn't provided");
|
|
3549
|
+
}
|
|
3550
|
+
const name = username.replace("@", "");
|
|
3551
|
+
const pointsResponse = await fetch(CONFIG.privateApiHost + "/private-api/points", {
|
|
3552
|
+
method: "POST",
|
|
3553
|
+
headers: {
|
|
3554
|
+
"Content-Type": "application/json"
|
|
3555
|
+
},
|
|
3556
|
+
body: JSON.stringify({ username: name })
|
|
3557
|
+
});
|
|
3558
|
+
if (!pointsResponse.ok) {
|
|
3559
|
+
throw new Error(`Failed to fetch points: ${pointsResponse.status}`);
|
|
3560
|
+
}
|
|
3561
|
+
const points = await pointsResponse.json();
|
|
3562
|
+
const transactionsResponse = await fetch(
|
|
3563
|
+
CONFIG.privateApiHost + "/private-api/point-list",
|
|
1498
3564
|
{
|
|
3565
|
+
method: "POST",
|
|
1499
3566
|
headers: {
|
|
1500
|
-
"Content-Type": "application/json"
|
|
1501
|
-
|
|
1502
|
-
}
|
|
3567
|
+
"Content-Type": "application/json"
|
|
3568
|
+
},
|
|
3569
|
+
body: JSON.stringify({ username: name, type: filter })
|
|
1503
3570
|
}
|
|
1504
3571
|
);
|
|
1505
|
-
|
|
3572
|
+
if (!transactionsResponse.ok) {
|
|
3573
|
+
throw new Error(`Failed to fetch point transactions: ${transactionsResponse.status}`);
|
|
3574
|
+
}
|
|
3575
|
+
const transactions = await transactionsResponse.json();
|
|
3576
|
+
return {
|
|
3577
|
+
points: points.points,
|
|
3578
|
+
uPoints: points.unclaimed_points,
|
|
3579
|
+
transactions
|
|
3580
|
+
};
|
|
3581
|
+
},
|
|
3582
|
+
staleTime: 3e4,
|
|
3583
|
+
refetchOnMount: true,
|
|
3584
|
+
enabled: !!username
|
|
3585
|
+
});
|
|
3586
|
+
}
|
|
3587
|
+
function searchQueryOptions(q, sort, hideLow, since, scroll_id, votes) {
|
|
3588
|
+
return queryOptions({
|
|
3589
|
+
queryKey: ["search", q, sort, hideLow, since, scroll_id, votes],
|
|
3590
|
+
queryFn: async () => {
|
|
3591
|
+
const data = { q, sort, hide_low: hideLow };
|
|
3592
|
+
if (since) data.since = since;
|
|
3593
|
+
if (scroll_id) data.scroll_id = scroll_id;
|
|
3594
|
+
if (votes) data.votes = votes;
|
|
3595
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
3596
|
+
method: "POST",
|
|
3597
|
+
headers: {
|
|
3598
|
+
"Content-Type": "application/json"
|
|
3599
|
+
},
|
|
3600
|
+
body: JSON.stringify(data)
|
|
3601
|
+
});
|
|
3602
|
+
if (!response.ok) {
|
|
3603
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
3604
|
+
}
|
|
3605
|
+
return response.json();
|
|
1506
3606
|
}
|
|
1507
3607
|
});
|
|
1508
3608
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
}
|
|
1514
|
-
|
|
3609
|
+
function getControversialRisingInfiniteQueryOptions(what, tag, enabled = true) {
|
|
3610
|
+
return infiniteQueryOptions({
|
|
3611
|
+
queryKey: ["search", "controversial-rising", what, tag],
|
|
3612
|
+
initialPageParam: { sid: void 0, hasNextPage: true },
|
|
3613
|
+
queryFn: async ({ pageParam }) => {
|
|
3614
|
+
if (!pageParam.hasNextPage) {
|
|
3615
|
+
return {
|
|
3616
|
+
hits: 0,
|
|
3617
|
+
took: 0,
|
|
3618
|
+
results: []
|
|
3619
|
+
};
|
|
3620
|
+
}
|
|
3621
|
+
let sinceDate;
|
|
3622
|
+
const now = /* @__PURE__ */ new Date();
|
|
3623
|
+
switch (tag) {
|
|
3624
|
+
case "today":
|
|
3625
|
+
sinceDate = new Date(now.getTime() - 24 * 60 * 60 * 1e3);
|
|
3626
|
+
break;
|
|
3627
|
+
case "week":
|
|
3628
|
+
sinceDate = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1e3);
|
|
3629
|
+
break;
|
|
3630
|
+
case "month":
|
|
3631
|
+
sinceDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1e3);
|
|
3632
|
+
break;
|
|
3633
|
+
case "year":
|
|
3634
|
+
sinceDate = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1e3);
|
|
3635
|
+
break;
|
|
3636
|
+
default:
|
|
3637
|
+
sinceDate = void 0;
|
|
3638
|
+
}
|
|
3639
|
+
const q = "* type:post";
|
|
3640
|
+
const sort = what === "rising" ? "children" : what;
|
|
3641
|
+
const since = sinceDate ? sinceDate.toISOString().split(".")[0] : void 0;
|
|
3642
|
+
const hideLow = "0";
|
|
3643
|
+
const votes = tag === "today" ? 50 : 200;
|
|
3644
|
+
const data = { q, sort, hide_low: hideLow };
|
|
3645
|
+
if (since) data.since = since;
|
|
3646
|
+
if (pageParam.sid) data.scroll_id = pageParam.sid;
|
|
3647
|
+
data.votes = votes;
|
|
3648
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
3649
|
+
method: "POST",
|
|
3650
|
+
headers: {
|
|
3651
|
+
"Content-Type": "application/json"
|
|
3652
|
+
},
|
|
3653
|
+
body: JSON.stringify(data)
|
|
3654
|
+
});
|
|
3655
|
+
if (!response.ok) {
|
|
3656
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
3657
|
+
}
|
|
3658
|
+
return response.json();
|
|
3659
|
+
},
|
|
3660
|
+
getNextPageParam: (resp) => {
|
|
3661
|
+
return {
|
|
3662
|
+
sid: resp?.scroll_id,
|
|
3663
|
+
hasNextPage: resp.results.length > 0
|
|
3664
|
+
};
|
|
3665
|
+
},
|
|
3666
|
+
enabled
|
|
3667
|
+
});
|
|
3668
|
+
}
|
|
3669
|
+
function buildQuery(entry, retry = 3) {
|
|
3670
|
+
const { json_metadata, permlink } = entry;
|
|
3671
|
+
let q = "*";
|
|
3672
|
+
q += ` -dporn type:post`;
|
|
3673
|
+
let tags;
|
|
3674
|
+
if (json_metadata && json_metadata.tags && Array.isArray(json_metadata.tags)) {
|
|
3675
|
+
tags = json_metadata.tags.filter((tag) => tag && tag !== "").filter((tag) => !tag.startsWith("hive-")).filter((_tag, ind) => ind < +retry).join(",");
|
|
3676
|
+
}
|
|
3677
|
+
if (tags && tags.length > 0) {
|
|
3678
|
+
q += ` tag:${tags}`;
|
|
3679
|
+
} else {
|
|
3680
|
+
const fperm = permlink.split("-");
|
|
3681
|
+
tags = fperm.filter((part) => part !== "").filter((part) => !/^-?\d+$/.test(part)).filter((part) => part.length > 2).join(",");
|
|
3682
|
+
q += ` tag:${tags}`;
|
|
3683
|
+
}
|
|
3684
|
+
return q;
|
|
3685
|
+
}
|
|
3686
|
+
function getSimilarEntriesQueryOptions(entry) {
|
|
3687
|
+
const query = buildQuery(entry);
|
|
1515
3688
|
return queryOptions({
|
|
1516
|
-
queryKey: ["
|
|
3689
|
+
queryKey: ["search", "similar-entries", entry.author, entry.permlink, query],
|
|
1517
3690
|
queryFn: async () => {
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
const data = await response.json();
|
|
1528
|
-
return {
|
|
1529
|
-
twitter: {
|
|
1530
|
-
username: data.twitter_username,
|
|
1531
|
-
profile: data.twitter_profile
|
|
3691
|
+
const data = {
|
|
3692
|
+
q: query,
|
|
3693
|
+
sort: "newest",
|
|
3694
|
+
hide_low: "0"
|
|
3695
|
+
};
|
|
3696
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
3697
|
+
method: "POST",
|
|
3698
|
+
headers: {
|
|
3699
|
+
"Content-Type": "application/json"
|
|
1532
3700
|
},
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
3701
|
+
body: JSON.stringify(data)
|
|
3702
|
+
});
|
|
3703
|
+
if (!response.ok) {
|
|
3704
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
3705
|
+
}
|
|
3706
|
+
const searchResponse = await response.json();
|
|
3707
|
+
const rawEntries = searchResponse.results.filter(
|
|
3708
|
+
(r) => r.permlink !== entry.permlink && r.tags.indexOf("nsfw") === -1
|
|
3709
|
+
);
|
|
3710
|
+
const entries = [];
|
|
3711
|
+
for (const result of rawEntries) {
|
|
3712
|
+
if (entries.find((y) => y.author === result.author) === void 0) {
|
|
3713
|
+
entries.push(result);
|
|
1536
3714
|
}
|
|
1537
|
-
}
|
|
3715
|
+
}
|
|
3716
|
+
return entries.slice(0, 3);
|
|
1538
3717
|
}
|
|
1539
3718
|
});
|
|
1540
3719
|
}
|
|
1541
|
-
function
|
|
1542
|
-
url,
|
|
1543
|
-
dimensions = [],
|
|
1544
|
-
metrics = ["visitors", "pageviews", "visit_duration"],
|
|
1545
|
-
enabled = true
|
|
1546
|
-
}) {
|
|
3720
|
+
function getSearchAccountQueryOptions(q, limit = 5, random = false) {
|
|
1547
3721
|
return queryOptions({
|
|
1548
|
-
queryKey: ["
|
|
3722
|
+
queryKey: ["search", "account", q, limit],
|
|
1549
3723
|
queryFn: async () => {
|
|
1550
|
-
const
|
|
1551
|
-
const response = await
|
|
3724
|
+
const data = { q, limit, random: +random };
|
|
3725
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-account", {
|
|
1552
3726
|
method: "POST",
|
|
1553
|
-
body: JSON.stringify({
|
|
1554
|
-
metrics,
|
|
1555
|
-
url: encodeURIComponent(url),
|
|
1556
|
-
dimensions
|
|
1557
|
-
}),
|
|
1558
3727
|
headers: {
|
|
1559
3728
|
"Content-Type": "application/json"
|
|
1560
|
-
}
|
|
3729
|
+
},
|
|
3730
|
+
body: JSON.stringify(data)
|
|
1561
3731
|
});
|
|
1562
|
-
|
|
3732
|
+
if (!response.ok) {
|
|
3733
|
+
throw new Error(`Failed to search accounts: ${response.status}`);
|
|
3734
|
+
}
|
|
3735
|
+
return response.json();
|
|
1563
3736
|
},
|
|
1564
|
-
enabled: !!
|
|
3737
|
+
enabled: !!q
|
|
1565
3738
|
});
|
|
1566
3739
|
}
|
|
1567
|
-
function
|
|
3740
|
+
function getSearchTopicsQueryOptions(q, limit = 20, random = false) {
|
|
1568
3741
|
return queryOptions({
|
|
1569
|
-
queryKey: ["
|
|
3742
|
+
queryKey: ["search", "topics", q],
|
|
1570
3743
|
queryFn: async () => {
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1573
|
-
"
|
|
1574
|
-
{
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
3744
|
+
const data = { q, limit, random: +random };
|
|
3745
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-tag", {
|
|
3746
|
+
method: "POST",
|
|
3747
|
+
headers: {
|
|
3748
|
+
"Content-Type": "application/json"
|
|
3749
|
+
},
|
|
3750
|
+
body: JSON.stringify(data)
|
|
3751
|
+
});
|
|
3752
|
+
if (!response.ok) {
|
|
3753
|
+
throw new Error(`Failed to search topics: ${response.status}`);
|
|
3754
|
+
}
|
|
3755
|
+
return response.json();
|
|
3756
|
+
},
|
|
3757
|
+
enabled: !!q
|
|
1578
3758
|
});
|
|
1579
3759
|
}
|
|
1580
|
-
function
|
|
1581
|
-
return
|
|
1582
|
-
queryKey: ["
|
|
1583
|
-
queryFn: async () => {
|
|
1584
|
-
const
|
|
1585
|
-
|
|
3760
|
+
function getSearchApiInfiniteQueryOptions(q, sort, hideLow, since, votes) {
|
|
3761
|
+
return infiniteQueryOptions({
|
|
3762
|
+
queryKey: ["search", "api", q, sort, hideLow, since, votes],
|
|
3763
|
+
queryFn: async ({ pageParam }) => {
|
|
3764
|
+
const payload = { q, sort, hide_low: hideLow };
|
|
3765
|
+
if (since) {
|
|
3766
|
+
payload.since = since;
|
|
3767
|
+
}
|
|
3768
|
+
if (pageParam) {
|
|
3769
|
+
payload.scroll_id = pageParam;
|
|
3770
|
+
}
|
|
3771
|
+
if (votes !== void 0) {
|
|
3772
|
+
payload.votes = votes;
|
|
3773
|
+
}
|
|
3774
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
3775
|
+
method: "POST",
|
|
3776
|
+
headers: {
|
|
3777
|
+
"Content-Type": "application/json"
|
|
3778
|
+
},
|
|
3779
|
+
body: JSON.stringify(payload)
|
|
3780
|
+
});
|
|
3781
|
+
if (!response.ok) {
|
|
3782
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
3783
|
+
}
|
|
3784
|
+
return response.json();
|
|
1586
3785
|
},
|
|
1587
|
-
|
|
3786
|
+
initialPageParam: void 0,
|
|
3787
|
+
getNextPageParam: (lastPage) => lastPage?.scroll_id,
|
|
3788
|
+
enabled: !!q
|
|
1588
3789
|
});
|
|
1589
3790
|
}
|
|
1590
|
-
function
|
|
3791
|
+
function getSearchPathQueryOptions(q) {
|
|
1591
3792
|
return queryOptions({
|
|
1592
|
-
queryKey: ["
|
|
1593
|
-
enabled: !!username,
|
|
3793
|
+
queryKey: ["search", "path", q],
|
|
1594
3794
|
queryFn: async () => {
|
|
1595
|
-
|
|
1596
|
-
|
|
3795
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-path", {
|
|
3796
|
+
method: "POST",
|
|
3797
|
+
headers: {
|
|
3798
|
+
"Content-Type": "application/json"
|
|
3799
|
+
},
|
|
3800
|
+
body: JSON.stringify({ q })
|
|
3801
|
+
});
|
|
3802
|
+
if (!response.ok) {
|
|
3803
|
+
throw new Error(`Search path failed: ${response.status}`);
|
|
1597
3804
|
}
|
|
1598
|
-
const
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
body: JSON.stringify({
|
|
1604
|
-
game_type: gameType,
|
|
1605
|
-
code: getAccessToken(username)
|
|
1606
|
-
}),
|
|
1607
|
-
headers: {
|
|
1608
|
-
"Content-Type": "application/json"
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
);
|
|
1612
|
-
return await response.json();
|
|
3805
|
+
const data = await response.json();
|
|
3806
|
+
if (data?.length > 0) {
|
|
3807
|
+
return data;
|
|
3808
|
+
}
|
|
3809
|
+
return [q];
|
|
1613
3810
|
}
|
|
1614
3811
|
});
|
|
1615
3812
|
}
|
|
1616
|
-
function
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
3813
|
+
function getBoostPlusPricesQueryOptions(accessToken) {
|
|
3814
|
+
return queryOptions({
|
|
3815
|
+
queryKey: ["promotions", "boost-plus-prices"],
|
|
3816
|
+
queryFn: async () => {
|
|
3817
|
+
if (!accessToken) {
|
|
3818
|
+
return [];
|
|
3819
|
+
}
|
|
3820
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/boost-plus-price", {
|
|
3821
|
+
method: "POST",
|
|
3822
|
+
headers: {
|
|
3823
|
+
"Content-Type": "application/json"
|
|
3824
|
+
},
|
|
3825
|
+
body: JSON.stringify({ code: accessToken })
|
|
3826
|
+
});
|
|
3827
|
+
if (!response.ok) {
|
|
3828
|
+
throw new Error(`Failed to fetch boost plus prices: ${response.status}`);
|
|
1626
3829
|
}
|
|
1627
|
-
const fetchApi = getBoundFetch();
|
|
1628
|
-
const response = await fetchApi(
|
|
1629
|
-
CONFIG.privateApiHost + "/private-api/post-game",
|
|
1630
|
-
{
|
|
1631
|
-
method: "POST",
|
|
1632
|
-
body: JSON.stringify({
|
|
1633
|
-
game_type: gameType,
|
|
1634
|
-
code: getAccessToken(username),
|
|
1635
|
-
key
|
|
1636
|
-
}),
|
|
1637
|
-
headers: {
|
|
1638
|
-
"Content-Type": "application/json"
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
);
|
|
1642
3830
|
return await response.json();
|
|
1643
3831
|
},
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
3832
|
+
staleTime: Infinity,
|
|
3833
|
+
refetchOnMount: true,
|
|
3834
|
+
enabled: !!accessToken
|
|
1647
3835
|
});
|
|
1648
3836
|
}
|
|
1649
|
-
function
|
|
3837
|
+
function getPromotePriceQueryOptions(accessToken) {
|
|
1650
3838
|
return queryOptions({
|
|
1651
|
-
queryKey: ["
|
|
1652
|
-
enabled,
|
|
3839
|
+
queryKey: ["promotions", "promote-price"],
|
|
1653
3840
|
queryFn: async () => {
|
|
1654
|
-
const response = await CONFIG.
|
|
1655
|
-
"
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
);
|
|
1665
|
-
|
|
1666
|
-
|
|
3841
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/promote-price", {
|
|
3842
|
+
method: "POST",
|
|
3843
|
+
headers: {
|
|
3844
|
+
"Content-Type": "application/json"
|
|
3845
|
+
},
|
|
3846
|
+
body: JSON.stringify({ code: accessToken })
|
|
3847
|
+
});
|
|
3848
|
+
if (!response.ok) {
|
|
3849
|
+
throw new Error(`Failed to fetch promote prices: ${response.status}`);
|
|
3850
|
+
}
|
|
3851
|
+
return await response.json();
|
|
3852
|
+
},
|
|
3853
|
+
enabled: !!accessToken
|
|
1667
3854
|
});
|
|
1668
3855
|
}
|
|
1669
|
-
function
|
|
3856
|
+
function getBoostPlusAccountPricesQueryOptions(account, accessToken) {
|
|
1670
3857
|
return queryOptions({
|
|
1671
|
-
queryKey: ["
|
|
1672
|
-
enabled: !!username && !!communityName,
|
|
3858
|
+
queryKey: ["promotions", "boost-plus-accounts", account],
|
|
1673
3859
|
queryFn: async () => {
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
3860
|
+
if (!accessToken || !account) {
|
|
3861
|
+
return null;
|
|
3862
|
+
}
|
|
3863
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/boosted-plus-account", {
|
|
3864
|
+
method: "POST",
|
|
3865
|
+
headers: {
|
|
3866
|
+
"Content-Type": "application/json"
|
|
3867
|
+
},
|
|
3868
|
+
body: JSON.stringify({ code: accessToken, account })
|
|
3869
|
+
});
|
|
3870
|
+
if (!response.ok) {
|
|
3871
|
+
throw new Error(`Failed to fetch boost plus account prices: ${response.status}`);
|
|
3872
|
+
}
|
|
3873
|
+
const responseData = await response.json();
|
|
3874
|
+
return responseData ? {
|
|
3875
|
+
account: responseData.account,
|
|
3876
|
+
expires: new Date(responseData.expires)
|
|
3877
|
+
} : null;
|
|
3878
|
+
},
|
|
3879
|
+
enabled: !!account && !!accessToken
|
|
1687
3880
|
});
|
|
1688
3881
|
}
|
|
1689
3882
|
|
|
1690
|
-
|
|
1691
|
-
var ROLES = /* @__PURE__ */ ((ROLES2) => {
|
|
1692
|
-
ROLES2["OWNER"] = "owner";
|
|
1693
|
-
ROLES2["ADMIN"] = "admin";
|
|
1694
|
-
ROLES2["MOD"] = "mod";
|
|
1695
|
-
ROLES2["MEMBER"] = "member";
|
|
1696
|
-
ROLES2["GUEST"] = "guest";
|
|
1697
|
-
ROLES2["MUTED"] = "muted";
|
|
1698
|
-
return ROLES2;
|
|
1699
|
-
})(ROLES || {});
|
|
1700
|
-
var roleMap = {
|
|
1701
|
-
["owner" /* OWNER */]: [
|
|
1702
|
-
"admin" /* ADMIN */,
|
|
1703
|
-
"mod" /* MOD */,
|
|
1704
|
-
"member" /* MEMBER */,
|
|
1705
|
-
"guest" /* GUEST */,
|
|
1706
|
-
"muted" /* MUTED */
|
|
1707
|
-
],
|
|
1708
|
-
["admin" /* ADMIN */]: ["mod" /* MOD */, "member" /* MEMBER */, "guest" /* GUEST */, "muted" /* MUTED */],
|
|
1709
|
-
["mod" /* MOD */]: ["member" /* MEMBER */, "guest" /* GUEST */, "muted" /* MUTED */]
|
|
1710
|
-
};
|
|
1711
|
-
|
|
1712
|
-
// src/modules/communities/utils/index.ts
|
|
1713
|
-
function getCommunityType(name, type_id) {
|
|
1714
|
-
if (name.startsWith("hive-3") || type_id === 3) return "Council";
|
|
1715
|
-
if (name.startsWith("hive-2") || type_id === 2) return "Journal";
|
|
1716
|
-
return "Topic";
|
|
1717
|
-
}
|
|
1718
|
-
function getCommunityPermissions({
|
|
1719
|
-
communityType,
|
|
1720
|
-
userRole,
|
|
1721
|
-
subscribed
|
|
1722
|
-
}) {
|
|
1723
|
-
const canPost = (() => {
|
|
1724
|
-
if (userRole === "muted" /* MUTED */) return false;
|
|
1725
|
-
if (communityType === "Topic") return true;
|
|
1726
|
-
return ["owner" /* OWNER */, "admin" /* ADMIN */, "mod" /* MOD */, "member" /* MEMBER */].includes(
|
|
1727
|
-
userRole
|
|
1728
|
-
);
|
|
1729
|
-
})();
|
|
1730
|
-
const canComment = (() => {
|
|
1731
|
-
if (userRole === "muted" /* MUTED */) return false;
|
|
1732
|
-
switch (communityType) {
|
|
1733
|
-
case "Topic":
|
|
1734
|
-
return true;
|
|
1735
|
-
case "Journal":
|
|
1736
|
-
return userRole !== "guest" /* GUEST */ || subscribed;
|
|
1737
|
-
case "Council":
|
|
1738
|
-
return canPost;
|
|
1739
|
-
}
|
|
1740
|
-
})();
|
|
1741
|
-
const isModerator = ["owner" /* OWNER */, "admin" /* ADMIN */, "mod" /* MOD */].includes(userRole);
|
|
1742
|
-
return {
|
|
1743
|
-
canPost,
|
|
1744
|
-
canComment,
|
|
1745
|
-
isModerator
|
|
1746
|
-
};
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
|
-
export { CONFIG, ConfigManager, mutations_exports as EcencyAnalytics, EcencyQueriesManager, HiveSignerIntegration, keychain_exports as Keychain, NaiMap, ROLES, Symbol2 as Symbol, ThreeSpeakIntegration, broadcastJson, buildProfileMetadata, checkUsernameWalletsPendingQueryOptions, decodeObj, dedupeAndSortKeyAuths, encodeObj, extractAccountProfile, getAccessToken, getAccountFullQueryOptions, getAccountPendingRecoveryQueryOptions, getAccountRcQueryOptions, getAccountRecoveriesQueryOptions, getAccountSubscriptionsQueryOptions, getActiveAccountBookmarksQueryOptions, getActiveAccountFavouritesQueryOptions, getBoundFetch, getChainPropertiesQueryOptions, getCommunitiesQueryOptions, getCommunityContextQueryOptions, getCommunityPermissions, getCommunityType, getDynamicPropsQueryOptions, getFragmentsQueryOptions, getGameStatusCheckQueryOptions, getHivePoshLinksQueryOptions, getLoginType, getPostingKey, getPromotedPostsQuery, getQueryClient, getRcStatsQueryOptions, getRefreshToken, getRelationshipBetweenAccountsQueryOptions, getSearchAccountsByUsernameQueryOptions, getStatsQueryOptions, getTrendingTagsQueryOptions, getUser, makeQueryClient, parseAsset, parseProfileMetadata, roleMap, useAccountFavouriteAdd, useAccountFavouriteDelete, useAccountRelationsUpdate, useAccountRevokeKey, useAccountRevokePosting, useAccountUpdate, useAccountUpdateKeyAuths, useAccountUpdatePassword, useAccountUpdateRecovery, useAddFragment, useBookmarkAdd, useBookmarkDelete, useBroadcastMutation, useEditFragment, useGameClaim, useRemoveFragment, useSignOperationByHivesigner, useSignOperationByKey, useSignOperationByKeychain };
|
|
3883
|
+
export { ACCOUNT_OPERATION_GROUPS, ALL_ACCOUNT_OPERATIONS, ALL_NOTIFY_TYPES, CONFIG, ConfigManager, mutations_exports as EcencyAnalytics, EcencyQueriesManager, HiveSignerIntegration, keychain_exports as Keychain, NaiMap, NotificationFilter, NotificationViewType, NotifyTypes, ROLES, SortOrder, Symbol2 as Symbol, ThreeSpeakIntegration, broadcastJson, buildProfileMetadata, checkUsernameWalletsPendingQueryOptions, decodeObj, dedupeAndSortKeyAuths, encodeObj, extractAccountProfile, getAccessToken, getAccountFullQueryOptions, getAccountNotificationsInfiniteQueryOptions, getAccountPendingRecoveryQueryOptions, getAccountPostsInfiniteQueryOptions, getAccountRcQueryOptions, getAccountRecoveriesQueryOptions, getAccountSubscriptionsQueryOptions, getAccountVoteHistoryInfiniteQueryOptions, getAccountsQueryOptions, getActiveAccountBookmarksQueryOptions, getActiveAccountFavouritesQueryOptions, getAnnouncementsQueryOptions, getBoostPlusAccountPricesQueryOptions, getBoostPlusPricesQueryOptions, getBotsQueryOptions, getBoundFetch, getChainPropertiesQueryOptions, getCollateralizedConversionRequestsQueryOptions, getCommentHistoryQueryOptions, getCommunitiesQueryOptions, getCommunityContextQueryOptions, getCommunityPermissions, getCommunitySubscribersQueryOptions, getCommunityType, getControversialRisingInfiniteQueryOptions, getConversionRequestsQueryOptions, getDeletedEntryQueryOptions, getDiscoverCurationQueryOptions, getDiscoverLeaderboardQueryOptions, getDiscussionsQueryOptions, getDraftsQueryOptions, getDynamicPropsQueryOptions, getEntryActiveVotesQueryOptions, getFollowCountQueryOptions, getFollowingQueryOptions, getFragmentsQueryOptions, getFriendsInfiniteQueryOptions, getGalleryImagesQueryOptions, getGameStatusCheckQueryOptions, getHiveHbdStatsQueryOptions, getHivePoshLinksQueryOptions, getImagesQueryOptions, getLoginType, getMarketDataQueryOptions, getMarketHistoryQueryOptions, getMarketStatisticsQueryOptions, getMutedUsersQueryOptions, getNotificationsInfiniteQueryOptions, getNotificationsSettingsQueryOptions, getNotificationsUnreadCountQueryOptions, getOpenOrdersQueryOptions, getOrderBookQueryOptions, getOutgoingRcDelegationsInfiniteQueryOptions, getPageStatsQueryOptions, getPointsQueryOptions, getPostHeaderQueryOptions, getPostQueryOptions, getPostTipsQueryOptions, getPostingKey, getPostsRankedInfiniteQueryOptions, getPromotePriceQueryOptions, getPromotedPostsQuery, getProposalQueryOptions, getProposalVotesInfiniteQueryOptions, getProposalsQueryOptions, getQueryClient, getRcStatsQueryOptions, getReblogsQueryOptions, getReceivedVestingSharesQueryOptions, getReferralsInfiniteQueryOptions, getReferralsStatsQueryOptions, getRefreshToken, getRelationshipBetweenAccountsQueryOptions, getRewardedCommunitiesQueryOptions, getSavingsWithdrawFromQueryOptions, getSchedulesQueryOptions, getSearchAccountQueryOptions, getSearchAccountsByUsernameQueryOptions, getSearchApiInfiniteQueryOptions, getSearchFriendsQueryOptions, getSearchPathQueryOptions, getSearchTopicsQueryOptions, getSimilarEntriesQueryOptions, getStatsQueryOptions, getTransactionsInfiniteQueryOptions, getTrendingTagsQueryOptions, getUser, getUserProposalVotesQueryOptions, getVestingDelegationsQueryOptions, getVisibleFirstLevelThreadItems, getWavesByHostQueryOptions, getWavesByTagQueryOptions, getWavesFollowingQueryOptions, getWavesTrendingTagsQueryOptions, getWithdrawRoutesQueryOptions, getWitnessesInfiniteQueryOptions, lookupAccountsQueryOptions, makeQueryClient, mapThreadItemsToWaveEntries, normalizeWaveEntryFromApi, parseAccounts, parseAsset, parseProfileMetadata, roleMap, searchQueryOptions, sortDiscussions, toEntryArray, useAccountFavouriteAdd, useAccountFavouriteDelete, useAccountRelationsUpdate, useAccountRevokeKey, useAccountRevokePosting, useAccountUpdate, useAccountUpdateKeyAuths, useAccountUpdatePassword, useAccountUpdateRecovery, useAddFragment, useBookmarkAdd, useBookmarkDelete, useBroadcastMutation, useEditFragment, useGameClaim, useRecordActivity, useRemoveFragment, useSignOperationByHivesigner, useSignOperationByKey, useSignOperationByKeychain };
|
|
1750
3884
|
//# sourceMappingURL=index.js.map
|
|
1751
3885
|
//# sourceMappingURL=index.js.map
|