@ecency/sdk 1.5.13 → 1.5.15
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 +170 -9
- package/dist/browser/index.js +1304 -1020
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +1315 -1019
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +1304 -1020
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -705,6 +705,18 @@ function getFollowCountQueryOptions(username) {
|
|
|
705
705
|
])
|
|
706
706
|
});
|
|
707
707
|
}
|
|
708
|
+
function getFollowersQueryOptions(following, startFollower, followType = "blog", limit = 100) {
|
|
709
|
+
return reactQuery.queryOptions({
|
|
710
|
+
queryKey: ["accounts", "followers", following, startFollower, followType, limit],
|
|
711
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_followers", [
|
|
712
|
+
following,
|
|
713
|
+
startFollower,
|
|
714
|
+
followType,
|
|
715
|
+
limit
|
|
716
|
+
]),
|
|
717
|
+
enabled: !!following
|
|
718
|
+
});
|
|
719
|
+
}
|
|
708
720
|
function getFollowingQueryOptions(follower, startFollowing, followType = "blog", limit = 100) {
|
|
709
721
|
return reactQuery.queryOptions({
|
|
710
722
|
queryKey: ["accounts", "following", follower, startFollowing, followType, limit],
|
|
@@ -1425,6 +1437,20 @@ function getEntryActiveVotesQueryOptions(entry) {
|
|
|
1425
1437
|
enabled: !!entry
|
|
1426
1438
|
});
|
|
1427
1439
|
}
|
|
1440
|
+
function getUserPostVoteQueryOptions(username, author, permlink) {
|
|
1441
|
+
return reactQuery.queryOptions({
|
|
1442
|
+
queryKey: ["posts", "user-vote", username, author, permlink],
|
|
1443
|
+
queryFn: async () => {
|
|
1444
|
+
const result = await CONFIG.hiveClient.call("database_api", "list_votes", {
|
|
1445
|
+
start: [username, author, permlink],
|
|
1446
|
+
limit: 1,
|
|
1447
|
+
order: "by_voter_comment"
|
|
1448
|
+
});
|
|
1449
|
+
return result?.votes?.[0] || null;
|
|
1450
|
+
},
|
|
1451
|
+
enabled: !!username && !!author && !!permlink
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1428
1454
|
function getContentQueryOptions(author, permlink) {
|
|
1429
1455
|
return reactQuery.queryOptions({
|
|
1430
1456
|
queryKey: ["posts", "content", author, permlink],
|
|
@@ -2340,8 +2366,8 @@ function toEntryArray(x) {
|
|
|
2340
2366
|
return Array.isArray(x) ? x : [];
|
|
2341
2367
|
}
|
|
2342
2368
|
async function getVisibleFirstLevelThreadItems(container) {
|
|
2343
|
-
const
|
|
2344
|
-
const discussionItemsRaw = await CONFIG.queryClient.fetchQuery(
|
|
2369
|
+
const queryOptions88 = getDiscussionsQueryOptions(container, "created" /* created */, true);
|
|
2370
|
+
const discussionItemsRaw = await CONFIG.queryClient.fetchQuery(queryOptions88);
|
|
2345
2371
|
const discussionItems = toEntryArray(discussionItemsRaw);
|
|
2346
2372
|
if (discussionItems.length <= 1) {
|
|
2347
2373
|
return [];
|
|
@@ -3313,10 +3339,14 @@ function useAddFragment(username, code) {
|
|
|
3313
3339
|
}
|
|
3314
3340
|
});
|
|
3315
3341
|
}
|
|
3316
|
-
function useEditFragment(username,
|
|
3342
|
+
function useEditFragment(username, code) {
|
|
3317
3343
|
return reactQuery.useMutation({
|
|
3318
|
-
mutationKey: ["posts", "edit-fragment", username
|
|
3319
|
-
mutationFn: async ({
|
|
3344
|
+
mutationKey: ["posts", "edit-fragment", username],
|
|
3345
|
+
mutationFn: async ({
|
|
3346
|
+
fragmentId,
|
|
3347
|
+
title,
|
|
3348
|
+
body
|
|
3349
|
+
}) => {
|
|
3320
3350
|
if (!code) {
|
|
3321
3351
|
throw new Error("[SDK][Posts] Missing access token");
|
|
3322
3352
|
}
|
|
@@ -3338,14 +3368,14 @@ function useEditFragment(username, fragmentId, code) {
|
|
|
3338
3368
|
);
|
|
3339
3369
|
return response.json();
|
|
3340
3370
|
},
|
|
3341
|
-
onSuccess(response) {
|
|
3371
|
+
onSuccess(response, variables) {
|
|
3342
3372
|
getQueryClient().setQueryData(
|
|
3343
3373
|
getFragmentsQueryOptions(username, code).queryKey,
|
|
3344
3374
|
(data) => {
|
|
3345
3375
|
if (!data) {
|
|
3346
3376
|
return [];
|
|
3347
3377
|
}
|
|
3348
|
-
const index = data.findIndex(({ id }) => id === fragmentId);
|
|
3378
|
+
const index = data.findIndex(({ id }) => id === variables.fragmentId);
|
|
3349
3379
|
if (index >= 0) {
|
|
3350
3380
|
data[index] = response;
|
|
3351
3381
|
}
|
|
@@ -3355,10 +3385,10 @@ function useEditFragment(username, fragmentId, code) {
|
|
|
3355
3385
|
}
|
|
3356
3386
|
});
|
|
3357
3387
|
}
|
|
3358
|
-
function useRemoveFragment(username,
|
|
3388
|
+
function useRemoveFragment(username, code) {
|
|
3359
3389
|
return reactQuery.useMutation({
|
|
3360
3390
|
mutationKey: ["posts", "remove-fragment", username],
|
|
3361
|
-
mutationFn: async () => {
|
|
3391
|
+
mutationFn: async ({ fragmentId }) => {
|
|
3362
3392
|
if (!code) {
|
|
3363
3393
|
throw new Error("[SDK][Posts] Missing access token");
|
|
3364
3394
|
}
|
|
@@ -3374,173 +3404,643 @@ function useRemoveFragment(username, fragmentId, code) {
|
|
|
3374
3404
|
}
|
|
3375
3405
|
});
|
|
3376
3406
|
},
|
|
3377
|
-
onSuccess() {
|
|
3407
|
+
onSuccess(_data, variables) {
|
|
3378
3408
|
getQueryClient().setQueryData(
|
|
3379
3409
|
getFragmentsQueryOptions(username, code).queryKey,
|
|
3380
|
-
(data) => [...data ?? []].filter(({ id }) => id !== fragmentId)
|
|
3410
|
+
(data) => [...data ?? []].filter(({ id }) => id !== variables.fragmentId)
|
|
3381
3411
|
);
|
|
3382
3412
|
}
|
|
3383
3413
|
});
|
|
3384
3414
|
}
|
|
3385
3415
|
|
|
3386
|
-
// src/modules/
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
}
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
response = await getContent(author, permlink);
|
|
3400
|
-
} catch (e) {
|
|
3401
|
-
response = void 0;
|
|
3416
|
+
// src/modules/private-api/requests.ts
|
|
3417
|
+
async function parseJsonResponse(response) {
|
|
3418
|
+
if (!response.ok) {
|
|
3419
|
+
let errorData = void 0;
|
|
3420
|
+
try {
|
|
3421
|
+
errorData = await response.json();
|
|
3422
|
+
} catch {
|
|
3423
|
+
errorData = void 0;
|
|
3424
|
+
}
|
|
3425
|
+
const error = new Error(`Request failed with status ${response.status}`);
|
|
3426
|
+
error.status = response.status;
|
|
3427
|
+
error.data = errorData;
|
|
3428
|
+
throw error;
|
|
3402
3429
|
}
|
|
3403
|
-
|
|
3404
|
-
|
|
3430
|
+
const text = await response.text();
|
|
3431
|
+
if (!text || text.trim() === "") {
|
|
3432
|
+
return "";
|
|
3405
3433
|
}
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3434
|
+
try {
|
|
3435
|
+
return JSON.parse(text);
|
|
3436
|
+
} catch (e) {
|
|
3437
|
+
console.warn("[SDK] Failed to parse JSON response:", e, "Response:", text);
|
|
3438
|
+
return "";
|
|
3409
3439
|
}
|
|
3410
|
-
return validatePostCreating(author, permlink, attempts + 1, options);
|
|
3411
3440
|
}
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
};
|
|
3424
|
-
}
|
|
3425
|
-
return { url: "", domain: "" };
|
|
3441
|
+
async function signUp(username, email, referral) {
|
|
3442
|
+
const fetchApi = getBoundFetch();
|
|
3443
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/account-create", {
|
|
3444
|
+
method: "POST",
|
|
3445
|
+
headers: {
|
|
3446
|
+
"Content-Type": "application/json"
|
|
3447
|
+
},
|
|
3448
|
+
body: JSON.stringify({ username, email, referral })
|
|
3449
|
+
});
|
|
3450
|
+
const data = await parseJsonResponse(response);
|
|
3451
|
+
return { status: response.status, data };
|
|
3426
3452
|
}
|
|
3427
|
-
function
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
const locationInfo = getLocationInfo();
|
|
3436
|
-
const url = options?.url ?? locationInfo.url;
|
|
3437
|
-
const domain = options?.domain ?? locationInfo.domain;
|
|
3438
|
-
await fetchApi(CONFIG.plausibleHost + "/api/event", {
|
|
3439
|
-
method: "POST",
|
|
3440
|
-
headers: {
|
|
3441
|
-
"Content-Type": "application/json"
|
|
3442
|
-
},
|
|
3443
|
-
body: JSON.stringify({
|
|
3444
|
-
name: activityType,
|
|
3445
|
-
url,
|
|
3446
|
-
domain,
|
|
3447
|
-
props: {
|
|
3448
|
-
username
|
|
3449
|
-
}
|
|
3450
|
-
})
|
|
3451
|
-
});
|
|
3452
|
-
}
|
|
3453
|
+
async function subscribeEmail(email) {
|
|
3454
|
+
const fetchApi = getBoundFetch();
|
|
3455
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/subscribe", {
|
|
3456
|
+
method: "POST",
|
|
3457
|
+
headers: {
|
|
3458
|
+
"Content-Type": "application/json"
|
|
3459
|
+
},
|
|
3460
|
+
body: JSON.stringify({ email })
|
|
3453
3461
|
});
|
|
3462
|
+
const data = await parseJsonResponse(response);
|
|
3463
|
+
return { status: response.status, data };
|
|
3454
3464
|
}
|
|
3455
|
-
function
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3465
|
+
async function usrActivity(code, ty, bl = "", tx = "") {
|
|
3466
|
+
const params = { code, ty };
|
|
3467
|
+
if (bl) {
|
|
3468
|
+
params.bl = bl;
|
|
3469
|
+
}
|
|
3470
|
+
if (tx) {
|
|
3471
|
+
params.tx = tx;
|
|
3472
|
+
}
|
|
3473
|
+
const fetchApi = getBoundFetch();
|
|
3474
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/usr-activity", {
|
|
3475
|
+
method: "POST",
|
|
3476
|
+
headers: {
|
|
3477
|
+
"Content-Type": "application/json"
|
|
3478
|
+
},
|
|
3479
|
+
body: JSON.stringify(params)
|
|
3468
3480
|
});
|
|
3481
|
+
await parseJsonResponse(response);
|
|
3469
3482
|
}
|
|
3470
|
-
function
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
const vestingWithdrawRate = typeof element.vesting_withdraw_rate === "string" ? element.vesting_withdraw_rate : element.vesting_withdraw_rate.toString();
|
|
3491
|
-
const effectiveVest = parseFloat(vestingShares) + parseFloat(receivedVestingShares) - parseFloat(delegatedVestingShares) - parseFloat(vestingWithdrawRate);
|
|
3492
|
-
curator.efficiency = curator.vests / effectiveVest;
|
|
3493
|
-
}
|
|
3494
|
-
data.sort((a, b) => b.efficiency - a.efficiency);
|
|
3495
|
-
return data;
|
|
3496
|
-
}
|
|
3483
|
+
async function getNotifications(code, filter, since = null, user = null) {
|
|
3484
|
+
const data = {
|
|
3485
|
+
code
|
|
3486
|
+
};
|
|
3487
|
+
if (filter) {
|
|
3488
|
+
data.filter = filter;
|
|
3489
|
+
}
|
|
3490
|
+
if (since) {
|
|
3491
|
+
data.since = since;
|
|
3492
|
+
}
|
|
3493
|
+
if (user) {
|
|
3494
|
+
data.user = user;
|
|
3495
|
+
}
|
|
3496
|
+
const fetchApi = getBoundFetch();
|
|
3497
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/notifications", {
|
|
3498
|
+
method: "POST",
|
|
3499
|
+
headers: {
|
|
3500
|
+
"Content-Type": "application/json"
|
|
3501
|
+
},
|
|
3502
|
+
body: JSON.stringify(data)
|
|
3497
3503
|
});
|
|
3504
|
+
return parseJsonResponse(response);
|
|
3498
3505
|
}
|
|
3499
|
-
function
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
}),
|
|
3514
|
-
signal
|
|
3515
|
-
});
|
|
3516
|
-
if (!response.ok) {
|
|
3517
|
-
throw new Error(`Failed to fetch page stats: ${response.status}`);
|
|
3518
|
-
}
|
|
3519
|
-
return response.json();
|
|
3506
|
+
async function saveNotificationSetting(code, username, system, allows_notify, notify_types, token) {
|
|
3507
|
+
const data = {
|
|
3508
|
+
code,
|
|
3509
|
+
username,
|
|
3510
|
+
token,
|
|
3511
|
+
system,
|
|
3512
|
+
allows_notify,
|
|
3513
|
+
notify_types
|
|
3514
|
+
};
|
|
3515
|
+
const fetchApi = getBoundFetch();
|
|
3516
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/register-device", {
|
|
3517
|
+
method: "POST",
|
|
3518
|
+
headers: {
|
|
3519
|
+
"Content-Type": "application/json"
|
|
3520
3520
|
},
|
|
3521
|
-
|
|
3521
|
+
body: JSON.stringify(data)
|
|
3522
3522
|
});
|
|
3523
|
+
return parseJsonResponse(response);
|
|
3523
3524
|
}
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3525
|
+
async function getNotificationSetting(code, username, token) {
|
|
3526
|
+
const data = { code, username, token };
|
|
3527
|
+
const fetchApi = getBoundFetch();
|
|
3528
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/detail-device", {
|
|
3529
|
+
method: "POST",
|
|
3530
|
+
headers: {
|
|
3531
|
+
"Content-Type": "application/json"
|
|
3532
|
+
},
|
|
3533
|
+
body: JSON.stringify(data)
|
|
3534
|
+
});
|
|
3535
|
+
return parseJsonResponse(response);
|
|
3536
|
+
}
|
|
3537
|
+
async function markNotifications(code, id) {
|
|
3538
|
+
const data = {
|
|
3539
|
+
code
|
|
3540
|
+
};
|
|
3541
|
+
if (id) {
|
|
3542
|
+
data.id = id;
|
|
3543
|
+
}
|
|
3544
|
+
const fetchApi = getBoundFetch();
|
|
3545
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/notifications/mark", {
|
|
3546
|
+
method: "POST",
|
|
3547
|
+
headers: {
|
|
3548
|
+
"Content-Type": "application/json"
|
|
3549
|
+
},
|
|
3550
|
+
body: JSON.stringify(data)
|
|
3551
|
+
});
|
|
3552
|
+
return parseJsonResponse(response);
|
|
3553
|
+
}
|
|
3554
|
+
async function addImage(code, url) {
|
|
3555
|
+
const data = { code, url };
|
|
3556
|
+
const fetchApi = getBoundFetch();
|
|
3557
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/images-add", {
|
|
3558
|
+
method: "POST",
|
|
3559
|
+
headers: {
|
|
3560
|
+
"Content-Type": "application/json"
|
|
3561
|
+
},
|
|
3562
|
+
body: JSON.stringify(data)
|
|
3563
|
+
});
|
|
3564
|
+
return parseJsonResponse(response);
|
|
3565
|
+
}
|
|
3566
|
+
async function uploadImage(file, token, signal) {
|
|
3567
|
+
const fetchApi = getBoundFetch();
|
|
3568
|
+
const formData = new FormData();
|
|
3569
|
+
formData.append("file", file);
|
|
3570
|
+
const response = await fetchApi(`${CONFIG.imageHost}/hs/${token}`, {
|
|
3571
|
+
method: "POST",
|
|
3572
|
+
body: formData,
|
|
3573
|
+
signal
|
|
3574
|
+
});
|
|
3575
|
+
return parseJsonResponse(response);
|
|
3576
|
+
}
|
|
3577
|
+
async function deleteImage(code, imageId) {
|
|
3578
|
+
const data = { code, id: imageId };
|
|
3579
|
+
const fetchApi = getBoundFetch();
|
|
3580
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/images-delete", {
|
|
3581
|
+
method: "POST",
|
|
3582
|
+
headers: {
|
|
3583
|
+
"Content-Type": "application/json"
|
|
3584
|
+
},
|
|
3585
|
+
body: JSON.stringify(data)
|
|
3586
|
+
});
|
|
3587
|
+
return parseJsonResponse(response);
|
|
3588
|
+
}
|
|
3589
|
+
async function addDraft(code, title, body, tags, meta) {
|
|
3590
|
+
const data = { code, title, body, tags, meta };
|
|
3591
|
+
const fetchApi = getBoundFetch();
|
|
3592
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/drafts-add", {
|
|
3593
|
+
method: "POST",
|
|
3594
|
+
headers: {
|
|
3595
|
+
"Content-Type": "application/json"
|
|
3596
|
+
},
|
|
3597
|
+
body: JSON.stringify(data)
|
|
3598
|
+
});
|
|
3599
|
+
return parseJsonResponse(response);
|
|
3600
|
+
}
|
|
3601
|
+
async function updateDraft(code, draftId, title, body, tags, meta) {
|
|
3602
|
+
const data = { code, id: draftId, title, body, tags, meta };
|
|
3603
|
+
const fetchApi = getBoundFetch();
|
|
3604
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/drafts-update", {
|
|
3605
|
+
method: "POST",
|
|
3606
|
+
headers: {
|
|
3607
|
+
"Content-Type": "application/json"
|
|
3608
|
+
},
|
|
3609
|
+
body: JSON.stringify(data)
|
|
3610
|
+
});
|
|
3611
|
+
return parseJsonResponse(response);
|
|
3612
|
+
}
|
|
3613
|
+
async function deleteDraft(code, draftId) {
|
|
3614
|
+
const data = { code, id: draftId };
|
|
3615
|
+
const fetchApi = getBoundFetch();
|
|
3616
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/drafts-delete", {
|
|
3617
|
+
method: "POST",
|
|
3618
|
+
headers: {
|
|
3619
|
+
"Content-Type": "application/json"
|
|
3620
|
+
},
|
|
3621
|
+
body: JSON.stringify(data)
|
|
3622
|
+
});
|
|
3623
|
+
return parseJsonResponse(response);
|
|
3624
|
+
}
|
|
3625
|
+
async function addSchedule(code, permlink, title, body, meta, options, schedule, reblog) {
|
|
3626
|
+
const data = {
|
|
3627
|
+
code,
|
|
3628
|
+
permlink,
|
|
3629
|
+
title,
|
|
3630
|
+
body,
|
|
3631
|
+
meta,
|
|
3632
|
+
schedule,
|
|
3633
|
+
reblog
|
|
3634
|
+
};
|
|
3635
|
+
if (options) {
|
|
3636
|
+
data.options = options;
|
|
3637
|
+
}
|
|
3638
|
+
const fetchApi = getBoundFetch();
|
|
3639
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/schedules-add", {
|
|
3640
|
+
method: "POST",
|
|
3641
|
+
headers: {
|
|
3642
|
+
"Content-Type": "application/json"
|
|
3643
|
+
},
|
|
3644
|
+
body: JSON.stringify(data)
|
|
3645
|
+
});
|
|
3646
|
+
return parseJsonResponse(response);
|
|
3647
|
+
}
|
|
3648
|
+
async function deleteSchedule(code, id) {
|
|
3649
|
+
const data = { code, id };
|
|
3650
|
+
const fetchApi = getBoundFetch();
|
|
3651
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/schedules-delete", {
|
|
3652
|
+
method: "POST",
|
|
3653
|
+
headers: {
|
|
3654
|
+
"Content-Type": "application/json"
|
|
3655
|
+
},
|
|
3656
|
+
body: JSON.stringify(data)
|
|
3657
|
+
});
|
|
3658
|
+
return parseJsonResponse(response);
|
|
3659
|
+
}
|
|
3660
|
+
async function moveSchedule(code, id) {
|
|
3661
|
+
const data = { code, id };
|
|
3662
|
+
const fetchApi = getBoundFetch();
|
|
3663
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/schedules-move", {
|
|
3664
|
+
method: "POST",
|
|
3665
|
+
headers: {
|
|
3666
|
+
"Content-Type": "application/json"
|
|
3667
|
+
},
|
|
3668
|
+
body: JSON.stringify(data)
|
|
3669
|
+
});
|
|
3670
|
+
return parseJsonResponse(response);
|
|
3671
|
+
}
|
|
3672
|
+
async function getPromotedPost(code, author, permlink) {
|
|
3673
|
+
const data = { code, author, permlink };
|
|
3674
|
+
const fetchApi = getBoundFetch();
|
|
3675
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/promoted-post", {
|
|
3676
|
+
method: "POST",
|
|
3677
|
+
headers: {
|
|
3678
|
+
"Content-Type": "application/json"
|
|
3679
|
+
},
|
|
3680
|
+
body: JSON.stringify(data)
|
|
3681
|
+
});
|
|
3682
|
+
return parseJsonResponse(response);
|
|
3683
|
+
}
|
|
3684
|
+
async function onboardEmail(username, email, friend) {
|
|
3685
|
+
const dataBody = {
|
|
3686
|
+
username,
|
|
3687
|
+
email,
|
|
3688
|
+
friend
|
|
3689
|
+
};
|
|
3690
|
+
const fetchApi = getBoundFetch();
|
|
3691
|
+
const response = await fetchApi(
|
|
3692
|
+
CONFIG.privateApiHost + "/private-api/account-create-friend",
|
|
3693
|
+
{
|
|
3694
|
+
method: "POST",
|
|
3695
|
+
headers: {
|
|
3696
|
+
"Content-Type": "application/json"
|
|
3697
|
+
},
|
|
3698
|
+
body: JSON.stringify(dataBody)
|
|
3699
|
+
}
|
|
3700
|
+
);
|
|
3701
|
+
return parseJsonResponse(response);
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3704
|
+
// src/modules/posts/mutations/use-add-draft.ts
|
|
3705
|
+
function useAddDraft(username, code, onSuccess, onError) {
|
|
3706
|
+
return reactQuery.useMutation({
|
|
3707
|
+
mutationKey: ["posts", "drafts", "add", username],
|
|
3708
|
+
mutationFn: async ({
|
|
3709
|
+
title,
|
|
3710
|
+
body,
|
|
3711
|
+
tags,
|
|
3712
|
+
meta
|
|
3713
|
+
}) => {
|
|
3714
|
+
if (!username || !code) {
|
|
3715
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for addDraft");
|
|
3716
|
+
}
|
|
3717
|
+
return addDraft(code, title, body, tags, meta);
|
|
3718
|
+
},
|
|
3719
|
+
onSuccess: () => {
|
|
3720
|
+
onSuccess?.();
|
|
3721
|
+
getQueryClient().invalidateQueries({
|
|
3722
|
+
queryKey: ["posts", "drafts", username]
|
|
3723
|
+
});
|
|
3724
|
+
},
|
|
3725
|
+
onError
|
|
3726
|
+
});
|
|
3727
|
+
}
|
|
3728
|
+
function useUpdateDraft(username, code, onSuccess, onError) {
|
|
3729
|
+
return reactQuery.useMutation({
|
|
3730
|
+
mutationKey: ["posts", "drafts", "update", username],
|
|
3731
|
+
mutationFn: async ({
|
|
3732
|
+
draftId,
|
|
3733
|
+
title,
|
|
3734
|
+
body,
|
|
3735
|
+
tags,
|
|
3736
|
+
meta
|
|
3737
|
+
}) => {
|
|
3738
|
+
if (!username || !code) {
|
|
3739
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for updateDraft");
|
|
3740
|
+
}
|
|
3741
|
+
return updateDraft(code, draftId, title, body, tags, meta);
|
|
3742
|
+
},
|
|
3743
|
+
onSuccess: () => {
|
|
3744
|
+
onSuccess?.();
|
|
3745
|
+
getQueryClient().invalidateQueries({
|
|
3746
|
+
queryKey: ["posts", "drafts", username]
|
|
3747
|
+
});
|
|
3748
|
+
},
|
|
3749
|
+
onError
|
|
3750
|
+
});
|
|
3751
|
+
}
|
|
3752
|
+
function useDeleteDraft(username, code, onSuccess, onError) {
|
|
3753
|
+
return reactQuery.useMutation({
|
|
3754
|
+
mutationKey: ["posts", "drafts", "delete", username],
|
|
3755
|
+
mutationFn: async ({ draftId }) => {
|
|
3756
|
+
if (!username || !code) {
|
|
3757
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for deleteDraft");
|
|
3758
|
+
}
|
|
3759
|
+
return deleteDraft(code, draftId);
|
|
3760
|
+
},
|
|
3761
|
+
onSuccess: () => {
|
|
3762
|
+
onSuccess?.();
|
|
3763
|
+
getQueryClient().invalidateQueries({
|
|
3764
|
+
queryKey: ["posts", "drafts", username]
|
|
3765
|
+
});
|
|
3766
|
+
},
|
|
3767
|
+
onError
|
|
3768
|
+
});
|
|
3769
|
+
}
|
|
3770
|
+
function useAddSchedule(username, code, onSuccess, onError) {
|
|
3771
|
+
return reactQuery.useMutation({
|
|
3772
|
+
mutationKey: ["posts", "schedules", "add", username],
|
|
3773
|
+
mutationFn: async ({
|
|
3774
|
+
permlink,
|
|
3775
|
+
title,
|
|
3776
|
+
body,
|
|
3777
|
+
meta,
|
|
3778
|
+
options,
|
|
3779
|
+
schedule,
|
|
3780
|
+
reblog
|
|
3781
|
+
}) => {
|
|
3782
|
+
if (!username || !code) {
|
|
3783
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for addSchedule");
|
|
3784
|
+
}
|
|
3785
|
+
return addSchedule(code, permlink, title, body, meta, options, schedule, reblog);
|
|
3786
|
+
},
|
|
3787
|
+
onSuccess: () => {
|
|
3788
|
+
onSuccess?.();
|
|
3789
|
+
getQueryClient().invalidateQueries({
|
|
3790
|
+
queryKey: ["posts", "schedules", username]
|
|
3791
|
+
});
|
|
3792
|
+
},
|
|
3793
|
+
onError
|
|
3794
|
+
});
|
|
3795
|
+
}
|
|
3796
|
+
function useDeleteSchedule(username, code, onSuccess, onError) {
|
|
3797
|
+
return reactQuery.useMutation({
|
|
3798
|
+
mutationKey: ["posts", "schedules", "delete", username],
|
|
3799
|
+
mutationFn: async ({ id }) => {
|
|
3800
|
+
if (!username || !code) {
|
|
3801
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for deleteSchedule");
|
|
3802
|
+
}
|
|
3803
|
+
return deleteSchedule(code, id);
|
|
3804
|
+
},
|
|
3805
|
+
onSuccess: () => {
|
|
3806
|
+
onSuccess?.();
|
|
3807
|
+
getQueryClient().invalidateQueries({
|
|
3808
|
+
queryKey: ["posts", "schedules", username]
|
|
3809
|
+
});
|
|
3810
|
+
},
|
|
3811
|
+
onError
|
|
3812
|
+
});
|
|
3813
|
+
}
|
|
3814
|
+
function useMoveSchedule(username, code, onSuccess, onError) {
|
|
3815
|
+
return reactQuery.useMutation({
|
|
3816
|
+
mutationKey: ["posts", "schedules", "move", username],
|
|
3817
|
+
mutationFn: async ({ id }) => {
|
|
3818
|
+
if (!username || !code) {
|
|
3819
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for moveSchedule");
|
|
3820
|
+
}
|
|
3821
|
+
return moveSchedule(code, id);
|
|
3822
|
+
},
|
|
3823
|
+
onSuccess: () => {
|
|
3824
|
+
onSuccess?.();
|
|
3825
|
+
getQueryClient().invalidateQueries({
|
|
3826
|
+
queryKey: ["posts", "schedules", username]
|
|
3827
|
+
});
|
|
3828
|
+
getQueryClient().invalidateQueries({
|
|
3829
|
+
queryKey: ["posts", "drafts", username]
|
|
3830
|
+
});
|
|
3831
|
+
},
|
|
3832
|
+
onError
|
|
3833
|
+
});
|
|
3834
|
+
}
|
|
3835
|
+
function useAddImage(username, code, onSuccess, onError) {
|
|
3836
|
+
return reactQuery.useMutation({
|
|
3837
|
+
mutationKey: ["posts", "images", "add", username],
|
|
3838
|
+
mutationFn: async ({ url }) => {
|
|
3839
|
+
if (!username || !code) {
|
|
3840
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for addImage");
|
|
3841
|
+
}
|
|
3842
|
+
return addImage(code, url);
|
|
3843
|
+
},
|
|
3844
|
+
onSuccess: () => {
|
|
3845
|
+
onSuccess?.();
|
|
3846
|
+
getQueryClient().invalidateQueries({
|
|
3847
|
+
queryKey: ["posts", "images", username]
|
|
3848
|
+
});
|
|
3849
|
+
},
|
|
3850
|
+
onError
|
|
3851
|
+
});
|
|
3852
|
+
}
|
|
3853
|
+
function useDeleteImage(username, code, onSuccess, onError) {
|
|
3854
|
+
return reactQuery.useMutation({
|
|
3855
|
+
mutationKey: ["posts", "images", "delete", username],
|
|
3856
|
+
mutationFn: async ({ imageId }) => {
|
|
3857
|
+
if (!username || !code) {
|
|
3858
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for deleteImage");
|
|
3859
|
+
}
|
|
3860
|
+
return deleteImage(code, imageId);
|
|
3861
|
+
},
|
|
3862
|
+
onSuccess: () => {
|
|
3863
|
+
onSuccess?.();
|
|
3864
|
+
getQueryClient().invalidateQueries({
|
|
3865
|
+
queryKey: ["posts", "images", username]
|
|
3866
|
+
});
|
|
3867
|
+
},
|
|
3868
|
+
onError
|
|
3869
|
+
});
|
|
3870
|
+
}
|
|
3871
|
+
function useUploadImage(onSuccess, onError) {
|
|
3872
|
+
return reactQuery.useMutation({
|
|
3873
|
+
mutationKey: ["posts", "images", "upload"],
|
|
3874
|
+
mutationFn: async ({
|
|
3875
|
+
file,
|
|
3876
|
+
token,
|
|
3877
|
+
signal
|
|
3878
|
+
}) => {
|
|
3879
|
+
return uploadImage(file, token, signal);
|
|
3880
|
+
},
|
|
3881
|
+
onSuccess,
|
|
3882
|
+
onError
|
|
3883
|
+
});
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
// src/modules/posts/utils/validate-post-creating.ts
|
|
3887
|
+
var DEFAULT_VALIDATE_POST_DELAYS = [3e3, 3e3, 3e3];
|
|
3888
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
3889
|
+
async function getContent(author, permlink) {
|
|
3890
|
+
return CONFIG.hiveClient.call("condenser_api", "get_content", [
|
|
3891
|
+
author,
|
|
3892
|
+
permlink
|
|
3893
|
+
]);
|
|
3894
|
+
}
|
|
3895
|
+
async function validatePostCreating(author, permlink, attempts = 0, options) {
|
|
3896
|
+
const delays = options?.delays ?? DEFAULT_VALIDATE_POST_DELAYS;
|
|
3897
|
+
let response;
|
|
3898
|
+
try {
|
|
3899
|
+
response = await getContent(author, permlink);
|
|
3900
|
+
} catch (e) {
|
|
3901
|
+
response = void 0;
|
|
3902
|
+
}
|
|
3903
|
+
if (response || attempts >= delays.length) {
|
|
3904
|
+
return;
|
|
3905
|
+
}
|
|
3906
|
+
const waitMs = delays[attempts];
|
|
3907
|
+
if (waitMs > 0) {
|
|
3908
|
+
await delay(waitMs);
|
|
3909
|
+
}
|
|
3910
|
+
return validatePostCreating(author, permlink, attempts + 1, options);
|
|
3911
|
+
}
|
|
3912
|
+
|
|
3913
|
+
// src/modules/analytics/mutations/index.ts
|
|
3914
|
+
var mutations_exports = {};
|
|
3915
|
+
__export(mutations_exports, {
|
|
3916
|
+
useRecordActivity: () => useRecordActivity
|
|
3917
|
+
});
|
|
3918
|
+
function getLocationInfo() {
|
|
3919
|
+
if (typeof window !== "undefined" && window.location) {
|
|
3920
|
+
return {
|
|
3921
|
+
url: window.location.href,
|
|
3922
|
+
domain: window.location.host
|
|
3923
|
+
};
|
|
3924
|
+
}
|
|
3925
|
+
return { url: "", domain: "" };
|
|
3926
|
+
}
|
|
3927
|
+
function useRecordActivity(username, activityType, options) {
|
|
3928
|
+
return reactQuery.useMutation({
|
|
3929
|
+
mutationKey: ["analytics", activityType],
|
|
3930
|
+
mutationFn: async () => {
|
|
3931
|
+
if (!activityType) {
|
|
3932
|
+
throw new Error("[SDK][Analytics] \u2013 no activity type provided");
|
|
3933
|
+
}
|
|
3934
|
+
const fetchApi = getBoundFetch();
|
|
3935
|
+
const locationInfo = getLocationInfo();
|
|
3936
|
+
const url = options?.url ?? locationInfo.url;
|
|
3937
|
+
const domain = options?.domain ?? locationInfo.domain;
|
|
3938
|
+
await fetchApi(CONFIG.plausibleHost + "/api/event", {
|
|
3939
|
+
method: "POST",
|
|
3940
|
+
headers: {
|
|
3941
|
+
"Content-Type": "application/json"
|
|
3942
|
+
},
|
|
3943
|
+
body: JSON.stringify({
|
|
3944
|
+
name: activityType,
|
|
3945
|
+
url,
|
|
3946
|
+
domain,
|
|
3947
|
+
props: {
|
|
3948
|
+
username
|
|
3949
|
+
}
|
|
3950
|
+
})
|
|
3951
|
+
});
|
|
3952
|
+
}
|
|
3953
|
+
});
|
|
3954
|
+
}
|
|
3955
|
+
function getDiscoverLeaderboardQueryOptions(duration) {
|
|
3956
|
+
return reactQuery.queryOptions({
|
|
3957
|
+
queryKey: ["analytics", "discover-leaderboard", duration],
|
|
3958
|
+
queryFn: async ({ signal }) => {
|
|
3959
|
+
const response = await fetch(
|
|
3960
|
+
CONFIG.privateApiHost + `/private-api/leaderboard/${duration}`,
|
|
3961
|
+
{ signal }
|
|
3962
|
+
);
|
|
3963
|
+
if (!response.ok) {
|
|
3964
|
+
throw new Error(`Failed to fetch leaderboard: ${response.status}`);
|
|
3965
|
+
}
|
|
3966
|
+
return response.json();
|
|
3967
|
+
}
|
|
3968
|
+
});
|
|
3969
|
+
}
|
|
3970
|
+
function getDiscoverCurationQueryOptions(duration) {
|
|
3971
|
+
return reactQuery.queryOptions({
|
|
3972
|
+
queryKey: ["analytics", "discover-curation", duration],
|
|
3973
|
+
queryFn: async ({ signal }) => {
|
|
3974
|
+
const response = await fetch(
|
|
3975
|
+
CONFIG.privateApiHost + `/private-api/curation/${duration}`,
|
|
3976
|
+
{ signal }
|
|
3977
|
+
);
|
|
3978
|
+
if (!response.ok) {
|
|
3979
|
+
throw new Error(`Failed to fetch curation data: ${response.status}`);
|
|
3980
|
+
}
|
|
3981
|
+
const data = await response.json();
|
|
3982
|
+
const accounts = data.map((item) => item.account);
|
|
3983
|
+
const accountsResponse = await CONFIG.hiveClient.database.getAccounts(accounts);
|
|
3984
|
+
for (let index = 0; index < accountsResponse.length; index++) {
|
|
3985
|
+
const element = accountsResponse[index];
|
|
3986
|
+
const curator = data[index];
|
|
3987
|
+
const vestingShares = typeof element.vesting_shares === "string" ? element.vesting_shares : element.vesting_shares.toString();
|
|
3988
|
+
const receivedVestingShares = typeof element.received_vesting_shares === "string" ? element.received_vesting_shares : element.received_vesting_shares.toString();
|
|
3989
|
+
const delegatedVestingShares = typeof element.delegated_vesting_shares === "string" ? element.delegated_vesting_shares : element.delegated_vesting_shares.toString();
|
|
3990
|
+
const vestingWithdrawRate = typeof element.vesting_withdraw_rate === "string" ? element.vesting_withdraw_rate : element.vesting_withdraw_rate.toString();
|
|
3991
|
+
const effectiveVest = parseFloat(vestingShares) + parseFloat(receivedVestingShares) - parseFloat(delegatedVestingShares) - parseFloat(vestingWithdrawRate);
|
|
3992
|
+
curator.efficiency = curator.vests / effectiveVest;
|
|
3993
|
+
}
|
|
3994
|
+
data.sort((a, b) => b.efficiency - a.efficiency);
|
|
3995
|
+
return data;
|
|
3996
|
+
}
|
|
3997
|
+
});
|
|
3998
|
+
}
|
|
3999
|
+
function getPageStatsQueryOptions(url, dimensions = [], metrics = ["visitors", "pageviews", "visit_duration"], dateRange) {
|
|
4000
|
+
return reactQuery.queryOptions({
|
|
4001
|
+
queryKey: ["analytics", "page-stats", url, dimensions, metrics, dateRange],
|
|
4002
|
+
queryFn: async ({ signal }) => {
|
|
4003
|
+
const response = await fetch(CONFIG.privateApiHost + "/api/stats", {
|
|
4004
|
+
method: "POST",
|
|
4005
|
+
headers: {
|
|
4006
|
+
"Content-Type": "application/json"
|
|
4007
|
+
},
|
|
4008
|
+
body: JSON.stringify({
|
|
4009
|
+
metrics,
|
|
4010
|
+
url: encodeURIComponent(url),
|
|
4011
|
+
dimensions,
|
|
4012
|
+
date_range: dateRange
|
|
4013
|
+
}),
|
|
4014
|
+
signal
|
|
4015
|
+
});
|
|
4016
|
+
if (!response.ok) {
|
|
4017
|
+
throw new Error(`Failed to fetch page stats: ${response.status}`);
|
|
4018
|
+
}
|
|
4019
|
+
return response.json();
|
|
4020
|
+
},
|
|
4021
|
+
enabled: !!url
|
|
4022
|
+
});
|
|
4023
|
+
}
|
|
4024
|
+
|
|
4025
|
+
// src/modules/integrations/3speak/queries/index.ts
|
|
4026
|
+
var queries_exports2 = {};
|
|
4027
|
+
__export(queries_exports2, {
|
|
4028
|
+
getAccountTokenQueryOptions: () => getAccountTokenQueryOptions,
|
|
4029
|
+
getAccountVideosQueryOptions: () => getAccountVideosQueryOptions
|
|
4030
|
+
});
|
|
4031
|
+
|
|
4032
|
+
// src/modules/integrations/hivesigner/queries/index.ts
|
|
4033
|
+
var queries_exports = {};
|
|
4034
|
+
__export(queries_exports, {
|
|
4035
|
+
getDecodeMemoQueryOptions: () => getDecodeMemoQueryOptions
|
|
4036
|
+
});
|
|
4037
|
+
function getDecodeMemoQueryOptions(username, memo, accessToken) {
|
|
4038
|
+
return reactQuery.queryOptions({
|
|
4039
|
+
queryKey: ["integrations", "hivesigner", "decode-memo", username],
|
|
4040
|
+
queryFn: async () => {
|
|
4041
|
+
if (accessToken) {
|
|
4042
|
+
const hsClient = new hs__default.default.Client({
|
|
4043
|
+
accessToken
|
|
3544
4044
|
});
|
|
3545
4045
|
return hsClient.decode(memo);
|
|
3546
4046
|
}
|
|
@@ -4097,6 +4597,63 @@ function getAnnouncementsQueryOptions() {
|
|
|
4097
4597
|
staleTime: 36e5
|
|
4098
4598
|
});
|
|
4099
4599
|
}
|
|
4600
|
+
function useMarkNotificationsRead(username, code, onSuccess, onError) {
|
|
4601
|
+
const queryClient = getQueryClient();
|
|
4602
|
+
return reactQuery.useMutation({
|
|
4603
|
+
mutationKey: ["notifications", "mark-read", username],
|
|
4604
|
+
mutationFn: async ({ id }) => {
|
|
4605
|
+
if (!username || !code) {
|
|
4606
|
+
throw new Error("[SDK][Notifications] \u2013 missing auth for markNotifications");
|
|
4607
|
+
}
|
|
4608
|
+
return markNotifications(code, id);
|
|
4609
|
+
},
|
|
4610
|
+
// Optimistic update: Immediately mark notifications as read in cache
|
|
4611
|
+
onMutate: async ({ id }) => {
|
|
4612
|
+
await queryClient.cancelQueries({ queryKey: ["notifications"] });
|
|
4613
|
+
const previousNotifications = [];
|
|
4614
|
+
const queriesData = queryClient.getQueriesData({
|
|
4615
|
+
queryKey: ["notifications"]
|
|
4616
|
+
});
|
|
4617
|
+
queriesData.forEach(([queryKey, data]) => {
|
|
4618
|
+
if (data) {
|
|
4619
|
+
previousNotifications.push([queryKey, data]);
|
|
4620
|
+
const updatedData = data.map((item) => ({
|
|
4621
|
+
...item,
|
|
4622
|
+
// If specific ID provided: mark only that notification
|
|
4623
|
+
// If no ID (mark all): mark ALL notifications
|
|
4624
|
+
read: !id || id === item.id ? 1 : item.read
|
|
4625
|
+
}));
|
|
4626
|
+
queryClient.setQueryData(queryKey, updatedData);
|
|
4627
|
+
}
|
|
4628
|
+
});
|
|
4629
|
+
return { previousNotifications };
|
|
4630
|
+
},
|
|
4631
|
+
onSuccess: (response, variables) => {
|
|
4632
|
+
const unreadCount = typeof response === "object" && response !== null ? response.unread : void 0;
|
|
4633
|
+
onSuccess?.(unreadCount);
|
|
4634
|
+
if (!variables.id) {
|
|
4635
|
+
queryClient.invalidateQueries({
|
|
4636
|
+
queryKey: ["notifications"]
|
|
4637
|
+
});
|
|
4638
|
+
}
|
|
4639
|
+
},
|
|
4640
|
+
// Rollback optimistic update on error
|
|
4641
|
+
onError: (error, _variables, context) => {
|
|
4642
|
+
if (context?.previousNotifications) {
|
|
4643
|
+
context.previousNotifications.forEach(([queryKey, data]) => {
|
|
4644
|
+
queryClient.setQueryData(queryKey, data);
|
|
4645
|
+
});
|
|
4646
|
+
}
|
|
4647
|
+
onError?.(error);
|
|
4648
|
+
},
|
|
4649
|
+
// Always refetch after mutation settles
|
|
4650
|
+
onSettled: () => {
|
|
4651
|
+
queryClient.invalidateQueries({
|
|
4652
|
+
queryKey: ["notifications"]
|
|
4653
|
+
});
|
|
4654
|
+
}
|
|
4655
|
+
});
|
|
4656
|
+
}
|
|
4100
4657
|
function getProposalQueryOptions(id) {
|
|
4101
4658
|
return reactQuery.queryOptions({
|
|
4102
4659
|
queryKey: ["proposals", "proposal", id],
|
|
@@ -4126,930 +4683,654 @@ function getProposalsQueryOptions() {
|
|
|
4126
4683
|
status: "all"
|
|
4127
4684
|
});
|
|
4128
4685
|
const proposals = response.proposals;
|
|
4129
|
-
const expired = proposals.filter((x) => x.status === "expired");
|
|
4130
|
-
const others = proposals.filter((x) => x.status !== "expired");
|
|
4131
|
-
return [...others, ...expired];
|
|
4132
|
-
}
|
|
4133
|
-
});
|
|
4134
|
-
}
|
|
4135
|
-
function getProposalVotesInfiniteQueryOptions(proposalId, voter, limit) {
|
|
4136
|
-
return reactQuery.infiniteQueryOptions({
|
|
4137
|
-
queryKey: ["proposals", "votes", proposalId, voter, limit],
|
|
4138
|
-
initialPageParam: voter,
|
|
4139
|
-
refetchOnMount: true,
|
|
4140
|
-
staleTime: 0,
|
|
4141
|
-
// Always refetch on mount
|
|
4142
|
-
queryFn: async ({ pageParam }) => {
|
|
4143
|
-
const startParam = pageParam ?? voter;
|
|
4144
|
-
const response = await CONFIG.hiveClient.call("condenser_api", "list_proposal_votes", [
|
|
4145
|
-
[proposalId, startParam],
|
|
4146
|
-
limit,
|
|
4147
|
-
"by_proposal_voter"
|
|
4148
|
-
]);
|
|
4149
|
-
const list = response.filter((x) => x.proposal?.proposal_id === proposalId).map((x) => ({ id: x.id, voter: x.voter }));
|
|
4150
|
-
const rawAccounts = await CONFIG.hiveClient.database.getAccounts(list.map((l) => l.voter));
|
|
4151
|
-
const accounts = parseAccounts(rawAccounts);
|
|
4152
|
-
const page = list.map((i) => ({
|
|
4153
|
-
...i,
|
|
4154
|
-
voterAccount: accounts.find((a) => i.voter === a.name)
|
|
4155
|
-
}));
|
|
4156
|
-
return page;
|
|
4157
|
-
},
|
|
4158
|
-
getNextPageParam: (lastPage) => {
|
|
4159
|
-
const last = lastPage?.[lastPage.length - 1];
|
|
4160
|
-
return last?.voter ?? void 0;
|
|
4161
|
-
}
|
|
4162
|
-
});
|
|
4163
|
-
}
|
|
4164
|
-
function getUserProposalVotesQueryOptions(voter) {
|
|
4165
|
-
return reactQuery.queryOptions({
|
|
4166
|
-
queryKey: ["proposals", "votes", "by-user", voter],
|
|
4167
|
-
enabled: !!voter && voter !== "",
|
|
4168
|
-
staleTime: 60 * 1e3,
|
|
4169
|
-
// Cache for 1 minute
|
|
4170
|
-
queryFn: async () => {
|
|
4171
|
-
if (!voter || voter === "") {
|
|
4172
|
-
return [];
|
|
4173
|
-
}
|
|
4174
|
-
const response = await CONFIG.hiveClient.call("database_api", "list_proposal_votes", {
|
|
4175
|
-
start: [voter],
|
|
4176
|
-
limit: 1e3,
|
|
4177
|
-
order: "by_voter_proposal",
|
|
4178
|
-
order_direction: "ascending",
|
|
4179
|
-
status: "votable"
|
|
4180
|
-
});
|
|
4181
|
-
const userVotes = (response.proposal_votes || []).filter((vote) => vote.voter === voter);
|
|
4182
|
-
return userVotes;
|
|
4183
|
-
}
|
|
4184
|
-
});
|
|
4185
|
-
}
|
|
4186
|
-
function getVestingDelegationsQueryOptions(username, from, limit = 50) {
|
|
4187
|
-
return reactQuery.queryOptions({
|
|
4188
|
-
queryKey: ["wallet", "vesting-delegations", username, from, limit],
|
|
4189
|
-
queryFn: () => CONFIG.hiveClient.database.call("get_vesting_delegations", [
|
|
4190
|
-
username,
|
|
4191
|
-
from,
|
|
4192
|
-
limit
|
|
4193
|
-
]),
|
|
4194
|
-
enabled: !!username
|
|
4195
|
-
});
|
|
4196
|
-
}
|
|
4197
|
-
function getConversionRequestsQueryOptions(account) {
|
|
4198
|
-
return reactQuery.queryOptions({
|
|
4199
|
-
queryKey: ["wallet", "conversion-requests", account],
|
|
4200
|
-
queryFn: () => CONFIG.hiveClient.database.call("get_conversion_requests", [
|
|
4201
|
-
account
|
|
4202
|
-
]),
|
|
4203
|
-
select: (data) => data.sort((a, b) => a.requestid - b.requestid)
|
|
4204
|
-
});
|
|
4205
|
-
}
|
|
4206
|
-
function getCollateralizedConversionRequestsQueryOptions(account) {
|
|
4207
|
-
return reactQuery.queryOptions({
|
|
4208
|
-
queryKey: ["wallet", "collateralized-conversion-requests", account],
|
|
4209
|
-
queryFn: () => CONFIG.hiveClient.database.call("get_collateralized_conversion_requests", [
|
|
4210
|
-
account
|
|
4211
|
-
]),
|
|
4212
|
-
select: (data) => data.sort((a, b) => a.requestid - b.requestid)
|
|
4213
|
-
});
|
|
4214
|
-
}
|
|
4215
|
-
function getSavingsWithdrawFromQueryOptions(account) {
|
|
4216
|
-
return reactQuery.queryOptions({
|
|
4217
|
-
queryKey: ["wallet", "savings-withdraw", account],
|
|
4218
|
-
queryFn: () => CONFIG.hiveClient.database.call("get_savings_withdraw_from", [
|
|
4219
|
-
account
|
|
4220
|
-
]),
|
|
4221
|
-
select: (data) => data.sort((a, b) => a.request_id - b.request_id)
|
|
4222
|
-
});
|
|
4223
|
-
}
|
|
4224
|
-
function getWithdrawRoutesQueryOptions(account) {
|
|
4225
|
-
return reactQuery.queryOptions({
|
|
4226
|
-
queryKey: ["wallet", "withdraw-routes", account],
|
|
4227
|
-
queryFn: () => CONFIG.hiveClient.database.call("get_withdraw_routes", [
|
|
4228
|
-
account,
|
|
4229
|
-
"outgoing"
|
|
4230
|
-
])
|
|
4231
|
-
});
|
|
4232
|
-
}
|
|
4233
|
-
function getOpenOrdersQueryOptions(user) {
|
|
4234
|
-
return reactQuery.queryOptions({
|
|
4235
|
-
queryKey: ["wallet", "open-orders", user],
|
|
4236
|
-
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_open_orders", [
|
|
4237
|
-
user
|
|
4238
|
-
]),
|
|
4239
|
-
select: (data) => data.sort((a, b) => a.orderid - b.orderid),
|
|
4240
|
-
enabled: !!user
|
|
4241
|
-
});
|
|
4242
|
-
}
|
|
4243
|
-
function getOutgoingRcDelegationsInfiniteQueryOptions(username, limit = 100) {
|
|
4244
|
-
return reactQuery.infiniteQueryOptions({
|
|
4245
|
-
queryKey: ["wallet", "outgoing-rc-delegations", username, limit],
|
|
4246
|
-
initialPageParam: null,
|
|
4247
|
-
queryFn: async ({ pageParam }) => {
|
|
4248
|
-
const response = await CONFIG.hiveClient.call("rc_api", "list_rc_direct_delegations", {
|
|
4249
|
-
start: [username, pageParam ?? ""],
|
|
4250
|
-
limit
|
|
4251
|
-
}).then((r) => r);
|
|
4252
|
-
let delegations = response.rc_direct_delegations || [];
|
|
4253
|
-
if (pageParam) {
|
|
4254
|
-
delegations = delegations.filter((delegation) => delegation.to !== pageParam);
|
|
4255
|
-
}
|
|
4256
|
-
return delegations;
|
|
4257
|
-
},
|
|
4258
|
-
getNextPageParam: (lastPage) => lastPage.length === limit ? lastPage[lastPage.length - 1].to : null
|
|
4259
|
-
});
|
|
4260
|
-
}
|
|
4261
|
-
function getIncomingRcQueryOptions(username) {
|
|
4262
|
-
return reactQuery.queryOptions({
|
|
4263
|
-
queryKey: ["wallet", "incoming-rc", username],
|
|
4264
|
-
enabled: !!username,
|
|
4265
|
-
queryFn: async () => {
|
|
4266
|
-
if (!username) {
|
|
4267
|
-
throw new Error("[SDK][Wallet] - Missing username for incoming RC");
|
|
4268
|
-
}
|
|
4269
|
-
const fetchApi = getBoundFetch();
|
|
4270
|
-
const response = await fetchApi(
|
|
4271
|
-
`${CONFIG.privateApiHost}/private-api/received-rc/${username}`
|
|
4272
|
-
);
|
|
4273
|
-
if (!response.ok) {
|
|
4274
|
-
throw new Error(`Failed to fetch incoming RC: ${response.status}`);
|
|
4275
|
-
}
|
|
4276
|
-
return response.json();
|
|
4277
|
-
}
|
|
4278
|
-
});
|
|
4279
|
-
}
|
|
4280
|
-
function getReceivedVestingSharesQueryOptions(username) {
|
|
4281
|
-
return reactQuery.queryOptions({
|
|
4282
|
-
queryKey: ["wallet", "received-vesting-shares", username],
|
|
4283
|
-
queryFn: async () => {
|
|
4284
|
-
const response = await fetch(
|
|
4285
|
-
CONFIG.privateApiHost + `/private-api/received-vesting/${username}`
|
|
4286
|
-
);
|
|
4287
|
-
if (!response.ok) {
|
|
4288
|
-
throw new Error(`Failed to fetch received vesting shares: ${response.status}`);
|
|
4289
|
-
}
|
|
4290
|
-
const data = await response.json();
|
|
4291
|
-
return data.list;
|
|
4686
|
+
const expired = proposals.filter((x) => x.status === "expired");
|
|
4687
|
+
const others = proposals.filter((x) => x.status !== "expired");
|
|
4688
|
+
return [...others, ...expired];
|
|
4292
4689
|
}
|
|
4293
4690
|
});
|
|
4294
4691
|
}
|
|
4295
|
-
function
|
|
4296
|
-
return reactQuery.queryOptions({
|
|
4297
|
-
queryKey: ["wallet", "recurrent-transfers", username],
|
|
4298
|
-
queryFn: () => CONFIG.hiveClient.call("condenser_api", "find_recurrent_transfers", [
|
|
4299
|
-
username
|
|
4300
|
-
]),
|
|
4301
|
-
enabled: !!username
|
|
4302
|
-
});
|
|
4303
|
-
}
|
|
4304
|
-
function getWitnessesInfiniteQueryOptions(limit) {
|
|
4692
|
+
function getProposalVotesInfiniteQueryOptions(proposalId, voter, limit) {
|
|
4305
4693
|
return reactQuery.infiniteQueryOptions({
|
|
4306
|
-
queryKey: ["
|
|
4307
|
-
initialPageParam:
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4694
|
+
queryKey: ["proposals", "votes", proposalId, voter, limit],
|
|
4695
|
+
initialPageParam: voter,
|
|
4696
|
+
refetchOnMount: true,
|
|
4697
|
+
staleTime: 0,
|
|
4698
|
+
// Always refetch on mount
|
|
4699
|
+
queryFn: async ({ pageParam }) => {
|
|
4700
|
+
const startParam = pageParam ?? voter;
|
|
4701
|
+
const response = await CONFIG.hiveClient.call("condenser_api", "list_proposal_votes", [
|
|
4702
|
+
[proposalId, startParam],
|
|
4703
|
+
limit,
|
|
4704
|
+
"by_proposal_voter"
|
|
4705
|
+
]);
|
|
4706
|
+
const list = response.filter((x) => x.proposal?.proposal_id === proposalId).map((x) => ({ id: x.id, voter: x.voter }));
|
|
4707
|
+
const rawAccounts = await CONFIG.hiveClient.database.getAccounts(list.map((l) => l.voter));
|
|
4708
|
+
const accounts = parseAccounts(rawAccounts);
|
|
4709
|
+
const page = list.map((i) => ({
|
|
4710
|
+
...i,
|
|
4711
|
+
voterAccount: accounts.find((a) => i.voter === a.name)
|
|
4712
|
+
}));
|
|
4713
|
+
return page;
|
|
4714
|
+
},
|
|
4312
4715
|
getNextPageParam: (lastPage) => {
|
|
4313
4716
|
const last = lastPage?.[lastPage.length - 1];
|
|
4314
|
-
return last
|
|
4717
|
+
return last?.voter ?? void 0;
|
|
4315
4718
|
}
|
|
4316
4719
|
});
|
|
4317
4720
|
}
|
|
4318
|
-
function
|
|
4319
|
-
return reactQuery.queryOptions({
|
|
4320
|
-
queryKey: ["market", "order-book", limit],
|
|
4321
|
-
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_order_book", [
|
|
4322
|
-
limit
|
|
4323
|
-
])
|
|
4324
|
-
});
|
|
4325
|
-
}
|
|
4326
|
-
function getMarketStatisticsQueryOptions() {
|
|
4721
|
+
function getUserProposalVotesQueryOptions(voter) {
|
|
4327
4722
|
return reactQuery.queryOptions({
|
|
4328
|
-
queryKey: ["
|
|
4329
|
-
|
|
4723
|
+
queryKey: ["proposals", "votes", "by-user", voter],
|
|
4724
|
+
enabled: !!voter && voter !== "",
|
|
4725
|
+
staleTime: 60 * 1e3,
|
|
4726
|
+
// Cache for 1 minute
|
|
4727
|
+
queryFn: async () => {
|
|
4728
|
+
if (!voter || voter === "") {
|
|
4729
|
+
return [];
|
|
4730
|
+
}
|
|
4731
|
+
const response = await CONFIG.hiveClient.call("database_api", "list_proposal_votes", {
|
|
4732
|
+
start: [voter],
|
|
4733
|
+
limit: 1e3,
|
|
4734
|
+
order: "by_voter_proposal",
|
|
4735
|
+
order_direction: "ascending",
|
|
4736
|
+
status: "votable"
|
|
4737
|
+
});
|
|
4738
|
+
const userVotes = (response.proposal_votes || []).filter((vote) => vote.voter === voter);
|
|
4739
|
+
return userVotes;
|
|
4740
|
+
}
|
|
4330
4741
|
});
|
|
4331
4742
|
}
|
|
4332
|
-
function
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4743
|
+
function getVestingDelegationsQueryOptions(username, limit = 50) {
|
|
4744
|
+
return reactQuery.infiniteQueryOptions({
|
|
4745
|
+
queryKey: ["wallet", "vesting-delegations", username, limit],
|
|
4746
|
+
initialPageParam: "",
|
|
4747
|
+
queryFn: async ({ pageParam }) => {
|
|
4748
|
+
const fetchLimit = pageParam ? limit + 1 : limit;
|
|
4749
|
+
const result = await CONFIG.hiveClient.database.call("get_vesting_delegations", [
|
|
4750
|
+
username,
|
|
4751
|
+
pageParam || "",
|
|
4752
|
+
fetchLimit
|
|
4753
|
+
]);
|
|
4754
|
+
if (pageParam && result.length > 0 && result[0]?.delegatee === pageParam) {
|
|
4755
|
+
return result.slice(1, limit + 1);
|
|
4756
|
+
}
|
|
4757
|
+
return result;
|
|
4758
|
+
},
|
|
4759
|
+
getNextPageParam: (lastPage) => {
|
|
4760
|
+
if (!lastPage || lastPage.length < limit) {
|
|
4761
|
+
return void 0;
|
|
4762
|
+
}
|
|
4763
|
+
const lastDelegation = lastPage[lastPage.length - 1];
|
|
4764
|
+
return lastDelegation?.delegatee;
|
|
4765
|
+
},
|
|
4766
|
+
enabled: !!username
|
|
4343
4767
|
});
|
|
4344
4768
|
}
|
|
4345
|
-
function
|
|
4769
|
+
function getConversionRequestsQueryOptions(account) {
|
|
4346
4770
|
return reactQuery.queryOptions({
|
|
4347
|
-
queryKey: ["
|
|
4348
|
-
queryFn:
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
[]
|
|
4353
|
-
);
|
|
4354
|
-
const now = /* @__PURE__ */ new Date();
|
|
4355
|
-
const oneDayAgo = new Date(now.getTime() - 864e5);
|
|
4356
|
-
const formatDate2 = (date) => {
|
|
4357
|
-
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
4358
|
-
};
|
|
4359
|
-
const dayChange = await CONFIG.hiveClient.call(
|
|
4360
|
-
"condenser_api",
|
|
4361
|
-
"get_market_history",
|
|
4362
|
-
[86400, formatDate2(oneDayAgo), formatDate2(now)]
|
|
4363
|
-
);
|
|
4364
|
-
const result = {
|
|
4365
|
-
price: +stats.latest,
|
|
4366
|
-
close: dayChange[0] ? dayChange[0].non_hive.open / dayChange[0].hive.open : 0,
|
|
4367
|
-
high: dayChange[0] ? dayChange[0].non_hive.high / dayChange[0].hive.high : 0,
|
|
4368
|
-
low: dayChange[0] ? dayChange[0].non_hive.low / dayChange[0].hive.low : 0,
|
|
4369
|
-
percent: dayChange[0] ? 100 - dayChange[0].non_hive.open / dayChange[0].hive.open * 100 / +stats.latest : 0,
|
|
4370
|
-
totalFromAsset: stats.hive_volume.split(" ")[0],
|
|
4371
|
-
totalToAsset: stats.hbd_volume.split(" ")[0]
|
|
4372
|
-
};
|
|
4373
|
-
return result;
|
|
4374
|
-
}
|
|
4771
|
+
queryKey: ["wallet", "conversion-requests", account],
|
|
4772
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_conversion_requests", [
|
|
4773
|
+
account
|
|
4774
|
+
]),
|
|
4775
|
+
select: (data) => data.sort((a, b) => a.requestid - b.requestid)
|
|
4375
4776
|
});
|
|
4376
4777
|
}
|
|
4377
|
-
function
|
|
4778
|
+
function getCollateralizedConversionRequestsQueryOptions(account) {
|
|
4378
4779
|
return reactQuery.queryOptions({
|
|
4379
|
-
queryKey: ["
|
|
4380
|
-
queryFn:
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
if (!response.ok) {
|
|
4385
|
-
throw new Error(`Failed to fetch market data: ${response.status}`);
|
|
4386
|
-
}
|
|
4387
|
-
return response.json();
|
|
4388
|
-
}
|
|
4780
|
+
queryKey: ["wallet", "collateralized-conversion-requests", account],
|
|
4781
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_collateralized_conversion_requests", [
|
|
4782
|
+
account
|
|
4783
|
+
]),
|
|
4784
|
+
select: (data) => data.sort((a, b) => a.requestid - b.requestid)
|
|
4389
4785
|
});
|
|
4390
4786
|
}
|
|
4391
|
-
function
|
|
4392
|
-
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
4393
|
-
}
|
|
4394
|
-
function getTradeHistoryQueryOptions(limit = 1e3, startDate, endDate) {
|
|
4395
|
-
const end = endDate ?? /* @__PURE__ */ new Date();
|
|
4396
|
-
const start = startDate ?? new Date(end.getTime() - 10 * 60 * 60 * 1e3);
|
|
4787
|
+
function getSavingsWithdrawFromQueryOptions(account) {
|
|
4397
4788
|
return reactQuery.queryOptions({
|
|
4398
|
-
queryKey: ["
|
|
4399
|
-
queryFn: () => CONFIG.hiveClient.call("
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
])
|
|
4789
|
+
queryKey: ["wallet", "savings-withdraw", account],
|
|
4790
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_savings_withdraw_from", [
|
|
4791
|
+
account
|
|
4792
|
+
]),
|
|
4793
|
+
select: (data) => data.sort((a, b) => a.request_id - b.request_id)
|
|
4404
4794
|
});
|
|
4405
4795
|
}
|
|
4406
|
-
|
|
4407
|
-
// src/modules/market/requests.ts
|
|
4408
|
-
async function parseJsonResponse(response) {
|
|
4409
|
-
const data = await response.json();
|
|
4410
|
-
if (!response.ok) {
|
|
4411
|
-
const error = new Error(`Request failed with status ${response.status}`);
|
|
4412
|
-
error.status = response.status;
|
|
4413
|
-
error.data = data;
|
|
4414
|
-
throw error;
|
|
4415
|
-
}
|
|
4416
|
-
return data;
|
|
4417
|
-
}
|
|
4418
|
-
async function getMarketData(coin, vsCurrency, fromTs, toTs) {
|
|
4419
|
-
const fetchApi = getBoundFetch();
|
|
4420
|
-
const url = `https://api.coingecko.com/api/v3/coins/${coin}/market_chart/range?vs_currency=${vsCurrency}&from=${fromTs}&to=${toTs}`;
|
|
4421
|
-
const response = await fetchApi(url);
|
|
4422
|
-
return parseJsonResponse(response);
|
|
4423
|
-
}
|
|
4424
|
-
async function getCurrencyRate(cur) {
|
|
4425
|
-
if (cur === "hbd") {
|
|
4426
|
-
return 1;
|
|
4427
|
-
}
|
|
4428
|
-
const fetchApi = getBoundFetch();
|
|
4429
|
-
const url = `https://api.coingecko.com/api/v3/simple/price?ids=hive_dollar&vs_currencies=${cur}`;
|
|
4430
|
-
const response = await fetchApi(url);
|
|
4431
|
-
const data = await parseJsonResponse(response);
|
|
4432
|
-
return data.hive_dollar[cur];
|
|
4433
|
-
}
|
|
4434
|
-
async function getCurrencyTokenRate(currency, token) {
|
|
4435
|
-
const fetchApi = getBoundFetch();
|
|
4436
|
-
const response = await fetchApi(
|
|
4437
|
-
CONFIG.privateApiHost + `/private-api/market-data/${currency === "hbd" ? "usd" : currency}/${token}`
|
|
4438
|
-
);
|
|
4439
|
-
return parseJsonResponse(response);
|
|
4440
|
-
}
|
|
4441
|
-
async function getCurrencyRates() {
|
|
4442
|
-
const fetchApi = getBoundFetch();
|
|
4443
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/market-data/latest");
|
|
4444
|
-
return parseJsonResponse(response);
|
|
4445
|
-
}
|
|
4446
|
-
async function getHivePrice() {
|
|
4447
|
-
const fetchApi = getBoundFetch();
|
|
4448
|
-
const response = await fetchApi(
|
|
4449
|
-
"https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd"
|
|
4450
|
-
);
|
|
4451
|
-
return parseJsonResponse(response);
|
|
4452
|
-
}
|
|
4453
|
-
function getPointsQueryOptions(username, filter = 0) {
|
|
4796
|
+
function getWithdrawRoutesQueryOptions(account) {
|
|
4454
4797
|
return reactQuery.queryOptions({
|
|
4455
|
-
queryKey: ["
|
|
4456
|
-
queryFn:
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
const name = username.replace("@", "");
|
|
4461
|
-
const pointsResponse = await fetch(CONFIG.privateApiHost + "/private-api/points", {
|
|
4462
|
-
method: "POST",
|
|
4463
|
-
headers: {
|
|
4464
|
-
"Content-Type": "application/json"
|
|
4465
|
-
},
|
|
4466
|
-
body: JSON.stringify({ username: name })
|
|
4467
|
-
});
|
|
4468
|
-
if (!pointsResponse.ok) {
|
|
4469
|
-
throw new Error(`Failed to fetch points: ${pointsResponse.status}`);
|
|
4470
|
-
}
|
|
4471
|
-
const points = await pointsResponse.json();
|
|
4472
|
-
const transactionsResponse = await fetch(
|
|
4473
|
-
CONFIG.privateApiHost + "/private-api/point-list",
|
|
4474
|
-
{
|
|
4475
|
-
method: "POST",
|
|
4476
|
-
headers: {
|
|
4477
|
-
"Content-Type": "application/json"
|
|
4478
|
-
},
|
|
4479
|
-
body: JSON.stringify({ username: name, type: filter })
|
|
4480
|
-
}
|
|
4481
|
-
);
|
|
4482
|
-
if (!transactionsResponse.ok) {
|
|
4483
|
-
throw new Error(`Failed to fetch point transactions: ${transactionsResponse.status}`);
|
|
4484
|
-
}
|
|
4485
|
-
const transactions = await transactionsResponse.json();
|
|
4486
|
-
return {
|
|
4487
|
-
points: points.points,
|
|
4488
|
-
uPoints: points.unclaimed_points,
|
|
4489
|
-
transactions
|
|
4490
|
-
};
|
|
4491
|
-
},
|
|
4492
|
-
staleTime: 3e4,
|
|
4493
|
-
refetchOnMount: true,
|
|
4494
|
-
enabled: !!username
|
|
4798
|
+
queryKey: ["wallet", "withdraw-routes", account],
|
|
4799
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_withdraw_routes", [
|
|
4800
|
+
account,
|
|
4801
|
+
"outgoing"
|
|
4802
|
+
])
|
|
4495
4803
|
});
|
|
4496
4804
|
}
|
|
4497
|
-
function
|
|
4805
|
+
function getOpenOrdersQueryOptions(user) {
|
|
4498
4806
|
return reactQuery.queryOptions({
|
|
4499
|
-
queryKey: ["
|
|
4500
|
-
queryFn:
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
4506
|
-
method: "POST",
|
|
4507
|
-
headers: {
|
|
4508
|
-
"Content-Type": "application/json"
|
|
4509
|
-
},
|
|
4510
|
-
body: JSON.stringify(data)
|
|
4511
|
-
});
|
|
4512
|
-
if (!response.ok) {
|
|
4513
|
-
throw new Error(`Search failed: ${response.status}`);
|
|
4514
|
-
}
|
|
4515
|
-
return response.json();
|
|
4516
|
-
}
|
|
4807
|
+
queryKey: ["wallet", "open-orders", user],
|
|
4808
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_open_orders", [
|
|
4809
|
+
user
|
|
4810
|
+
]),
|
|
4811
|
+
select: (data) => data.sort((a, b) => a.orderid - b.orderid),
|
|
4812
|
+
enabled: !!user
|
|
4517
4813
|
});
|
|
4518
4814
|
}
|
|
4519
|
-
function
|
|
4815
|
+
function getOutgoingRcDelegationsInfiniteQueryOptions(username, limit = 100) {
|
|
4520
4816
|
return reactQuery.infiniteQueryOptions({
|
|
4521
|
-
queryKey: ["
|
|
4522
|
-
initialPageParam:
|
|
4817
|
+
queryKey: ["wallet", "outgoing-rc-delegations", username, limit],
|
|
4818
|
+
initialPageParam: null,
|
|
4523
4819
|
queryFn: async ({ pageParam }) => {
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
let sinceDate;
|
|
4532
|
-
const now = /* @__PURE__ */ new Date();
|
|
4533
|
-
switch (tag) {
|
|
4534
|
-
case "today":
|
|
4535
|
-
sinceDate = new Date(now.getTime() - 24 * 60 * 60 * 1e3);
|
|
4536
|
-
break;
|
|
4537
|
-
case "week":
|
|
4538
|
-
sinceDate = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1e3);
|
|
4539
|
-
break;
|
|
4540
|
-
case "month":
|
|
4541
|
-
sinceDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1e3);
|
|
4542
|
-
break;
|
|
4543
|
-
case "year":
|
|
4544
|
-
sinceDate = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1e3);
|
|
4545
|
-
break;
|
|
4546
|
-
default:
|
|
4547
|
-
sinceDate = void 0;
|
|
4548
|
-
}
|
|
4549
|
-
const q = "* type:post";
|
|
4550
|
-
const sort = what === "rising" ? "children" : what;
|
|
4551
|
-
const since = sinceDate ? sinceDate.toISOString().split(".")[0] : void 0;
|
|
4552
|
-
const hideLow = "0";
|
|
4553
|
-
const votes = tag === "today" ? 50 : 200;
|
|
4554
|
-
const data = { q, sort, hide_low: hideLow };
|
|
4555
|
-
if (since) data.since = since;
|
|
4556
|
-
if (pageParam.sid) data.scroll_id = pageParam.sid;
|
|
4557
|
-
data.votes = votes;
|
|
4558
|
-
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
4559
|
-
method: "POST",
|
|
4560
|
-
headers: {
|
|
4561
|
-
"Content-Type": "application/json"
|
|
4562
|
-
},
|
|
4563
|
-
body: JSON.stringify(data)
|
|
4564
|
-
});
|
|
4565
|
-
if (!response.ok) {
|
|
4566
|
-
throw new Error(`Search failed: ${response.status}`);
|
|
4820
|
+
const response = await CONFIG.hiveClient.call("rc_api", "list_rc_direct_delegations", {
|
|
4821
|
+
start: [username, pageParam ?? ""],
|
|
4822
|
+
limit
|
|
4823
|
+
}).then((r) => r);
|
|
4824
|
+
let delegations = response.rc_direct_delegations || [];
|
|
4825
|
+
if (pageParam) {
|
|
4826
|
+
delegations = delegations.filter((delegation) => delegation.to !== pageParam);
|
|
4567
4827
|
}
|
|
4568
|
-
return
|
|
4569
|
-
},
|
|
4570
|
-
getNextPageParam: (resp) => {
|
|
4571
|
-
return {
|
|
4572
|
-
sid: resp?.scroll_id,
|
|
4573
|
-
hasNextPage: resp.results.length > 0
|
|
4574
|
-
};
|
|
4828
|
+
return delegations;
|
|
4575
4829
|
},
|
|
4576
|
-
|
|
4830
|
+
getNextPageParam: (lastPage) => lastPage.length === limit ? lastPage[lastPage.length - 1].to : null
|
|
4577
4831
|
});
|
|
4578
4832
|
}
|
|
4579
|
-
function
|
|
4580
|
-
const { json_metadata, permlink } = entry;
|
|
4581
|
-
let q = "*";
|
|
4582
|
-
q += ` -dporn type:post`;
|
|
4583
|
-
let tags;
|
|
4584
|
-
if (json_metadata && json_metadata.tags && Array.isArray(json_metadata.tags)) {
|
|
4585
|
-
tags = json_metadata.tags.filter((tag) => tag && tag !== "" && typeof tag === "string").filter((tag) => !tag.startsWith("hive-")).filter((_tag, ind) => ind < +retry).join(",");
|
|
4586
|
-
}
|
|
4587
|
-
if (tags && tags.length > 0) {
|
|
4588
|
-
q += ` tag:${tags}`;
|
|
4589
|
-
} else {
|
|
4590
|
-
const fperm = permlink.split("-");
|
|
4591
|
-
tags = fperm.filter((part) => part !== "").filter((part) => !/^-?\d+$/.test(part)).filter((part) => part.length > 2).join(",");
|
|
4592
|
-
q += ` tag:${tags}`;
|
|
4593
|
-
}
|
|
4594
|
-
return q;
|
|
4595
|
-
}
|
|
4596
|
-
function getSimilarEntriesQueryOptions(entry) {
|
|
4597
|
-
const query = buildQuery(entry);
|
|
4833
|
+
function getIncomingRcQueryOptions(username) {
|
|
4598
4834
|
return reactQuery.queryOptions({
|
|
4599
|
-
queryKey: ["
|
|
4835
|
+
queryKey: ["wallet", "incoming-rc", username],
|
|
4836
|
+
enabled: !!username,
|
|
4600
4837
|
queryFn: async () => {
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
sort: "newest",
|
|
4604
|
-
hide_low: "0"
|
|
4605
|
-
};
|
|
4606
|
-
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
4607
|
-
method: "POST",
|
|
4608
|
-
headers: {
|
|
4609
|
-
"Content-Type": "application/json"
|
|
4610
|
-
},
|
|
4611
|
-
body: JSON.stringify(data)
|
|
4612
|
-
});
|
|
4613
|
-
if (!response.ok) {
|
|
4614
|
-
throw new Error(`Search failed: ${response.status}`);
|
|
4838
|
+
if (!username) {
|
|
4839
|
+
throw new Error("[SDK][Wallet] - Missing username for incoming RC");
|
|
4615
4840
|
}
|
|
4616
|
-
const
|
|
4617
|
-
const
|
|
4618
|
-
|
|
4841
|
+
const fetchApi = getBoundFetch();
|
|
4842
|
+
const response = await fetchApi(
|
|
4843
|
+
`${CONFIG.privateApiHost}/private-api/received-rc/${username}`
|
|
4619
4844
|
);
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
if (entries.find((y) => y.author === result.author) === void 0) {
|
|
4623
|
-
entries.push(result);
|
|
4624
|
-
}
|
|
4845
|
+
if (!response.ok) {
|
|
4846
|
+
throw new Error(`Failed to fetch incoming RC: ${response.status}`);
|
|
4625
4847
|
}
|
|
4626
|
-
return
|
|
4848
|
+
return response.json();
|
|
4627
4849
|
}
|
|
4628
4850
|
});
|
|
4629
4851
|
}
|
|
4630
|
-
function
|
|
4852
|
+
function getReceivedVestingSharesQueryOptions(username) {
|
|
4631
4853
|
return reactQuery.queryOptions({
|
|
4632
|
-
queryKey: ["
|
|
4854
|
+
queryKey: ["wallet", "received-vesting-shares", username],
|
|
4633
4855
|
queryFn: async () => {
|
|
4634
|
-
const
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
headers: {
|
|
4638
|
-
"Content-Type": "application/json"
|
|
4639
|
-
},
|
|
4640
|
-
body: JSON.stringify(data)
|
|
4641
|
-
});
|
|
4856
|
+
const response = await fetch(
|
|
4857
|
+
CONFIG.privateApiHost + `/private-api/received-vesting/${username}`
|
|
4858
|
+
);
|
|
4642
4859
|
if (!response.ok) {
|
|
4643
|
-
throw new Error(`Failed to
|
|
4860
|
+
throw new Error(`Failed to fetch received vesting shares: ${response.status}`);
|
|
4644
4861
|
}
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4862
|
+
const data = await response.json();
|
|
4863
|
+
return data.list;
|
|
4864
|
+
}
|
|
4648
4865
|
});
|
|
4649
4866
|
}
|
|
4650
|
-
function
|
|
4867
|
+
function getRecurrentTransfersQueryOptions(username) {
|
|
4651
4868
|
return reactQuery.queryOptions({
|
|
4652
|
-
queryKey: ["
|
|
4869
|
+
queryKey: ["wallet", "recurrent-transfers", username],
|
|
4870
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "find_recurrent_transfers", [
|
|
4871
|
+
username
|
|
4872
|
+
]),
|
|
4873
|
+
enabled: !!username
|
|
4874
|
+
});
|
|
4875
|
+
}
|
|
4876
|
+
function getWitnessesInfiniteQueryOptions(limit) {
|
|
4877
|
+
return reactQuery.infiniteQueryOptions({
|
|
4878
|
+
queryKey: ["witnesses", "list", limit],
|
|
4879
|
+
initialPageParam: "",
|
|
4880
|
+
queryFn: async ({ pageParam }) => CONFIG.hiveClient.call("condenser_api", "get_witnesses_by_vote", [
|
|
4881
|
+
pageParam,
|
|
4882
|
+
limit
|
|
4883
|
+
]),
|
|
4884
|
+
getNextPageParam: (lastPage) => {
|
|
4885
|
+
const last = lastPage?.[lastPage.length - 1];
|
|
4886
|
+
return last ? last.owner : void 0;
|
|
4887
|
+
}
|
|
4888
|
+
});
|
|
4889
|
+
}
|
|
4890
|
+
function getOrderBookQueryOptions(limit = 500) {
|
|
4891
|
+
return reactQuery.queryOptions({
|
|
4892
|
+
queryKey: ["market", "order-book", limit],
|
|
4893
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_order_book", [
|
|
4894
|
+
limit
|
|
4895
|
+
])
|
|
4896
|
+
});
|
|
4897
|
+
}
|
|
4898
|
+
function getMarketStatisticsQueryOptions() {
|
|
4899
|
+
return reactQuery.queryOptions({
|
|
4900
|
+
queryKey: ["market", "statistics"],
|
|
4901
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_ticker", [])
|
|
4902
|
+
});
|
|
4903
|
+
}
|
|
4904
|
+
function getMarketHistoryQueryOptions(seconds, startDate, endDate) {
|
|
4905
|
+
const formatDate2 = (date) => {
|
|
4906
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
4907
|
+
};
|
|
4908
|
+
return reactQuery.queryOptions({
|
|
4909
|
+
queryKey: ["market", "history", seconds, startDate.getTime(), endDate.getTime()],
|
|
4910
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_market_history", [
|
|
4911
|
+
seconds,
|
|
4912
|
+
formatDate2(startDate),
|
|
4913
|
+
formatDate2(endDate)
|
|
4914
|
+
])
|
|
4915
|
+
});
|
|
4916
|
+
}
|
|
4917
|
+
function getHiveHbdStatsQueryOptions() {
|
|
4918
|
+
return reactQuery.queryOptions({
|
|
4919
|
+
queryKey: ["market", "hive-hbd-stats"],
|
|
4653
4920
|
queryFn: async () => {
|
|
4654
|
-
const
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4921
|
+
const stats = await CONFIG.hiveClient.call(
|
|
4922
|
+
"condenser_api",
|
|
4923
|
+
"get_ticker",
|
|
4924
|
+
[]
|
|
4925
|
+
);
|
|
4926
|
+
const now = /* @__PURE__ */ new Date();
|
|
4927
|
+
const oneDayAgo = new Date(now.getTime() - 864e5);
|
|
4928
|
+
const formatDate2 = (date) => {
|
|
4929
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
4930
|
+
};
|
|
4931
|
+
const dayChange = await CONFIG.hiveClient.call(
|
|
4932
|
+
"condenser_api",
|
|
4933
|
+
"get_market_history",
|
|
4934
|
+
[86400, formatDate2(oneDayAgo), formatDate2(now)]
|
|
4935
|
+
);
|
|
4936
|
+
const result = {
|
|
4937
|
+
price: +stats.latest,
|
|
4938
|
+
close: dayChange[0] ? dayChange[0].non_hive.open / dayChange[0].hive.open : 0,
|
|
4939
|
+
high: dayChange[0] ? dayChange[0].non_hive.high / dayChange[0].hive.high : 0,
|
|
4940
|
+
low: dayChange[0] ? dayChange[0].non_hive.low / dayChange[0].hive.low : 0,
|
|
4941
|
+
percent: dayChange[0] ? 100 - dayChange[0].non_hive.open / dayChange[0].hive.open * 100 / +stats.latest : 0,
|
|
4942
|
+
totalFromAsset: stats.hive_volume.split(" ")[0],
|
|
4943
|
+
totalToAsset: stats.hbd_volume.split(" ")[0]
|
|
4944
|
+
};
|
|
4945
|
+
return result;
|
|
4946
|
+
}
|
|
4668
4947
|
});
|
|
4669
4948
|
}
|
|
4670
|
-
function
|
|
4671
|
-
return reactQuery.
|
|
4672
|
-
queryKey: ["
|
|
4673
|
-
queryFn: async ({
|
|
4674
|
-
const
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
}
|
|
4678
|
-
if (pageParam) {
|
|
4679
|
-
payload.scroll_id = pageParam;
|
|
4680
|
-
}
|
|
4681
|
-
if (votes !== void 0) {
|
|
4682
|
-
payload.votes = votes;
|
|
4683
|
-
}
|
|
4684
|
-
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
4685
|
-
method: "POST",
|
|
4686
|
-
headers: {
|
|
4687
|
-
"Content-Type": "application/json"
|
|
4688
|
-
},
|
|
4689
|
-
body: JSON.stringify(payload)
|
|
4690
|
-
});
|
|
4949
|
+
function getMarketDataQueryOptions(coin, vsCurrency, fromTs, toTs) {
|
|
4950
|
+
return reactQuery.queryOptions({
|
|
4951
|
+
queryKey: ["market", "data", coin, vsCurrency, fromTs, toTs],
|
|
4952
|
+
queryFn: async ({ signal }) => {
|
|
4953
|
+
const fetchApi = getBoundFetch();
|
|
4954
|
+
const url = `https://api.coingecko.com/api/v3/coins/${coin}/market_chart/range?vs_currency=${vsCurrency}&from=${fromTs}&to=${toTs}`;
|
|
4955
|
+
const response = await fetchApi(url, { signal });
|
|
4691
4956
|
if (!response.ok) {
|
|
4692
|
-
throw new Error(`
|
|
4957
|
+
throw new Error(`Failed to fetch market data: ${response.status}`);
|
|
4693
4958
|
}
|
|
4694
4959
|
return response.json();
|
|
4695
|
-
}
|
|
4696
|
-
initialPageParam: void 0,
|
|
4697
|
-
getNextPageParam: (lastPage) => lastPage?.scroll_id,
|
|
4698
|
-
enabled: !!q
|
|
4960
|
+
}
|
|
4699
4961
|
});
|
|
4700
4962
|
}
|
|
4701
|
-
function
|
|
4963
|
+
function formatDate(date) {
|
|
4964
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
4965
|
+
}
|
|
4966
|
+
function getTradeHistoryQueryOptions(limit = 1e3, startDate, endDate) {
|
|
4967
|
+
const end = endDate ?? /* @__PURE__ */ new Date();
|
|
4968
|
+
const start = startDate ?? new Date(end.getTime() - 10 * 60 * 60 * 1e3);
|
|
4702
4969
|
return reactQuery.queryOptions({
|
|
4703
|
-
queryKey: ["
|
|
4704
|
-
queryFn:
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
},
|
|
4710
|
-
body: JSON.stringify({ q })
|
|
4711
|
-
});
|
|
4712
|
-
if (!response.ok) {
|
|
4713
|
-
throw new Error(`Search path failed: ${response.status}`);
|
|
4714
|
-
}
|
|
4715
|
-
const data = await response.json();
|
|
4716
|
-
if (data?.length > 0) {
|
|
4717
|
-
return data;
|
|
4718
|
-
}
|
|
4719
|
-
return [q];
|
|
4720
|
-
}
|
|
4970
|
+
queryKey: ["market", "trade-history", limit, start.getTime(), end.getTime()],
|
|
4971
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_trade_history", [
|
|
4972
|
+
formatDate(start),
|
|
4973
|
+
formatDate(end),
|
|
4974
|
+
limit
|
|
4975
|
+
])
|
|
4721
4976
|
});
|
|
4722
4977
|
}
|
|
4723
4978
|
|
|
4724
|
-
// src/modules/
|
|
4979
|
+
// src/modules/market/requests.ts
|
|
4725
4980
|
async function parseJsonResponse2(response) {
|
|
4726
|
-
const
|
|
4727
|
-
try {
|
|
4728
|
-
return await response.json();
|
|
4729
|
-
} catch {
|
|
4730
|
-
try {
|
|
4731
|
-
return await response.text();
|
|
4732
|
-
} catch {
|
|
4733
|
-
return void 0;
|
|
4734
|
-
}
|
|
4735
|
-
}
|
|
4736
|
-
};
|
|
4737
|
-
const data = await parseBody();
|
|
4981
|
+
const data = await response.json();
|
|
4738
4982
|
if (!response.ok) {
|
|
4739
4983
|
const error = new Error(`Request failed with status ${response.status}`);
|
|
4740
4984
|
error.status = response.status;
|
|
4741
4985
|
error.data = data;
|
|
4742
4986
|
throw error;
|
|
4743
4987
|
}
|
|
4744
|
-
if (data === void 0) {
|
|
4745
|
-
throw new Error("Response body was empty or invalid JSON");
|
|
4746
|
-
}
|
|
4747
4988
|
return data;
|
|
4748
4989
|
}
|
|
4749
|
-
async function
|
|
4750
|
-
const data = { q, sort, hide_low: hideLow };
|
|
4751
|
-
if (since) {
|
|
4752
|
-
data.since = since;
|
|
4753
|
-
}
|
|
4754
|
-
if (scroll_id) {
|
|
4755
|
-
data.scroll_id = scroll_id;
|
|
4756
|
-
}
|
|
4757
|
-
if (votes) {
|
|
4758
|
-
data.votes = votes;
|
|
4759
|
-
}
|
|
4990
|
+
async function getMarketData(coin, vsCurrency, fromTs, toTs) {
|
|
4760
4991
|
const fetchApi = getBoundFetch();
|
|
4761
|
-
const
|
|
4762
|
-
|
|
4763
|
-
headers: {
|
|
4764
|
-
"Content-Type": "application/json"
|
|
4765
|
-
},
|
|
4766
|
-
body: JSON.stringify(data)
|
|
4767
|
-
});
|
|
4992
|
+
const url = `https://api.coingecko.com/api/v3/coins/${coin}/market_chart/range?vs_currency=${vsCurrency}&from=${fromTs}&to=${toTs}`;
|
|
4993
|
+
const response = await fetchApi(url);
|
|
4768
4994
|
return parseJsonResponse2(response);
|
|
4769
4995
|
}
|
|
4770
|
-
async function
|
|
4771
|
-
|
|
4996
|
+
async function getCurrencyRate(cur) {
|
|
4997
|
+
if (cur === "hbd") {
|
|
4998
|
+
return 1;
|
|
4999
|
+
}
|
|
4772
5000
|
const fetchApi = getBoundFetch();
|
|
4773
|
-
const
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
5001
|
+
const url = `https://api.coingecko.com/api/v3/simple/price?ids=hive_dollar&vs_currencies=${cur}`;
|
|
5002
|
+
const response = await fetchApi(url);
|
|
5003
|
+
const data = await parseJsonResponse2(response);
|
|
5004
|
+
return data.hive_dollar[cur];
|
|
5005
|
+
}
|
|
5006
|
+
async function getCurrencyTokenRate(currency, token) {
|
|
5007
|
+
const fetchApi = getBoundFetch();
|
|
5008
|
+
const response = await fetchApi(
|
|
5009
|
+
CONFIG.privateApiHost + `/private-api/market-data/${currency === "hbd" ? "usd" : currency}/${token}`
|
|
5010
|
+
);
|
|
4780
5011
|
return parseJsonResponse2(response);
|
|
4781
5012
|
}
|
|
4782
|
-
async function
|
|
4783
|
-
const data = { q, limit, random };
|
|
5013
|
+
async function getCurrencyRates() {
|
|
4784
5014
|
const fetchApi = getBoundFetch();
|
|
4785
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
4786
|
-
method: "POST",
|
|
4787
|
-
headers: {
|
|
4788
|
-
"Content-Type": "application/json"
|
|
4789
|
-
},
|
|
4790
|
-
body: JSON.stringify(data)
|
|
4791
|
-
});
|
|
5015
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/market-data/latest");
|
|
4792
5016
|
return parseJsonResponse2(response);
|
|
4793
5017
|
}
|
|
4794
|
-
async function
|
|
5018
|
+
async function getHivePrice() {
|
|
4795
5019
|
const fetchApi = getBoundFetch();
|
|
4796
|
-
const response = await fetchApi(
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
5020
|
+
const response = await fetchApi(
|
|
5021
|
+
"https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd"
|
|
5022
|
+
);
|
|
5023
|
+
return parseJsonResponse2(response);
|
|
5024
|
+
}
|
|
5025
|
+
function getPointsQueryOptions(username, filter = 0) {
|
|
5026
|
+
return reactQuery.queryOptions({
|
|
5027
|
+
queryKey: ["points", username, filter],
|
|
5028
|
+
queryFn: async () => {
|
|
5029
|
+
if (!username) {
|
|
5030
|
+
throw new Error("Get points query \u2013 username wasn't provided");
|
|
5031
|
+
}
|
|
5032
|
+
const name = username.replace("@", "");
|
|
5033
|
+
const pointsResponse = await fetch(CONFIG.privateApiHost + "/private-api/points", {
|
|
5034
|
+
method: "POST",
|
|
5035
|
+
headers: {
|
|
5036
|
+
"Content-Type": "application/json"
|
|
5037
|
+
},
|
|
5038
|
+
body: JSON.stringify({ username: name })
|
|
5039
|
+
});
|
|
5040
|
+
if (!pointsResponse.ok) {
|
|
5041
|
+
throw new Error(`Failed to fetch points: ${pointsResponse.status}`);
|
|
5042
|
+
}
|
|
5043
|
+
const points = await pointsResponse.json();
|
|
5044
|
+
const transactionsResponse = await fetch(
|
|
5045
|
+
CONFIG.privateApiHost + "/private-api/point-list",
|
|
5046
|
+
{
|
|
5047
|
+
method: "POST",
|
|
5048
|
+
headers: {
|
|
5049
|
+
"Content-Type": "application/json"
|
|
5050
|
+
},
|
|
5051
|
+
body: JSON.stringify({ username: name, type: filter })
|
|
5052
|
+
}
|
|
5053
|
+
);
|
|
5054
|
+
if (!transactionsResponse.ok) {
|
|
5055
|
+
throw new Error(`Failed to fetch point transactions: ${transactionsResponse.status}`);
|
|
5056
|
+
}
|
|
5057
|
+
const transactions = await transactionsResponse.json();
|
|
5058
|
+
return {
|
|
5059
|
+
points: points.points,
|
|
5060
|
+
uPoints: points.unclaimed_points,
|
|
5061
|
+
transactions
|
|
5062
|
+
};
|
|
4800
5063
|
},
|
|
4801
|
-
|
|
5064
|
+
staleTime: 3e4,
|
|
5065
|
+
refetchOnMount: true,
|
|
5066
|
+
enabled: !!username
|
|
4802
5067
|
});
|
|
4803
|
-
const data = await parseJsonResponse2(response);
|
|
4804
|
-
return data?.length > 0 ? data : [q];
|
|
4805
5068
|
}
|
|
4806
|
-
function
|
|
5069
|
+
function searchQueryOptions(q, sort, hideLow, since, scroll_id, votes) {
|
|
4807
5070
|
return reactQuery.queryOptions({
|
|
4808
|
-
queryKey: ["
|
|
5071
|
+
queryKey: ["search", q, sort, hideLow, since, scroll_id, votes],
|
|
4809
5072
|
queryFn: async () => {
|
|
4810
|
-
|
|
4811
|
-
|
|
5073
|
+
const data = { q, sort, hide_low: hideLow };
|
|
5074
|
+
if (since) data.since = since;
|
|
5075
|
+
if (scroll_id) data.scroll_id = scroll_id;
|
|
5076
|
+
if (votes) data.votes = votes;
|
|
5077
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
5078
|
+
method: "POST",
|
|
5079
|
+
headers: {
|
|
5080
|
+
"Content-Type": "application/json"
|
|
5081
|
+
},
|
|
5082
|
+
body: JSON.stringify(data)
|
|
5083
|
+
});
|
|
5084
|
+
if (!response.ok) {
|
|
5085
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
5086
|
+
}
|
|
5087
|
+
return response.json();
|
|
5088
|
+
}
|
|
5089
|
+
});
|
|
5090
|
+
}
|
|
5091
|
+
function getControversialRisingInfiniteQueryOptions(what, tag, enabled = true) {
|
|
5092
|
+
return reactQuery.infiniteQueryOptions({
|
|
5093
|
+
queryKey: ["search", "controversial-rising", what, tag],
|
|
5094
|
+
initialPageParam: { sid: void 0, hasNextPage: true },
|
|
5095
|
+
queryFn: async ({ pageParam }) => {
|
|
5096
|
+
if (!pageParam.hasNextPage) {
|
|
5097
|
+
return {
|
|
5098
|
+
hits: 0,
|
|
5099
|
+
took: 0,
|
|
5100
|
+
results: []
|
|
5101
|
+
};
|
|
5102
|
+
}
|
|
5103
|
+
let sinceDate;
|
|
5104
|
+
const now = /* @__PURE__ */ new Date();
|
|
5105
|
+
switch (tag) {
|
|
5106
|
+
case "today":
|
|
5107
|
+
sinceDate = new Date(now.getTime() - 24 * 60 * 60 * 1e3);
|
|
5108
|
+
break;
|
|
5109
|
+
case "week":
|
|
5110
|
+
sinceDate = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1e3);
|
|
5111
|
+
break;
|
|
5112
|
+
case "month":
|
|
5113
|
+
sinceDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1e3);
|
|
5114
|
+
break;
|
|
5115
|
+
case "year":
|
|
5116
|
+
sinceDate = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1e3);
|
|
5117
|
+
break;
|
|
5118
|
+
default:
|
|
5119
|
+
sinceDate = void 0;
|
|
4812
5120
|
}
|
|
4813
|
-
const
|
|
5121
|
+
const q = "* type:post";
|
|
5122
|
+
const sort = what === "rising" ? "children" : what;
|
|
5123
|
+
const since = sinceDate ? sinceDate.toISOString().split(".")[0] : void 0;
|
|
5124
|
+
const hideLow = "0";
|
|
5125
|
+
const votes = tag === "today" ? 50 : 200;
|
|
5126
|
+
const data = { q, sort, hide_low: hideLow };
|
|
5127
|
+
if (since) data.since = since;
|
|
5128
|
+
if (pageParam.sid) data.scroll_id = pageParam.sid;
|
|
5129
|
+
data.votes = votes;
|
|
5130
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
4814
5131
|
method: "POST",
|
|
4815
5132
|
headers: {
|
|
4816
5133
|
"Content-Type": "application/json"
|
|
4817
5134
|
},
|
|
4818
|
-
body: JSON.stringify(
|
|
5135
|
+
body: JSON.stringify(data)
|
|
4819
5136
|
});
|
|
4820
5137
|
if (!response.ok) {
|
|
4821
|
-
throw new Error(`
|
|
5138
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
4822
5139
|
}
|
|
4823
|
-
return
|
|
5140
|
+
return response.json();
|
|
4824
5141
|
},
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
5142
|
+
getNextPageParam: (resp) => {
|
|
5143
|
+
return {
|
|
5144
|
+
sid: resp?.scroll_id,
|
|
5145
|
+
hasNextPage: resp.results.length > 0
|
|
5146
|
+
};
|
|
5147
|
+
},
|
|
5148
|
+
enabled
|
|
4828
5149
|
});
|
|
4829
5150
|
}
|
|
4830
|
-
function
|
|
5151
|
+
function buildQuery(entry, retry = 3) {
|
|
5152
|
+
const { json_metadata, permlink } = entry;
|
|
5153
|
+
let q = "*";
|
|
5154
|
+
q += ` -dporn type:post`;
|
|
5155
|
+
let tags;
|
|
5156
|
+
if (json_metadata && json_metadata.tags && Array.isArray(json_metadata.tags)) {
|
|
5157
|
+
tags = json_metadata.tags.filter((tag) => tag && tag !== "" && typeof tag === "string").filter((tag) => !tag.startsWith("hive-")).filter((_tag, ind) => ind < +retry).join(",");
|
|
5158
|
+
}
|
|
5159
|
+
if (tags && tags.length > 0) {
|
|
5160
|
+
q += ` tag:${tags}`;
|
|
5161
|
+
} else {
|
|
5162
|
+
const fperm = permlink.split("-");
|
|
5163
|
+
tags = fperm.filter((part) => part !== "").filter((part) => !/^-?\d+$/.test(part)).filter((part) => part.length > 2).join(",");
|
|
5164
|
+
q += ` tag:${tags}`;
|
|
5165
|
+
}
|
|
5166
|
+
return q;
|
|
5167
|
+
}
|
|
5168
|
+
function getSimilarEntriesQueryOptions(entry) {
|
|
5169
|
+
const query = buildQuery(entry);
|
|
4831
5170
|
return reactQuery.queryOptions({
|
|
4832
|
-
queryKey: ["
|
|
5171
|
+
queryKey: ["search", "similar-entries", entry.author, entry.permlink, query],
|
|
4833
5172
|
queryFn: async () => {
|
|
4834
|
-
const
|
|
5173
|
+
const data = {
|
|
5174
|
+
q: query,
|
|
5175
|
+
sort: "newest",
|
|
5176
|
+
hide_low: "0"
|
|
5177
|
+
};
|
|
5178
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
4835
5179
|
method: "POST",
|
|
4836
5180
|
headers: {
|
|
4837
5181
|
"Content-Type": "application/json"
|
|
4838
5182
|
},
|
|
4839
|
-
body: JSON.stringify(
|
|
5183
|
+
body: JSON.stringify(data)
|
|
4840
5184
|
});
|
|
4841
5185
|
if (!response.ok) {
|
|
4842
|
-
throw new Error(`
|
|
5186
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
4843
5187
|
}
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
5188
|
+
const searchResponse = await response.json();
|
|
5189
|
+
const rawEntries = searchResponse.results.filter(
|
|
5190
|
+
(r) => r.permlink !== entry.permlink && r.tags.indexOf("nsfw") === -1
|
|
5191
|
+
);
|
|
5192
|
+
const entries = [];
|
|
5193
|
+
for (const result of rawEntries) {
|
|
5194
|
+
if (entries.find((y) => y.author === result.author) === void 0) {
|
|
5195
|
+
entries.push(result);
|
|
5196
|
+
}
|
|
5197
|
+
}
|
|
5198
|
+
return entries.slice(0, 3);
|
|
5199
|
+
}
|
|
4847
5200
|
});
|
|
4848
5201
|
}
|
|
4849
|
-
function
|
|
5202
|
+
function getSearchAccountQueryOptions(q, limit = 5, random = false) {
|
|
4850
5203
|
return reactQuery.queryOptions({
|
|
4851
|
-
queryKey: ["
|
|
5204
|
+
queryKey: ["search", "account", q, limit],
|
|
4852
5205
|
queryFn: async () => {
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
}
|
|
4856
|
-
const response = await fetch(CONFIG.privateApiHost + "/private-api/boosted-plus-account", {
|
|
5206
|
+
const data = { q, limit, random: +random };
|
|
5207
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-account", {
|
|
4857
5208
|
method: "POST",
|
|
4858
5209
|
headers: {
|
|
4859
5210
|
"Content-Type": "application/json"
|
|
4860
5211
|
},
|
|
4861
|
-
body: JSON.stringify(
|
|
5212
|
+
body: JSON.stringify(data)
|
|
4862
5213
|
});
|
|
4863
5214
|
if (!response.ok) {
|
|
4864
|
-
throw new Error(`Failed to
|
|
5215
|
+
throw new Error(`Failed to search accounts: ${response.status}`);
|
|
4865
5216
|
}
|
|
4866
|
-
|
|
4867
|
-
return responseData ? {
|
|
4868
|
-
account: responseData.account,
|
|
4869
|
-
expires: new Date(responseData.expires)
|
|
4870
|
-
} : null;
|
|
4871
|
-
},
|
|
4872
|
-
enabled: !!account && !!accessToken
|
|
4873
|
-
});
|
|
4874
|
-
}
|
|
4875
|
-
|
|
4876
|
-
// src/modules/private-api/requests.ts
|
|
4877
|
-
async function parseJsonResponse3(response) {
|
|
4878
|
-
if (!response.ok) {
|
|
4879
|
-
let errorData = void 0;
|
|
4880
|
-
try {
|
|
4881
|
-
errorData = await response.json();
|
|
4882
|
-
} catch {
|
|
4883
|
-
errorData = void 0;
|
|
4884
|
-
}
|
|
4885
|
-
const error = new Error(`Request failed with status ${response.status}`);
|
|
4886
|
-
error.status = response.status;
|
|
4887
|
-
error.data = errorData;
|
|
4888
|
-
throw error;
|
|
4889
|
-
}
|
|
4890
|
-
const text = await response.text();
|
|
4891
|
-
if (!text || text.trim() === "") {
|
|
4892
|
-
return "";
|
|
4893
|
-
}
|
|
4894
|
-
try {
|
|
4895
|
-
return JSON.parse(text);
|
|
4896
|
-
} catch (e) {
|
|
4897
|
-
console.warn("[SDK] Failed to parse JSON response:", e, "Response:", text);
|
|
4898
|
-
return "";
|
|
4899
|
-
}
|
|
4900
|
-
}
|
|
4901
|
-
async function signUp(username, email, referral) {
|
|
4902
|
-
const fetchApi = getBoundFetch();
|
|
4903
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/account-create", {
|
|
4904
|
-
method: "POST",
|
|
4905
|
-
headers: {
|
|
4906
|
-
"Content-Type": "application/json"
|
|
4907
|
-
},
|
|
4908
|
-
body: JSON.stringify({ username, email, referral })
|
|
4909
|
-
});
|
|
4910
|
-
const data = await parseJsonResponse3(response);
|
|
4911
|
-
return { status: response.status, data };
|
|
4912
|
-
}
|
|
4913
|
-
async function subscribeEmail(email) {
|
|
4914
|
-
const fetchApi = getBoundFetch();
|
|
4915
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/subscribe", {
|
|
4916
|
-
method: "POST",
|
|
4917
|
-
headers: {
|
|
4918
|
-
"Content-Type": "application/json"
|
|
4919
|
-
},
|
|
4920
|
-
body: JSON.stringify({ email })
|
|
4921
|
-
});
|
|
4922
|
-
const data = await parseJsonResponse3(response);
|
|
4923
|
-
return { status: response.status, data };
|
|
4924
|
-
}
|
|
4925
|
-
async function usrActivity(code, ty, bl = "", tx = "") {
|
|
4926
|
-
const params = { code, ty };
|
|
4927
|
-
if (bl) {
|
|
4928
|
-
params.bl = bl;
|
|
4929
|
-
}
|
|
4930
|
-
if (tx) {
|
|
4931
|
-
params.tx = tx;
|
|
4932
|
-
}
|
|
4933
|
-
const fetchApi = getBoundFetch();
|
|
4934
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/usr-activity", {
|
|
4935
|
-
method: "POST",
|
|
4936
|
-
headers: {
|
|
4937
|
-
"Content-Type": "application/json"
|
|
4938
|
-
},
|
|
4939
|
-
body: JSON.stringify(params)
|
|
4940
|
-
});
|
|
4941
|
-
await parseJsonResponse3(response);
|
|
4942
|
-
}
|
|
4943
|
-
async function getNotifications(code, filter, since = null, user = null) {
|
|
4944
|
-
const data = {
|
|
4945
|
-
code
|
|
4946
|
-
};
|
|
4947
|
-
if (filter) {
|
|
4948
|
-
data.filter = filter;
|
|
4949
|
-
}
|
|
4950
|
-
if (since) {
|
|
4951
|
-
data.since = since;
|
|
4952
|
-
}
|
|
4953
|
-
if (user) {
|
|
4954
|
-
data.user = user;
|
|
4955
|
-
}
|
|
4956
|
-
const fetchApi = getBoundFetch();
|
|
4957
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/notifications", {
|
|
4958
|
-
method: "POST",
|
|
4959
|
-
headers: {
|
|
4960
|
-
"Content-Type": "application/json"
|
|
4961
|
-
},
|
|
4962
|
-
body: JSON.stringify(data)
|
|
4963
|
-
});
|
|
4964
|
-
return parseJsonResponse3(response);
|
|
4965
|
-
}
|
|
4966
|
-
async function saveNotificationSetting(code, username, system, allows_notify, notify_types, token) {
|
|
4967
|
-
const data = {
|
|
4968
|
-
code,
|
|
4969
|
-
username,
|
|
4970
|
-
token,
|
|
4971
|
-
system,
|
|
4972
|
-
allows_notify,
|
|
4973
|
-
notify_types
|
|
4974
|
-
};
|
|
4975
|
-
const fetchApi = getBoundFetch();
|
|
4976
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/register-device", {
|
|
4977
|
-
method: "POST",
|
|
4978
|
-
headers: {
|
|
4979
|
-
"Content-Type": "application/json"
|
|
4980
|
-
},
|
|
4981
|
-
body: JSON.stringify(data)
|
|
4982
|
-
});
|
|
4983
|
-
return parseJsonResponse3(response);
|
|
4984
|
-
}
|
|
4985
|
-
async function getNotificationSetting(code, username, token) {
|
|
4986
|
-
const data = { code, username, token };
|
|
4987
|
-
const fetchApi = getBoundFetch();
|
|
4988
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/detail-device", {
|
|
4989
|
-
method: "POST",
|
|
4990
|
-
headers: {
|
|
4991
|
-
"Content-Type": "application/json"
|
|
4992
|
-
},
|
|
4993
|
-
body: JSON.stringify(data)
|
|
4994
|
-
});
|
|
4995
|
-
return parseJsonResponse3(response);
|
|
4996
|
-
}
|
|
4997
|
-
async function markNotifications(code, id) {
|
|
4998
|
-
const data = {
|
|
4999
|
-
code
|
|
5000
|
-
};
|
|
5001
|
-
if (id) {
|
|
5002
|
-
data.id = id;
|
|
5003
|
-
}
|
|
5004
|
-
const fetchApi = getBoundFetch();
|
|
5005
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/notifications/mark", {
|
|
5006
|
-
method: "POST",
|
|
5007
|
-
headers: {
|
|
5008
|
-
"Content-Type": "application/json"
|
|
5217
|
+
return response.json();
|
|
5009
5218
|
},
|
|
5010
|
-
|
|
5219
|
+
enabled: !!q
|
|
5011
5220
|
});
|
|
5012
|
-
return parseJsonResponse3(response);
|
|
5013
5221
|
}
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5222
|
+
function getSearchTopicsQueryOptions(q, limit = 20, random = false) {
|
|
5223
|
+
return reactQuery.queryOptions({
|
|
5224
|
+
queryKey: ["search", "topics", q],
|
|
5225
|
+
queryFn: async () => {
|
|
5226
|
+
const data = { q, limit, random: +random };
|
|
5227
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-tag", {
|
|
5228
|
+
method: "POST",
|
|
5229
|
+
headers: {
|
|
5230
|
+
"Content-Type": "application/json"
|
|
5231
|
+
},
|
|
5232
|
+
body: JSON.stringify(data)
|
|
5233
|
+
});
|
|
5234
|
+
if (!response.ok) {
|
|
5235
|
+
throw new Error(`Failed to search topics: ${response.status}`);
|
|
5236
|
+
}
|
|
5237
|
+
return response.json();
|
|
5021
5238
|
},
|
|
5022
|
-
|
|
5239
|
+
enabled: !!q
|
|
5023
5240
|
});
|
|
5024
|
-
return parseJsonResponse3(response);
|
|
5025
5241
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5242
|
+
function getSearchApiInfiniteQueryOptions(q, sort, hideLow, since, votes) {
|
|
5243
|
+
return reactQuery.infiniteQueryOptions({
|
|
5244
|
+
queryKey: ["search", "api", q, sort, hideLow, since, votes],
|
|
5245
|
+
queryFn: async ({ pageParam }) => {
|
|
5246
|
+
const payload = { q, sort, hide_low: hideLow };
|
|
5247
|
+
if (since) {
|
|
5248
|
+
payload.since = since;
|
|
5249
|
+
}
|
|
5250
|
+
if (pageParam) {
|
|
5251
|
+
payload.scroll_id = pageParam;
|
|
5252
|
+
}
|
|
5253
|
+
if (votes !== void 0) {
|
|
5254
|
+
payload.votes = votes;
|
|
5255
|
+
}
|
|
5256
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
5257
|
+
method: "POST",
|
|
5258
|
+
headers: {
|
|
5259
|
+
"Content-Type": "application/json"
|
|
5260
|
+
},
|
|
5261
|
+
body: JSON.stringify(payload)
|
|
5262
|
+
});
|
|
5263
|
+
if (!response.ok) {
|
|
5264
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
5265
|
+
}
|
|
5266
|
+
return response.json();
|
|
5267
|
+
},
|
|
5268
|
+
initialPageParam: void 0,
|
|
5269
|
+
getNextPageParam: (lastPage) => lastPage?.scroll_id,
|
|
5270
|
+
enabled: !!q
|
|
5034
5271
|
});
|
|
5035
|
-
return parseJsonResponse3(response);
|
|
5036
5272
|
}
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5273
|
+
function getSearchPathQueryOptions(q) {
|
|
5274
|
+
return reactQuery.queryOptions({
|
|
5275
|
+
queryKey: ["search", "path", q],
|
|
5276
|
+
queryFn: async () => {
|
|
5277
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-path", {
|
|
5278
|
+
method: "POST",
|
|
5279
|
+
headers: {
|
|
5280
|
+
"Content-Type": "application/json"
|
|
5281
|
+
},
|
|
5282
|
+
body: JSON.stringify({ q })
|
|
5283
|
+
});
|
|
5284
|
+
if (!response.ok) {
|
|
5285
|
+
throw new Error(`Search path failed: ${response.status}`);
|
|
5286
|
+
}
|
|
5287
|
+
const data = await response.json();
|
|
5288
|
+
if (data?.length > 0) {
|
|
5289
|
+
return data;
|
|
5290
|
+
}
|
|
5291
|
+
return [q];
|
|
5292
|
+
}
|
|
5046
5293
|
});
|
|
5047
|
-
return parseJsonResponse3(response);
|
|
5048
5294
|
}
|
|
5049
|
-
|
|
5050
|
-
|
|
5295
|
+
|
|
5296
|
+
// src/modules/search/requests.ts
|
|
5297
|
+
async function parseJsonResponse3(response) {
|
|
5298
|
+
const parseBody = async () => {
|
|
5299
|
+
try {
|
|
5300
|
+
return await response.json();
|
|
5301
|
+
} catch {
|
|
5302
|
+
try {
|
|
5303
|
+
return await response.text();
|
|
5304
|
+
} catch {
|
|
5305
|
+
return void 0;
|
|
5306
|
+
}
|
|
5307
|
+
}
|
|
5308
|
+
};
|
|
5309
|
+
const data = await parseBody();
|
|
5310
|
+
if (!response.ok) {
|
|
5311
|
+
const error = new Error(`Request failed with status ${response.status}`);
|
|
5312
|
+
error.status = response.status;
|
|
5313
|
+
error.data = data;
|
|
5314
|
+
throw error;
|
|
5315
|
+
}
|
|
5316
|
+
if (data === void 0) {
|
|
5317
|
+
throw new Error("Response body was empty or invalid JSON");
|
|
5318
|
+
}
|
|
5319
|
+
return data;
|
|
5320
|
+
}
|
|
5321
|
+
async function search(q, sort, hideLow, since, scroll_id, votes) {
|
|
5322
|
+
const data = { q, sort, hide_low: hideLow };
|
|
5323
|
+
if (since) {
|
|
5324
|
+
data.since = since;
|
|
5325
|
+
}
|
|
5326
|
+
if (scroll_id) {
|
|
5327
|
+
data.scroll_id = scroll_id;
|
|
5328
|
+
}
|
|
5329
|
+
if (votes) {
|
|
5330
|
+
data.votes = votes;
|
|
5331
|
+
}
|
|
5051
5332
|
const fetchApi = getBoundFetch();
|
|
5052
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
5333
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/search-api/search", {
|
|
5053
5334
|
method: "POST",
|
|
5054
5335
|
headers: {
|
|
5055
5336
|
"Content-Type": "application/json"
|
|
@@ -5058,10 +5339,10 @@ async function addDraft(code, title, body, tags, meta) {
|
|
|
5058
5339
|
});
|
|
5059
5340
|
return parseJsonResponse3(response);
|
|
5060
5341
|
}
|
|
5061
|
-
async function
|
|
5062
|
-
const data = {
|
|
5342
|
+
async function searchAccount(q = "", limit = 20, random = 1) {
|
|
5343
|
+
const data = { q, limit, random };
|
|
5063
5344
|
const fetchApi = getBoundFetch();
|
|
5064
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
5345
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/search-api/search-account", {
|
|
5065
5346
|
method: "POST",
|
|
5066
5347
|
headers: {
|
|
5067
5348
|
"Content-Type": "application/json"
|
|
@@ -5070,10 +5351,10 @@ async function updateDraft(code, draftId, title, body, tags, meta) {
|
|
|
5070
5351
|
});
|
|
5071
5352
|
return parseJsonResponse3(response);
|
|
5072
5353
|
}
|
|
5073
|
-
async function
|
|
5074
|
-
const data = {
|
|
5354
|
+
async function searchTag(q = "", limit = 20, random = 0) {
|
|
5355
|
+
const data = { q, limit, random };
|
|
5075
5356
|
const fetchApi = getBoundFetch();
|
|
5076
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
5357
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/search-api/search-tag", {
|
|
5077
5358
|
method: "POST",
|
|
5078
5359
|
headers: {
|
|
5079
5360
|
"Content-Type": "application/json"
|
|
@@ -5082,83 +5363,86 @@ async function deleteDraft(code, draftId) {
|
|
|
5082
5363
|
});
|
|
5083
5364
|
return parseJsonResponse3(response);
|
|
5084
5365
|
}
|
|
5085
|
-
async function
|
|
5086
|
-
const data = {
|
|
5087
|
-
code,
|
|
5088
|
-
permlink,
|
|
5089
|
-
title,
|
|
5090
|
-
body,
|
|
5091
|
-
meta,
|
|
5092
|
-
schedule,
|
|
5093
|
-
reblog
|
|
5094
|
-
};
|
|
5095
|
-
if (options) {
|
|
5096
|
-
data.options = options;
|
|
5097
|
-
}
|
|
5366
|
+
async function searchPath(q) {
|
|
5098
5367
|
const fetchApi = getBoundFetch();
|
|
5099
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
5368
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/search-api/search-path", {
|
|
5100
5369
|
method: "POST",
|
|
5101
5370
|
headers: {
|
|
5102
5371
|
"Content-Type": "application/json"
|
|
5103
5372
|
},
|
|
5104
|
-
body: JSON.stringify(
|
|
5373
|
+
body: JSON.stringify({ q })
|
|
5105
5374
|
});
|
|
5106
|
-
|
|
5375
|
+
const data = await parseJsonResponse3(response);
|
|
5376
|
+
return data?.length > 0 ? data : [q];
|
|
5107
5377
|
}
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5378
|
+
function getBoostPlusPricesQueryOptions(accessToken) {
|
|
5379
|
+
return reactQuery.queryOptions({
|
|
5380
|
+
queryKey: ["promotions", "boost-plus-prices"],
|
|
5381
|
+
queryFn: async () => {
|
|
5382
|
+
if (!accessToken) {
|
|
5383
|
+
return [];
|
|
5384
|
+
}
|
|
5385
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/boost-plus-price", {
|
|
5386
|
+
method: "POST",
|
|
5387
|
+
headers: {
|
|
5388
|
+
"Content-Type": "application/json"
|
|
5389
|
+
},
|
|
5390
|
+
body: JSON.stringify({ code: accessToken })
|
|
5391
|
+
});
|
|
5392
|
+
if (!response.ok) {
|
|
5393
|
+
throw new Error(`Failed to fetch boost plus prices: ${response.status}`);
|
|
5394
|
+
}
|
|
5395
|
+
return await response.json();
|
|
5115
5396
|
},
|
|
5116
|
-
|
|
5397
|
+
staleTime: Infinity,
|
|
5398
|
+
refetchOnMount: true,
|
|
5399
|
+
enabled: !!accessToken
|
|
5117
5400
|
});
|
|
5118
|
-
return parseJsonResponse3(response);
|
|
5119
5401
|
}
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5402
|
+
function getPromotePriceQueryOptions(accessToken) {
|
|
5403
|
+
return reactQuery.queryOptions({
|
|
5404
|
+
queryKey: ["promotions", "promote-price"],
|
|
5405
|
+
queryFn: async () => {
|
|
5406
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/promote-price", {
|
|
5407
|
+
method: "POST",
|
|
5408
|
+
headers: {
|
|
5409
|
+
"Content-Type": "application/json"
|
|
5410
|
+
},
|
|
5411
|
+
body: JSON.stringify({ code: accessToken })
|
|
5412
|
+
});
|
|
5413
|
+
if (!response.ok) {
|
|
5414
|
+
throw new Error(`Failed to fetch promote prices: ${response.status}`);
|
|
5415
|
+
}
|
|
5416
|
+
return await response.json();
|
|
5127
5417
|
},
|
|
5128
|
-
|
|
5418
|
+
enabled: !!accessToken
|
|
5129
5419
|
});
|
|
5130
|
-
return parseJsonResponse3(response);
|
|
5131
5420
|
}
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5421
|
+
function getBoostPlusAccountPricesQueryOptions(account, accessToken) {
|
|
5422
|
+
return reactQuery.queryOptions({
|
|
5423
|
+
queryKey: ["promotions", "boost-plus-accounts", account],
|
|
5424
|
+
queryFn: async () => {
|
|
5425
|
+
if (!accessToken || !account) {
|
|
5426
|
+
return null;
|
|
5427
|
+
}
|
|
5428
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/boosted-plus-account", {
|
|
5429
|
+
method: "POST",
|
|
5430
|
+
headers: {
|
|
5431
|
+
"Content-Type": "application/json"
|
|
5432
|
+
},
|
|
5433
|
+
body: JSON.stringify({ code: accessToken, account })
|
|
5434
|
+
});
|
|
5435
|
+
if (!response.ok) {
|
|
5436
|
+
throw new Error(`Failed to fetch boost plus account prices: ${response.status}`);
|
|
5437
|
+
}
|
|
5438
|
+
const responseData = await response.json();
|
|
5439
|
+
return responseData ? {
|
|
5440
|
+
account: responseData.account,
|
|
5441
|
+
expires: new Date(responseData.expires)
|
|
5442
|
+
} : null;
|
|
5139
5443
|
},
|
|
5140
|
-
|
|
5444
|
+
enabled: !!account && !!accessToken
|
|
5141
5445
|
});
|
|
5142
|
-
return parseJsonResponse3(response);
|
|
5143
|
-
}
|
|
5144
|
-
async function onboardEmail(username, email, friend) {
|
|
5145
|
-
const dataBody = {
|
|
5146
|
-
username,
|
|
5147
|
-
email,
|
|
5148
|
-
friend
|
|
5149
|
-
};
|
|
5150
|
-
const fetchApi = getBoundFetch();
|
|
5151
|
-
const response = await fetchApi(
|
|
5152
|
-
CONFIG.privateApiHost + "/private-api/account-create-friend",
|
|
5153
|
-
{
|
|
5154
|
-
method: "POST",
|
|
5155
|
-
headers: {
|
|
5156
|
-
"Content-Type": "application/json"
|
|
5157
|
-
},
|
|
5158
|
-
body: JSON.stringify(dataBody)
|
|
5159
|
-
}
|
|
5160
|
-
);
|
|
5161
|
-
return parseJsonResponse3(response);
|
|
5162
5446
|
}
|
|
5163
5447
|
|
|
5164
5448
|
// src/modules/auth/requests.ts
|
|
@@ -5541,6 +5825,7 @@ exports.getEntryActiveVotesQueryOptions = getEntryActiveVotesQueryOptions;
|
|
|
5541
5825
|
exports.getFavouritesInfiniteQueryOptions = getFavouritesInfiniteQueryOptions;
|
|
5542
5826
|
exports.getFavouritesQueryOptions = getFavouritesQueryOptions;
|
|
5543
5827
|
exports.getFollowCountQueryOptions = getFollowCountQueryOptions;
|
|
5828
|
+
exports.getFollowersQueryOptions = getFollowersQueryOptions;
|
|
5544
5829
|
exports.getFollowingQueryOptions = getFollowingQueryOptions;
|
|
5545
5830
|
exports.getFragmentsInfiniteQueryOptions = getFragmentsInfiniteQueryOptions;
|
|
5546
5831
|
exports.getFragmentsQueryOptions = getFragmentsQueryOptions;
|
|
@@ -5624,6 +5909,7 @@ exports.getTradeHistoryQueryOptions = getTradeHistoryQueryOptions;
|
|
|
5624
5909
|
exports.getTransactionsInfiniteQueryOptions = getTransactionsInfiniteQueryOptions;
|
|
5625
5910
|
exports.getTrendingTagsQueryOptions = getTrendingTagsQueryOptions;
|
|
5626
5911
|
exports.getTrendingTagsWithStatsQueryOptions = getTrendingTagsWithStatsQueryOptions;
|
|
5912
|
+
exports.getUserPostVoteQueryOptions = getUserPostVoteQueryOptions;
|
|
5627
5913
|
exports.getUserProposalVotesQueryOptions = getUserProposalVotesQueryOptions;
|
|
5628
5914
|
exports.getVestingDelegationsQueryOptions = getVestingDelegationsQueryOptions;
|
|
5629
5915
|
exports.getVisibleFirstLevelThreadItems = getVisibleFirstLevelThreadItems;
|
|
@@ -5673,17 +5959,27 @@ exports.useAccountUpdate = useAccountUpdate;
|
|
|
5673
5959
|
exports.useAccountUpdateKeyAuths = useAccountUpdateKeyAuths;
|
|
5674
5960
|
exports.useAccountUpdatePassword = useAccountUpdatePassword;
|
|
5675
5961
|
exports.useAccountUpdateRecovery = useAccountUpdateRecovery;
|
|
5962
|
+
exports.useAddDraft = useAddDraft;
|
|
5676
5963
|
exports.useAddFragment = useAddFragment;
|
|
5964
|
+
exports.useAddImage = useAddImage;
|
|
5965
|
+
exports.useAddSchedule = useAddSchedule;
|
|
5677
5966
|
exports.useBookmarkAdd = useBookmarkAdd;
|
|
5678
5967
|
exports.useBookmarkDelete = useBookmarkDelete;
|
|
5679
5968
|
exports.useBroadcastMutation = useBroadcastMutation;
|
|
5969
|
+
exports.useDeleteDraft = useDeleteDraft;
|
|
5970
|
+
exports.useDeleteImage = useDeleteImage;
|
|
5971
|
+
exports.useDeleteSchedule = useDeleteSchedule;
|
|
5680
5972
|
exports.useEditFragment = useEditFragment;
|
|
5681
5973
|
exports.useGameClaim = useGameClaim;
|
|
5974
|
+
exports.useMarkNotificationsRead = useMarkNotificationsRead;
|
|
5975
|
+
exports.useMoveSchedule = useMoveSchedule;
|
|
5682
5976
|
exports.useRecordActivity = useRecordActivity;
|
|
5683
5977
|
exports.useRemoveFragment = useRemoveFragment;
|
|
5684
5978
|
exports.useSignOperationByHivesigner = useSignOperationByHivesigner;
|
|
5685
5979
|
exports.useSignOperationByKey = useSignOperationByKey;
|
|
5686
5980
|
exports.useSignOperationByKeychain = useSignOperationByKeychain;
|
|
5981
|
+
exports.useUpdateDraft = useUpdateDraft;
|
|
5982
|
+
exports.useUploadImage = useUploadImage;
|
|
5687
5983
|
exports.usrActivity = usrActivity;
|
|
5688
5984
|
exports.validatePostCreating = validatePostCreating;
|
|
5689
5985
|
exports.votingPower = votingPower;
|