@ecency/sdk 1.5.13 → 1.5.14
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 +136 -9
- package/dist/browser/index.js +1263 -1005
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +1272 -1004
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +1263 -1005
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -2340,8 +2340,8 @@ function toEntryArray(x) {
|
|
|
2340
2340
|
return Array.isArray(x) ? x : [];
|
|
2341
2341
|
}
|
|
2342
2342
|
async function getVisibleFirstLevelThreadItems(container) {
|
|
2343
|
-
const
|
|
2344
|
-
const discussionItemsRaw = await CONFIG.queryClient.fetchQuery(
|
|
2343
|
+
const queryOptions86 = getDiscussionsQueryOptions(container, "created" /* created */, true);
|
|
2344
|
+
const discussionItemsRaw = await CONFIG.queryClient.fetchQuery(queryOptions86);
|
|
2345
2345
|
const discussionItems = toEntryArray(discussionItemsRaw);
|
|
2346
2346
|
if (discussionItems.length <= 1) {
|
|
2347
2347
|
return [];
|
|
@@ -3313,10 +3313,14 @@ function useAddFragment(username, code) {
|
|
|
3313
3313
|
}
|
|
3314
3314
|
});
|
|
3315
3315
|
}
|
|
3316
|
-
function useEditFragment(username,
|
|
3316
|
+
function useEditFragment(username, code) {
|
|
3317
3317
|
return reactQuery.useMutation({
|
|
3318
|
-
mutationKey: ["posts", "edit-fragment", username
|
|
3319
|
-
mutationFn: async ({
|
|
3318
|
+
mutationKey: ["posts", "edit-fragment", username],
|
|
3319
|
+
mutationFn: async ({
|
|
3320
|
+
fragmentId,
|
|
3321
|
+
title,
|
|
3322
|
+
body
|
|
3323
|
+
}) => {
|
|
3320
3324
|
if (!code) {
|
|
3321
3325
|
throw new Error("[SDK][Posts] Missing access token");
|
|
3322
3326
|
}
|
|
@@ -3338,14 +3342,14 @@ function useEditFragment(username, fragmentId, code) {
|
|
|
3338
3342
|
);
|
|
3339
3343
|
return response.json();
|
|
3340
3344
|
},
|
|
3341
|
-
onSuccess(response) {
|
|
3345
|
+
onSuccess(response, variables) {
|
|
3342
3346
|
getQueryClient().setQueryData(
|
|
3343
3347
|
getFragmentsQueryOptions(username, code).queryKey,
|
|
3344
3348
|
(data) => {
|
|
3345
3349
|
if (!data) {
|
|
3346
3350
|
return [];
|
|
3347
3351
|
}
|
|
3348
|
-
const index = data.findIndex(({ id }) => id === fragmentId);
|
|
3352
|
+
const index = data.findIndex(({ id }) => id === variables.fragmentId);
|
|
3349
3353
|
if (index >= 0) {
|
|
3350
3354
|
data[index] = response;
|
|
3351
3355
|
}
|
|
@@ -3355,10 +3359,10 @@ function useEditFragment(username, fragmentId, code) {
|
|
|
3355
3359
|
}
|
|
3356
3360
|
});
|
|
3357
3361
|
}
|
|
3358
|
-
function useRemoveFragment(username,
|
|
3362
|
+
function useRemoveFragment(username, code) {
|
|
3359
3363
|
return reactQuery.useMutation({
|
|
3360
3364
|
mutationKey: ["posts", "remove-fragment", username],
|
|
3361
|
-
mutationFn: async () => {
|
|
3365
|
+
mutationFn: async ({ fragmentId }) => {
|
|
3362
3366
|
if (!code) {
|
|
3363
3367
|
throw new Error("[SDK][Posts] Missing access token");
|
|
3364
3368
|
}
|
|
@@ -3374,161 +3378,631 @@ function useRemoveFragment(username, fragmentId, code) {
|
|
|
3374
3378
|
}
|
|
3375
3379
|
});
|
|
3376
3380
|
},
|
|
3377
|
-
onSuccess() {
|
|
3381
|
+
onSuccess(_data, variables) {
|
|
3378
3382
|
getQueryClient().setQueryData(
|
|
3379
3383
|
getFragmentsQueryOptions(username, code).queryKey,
|
|
3380
|
-
(data) => [...data ?? []].filter(({ id }) => id !== fragmentId)
|
|
3384
|
+
(data) => [...data ?? []].filter(({ id }) => id !== variables.fragmentId)
|
|
3381
3385
|
);
|
|
3382
3386
|
}
|
|
3383
3387
|
});
|
|
3384
3388
|
}
|
|
3385
3389
|
|
|
3386
|
-
// src/modules/
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
}
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3390
|
+
// src/modules/private-api/requests.ts
|
|
3391
|
+
async function parseJsonResponse(response) {
|
|
3392
|
+
if (!response.ok) {
|
|
3393
|
+
let errorData = void 0;
|
|
3394
|
+
try {
|
|
3395
|
+
errorData = await response.json();
|
|
3396
|
+
} catch {
|
|
3397
|
+
errorData = void 0;
|
|
3398
|
+
}
|
|
3399
|
+
const error = new Error(`Request failed with status ${response.status}`);
|
|
3400
|
+
error.status = response.status;
|
|
3401
|
+
error.data = errorData;
|
|
3402
|
+
throw error;
|
|
3403
|
+
}
|
|
3404
|
+
const text = await response.text();
|
|
3405
|
+
if (!text || text.trim() === "") {
|
|
3406
|
+
return "";
|
|
3407
|
+
}
|
|
3398
3408
|
try {
|
|
3399
|
-
|
|
3409
|
+
return JSON.parse(text);
|
|
3400
3410
|
} catch (e) {
|
|
3401
|
-
response
|
|
3411
|
+
console.warn("[SDK] Failed to parse JSON response:", e, "Response:", text);
|
|
3412
|
+
return "";
|
|
3402
3413
|
}
|
|
3403
|
-
|
|
3404
|
-
|
|
3414
|
+
}
|
|
3415
|
+
async function signUp(username, email, referral) {
|
|
3416
|
+
const fetchApi = getBoundFetch();
|
|
3417
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/account-create", {
|
|
3418
|
+
method: "POST",
|
|
3419
|
+
headers: {
|
|
3420
|
+
"Content-Type": "application/json"
|
|
3421
|
+
},
|
|
3422
|
+
body: JSON.stringify({ username, email, referral })
|
|
3423
|
+
});
|
|
3424
|
+
const data = await parseJsonResponse(response);
|
|
3425
|
+
return { status: response.status, data };
|
|
3426
|
+
}
|
|
3427
|
+
async function subscribeEmail(email) {
|
|
3428
|
+
const fetchApi = getBoundFetch();
|
|
3429
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/subscribe", {
|
|
3430
|
+
method: "POST",
|
|
3431
|
+
headers: {
|
|
3432
|
+
"Content-Type": "application/json"
|
|
3433
|
+
},
|
|
3434
|
+
body: JSON.stringify({ email })
|
|
3435
|
+
});
|
|
3436
|
+
const data = await parseJsonResponse(response);
|
|
3437
|
+
return { status: response.status, data };
|
|
3438
|
+
}
|
|
3439
|
+
async function usrActivity(code, ty, bl = "", tx = "") {
|
|
3440
|
+
const params = { code, ty };
|
|
3441
|
+
if (bl) {
|
|
3442
|
+
params.bl = bl;
|
|
3405
3443
|
}
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
await delay(waitMs);
|
|
3444
|
+
if (tx) {
|
|
3445
|
+
params.tx = tx;
|
|
3409
3446
|
}
|
|
3410
|
-
|
|
3447
|
+
const fetchApi = getBoundFetch();
|
|
3448
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/usr-activity", {
|
|
3449
|
+
method: "POST",
|
|
3450
|
+
headers: {
|
|
3451
|
+
"Content-Type": "application/json"
|
|
3452
|
+
},
|
|
3453
|
+
body: JSON.stringify(params)
|
|
3454
|
+
});
|
|
3455
|
+
await parseJsonResponse(response);
|
|
3411
3456
|
}
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
function getLocationInfo() {
|
|
3419
|
-
if (typeof window !== "undefined" && window.location) {
|
|
3420
|
-
return {
|
|
3421
|
-
url: window.location.href,
|
|
3422
|
-
domain: window.location.host
|
|
3423
|
-
};
|
|
3457
|
+
async function getNotifications(code, filter, since = null, user = null) {
|
|
3458
|
+
const data = {
|
|
3459
|
+
code
|
|
3460
|
+
};
|
|
3461
|
+
if (filter) {
|
|
3462
|
+
data.filter = filter;
|
|
3424
3463
|
}
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
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
|
-
}
|
|
3464
|
+
if (since) {
|
|
3465
|
+
data.since = since;
|
|
3466
|
+
}
|
|
3467
|
+
if (user) {
|
|
3468
|
+
data.user = user;
|
|
3469
|
+
}
|
|
3470
|
+
const fetchApi = getBoundFetch();
|
|
3471
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/notifications", {
|
|
3472
|
+
method: "POST",
|
|
3473
|
+
headers: {
|
|
3474
|
+
"Content-Type": "application/json"
|
|
3475
|
+
},
|
|
3476
|
+
body: JSON.stringify(data)
|
|
3453
3477
|
});
|
|
3478
|
+
return parseJsonResponse(response);
|
|
3454
3479
|
}
|
|
3455
|
-
function
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3480
|
+
async function saveNotificationSetting(code, username, system, allows_notify, notify_types, token) {
|
|
3481
|
+
const data = {
|
|
3482
|
+
code,
|
|
3483
|
+
username,
|
|
3484
|
+
token,
|
|
3485
|
+
system,
|
|
3486
|
+
allows_notify,
|
|
3487
|
+
notify_types
|
|
3488
|
+
};
|
|
3489
|
+
const fetchApi = getBoundFetch();
|
|
3490
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/register-device", {
|
|
3491
|
+
method: "POST",
|
|
3492
|
+
headers: {
|
|
3493
|
+
"Content-Type": "application/json"
|
|
3494
|
+
},
|
|
3495
|
+
body: JSON.stringify(data)
|
|
3468
3496
|
});
|
|
3497
|
+
return parseJsonResponse(response);
|
|
3469
3498
|
}
|
|
3470
|
-
function
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
throw new Error(`Failed to fetch curation data: ${response.status}`);
|
|
3480
|
-
}
|
|
3481
|
-
const data = await response.json();
|
|
3482
|
-
const accounts = data.map((item) => item.account);
|
|
3483
|
-
const accountsResponse = await CONFIG.hiveClient.database.getAccounts(accounts);
|
|
3484
|
-
for (let index = 0; index < accountsResponse.length; index++) {
|
|
3485
|
-
const element = accountsResponse[index];
|
|
3486
|
-
const curator = data[index];
|
|
3487
|
-
const vestingShares = typeof element.vesting_shares === "string" ? element.vesting_shares : element.vesting_shares.toString();
|
|
3488
|
-
const receivedVestingShares = typeof element.received_vesting_shares === "string" ? element.received_vesting_shares : element.received_vesting_shares.toString();
|
|
3489
|
-
const delegatedVestingShares = typeof element.delegated_vesting_shares === "string" ? element.delegated_vesting_shares : element.delegated_vesting_shares.toString();
|
|
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
|
-
}
|
|
3499
|
+
async function getNotificationSetting(code, username, token) {
|
|
3500
|
+
const data = { code, username, token };
|
|
3501
|
+
const fetchApi = getBoundFetch();
|
|
3502
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/detail-device", {
|
|
3503
|
+
method: "POST",
|
|
3504
|
+
headers: {
|
|
3505
|
+
"Content-Type": "application/json"
|
|
3506
|
+
},
|
|
3507
|
+
body: JSON.stringify(data)
|
|
3497
3508
|
});
|
|
3509
|
+
return parseJsonResponse(response);
|
|
3498
3510
|
}
|
|
3499
|
-
function
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
dimensions,
|
|
3512
|
-
date_range: dateRange
|
|
3513
|
-
}),
|
|
3514
|
-
signal
|
|
3515
|
-
});
|
|
3516
|
-
if (!response.ok) {
|
|
3517
|
-
throw new Error(`Failed to fetch page stats: ${response.status}`);
|
|
3518
|
-
}
|
|
3519
|
-
return response.json();
|
|
3511
|
+
async function markNotifications(code, id) {
|
|
3512
|
+
const data = {
|
|
3513
|
+
code
|
|
3514
|
+
};
|
|
3515
|
+
if (id) {
|
|
3516
|
+
data.id = id;
|
|
3517
|
+
}
|
|
3518
|
+
const fetchApi = getBoundFetch();
|
|
3519
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/notifications/mark", {
|
|
3520
|
+
method: "POST",
|
|
3521
|
+
headers: {
|
|
3522
|
+
"Content-Type": "application/json"
|
|
3520
3523
|
},
|
|
3521
|
-
|
|
3524
|
+
body: JSON.stringify(data)
|
|
3525
|
+
});
|
|
3526
|
+
return parseJsonResponse(response);
|
|
3527
|
+
}
|
|
3528
|
+
async function addImage(code, url) {
|
|
3529
|
+
const data = { code, url };
|
|
3530
|
+
const fetchApi = getBoundFetch();
|
|
3531
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/images-add", {
|
|
3532
|
+
method: "POST",
|
|
3533
|
+
headers: {
|
|
3534
|
+
"Content-Type": "application/json"
|
|
3535
|
+
},
|
|
3536
|
+
body: JSON.stringify(data)
|
|
3537
|
+
});
|
|
3538
|
+
return parseJsonResponse(response);
|
|
3539
|
+
}
|
|
3540
|
+
async function uploadImage(file, token, signal) {
|
|
3541
|
+
const fetchApi = getBoundFetch();
|
|
3542
|
+
const formData = new FormData();
|
|
3543
|
+
formData.append("file", file);
|
|
3544
|
+
const response = await fetchApi(`${CONFIG.imageHost}/hs/${token}`, {
|
|
3545
|
+
method: "POST",
|
|
3546
|
+
body: formData,
|
|
3547
|
+
signal
|
|
3548
|
+
});
|
|
3549
|
+
return parseJsonResponse(response);
|
|
3550
|
+
}
|
|
3551
|
+
async function deleteImage(code, imageId) {
|
|
3552
|
+
const data = { code, id: imageId };
|
|
3553
|
+
const fetchApi = getBoundFetch();
|
|
3554
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/images-delete", {
|
|
3555
|
+
method: "POST",
|
|
3556
|
+
headers: {
|
|
3557
|
+
"Content-Type": "application/json"
|
|
3558
|
+
},
|
|
3559
|
+
body: JSON.stringify(data)
|
|
3560
|
+
});
|
|
3561
|
+
return parseJsonResponse(response);
|
|
3562
|
+
}
|
|
3563
|
+
async function addDraft(code, title, body, tags, meta) {
|
|
3564
|
+
const data = { code, title, body, tags, meta };
|
|
3565
|
+
const fetchApi = getBoundFetch();
|
|
3566
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/drafts-add", {
|
|
3567
|
+
method: "POST",
|
|
3568
|
+
headers: {
|
|
3569
|
+
"Content-Type": "application/json"
|
|
3570
|
+
},
|
|
3571
|
+
body: JSON.stringify(data)
|
|
3572
|
+
});
|
|
3573
|
+
return parseJsonResponse(response);
|
|
3574
|
+
}
|
|
3575
|
+
async function updateDraft(code, draftId, title, body, tags, meta) {
|
|
3576
|
+
const data = { code, id: draftId, title, body, tags, meta };
|
|
3577
|
+
const fetchApi = getBoundFetch();
|
|
3578
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/drafts-update", {
|
|
3579
|
+
method: "POST",
|
|
3580
|
+
headers: {
|
|
3581
|
+
"Content-Type": "application/json"
|
|
3582
|
+
},
|
|
3583
|
+
body: JSON.stringify(data)
|
|
3584
|
+
});
|
|
3585
|
+
return parseJsonResponse(response);
|
|
3586
|
+
}
|
|
3587
|
+
async function deleteDraft(code, draftId) {
|
|
3588
|
+
const data = { code, id: draftId };
|
|
3589
|
+
const fetchApi = getBoundFetch();
|
|
3590
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/drafts-delete", {
|
|
3591
|
+
method: "POST",
|
|
3592
|
+
headers: {
|
|
3593
|
+
"Content-Type": "application/json"
|
|
3594
|
+
},
|
|
3595
|
+
body: JSON.stringify(data)
|
|
3596
|
+
});
|
|
3597
|
+
return parseJsonResponse(response);
|
|
3598
|
+
}
|
|
3599
|
+
async function addSchedule(code, permlink, title, body, meta, options, schedule, reblog) {
|
|
3600
|
+
const data = {
|
|
3601
|
+
code,
|
|
3602
|
+
permlink,
|
|
3603
|
+
title,
|
|
3604
|
+
body,
|
|
3605
|
+
meta,
|
|
3606
|
+
schedule,
|
|
3607
|
+
reblog
|
|
3608
|
+
};
|
|
3609
|
+
if (options) {
|
|
3610
|
+
data.options = options;
|
|
3611
|
+
}
|
|
3612
|
+
const fetchApi = getBoundFetch();
|
|
3613
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/schedules-add", {
|
|
3614
|
+
method: "POST",
|
|
3615
|
+
headers: {
|
|
3616
|
+
"Content-Type": "application/json"
|
|
3617
|
+
},
|
|
3618
|
+
body: JSON.stringify(data)
|
|
3619
|
+
});
|
|
3620
|
+
return parseJsonResponse(response);
|
|
3621
|
+
}
|
|
3622
|
+
async function deleteSchedule(code, id) {
|
|
3623
|
+
const data = { code, id };
|
|
3624
|
+
const fetchApi = getBoundFetch();
|
|
3625
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/schedules-delete", {
|
|
3626
|
+
method: "POST",
|
|
3627
|
+
headers: {
|
|
3628
|
+
"Content-Type": "application/json"
|
|
3629
|
+
},
|
|
3630
|
+
body: JSON.stringify(data)
|
|
3631
|
+
});
|
|
3632
|
+
return parseJsonResponse(response);
|
|
3633
|
+
}
|
|
3634
|
+
async function moveSchedule(code, id) {
|
|
3635
|
+
const data = { code, id };
|
|
3636
|
+
const fetchApi = getBoundFetch();
|
|
3637
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/schedules-move", {
|
|
3638
|
+
method: "POST",
|
|
3639
|
+
headers: {
|
|
3640
|
+
"Content-Type": "application/json"
|
|
3641
|
+
},
|
|
3642
|
+
body: JSON.stringify(data)
|
|
3643
|
+
});
|
|
3644
|
+
return parseJsonResponse(response);
|
|
3645
|
+
}
|
|
3646
|
+
async function getPromotedPost(code, author, permlink) {
|
|
3647
|
+
const data = { code, author, permlink };
|
|
3648
|
+
const fetchApi = getBoundFetch();
|
|
3649
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/promoted-post", {
|
|
3650
|
+
method: "POST",
|
|
3651
|
+
headers: {
|
|
3652
|
+
"Content-Type": "application/json"
|
|
3653
|
+
},
|
|
3654
|
+
body: JSON.stringify(data)
|
|
3655
|
+
});
|
|
3656
|
+
return parseJsonResponse(response);
|
|
3657
|
+
}
|
|
3658
|
+
async function onboardEmail(username, email, friend) {
|
|
3659
|
+
const dataBody = {
|
|
3660
|
+
username,
|
|
3661
|
+
email,
|
|
3662
|
+
friend
|
|
3663
|
+
};
|
|
3664
|
+
const fetchApi = getBoundFetch();
|
|
3665
|
+
const response = await fetchApi(
|
|
3666
|
+
CONFIG.privateApiHost + "/private-api/account-create-friend",
|
|
3667
|
+
{
|
|
3668
|
+
method: "POST",
|
|
3669
|
+
headers: {
|
|
3670
|
+
"Content-Type": "application/json"
|
|
3671
|
+
},
|
|
3672
|
+
body: JSON.stringify(dataBody)
|
|
3673
|
+
}
|
|
3674
|
+
);
|
|
3675
|
+
return parseJsonResponse(response);
|
|
3676
|
+
}
|
|
3677
|
+
|
|
3678
|
+
// src/modules/posts/mutations/use-add-draft.ts
|
|
3679
|
+
function useAddDraft(username, code, onSuccess, onError) {
|
|
3680
|
+
return reactQuery.useMutation({
|
|
3681
|
+
mutationKey: ["posts", "drafts", "add", username],
|
|
3682
|
+
mutationFn: async ({
|
|
3683
|
+
title,
|
|
3684
|
+
body,
|
|
3685
|
+
tags,
|
|
3686
|
+
meta
|
|
3687
|
+
}) => {
|
|
3688
|
+
if (!username || !code) {
|
|
3689
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for addDraft");
|
|
3690
|
+
}
|
|
3691
|
+
return addDraft(code, title, body, tags, meta);
|
|
3692
|
+
},
|
|
3693
|
+
onSuccess: () => {
|
|
3694
|
+
onSuccess?.();
|
|
3695
|
+
getQueryClient().invalidateQueries({
|
|
3696
|
+
queryKey: ["posts", "drafts", username]
|
|
3697
|
+
});
|
|
3698
|
+
},
|
|
3699
|
+
onError
|
|
3700
|
+
});
|
|
3701
|
+
}
|
|
3702
|
+
function useUpdateDraft(username, code, onSuccess, onError) {
|
|
3703
|
+
return reactQuery.useMutation({
|
|
3704
|
+
mutationKey: ["posts", "drafts", "update", username],
|
|
3705
|
+
mutationFn: async ({
|
|
3706
|
+
draftId,
|
|
3707
|
+
title,
|
|
3708
|
+
body,
|
|
3709
|
+
tags,
|
|
3710
|
+
meta
|
|
3711
|
+
}) => {
|
|
3712
|
+
if (!username || !code) {
|
|
3713
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for updateDraft");
|
|
3714
|
+
}
|
|
3715
|
+
return updateDraft(code, draftId, title, body, tags, meta);
|
|
3716
|
+
},
|
|
3717
|
+
onSuccess: () => {
|
|
3718
|
+
onSuccess?.();
|
|
3719
|
+
getQueryClient().invalidateQueries({
|
|
3720
|
+
queryKey: ["posts", "drafts", username]
|
|
3721
|
+
});
|
|
3722
|
+
},
|
|
3723
|
+
onError
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3726
|
+
function useDeleteDraft(username, code, onSuccess, onError) {
|
|
3727
|
+
return reactQuery.useMutation({
|
|
3728
|
+
mutationKey: ["posts", "drafts", "delete", username],
|
|
3729
|
+
mutationFn: async ({ draftId }) => {
|
|
3730
|
+
if (!username || !code) {
|
|
3731
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for deleteDraft");
|
|
3732
|
+
}
|
|
3733
|
+
return deleteDraft(code, draftId);
|
|
3734
|
+
},
|
|
3735
|
+
onSuccess: () => {
|
|
3736
|
+
onSuccess?.();
|
|
3737
|
+
getQueryClient().invalidateQueries({
|
|
3738
|
+
queryKey: ["posts", "drafts", username]
|
|
3739
|
+
});
|
|
3740
|
+
},
|
|
3741
|
+
onError
|
|
3742
|
+
});
|
|
3743
|
+
}
|
|
3744
|
+
function useAddSchedule(username, code, onSuccess, onError) {
|
|
3745
|
+
return reactQuery.useMutation({
|
|
3746
|
+
mutationKey: ["posts", "schedules", "add", username],
|
|
3747
|
+
mutationFn: async ({
|
|
3748
|
+
permlink,
|
|
3749
|
+
title,
|
|
3750
|
+
body,
|
|
3751
|
+
meta,
|
|
3752
|
+
options,
|
|
3753
|
+
schedule,
|
|
3754
|
+
reblog
|
|
3755
|
+
}) => {
|
|
3756
|
+
if (!username || !code) {
|
|
3757
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for addSchedule");
|
|
3758
|
+
}
|
|
3759
|
+
return addSchedule(code, permlink, title, body, meta, options, schedule, reblog);
|
|
3760
|
+
},
|
|
3761
|
+
onSuccess: () => {
|
|
3762
|
+
onSuccess?.();
|
|
3763
|
+
getQueryClient().invalidateQueries({
|
|
3764
|
+
queryKey: ["posts", "schedules", username]
|
|
3765
|
+
});
|
|
3766
|
+
},
|
|
3767
|
+
onError
|
|
3768
|
+
});
|
|
3769
|
+
}
|
|
3770
|
+
function useDeleteSchedule(username, code, onSuccess, onError) {
|
|
3771
|
+
return reactQuery.useMutation({
|
|
3772
|
+
mutationKey: ["posts", "schedules", "delete", username],
|
|
3773
|
+
mutationFn: async ({ id }) => {
|
|
3774
|
+
if (!username || !code) {
|
|
3775
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for deleteSchedule");
|
|
3776
|
+
}
|
|
3777
|
+
return deleteSchedule(code, id);
|
|
3778
|
+
},
|
|
3779
|
+
onSuccess: () => {
|
|
3780
|
+
onSuccess?.();
|
|
3781
|
+
getQueryClient().invalidateQueries({
|
|
3782
|
+
queryKey: ["posts", "schedules", username]
|
|
3783
|
+
});
|
|
3784
|
+
},
|
|
3785
|
+
onError
|
|
3786
|
+
});
|
|
3787
|
+
}
|
|
3788
|
+
function useMoveSchedule(username, code, onSuccess, onError) {
|
|
3789
|
+
return reactQuery.useMutation({
|
|
3790
|
+
mutationKey: ["posts", "schedules", "move", username],
|
|
3791
|
+
mutationFn: async ({ id }) => {
|
|
3792
|
+
if (!username || !code) {
|
|
3793
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for moveSchedule");
|
|
3794
|
+
}
|
|
3795
|
+
return moveSchedule(code, id);
|
|
3796
|
+
},
|
|
3797
|
+
onSuccess: () => {
|
|
3798
|
+
onSuccess?.();
|
|
3799
|
+
getQueryClient().invalidateQueries({
|
|
3800
|
+
queryKey: ["posts", "schedules", username]
|
|
3801
|
+
});
|
|
3802
|
+
getQueryClient().invalidateQueries({
|
|
3803
|
+
queryKey: ["posts", "drafts", username]
|
|
3804
|
+
});
|
|
3805
|
+
},
|
|
3806
|
+
onError
|
|
3807
|
+
});
|
|
3808
|
+
}
|
|
3809
|
+
function useAddImage(username, code, onSuccess, onError) {
|
|
3810
|
+
return reactQuery.useMutation({
|
|
3811
|
+
mutationKey: ["posts", "images", "add", username],
|
|
3812
|
+
mutationFn: async ({ url }) => {
|
|
3813
|
+
if (!username || !code) {
|
|
3814
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for addImage");
|
|
3815
|
+
}
|
|
3816
|
+
return addImage(code, url);
|
|
3817
|
+
},
|
|
3818
|
+
onSuccess: () => {
|
|
3819
|
+
onSuccess?.();
|
|
3820
|
+
getQueryClient().invalidateQueries({
|
|
3821
|
+
queryKey: ["posts", "images", username]
|
|
3822
|
+
});
|
|
3823
|
+
},
|
|
3824
|
+
onError
|
|
3825
|
+
});
|
|
3826
|
+
}
|
|
3827
|
+
function useDeleteImage(username, code, onSuccess, onError) {
|
|
3828
|
+
return reactQuery.useMutation({
|
|
3829
|
+
mutationKey: ["posts", "images", "delete", username],
|
|
3830
|
+
mutationFn: async ({ imageId }) => {
|
|
3831
|
+
if (!username || !code) {
|
|
3832
|
+
throw new Error("[SDK][Posts] \u2013 missing auth for deleteImage");
|
|
3833
|
+
}
|
|
3834
|
+
return deleteImage(code, imageId);
|
|
3835
|
+
},
|
|
3836
|
+
onSuccess: () => {
|
|
3837
|
+
onSuccess?.();
|
|
3838
|
+
getQueryClient().invalidateQueries({
|
|
3839
|
+
queryKey: ["posts", "images", username]
|
|
3840
|
+
});
|
|
3841
|
+
},
|
|
3842
|
+
onError
|
|
3843
|
+
});
|
|
3844
|
+
}
|
|
3845
|
+
function useUploadImage(onSuccess, onError) {
|
|
3846
|
+
return reactQuery.useMutation({
|
|
3847
|
+
mutationKey: ["posts", "images", "upload"],
|
|
3848
|
+
mutationFn: async ({
|
|
3849
|
+
file,
|
|
3850
|
+
token,
|
|
3851
|
+
signal
|
|
3852
|
+
}) => {
|
|
3853
|
+
return uploadImage(file, token, signal);
|
|
3854
|
+
},
|
|
3855
|
+
onSuccess,
|
|
3856
|
+
onError
|
|
3857
|
+
});
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3860
|
+
// src/modules/posts/utils/validate-post-creating.ts
|
|
3861
|
+
var DEFAULT_VALIDATE_POST_DELAYS = [3e3, 3e3, 3e3];
|
|
3862
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
3863
|
+
async function getContent(author, permlink) {
|
|
3864
|
+
return CONFIG.hiveClient.call("condenser_api", "get_content", [
|
|
3865
|
+
author,
|
|
3866
|
+
permlink
|
|
3867
|
+
]);
|
|
3868
|
+
}
|
|
3869
|
+
async function validatePostCreating(author, permlink, attempts = 0, options) {
|
|
3870
|
+
const delays = options?.delays ?? DEFAULT_VALIDATE_POST_DELAYS;
|
|
3871
|
+
let response;
|
|
3872
|
+
try {
|
|
3873
|
+
response = await getContent(author, permlink);
|
|
3874
|
+
} catch (e) {
|
|
3875
|
+
response = void 0;
|
|
3876
|
+
}
|
|
3877
|
+
if (response || attempts >= delays.length) {
|
|
3878
|
+
return;
|
|
3879
|
+
}
|
|
3880
|
+
const waitMs = delays[attempts];
|
|
3881
|
+
if (waitMs > 0) {
|
|
3882
|
+
await delay(waitMs);
|
|
3883
|
+
}
|
|
3884
|
+
return validatePostCreating(author, permlink, attempts + 1, options);
|
|
3885
|
+
}
|
|
3886
|
+
|
|
3887
|
+
// src/modules/analytics/mutations/index.ts
|
|
3888
|
+
var mutations_exports = {};
|
|
3889
|
+
__export(mutations_exports, {
|
|
3890
|
+
useRecordActivity: () => useRecordActivity
|
|
3891
|
+
});
|
|
3892
|
+
function getLocationInfo() {
|
|
3893
|
+
if (typeof window !== "undefined" && window.location) {
|
|
3894
|
+
return {
|
|
3895
|
+
url: window.location.href,
|
|
3896
|
+
domain: window.location.host
|
|
3897
|
+
};
|
|
3898
|
+
}
|
|
3899
|
+
return { url: "", domain: "" };
|
|
3900
|
+
}
|
|
3901
|
+
function useRecordActivity(username, activityType, options) {
|
|
3902
|
+
return reactQuery.useMutation({
|
|
3903
|
+
mutationKey: ["analytics", activityType],
|
|
3904
|
+
mutationFn: async () => {
|
|
3905
|
+
if (!activityType) {
|
|
3906
|
+
throw new Error("[SDK][Analytics] \u2013 no activity type provided");
|
|
3907
|
+
}
|
|
3908
|
+
const fetchApi = getBoundFetch();
|
|
3909
|
+
const locationInfo = getLocationInfo();
|
|
3910
|
+
const url = options?.url ?? locationInfo.url;
|
|
3911
|
+
const domain = options?.domain ?? locationInfo.domain;
|
|
3912
|
+
await fetchApi(CONFIG.plausibleHost + "/api/event", {
|
|
3913
|
+
method: "POST",
|
|
3914
|
+
headers: {
|
|
3915
|
+
"Content-Type": "application/json"
|
|
3916
|
+
},
|
|
3917
|
+
body: JSON.stringify({
|
|
3918
|
+
name: activityType,
|
|
3919
|
+
url,
|
|
3920
|
+
domain,
|
|
3921
|
+
props: {
|
|
3922
|
+
username
|
|
3923
|
+
}
|
|
3924
|
+
})
|
|
3925
|
+
});
|
|
3926
|
+
}
|
|
3927
|
+
});
|
|
3928
|
+
}
|
|
3929
|
+
function getDiscoverLeaderboardQueryOptions(duration) {
|
|
3930
|
+
return reactQuery.queryOptions({
|
|
3931
|
+
queryKey: ["analytics", "discover-leaderboard", duration],
|
|
3932
|
+
queryFn: async ({ signal }) => {
|
|
3933
|
+
const response = await fetch(
|
|
3934
|
+
CONFIG.privateApiHost + `/private-api/leaderboard/${duration}`,
|
|
3935
|
+
{ signal }
|
|
3936
|
+
);
|
|
3937
|
+
if (!response.ok) {
|
|
3938
|
+
throw new Error(`Failed to fetch leaderboard: ${response.status}`);
|
|
3939
|
+
}
|
|
3940
|
+
return response.json();
|
|
3941
|
+
}
|
|
3942
|
+
});
|
|
3943
|
+
}
|
|
3944
|
+
function getDiscoverCurationQueryOptions(duration) {
|
|
3945
|
+
return reactQuery.queryOptions({
|
|
3946
|
+
queryKey: ["analytics", "discover-curation", duration],
|
|
3947
|
+
queryFn: async ({ signal }) => {
|
|
3948
|
+
const response = await fetch(
|
|
3949
|
+
CONFIG.privateApiHost + `/private-api/curation/${duration}`,
|
|
3950
|
+
{ signal }
|
|
3951
|
+
);
|
|
3952
|
+
if (!response.ok) {
|
|
3953
|
+
throw new Error(`Failed to fetch curation data: ${response.status}`);
|
|
3954
|
+
}
|
|
3955
|
+
const data = await response.json();
|
|
3956
|
+
const accounts = data.map((item) => item.account);
|
|
3957
|
+
const accountsResponse = await CONFIG.hiveClient.database.getAccounts(accounts);
|
|
3958
|
+
for (let index = 0; index < accountsResponse.length; index++) {
|
|
3959
|
+
const element = accountsResponse[index];
|
|
3960
|
+
const curator = data[index];
|
|
3961
|
+
const vestingShares = typeof element.vesting_shares === "string" ? element.vesting_shares : element.vesting_shares.toString();
|
|
3962
|
+
const receivedVestingShares = typeof element.received_vesting_shares === "string" ? element.received_vesting_shares : element.received_vesting_shares.toString();
|
|
3963
|
+
const delegatedVestingShares = typeof element.delegated_vesting_shares === "string" ? element.delegated_vesting_shares : element.delegated_vesting_shares.toString();
|
|
3964
|
+
const vestingWithdrawRate = typeof element.vesting_withdraw_rate === "string" ? element.vesting_withdraw_rate : element.vesting_withdraw_rate.toString();
|
|
3965
|
+
const effectiveVest = parseFloat(vestingShares) + parseFloat(receivedVestingShares) - parseFloat(delegatedVestingShares) - parseFloat(vestingWithdrawRate);
|
|
3966
|
+
curator.efficiency = curator.vests / effectiveVest;
|
|
3967
|
+
}
|
|
3968
|
+
data.sort((a, b) => b.efficiency - a.efficiency);
|
|
3969
|
+
return data;
|
|
3970
|
+
}
|
|
3971
|
+
});
|
|
3972
|
+
}
|
|
3973
|
+
function getPageStatsQueryOptions(url, dimensions = [], metrics = ["visitors", "pageviews", "visit_duration"], dateRange) {
|
|
3974
|
+
return reactQuery.queryOptions({
|
|
3975
|
+
queryKey: ["analytics", "page-stats", url, dimensions, metrics, dateRange],
|
|
3976
|
+
queryFn: async ({ signal }) => {
|
|
3977
|
+
const response = await fetch(CONFIG.privateApiHost + "/api/stats", {
|
|
3978
|
+
method: "POST",
|
|
3979
|
+
headers: {
|
|
3980
|
+
"Content-Type": "application/json"
|
|
3981
|
+
},
|
|
3982
|
+
body: JSON.stringify({
|
|
3983
|
+
metrics,
|
|
3984
|
+
url: encodeURIComponent(url),
|
|
3985
|
+
dimensions,
|
|
3986
|
+
date_range: dateRange
|
|
3987
|
+
}),
|
|
3988
|
+
signal
|
|
3989
|
+
});
|
|
3990
|
+
if (!response.ok) {
|
|
3991
|
+
throw new Error(`Failed to fetch page stats: ${response.status}`);
|
|
3992
|
+
}
|
|
3993
|
+
return response.json();
|
|
3994
|
+
},
|
|
3995
|
+
enabled: !!url
|
|
3522
3996
|
});
|
|
3523
3997
|
}
|
|
3524
3998
|
|
|
3525
|
-
// src/modules/integrations/3speak/queries/index.ts
|
|
3526
|
-
var queries_exports2 = {};
|
|
3527
|
-
__export(queries_exports2, {
|
|
3528
|
-
getAccountTokenQueryOptions: () => getAccountTokenQueryOptions,
|
|
3529
|
-
getAccountVideosQueryOptions: () => getAccountVideosQueryOptions
|
|
3530
|
-
});
|
|
3531
|
-
|
|
3999
|
+
// src/modules/integrations/3speak/queries/index.ts
|
|
4000
|
+
var queries_exports2 = {};
|
|
4001
|
+
__export(queries_exports2, {
|
|
4002
|
+
getAccountTokenQueryOptions: () => getAccountTokenQueryOptions,
|
|
4003
|
+
getAccountVideosQueryOptions: () => getAccountVideosQueryOptions
|
|
4004
|
+
});
|
|
4005
|
+
|
|
3532
4006
|
// src/modules/integrations/hivesigner/queries/index.ts
|
|
3533
4007
|
var queries_exports = {};
|
|
3534
4008
|
__export(queries_exports, {
|
|
@@ -4097,6 +4571,63 @@ function getAnnouncementsQueryOptions() {
|
|
|
4097
4571
|
staleTime: 36e5
|
|
4098
4572
|
});
|
|
4099
4573
|
}
|
|
4574
|
+
function useMarkNotificationsRead(username, code, onSuccess, onError) {
|
|
4575
|
+
const queryClient = getQueryClient();
|
|
4576
|
+
return reactQuery.useMutation({
|
|
4577
|
+
mutationKey: ["notifications", "mark-read", username],
|
|
4578
|
+
mutationFn: async ({ id }) => {
|
|
4579
|
+
if (!username || !code) {
|
|
4580
|
+
throw new Error("[SDK][Notifications] \u2013 missing auth for markNotifications");
|
|
4581
|
+
}
|
|
4582
|
+
return markNotifications(code, id);
|
|
4583
|
+
},
|
|
4584
|
+
// Optimistic update: Immediately mark notifications as read in cache
|
|
4585
|
+
onMutate: async ({ id }) => {
|
|
4586
|
+
await queryClient.cancelQueries({ queryKey: ["notifications"] });
|
|
4587
|
+
const previousNotifications = [];
|
|
4588
|
+
const queriesData = queryClient.getQueriesData({
|
|
4589
|
+
queryKey: ["notifications"]
|
|
4590
|
+
});
|
|
4591
|
+
queriesData.forEach(([queryKey, data]) => {
|
|
4592
|
+
if (data) {
|
|
4593
|
+
previousNotifications.push([queryKey, data]);
|
|
4594
|
+
const updatedData = data.map((item) => ({
|
|
4595
|
+
...item,
|
|
4596
|
+
// If specific ID provided: mark only that notification
|
|
4597
|
+
// If no ID (mark all): mark ALL notifications
|
|
4598
|
+
read: !id || id === item.id ? 1 : item.read
|
|
4599
|
+
}));
|
|
4600
|
+
queryClient.setQueryData(queryKey, updatedData);
|
|
4601
|
+
}
|
|
4602
|
+
});
|
|
4603
|
+
return { previousNotifications };
|
|
4604
|
+
},
|
|
4605
|
+
onSuccess: (response, variables) => {
|
|
4606
|
+
const unreadCount = typeof response === "object" && response !== null ? response.unread : void 0;
|
|
4607
|
+
onSuccess?.(unreadCount);
|
|
4608
|
+
if (!variables.id) {
|
|
4609
|
+
queryClient.invalidateQueries({
|
|
4610
|
+
queryKey: ["notifications"]
|
|
4611
|
+
});
|
|
4612
|
+
}
|
|
4613
|
+
},
|
|
4614
|
+
// Rollback optimistic update on error
|
|
4615
|
+
onError: (error, _variables, context) => {
|
|
4616
|
+
if (context?.previousNotifications) {
|
|
4617
|
+
context.previousNotifications.forEach(([queryKey, data]) => {
|
|
4618
|
+
queryClient.setQueryData(queryKey, data);
|
|
4619
|
+
});
|
|
4620
|
+
}
|
|
4621
|
+
onError?.(error);
|
|
4622
|
+
},
|
|
4623
|
+
// Always refetch after mutation settles
|
|
4624
|
+
onSettled: () => {
|
|
4625
|
+
queryClient.invalidateQueries({
|
|
4626
|
+
queryKey: ["notifications"]
|
|
4627
|
+
});
|
|
4628
|
+
}
|
|
4629
|
+
});
|
|
4630
|
+
}
|
|
4100
4631
|
function getProposalQueryOptions(id) {
|
|
4101
4632
|
return reactQuery.queryOptions({
|
|
4102
4633
|
queryKey: ["proposals", "proposal", id],
|
|
@@ -4126,930 +4657,654 @@ function getProposalsQueryOptions() {
|
|
|
4126
4657
|
status: "all"
|
|
4127
4658
|
});
|
|
4128
4659
|
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;
|
|
4660
|
+
const expired = proposals.filter((x) => x.status === "expired");
|
|
4661
|
+
const others = proposals.filter((x) => x.status !== "expired");
|
|
4662
|
+
return [...others, ...expired];
|
|
4292
4663
|
}
|
|
4293
4664
|
});
|
|
4294
4665
|
}
|
|
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) {
|
|
4666
|
+
function getProposalVotesInfiniteQueryOptions(proposalId, voter, limit) {
|
|
4305
4667
|
return reactQuery.infiniteQueryOptions({
|
|
4306
|
-
queryKey: ["
|
|
4307
|
-
initialPageParam:
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4668
|
+
queryKey: ["proposals", "votes", proposalId, voter, limit],
|
|
4669
|
+
initialPageParam: voter,
|
|
4670
|
+
refetchOnMount: true,
|
|
4671
|
+
staleTime: 0,
|
|
4672
|
+
// Always refetch on mount
|
|
4673
|
+
queryFn: async ({ pageParam }) => {
|
|
4674
|
+
const startParam = pageParam ?? voter;
|
|
4675
|
+
const response = await CONFIG.hiveClient.call("condenser_api", "list_proposal_votes", [
|
|
4676
|
+
[proposalId, startParam],
|
|
4677
|
+
limit,
|
|
4678
|
+
"by_proposal_voter"
|
|
4679
|
+
]);
|
|
4680
|
+
const list = response.filter((x) => x.proposal?.proposal_id === proposalId).map((x) => ({ id: x.id, voter: x.voter }));
|
|
4681
|
+
const rawAccounts = await CONFIG.hiveClient.database.getAccounts(list.map((l) => l.voter));
|
|
4682
|
+
const accounts = parseAccounts(rawAccounts);
|
|
4683
|
+
const page = list.map((i) => ({
|
|
4684
|
+
...i,
|
|
4685
|
+
voterAccount: accounts.find((a) => i.voter === a.name)
|
|
4686
|
+
}));
|
|
4687
|
+
return page;
|
|
4688
|
+
},
|
|
4312
4689
|
getNextPageParam: (lastPage) => {
|
|
4313
4690
|
const last = lastPage?.[lastPage.length - 1];
|
|
4314
|
-
return last
|
|
4691
|
+
return last?.voter ?? void 0;
|
|
4315
4692
|
}
|
|
4316
4693
|
});
|
|
4317
4694
|
}
|
|
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() {
|
|
4695
|
+
function getUserProposalVotesQueryOptions(voter) {
|
|
4327
4696
|
return reactQuery.queryOptions({
|
|
4328
|
-
queryKey: ["
|
|
4329
|
-
|
|
4697
|
+
queryKey: ["proposals", "votes", "by-user", voter],
|
|
4698
|
+
enabled: !!voter && voter !== "",
|
|
4699
|
+
staleTime: 60 * 1e3,
|
|
4700
|
+
// Cache for 1 minute
|
|
4701
|
+
queryFn: async () => {
|
|
4702
|
+
if (!voter || voter === "") {
|
|
4703
|
+
return [];
|
|
4704
|
+
}
|
|
4705
|
+
const response = await CONFIG.hiveClient.call("database_api", "list_proposal_votes", {
|
|
4706
|
+
start: [voter],
|
|
4707
|
+
limit: 1e3,
|
|
4708
|
+
order: "by_voter_proposal",
|
|
4709
|
+
order_direction: "ascending",
|
|
4710
|
+
status: "votable"
|
|
4711
|
+
});
|
|
4712
|
+
const userVotes = (response.proposal_votes || []).filter((vote) => vote.voter === voter);
|
|
4713
|
+
return userVotes;
|
|
4714
|
+
}
|
|
4330
4715
|
});
|
|
4331
4716
|
}
|
|
4332
|
-
function
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4717
|
+
function getVestingDelegationsQueryOptions(username, limit = 50) {
|
|
4718
|
+
return reactQuery.infiniteQueryOptions({
|
|
4719
|
+
queryKey: ["wallet", "vesting-delegations", username, limit],
|
|
4720
|
+
initialPageParam: "",
|
|
4721
|
+
queryFn: async ({ pageParam }) => {
|
|
4722
|
+
const fetchLimit = pageParam ? limit + 1 : limit;
|
|
4723
|
+
const result = await CONFIG.hiveClient.database.call("get_vesting_delegations", [
|
|
4724
|
+
username,
|
|
4725
|
+
pageParam || "",
|
|
4726
|
+
fetchLimit
|
|
4727
|
+
]);
|
|
4728
|
+
if (pageParam && result.length > 0 && result[0]?.delegatee === pageParam) {
|
|
4729
|
+
return result.slice(1, limit + 1);
|
|
4730
|
+
}
|
|
4731
|
+
return result;
|
|
4732
|
+
},
|
|
4733
|
+
getNextPageParam: (lastPage) => {
|
|
4734
|
+
if (!lastPage || lastPage.length < limit) {
|
|
4735
|
+
return void 0;
|
|
4736
|
+
}
|
|
4737
|
+
const lastDelegation = lastPage[lastPage.length - 1];
|
|
4738
|
+
return lastDelegation?.delegatee;
|
|
4739
|
+
},
|
|
4740
|
+
enabled: !!username
|
|
4343
4741
|
});
|
|
4344
4742
|
}
|
|
4345
|
-
function
|
|
4743
|
+
function getConversionRequestsQueryOptions(account) {
|
|
4346
4744
|
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
|
-
}
|
|
4745
|
+
queryKey: ["wallet", "conversion-requests", account],
|
|
4746
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_conversion_requests", [
|
|
4747
|
+
account
|
|
4748
|
+
]),
|
|
4749
|
+
select: (data) => data.sort((a, b) => a.requestid - b.requestid)
|
|
4375
4750
|
});
|
|
4376
4751
|
}
|
|
4377
|
-
function
|
|
4752
|
+
function getCollateralizedConversionRequestsQueryOptions(account) {
|
|
4378
4753
|
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
|
-
}
|
|
4754
|
+
queryKey: ["wallet", "collateralized-conversion-requests", account],
|
|
4755
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_collateralized_conversion_requests", [
|
|
4756
|
+
account
|
|
4757
|
+
]),
|
|
4758
|
+
select: (data) => data.sort((a, b) => a.requestid - b.requestid)
|
|
4389
4759
|
});
|
|
4390
4760
|
}
|
|
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);
|
|
4761
|
+
function getSavingsWithdrawFromQueryOptions(account) {
|
|
4397
4762
|
return reactQuery.queryOptions({
|
|
4398
|
-
queryKey: ["
|
|
4399
|
-
queryFn: () => CONFIG.hiveClient.call("
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
])
|
|
4763
|
+
queryKey: ["wallet", "savings-withdraw", account],
|
|
4764
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_savings_withdraw_from", [
|
|
4765
|
+
account
|
|
4766
|
+
]),
|
|
4767
|
+
select: (data) => data.sort((a, b) => a.request_id - b.request_id)
|
|
4404
4768
|
});
|
|
4405
4769
|
}
|
|
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) {
|
|
4770
|
+
function getWithdrawRoutesQueryOptions(account) {
|
|
4454
4771
|
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
|
|
4772
|
+
queryKey: ["wallet", "withdraw-routes", account],
|
|
4773
|
+
queryFn: () => CONFIG.hiveClient.database.call("get_withdraw_routes", [
|
|
4774
|
+
account,
|
|
4775
|
+
"outgoing"
|
|
4776
|
+
])
|
|
4495
4777
|
});
|
|
4496
4778
|
}
|
|
4497
|
-
function
|
|
4779
|
+
function getOpenOrdersQueryOptions(user) {
|
|
4498
4780
|
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
|
-
}
|
|
4781
|
+
queryKey: ["wallet", "open-orders", user],
|
|
4782
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_open_orders", [
|
|
4783
|
+
user
|
|
4784
|
+
]),
|
|
4785
|
+
select: (data) => data.sort((a, b) => a.orderid - b.orderid),
|
|
4786
|
+
enabled: !!user
|
|
4517
4787
|
});
|
|
4518
4788
|
}
|
|
4519
|
-
function
|
|
4789
|
+
function getOutgoingRcDelegationsInfiniteQueryOptions(username, limit = 100) {
|
|
4520
4790
|
return reactQuery.infiniteQueryOptions({
|
|
4521
|
-
queryKey: ["
|
|
4522
|
-
initialPageParam:
|
|
4791
|
+
queryKey: ["wallet", "outgoing-rc-delegations", username, limit],
|
|
4792
|
+
initialPageParam: null,
|
|
4523
4793
|
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}`);
|
|
4794
|
+
const response = await CONFIG.hiveClient.call("rc_api", "list_rc_direct_delegations", {
|
|
4795
|
+
start: [username, pageParam ?? ""],
|
|
4796
|
+
limit
|
|
4797
|
+
}).then((r) => r);
|
|
4798
|
+
let delegations = response.rc_direct_delegations || [];
|
|
4799
|
+
if (pageParam) {
|
|
4800
|
+
delegations = delegations.filter((delegation) => delegation.to !== pageParam);
|
|
4567
4801
|
}
|
|
4568
|
-
return
|
|
4569
|
-
},
|
|
4570
|
-
getNextPageParam: (resp) => {
|
|
4571
|
-
return {
|
|
4572
|
-
sid: resp?.scroll_id,
|
|
4573
|
-
hasNextPage: resp.results.length > 0
|
|
4574
|
-
};
|
|
4802
|
+
return delegations;
|
|
4575
4803
|
},
|
|
4576
|
-
|
|
4804
|
+
getNextPageParam: (lastPage) => lastPage.length === limit ? lastPage[lastPage.length - 1].to : null
|
|
4577
4805
|
});
|
|
4578
4806
|
}
|
|
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);
|
|
4807
|
+
function getIncomingRcQueryOptions(username) {
|
|
4598
4808
|
return reactQuery.queryOptions({
|
|
4599
|
-
queryKey: ["
|
|
4809
|
+
queryKey: ["wallet", "incoming-rc", username],
|
|
4810
|
+
enabled: !!username,
|
|
4600
4811
|
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}`);
|
|
4812
|
+
if (!username) {
|
|
4813
|
+
throw new Error("[SDK][Wallet] - Missing username for incoming RC");
|
|
4615
4814
|
}
|
|
4616
|
-
const
|
|
4617
|
-
const
|
|
4618
|
-
|
|
4815
|
+
const fetchApi = getBoundFetch();
|
|
4816
|
+
const response = await fetchApi(
|
|
4817
|
+
`${CONFIG.privateApiHost}/private-api/received-rc/${username}`
|
|
4619
4818
|
);
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
if (entries.find((y) => y.author === result.author) === void 0) {
|
|
4623
|
-
entries.push(result);
|
|
4624
|
-
}
|
|
4819
|
+
if (!response.ok) {
|
|
4820
|
+
throw new Error(`Failed to fetch incoming RC: ${response.status}`);
|
|
4625
4821
|
}
|
|
4626
|
-
return
|
|
4822
|
+
return response.json();
|
|
4627
4823
|
}
|
|
4628
4824
|
});
|
|
4629
4825
|
}
|
|
4630
|
-
function
|
|
4826
|
+
function getReceivedVestingSharesQueryOptions(username) {
|
|
4631
4827
|
return reactQuery.queryOptions({
|
|
4632
|
-
queryKey: ["
|
|
4828
|
+
queryKey: ["wallet", "received-vesting-shares", username],
|
|
4633
4829
|
queryFn: async () => {
|
|
4634
|
-
const
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
headers: {
|
|
4638
|
-
"Content-Type": "application/json"
|
|
4639
|
-
},
|
|
4640
|
-
body: JSON.stringify(data)
|
|
4641
|
-
});
|
|
4830
|
+
const response = await fetch(
|
|
4831
|
+
CONFIG.privateApiHost + `/private-api/received-vesting/${username}`
|
|
4832
|
+
);
|
|
4642
4833
|
if (!response.ok) {
|
|
4643
|
-
throw new Error(`Failed to
|
|
4834
|
+
throw new Error(`Failed to fetch received vesting shares: ${response.status}`);
|
|
4644
4835
|
}
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4836
|
+
const data = await response.json();
|
|
4837
|
+
return data.list;
|
|
4838
|
+
}
|
|
4648
4839
|
});
|
|
4649
4840
|
}
|
|
4650
|
-
function
|
|
4841
|
+
function getRecurrentTransfersQueryOptions(username) {
|
|
4651
4842
|
return reactQuery.queryOptions({
|
|
4652
|
-
queryKey: ["
|
|
4843
|
+
queryKey: ["wallet", "recurrent-transfers", username],
|
|
4844
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "find_recurrent_transfers", [
|
|
4845
|
+
username
|
|
4846
|
+
]),
|
|
4847
|
+
enabled: !!username
|
|
4848
|
+
});
|
|
4849
|
+
}
|
|
4850
|
+
function getWitnessesInfiniteQueryOptions(limit) {
|
|
4851
|
+
return reactQuery.infiniteQueryOptions({
|
|
4852
|
+
queryKey: ["witnesses", "list", limit],
|
|
4853
|
+
initialPageParam: "",
|
|
4854
|
+
queryFn: async ({ pageParam }) => CONFIG.hiveClient.call("condenser_api", "get_witnesses_by_vote", [
|
|
4855
|
+
pageParam,
|
|
4856
|
+
limit
|
|
4857
|
+
]),
|
|
4858
|
+
getNextPageParam: (lastPage) => {
|
|
4859
|
+
const last = lastPage?.[lastPage.length - 1];
|
|
4860
|
+
return last ? last.owner : void 0;
|
|
4861
|
+
}
|
|
4862
|
+
});
|
|
4863
|
+
}
|
|
4864
|
+
function getOrderBookQueryOptions(limit = 500) {
|
|
4865
|
+
return reactQuery.queryOptions({
|
|
4866
|
+
queryKey: ["market", "order-book", limit],
|
|
4867
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_order_book", [
|
|
4868
|
+
limit
|
|
4869
|
+
])
|
|
4870
|
+
});
|
|
4871
|
+
}
|
|
4872
|
+
function getMarketStatisticsQueryOptions() {
|
|
4873
|
+
return reactQuery.queryOptions({
|
|
4874
|
+
queryKey: ["market", "statistics"],
|
|
4875
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_ticker", [])
|
|
4876
|
+
});
|
|
4877
|
+
}
|
|
4878
|
+
function getMarketHistoryQueryOptions(seconds, startDate, endDate) {
|
|
4879
|
+
const formatDate2 = (date) => {
|
|
4880
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
4881
|
+
};
|
|
4882
|
+
return reactQuery.queryOptions({
|
|
4883
|
+
queryKey: ["market", "history", seconds, startDate.getTime(), endDate.getTime()],
|
|
4884
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_market_history", [
|
|
4885
|
+
seconds,
|
|
4886
|
+
formatDate2(startDate),
|
|
4887
|
+
formatDate2(endDate)
|
|
4888
|
+
])
|
|
4889
|
+
});
|
|
4890
|
+
}
|
|
4891
|
+
function getHiveHbdStatsQueryOptions() {
|
|
4892
|
+
return reactQuery.queryOptions({
|
|
4893
|
+
queryKey: ["market", "hive-hbd-stats"],
|
|
4653
4894
|
queryFn: async () => {
|
|
4654
|
-
const
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4895
|
+
const stats = await CONFIG.hiveClient.call(
|
|
4896
|
+
"condenser_api",
|
|
4897
|
+
"get_ticker",
|
|
4898
|
+
[]
|
|
4899
|
+
);
|
|
4900
|
+
const now = /* @__PURE__ */ new Date();
|
|
4901
|
+
const oneDayAgo = new Date(now.getTime() - 864e5);
|
|
4902
|
+
const formatDate2 = (date) => {
|
|
4903
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
4904
|
+
};
|
|
4905
|
+
const dayChange = await CONFIG.hiveClient.call(
|
|
4906
|
+
"condenser_api",
|
|
4907
|
+
"get_market_history",
|
|
4908
|
+
[86400, formatDate2(oneDayAgo), formatDate2(now)]
|
|
4909
|
+
);
|
|
4910
|
+
const result = {
|
|
4911
|
+
price: +stats.latest,
|
|
4912
|
+
close: dayChange[0] ? dayChange[0].non_hive.open / dayChange[0].hive.open : 0,
|
|
4913
|
+
high: dayChange[0] ? dayChange[0].non_hive.high / dayChange[0].hive.high : 0,
|
|
4914
|
+
low: dayChange[0] ? dayChange[0].non_hive.low / dayChange[0].hive.low : 0,
|
|
4915
|
+
percent: dayChange[0] ? 100 - dayChange[0].non_hive.open / dayChange[0].hive.open * 100 / +stats.latest : 0,
|
|
4916
|
+
totalFromAsset: stats.hive_volume.split(" ")[0],
|
|
4917
|
+
totalToAsset: stats.hbd_volume.split(" ")[0]
|
|
4918
|
+
};
|
|
4919
|
+
return result;
|
|
4920
|
+
}
|
|
4668
4921
|
});
|
|
4669
4922
|
}
|
|
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
|
-
});
|
|
4923
|
+
function getMarketDataQueryOptions(coin, vsCurrency, fromTs, toTs) {
|
|
4924
|
+
return reactQuery.queryOptions({
|
|
4925
|
+
queryKey: ["market", "data", coin, vsCurrency, fromTs, toTs],
|
|
4926
|
+
queryFn: async ({ signal }) => {
|
|
4927
|
+
const fetchApi = getBoundFetch();
|
|
4928
|
+
const url = `https://api.coingecko.com/api/v3/coins/${coin}/market_chart/range?vs_currency=${vsCurrency}&from=${fromTs}&to=${toTs}`;
|
|
4929
|
+
const response = await fetchApi(url, { signal });
|
|
4691
4930
|
if (!response.ok) {
|
|
4692
|
-
throw new Error(`
|
|
4931
|
+
throw new Error(`Failed to fetch market data: ${response.status}`);
|
|
4693
4932
|
}
|
|
4694
4933
|
return response.json();
|
|
4695
|
-
}
|
|
4696
|
-
initialPageParam: void 0,
|
|
4697
|
-
getNextPageParam: (lastPage) => lastPage?.scroll_id,
|
|
4698
|
-
enabled: !!q
|
|
4934
|
+
}
|
|
4699
4935
|
});
|
|
4700
4936
|
}
|
|
4701
|
-
function
|
|
4937
|
+
function formatDate(date) {
|
|
4938
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "");
|
|
4939
|
+
}
|
|
4940
|
+
function getTradeHistoryQueryOptions(limit = 1e3, startDate, endDate) {
|
|
4941
|
+
const end = endDate ?? /* @__PURE__ */ new Date();
|
|
4942
|
+
const start = startDate ?? new Date(end.getTime() - 10 * 60 * 60 * 1e3);
|
|
4702
4943
|
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
|
-
}
|
|
4944
|
+
queryKey: ["market", "trade-history", limit, start.getTime(), end.getTime()],
|
|
4945
|
+
queryFn: () => CONFIG.hiveClient.call("condenser_api", "get_trade_history", [
|
|
4946
|
+
formatDate(start),
|
|
4947
|
+
formatDate(end),
|
|
4948
|
+
limit
|
|
4949
|
+
])
|
|
4721
4950
|
});
|
|
4722
4951
|
}
|
|
4723
4952
|
|
|
4724
|
-
// src/modules/
|
|
4953
|
+
// src/modules/market/requests.ts
|
|
4725
4954
|
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();
|
|
4955
|
+
const data = await response.json();
|
|
4738
4956
|
if (!response.ok) {
|
|
4739
4957
|
const error = new Error(`Request failed with status ${response.status}`);
|
|
4740
4958
|
error.status = response.status;
|
|
4741
4959
|
error.data = data;
|
|
4742
4960
|
throw error;
|
|
4743
4961
|
}
|
|
4744
|
-
if (data === void 0) {
|
|
4745
|
-
throw new Error("Response body was empty or invalid JSON");
|
|
4746
|
-
}
|
|
4747
4962
|
return data;
|
|
4748
4963
|
}
|
|
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
|
-
}
|
|
4964
|
+
async function getMarketData(coin, vsCurrency, fromTs, toTs) {
|
|
4760
4965
|
const fetchApi = getBoundFetch();
|
|
4761
|
-
const
|
|
4762
|
-
|
|
4763
|
-
headers: {
|
|
4764
|
-
"Content-Type": "application/json"
|
|
4765
|
-
},
|
|
4766
|
-
body: JSON.stringify(data)
|
|
4767
|
-
});
|
|
4966
|
+
const url = `https://api.coingecko.com/api/v3/coins/${coin}/market_chart/range?vs_currency=${vsCurrency}&from=${fromTs}&to=${toTs}`;
|
|
4967
|
+
const response = await fetchApi(url);
|
|
4768
4968
|
return parseJsonResponse2(response);
|
|
4769
4969
|
}
|
|
4770
|
-
async function
|
|
4771
|
-
|
|
4970
|
+
async function getCurrencyRate(cur) {
|
|
4971
|
+
if (cur === "hbd") {
|
|
4972
|
+
return 1;
|
|
4973
|
+
}
|
|
4772
4974
|
const fetchApi = getBoundFetch();
|
|
4773
|
-
const
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4975
|
+
const url = `https://api.coingecko.com/api/v3/simple/price?ids=hive_dollar&vs_currencies=${cur}`;
|
|
4976
|
+
const response = await fetchApi(url);
|
|
4977
|
+
const data = await parseJsonResponse2(response);
|
|
4978
|
+
return data.hive_dollar[cur];
|
|
4979
|
+
}
|
|
4980
|
+
async function getCurrencyTokenRate(currency, token) {
|
|
4981
|
+
const fetchApi = getBoundFetch();
|
|
4982
|
+
const response = await fetchApi(
|
|
4983
|
+
CONFIG.privateApiHost + `/private-api/market-data/${currency === "hbd" ? "usd" : currency}/${token}`
|
|
4984
|
+
);
|
|
4780
4985
|
return parseJsonResponse2(response);
|
|
4781
4986
|
}
|
|
4782
|
-
async function
|
|
4783
|
-
const data = { q, limit, random };
|
|
4987
|
+
async function getCurrencyRates() {
|
|
4784
4988
|
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
|
-
});
|
|
4989
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/market-data/latest");
|
|
4792
4990
|
return parseJsonResponse2(response);
|
|
4793
4991
|
}
|
|
4794
|
-
async function
|
|
4992
|
+
async function getHivePrice() {
|
|
4795
4993
|
const fetchApi = getBoundFetch();
|
|
4796
|
-
const response = await fetchApi(
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4994
|
+
const response = await fetchApi(
|
|
4995
|
+
"https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd"
|
|
4996
|
+
);
|
|
4997
|
+
return parseJsonResponse2(response);
|
|
4998
|
+
}
|
|
4999
|
+
function getPointsQueryOptions(username, filter = 0) {
|
|
5000
|
+
return reactQuery.queryOptions({
|
|
5001
|
+
queryKey: ["points", username, filter],
|
|
5002
|
+
queryFn: async () => {
|
|
5003
|
+
if (!username) {
|
|
5004
|
+
throw new Error("Get points query \u2013 username wasn't provided");
|
|
5005
|
+
}
|
|
5006
|
+
const name = username.replace("@", "");
|
|
5007
|
+
const pointsResponse = await fetch(CONFIG.privateApiHost + "/private-api/points", {
|
|
5008
|
+
method: "POST",
|
|
5009
|
+
headers: {
|
|
5010
|
+
"Content-Type": "application/json"
|
|
5011
|
+
},
|
|
5012
|
+
body: JSON.stringify({ username: name })
|
|
5013
|
+
});
|
|
5014
|
+
if (!pointsResponse.ok) {
|
|
5015
|
+
throw new Error(`Failed to fetch points: ${pointsResponse.status}`);
|
|
5016
|
+
}
|
|
5017
|
+
const points = await pointsResponse.json();
|
|
5018
|
+
const transactionsResponse = await fetch(
|
|
5019
|
+
CONFIG.privateApiHost + "/private-api/point-list",
|
|
5020
|
+
{
|
|
5021
|
+
method: "POST",
|
|
5022
|
+
headers: {
|
|
5023
|
+
"Content-Type": "application/json"
|
|
5024
|
+
},
|
|
5025
|
+
body: JSON.stringify({ username: name, type: filter })
|
|
5026
|
+
}
|
|
5027
|
+
);
|
|
5028
|
+
if (!transactionsResponse.ok) {
|
|
5029
|
+
throw new Error(`Failed to fetch point transactions: ${transactionsResponse.status}`);
|
|
5030
|
+
}
|
|
5031
|
+
const transactions = await transactionsResponse.json();
|
|
5032
|
+
return {
|
|
5033
|
+
points: points.points,
|
|
5034
|
+
uPoints: points.unclaimed_points,
|
|
5035
|
+
transactions
|
|
5036
|
+
};
|
|
4800
5037
|
},
|
|
4801
|
-
|
|
5038
|
+
staleTime: 3e4,
|
|
5039
|
+
refetchOnMount: true,
|
|
5040
|
+
enabled: !!username
|
|
4802
5041
|
});
|
|
4803
|
-
const data = await parseJsonResponse2(response);
|
|
4804
|
-
return data?.length > 0 ? data : [q];
|
|
4805
5042
|
}
|
|
4806
|
-
function
|
|
5043
|
+
function searchQueryOptions(q, sort, hideLow, since, scroll_id, votes) {
|
|
4807
5044
|
return reactQuery.queryOptions({
|
|
4808
|
-
queryKey: ["
|
|
5045
|
+
queryKey: ["search", q, sort, hideLow, since, scroll_id, votes],
|
|
4809
5046
|
queryFn: async () => {
|
|
4810
|
-
|
|
4811
|
-
|
|
5047
|
+
const data = { q, sort, hide_low: hideLow };
|
|
5048
|
+
if (since) data.since = since;
|
|
5049
|
+
if (scroll_id) data.scroll_id = scroll_id;
|
|
5050
|
+
if (votes) data.votes = votes;
|
|
5051
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
5052
|
+
method: "POST",
|
|
5053
|
+
headers: {
|
|
5054
|
+
"Content-Type": "application/json"
|
|
5055
|
+
},
|
|
5056
|
+
body: JSON.stringify(data)
|
|
5057
|
+
});
|
|
5058
|
+
if (!response.ok) {
|
|
5059
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
5060
|
+
}
|
|
5061
|
+
return response.json();
|
|
5062
|
+
}
|
|
5063
|
+
});
|
|
5064
|
+
}
|
|
5065
|
+
function getControversialRisingInfiniteQueryOptions(what, tag, enabled = true) {
|
|
5066
|
+
return reactQuery.infiniteQueryOptions({
|
|
5067
|
+
queryKey: ["search", "controversial-rising", what, tag],
|
|
5068
|
+
initialPageParam: { sid: void 0, hasNextPage: true },
|
|
5069
|
+
queryFn: async ({ pageParam }) => {
|
|
5070
|
+
if (!pageParam.hasNextPage) {
|
|
5071
|
+
return {
|
|
5072
|
+
hits: 0,
|
|
5073
|
+
took: 0,
|
|
5074
|
+
results: []
|
|
5075
|
+
};
|
|
5076
|
+
}
|
|
5077
|
+
let sinceDate;
|
|
5078
|
+
const now = /* @__PURE__ */ new Date();
|
|
5079
|
+
switch (tag) {
|
|
5080
|
+
case "today":
|
|
5081
|
+
sinceDate = new Date(now.getTime() - 24 * 60 * 60 * 1e3);
|
|
5082
|
+
break;
|
|
5083
|
+
case "week":
|
|
5084
|
+
sinceDate = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1e3);
|
|
5085
|
+
break;
|
|
5086
|
+
case "month":
|
|
5087
|
+
sinceDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1e3);
|
|
5088
|
+
break;
|
|
5089
|
+
case "year":
|
|
5090
|
+
sinceDate = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1e3);
|
|
5091
|
+
break;
|
|
5092
|
+
default:
|
|
5093
|
+
sinceDate = void 0;
|
|
4812
5094
|
}
|
|
4813
|
-
const
|
|
5095
|
+
const q = "* type:post";
|
|
5096
|
+
const sort = what === "rising" ? "children" : what;
|
|
5097
|
+
const since = sinceDate ? sinceDate.toISOString().split(".")[0] : void 0;
|
|
5098
|
+
const hideLow = "0";
|
|
5099
|
+
const votes = tag === "today" ? 50 : 200;
|
|
5100
|
+
const data = { q, sort, hide_low: hideLow };
|
|
5101
|
+
if (since) data.since = since;
|
|
5102
|
+
if (pageParam.sid) data.scroll_id = pageParam.sid;
|
|
5103
|
+
data.votes = votes;
|
|
5104
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
4814
5105
|
method: "POST",
|
|
4815
5106
|
headers: {
|
|
4816
5107
|
"Content-Type": "application/json"
|
|
4817
5108
|
},
|
|
4818
|
-
body: JSON.stringify(
|
|
5109
|
+
body: JSON.stringify(data)
|
|
4819
5110
|
});
|
|
4820
5111
|
if (!response.ok) {
|
|
4821
|
-
throw new Error(`
|
|
5112
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
4822
5113
|
}
|
|
4823
|
-
return
|
|
5114
|
+
return response.json();
|
|
4824
5115
|
},
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
5116
|
+
getNextPageParam: (resp) => {
|
|
5117
|
+
return {
|
|
5118
|
+
sid: resp?.scroll_id,
|
|
5119
|
+
hasNextPage: resp.results.length > 0
|
|
5120
|
+
};
|
|
5121
|
+
},
|
|
5122
|
+
enabled
|
|
4828
5123
|
});
|
|
4829
5124
|
}
|
|
4830
|
-
function
|
|
5125
|
+
function buildQuery(entry, retry = 3) {
|
|
5126
|
+
const { json_metadata, permlink } = entry;
|
|
5127
|
+
let q = "*";
|
|
5128
|
+
q += ` -dporn type:post`;
|
|
5129
|
+
let tags;
|
|
5130
|
+
if (json_metadata && json_metadata.tags && Array.isArray(json_metadata.tags)) {
|
|
5131
|
+
tags = json_metadata.tags.filter((tag) => tag && tag !== "" && typeof tag === "string").filter((tag) => !tag.startsWith("hive-")).filter((_tag, ind) => ind < +retry).join(",");
|
|
5132
|
+
}
|
|
5133
|
+
if (tags && tags.length > 0) {
|
|
5134
|
+
q += ` tag:${tags}`;
|
|
5135
|
+
} else {
|
|
5136
|
+
const fperm = permlink.split("-");
|
|
5137
|
+
tags = fperm.filter((part) => part !== "").filter((part) => !/^-?\d+$/.test(part)).filter((part) => part.length > 2).join(",");
|
|
5138
|
+
q += ` tag:${tags}`;
|
|
5139
|
+
}
|
|
5140
|
+
return q;
|
|
5141
|
+
}
|
|
5142
|
+
function getSimilarEntriesQueryOptions(entry) {
|
|
5143
|
+
const query = buildQuery(entry);
|
|
4831
5144
|
return reactQuery.queryOptions({
|
|
4832
|
-
queryKey: ["
|
|
5145
|
+
queryKey: ["search", "similar-entries", entry.author, entry.permlink, query],
|
|
4833
5146
|
queryFn: async () => {
|
|
4834
|
-
const
|
|
5147
|
+
const data = {
|
|
5148
|
+
q: query,
|
|
5149
|
+
sort: "newest",
|
|
5150
|
+
hide_low: "0"
|
|
5151
|
+
};
|
|
5152
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
4835
5153
|
method: "POST",
|
|
4836
5154
|
headers: {
|
|
4837
5155
|
"Content-Type": "application/json"
|
|
4838
5156
|
},
|
|
4839
|
-
body: JSON.stringify(
|
|
5157
|
+
body: JSON.stringify(data)
|
|
4840
5158
|
});
|
|
4841
5159
|
if (!response.ok) {
|
|
4842
|
-
throw new Error(`
|
|
5160
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
4843
5161
|
}
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
5162
|
+
const searchResponse = await response.json();
|
|
5163
|
+
const rawEntries = searchResponse.results.filter(
|
|
5164
|
+
(r) => r.permlink !== entry.permlink && r.tags.indexOf("nsfw") === -1
|
|
5165
|
+
);
|
|
5166
|
+
const entries = [];
|
|
5167
|
+
for (const result of rawEntries) {
|
|
5168
|
+
if (entries.find((y) => y.author === result.author) === void 0) {
|
|
5169
|
+
entries.push(result);
|
|
5170
|
+
}
|
|
5171
|
+
}
|
|
5172
|
+
return entries.slice(0, 3);
|
|
5173
|
+
}
|
|
4847
5174
|
});
|
|
4848
5175
|
}
|
|
4849
|
-
function
|
|
5176
|
+
function getSearchAccountQueryOptions(q, limit = 5, random = false) {
|
|
4850
5177
|
return reactQuery.queryOptions({
|
|
4851
|
-
queryKey: ["
|
|
5178
|
+
queryKey: ["search", "account", q, limit],
|
|
4852
5179
|
queryFn: async () => {
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
}
|
|
4856
|
-
const response = await fetch(CONFIG.privateApiHost + "/private-api/boosted-plus-account", {
|
|
5180
|
+
const data = { q, limit, random: +random };
|
|
5181
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-account", {
|
|
4857
5182
|
method: "POST",
|
|
4858
5183
|
headers: {
|
|
4859
5184
|
"Content-Type": "application/json"
|
|
4860
5185
|
},
|
|
4861
|
-
body: JSON.stringify(
|
|
5186
|
+
body: JSON.stringify(data)
|
|
4862
5187
|
});
|
|
4863
5188
|
if (!response.ok) {
|
|
4864
|
-
throw new Error(`Failed to
|
|
5189
|
+
throw new Error(`Failed to search accounts: ${response.status}`);
|
|
4865
5190
|
}
|
|
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"
|
|
5191
|
+
return response.json();
|
|
5009
5192
|
},
|
|
5010
|
-
|
|
5193
|
+
enabled: !!q
|
|
5011
5194
|
});
|
|
5012
|
-
return parseJsonResponse3(response);
|
|
5013
5195
|
}
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5196
|
+
function getSearchTopicsQueryOptions(q, limit = 20, random = false) {
|
|
5197
|
+
return reactQuery.queryOptions({
|
|
5198
|
+
queryKey: ["search", "topics", q],
|
|
5199
|
+
queryFn: async () => {
|
|
5200
|
+
const data = { q, limit, random: +random };
|
|
5201
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-tag", {
|
|
5202
|
+
method: "POST",
|
|
5203
|
+
headers: {
|
|
5204
|
+
"Content-Type": "application/json"
|
|
5205
|
+
},
|
|
5206
|
+
body: JSON.stringify(data)
|
|
5207
|
+
});
|
|
5208
|
+
if (!response.ok) {
|
|
5209
|
+
throw new Error(`Failed to search topics: ${response.status}`);
|
|
5210
|
+
}
|
|
5211
|
+
return response.json();
|
|
5021
5212
|
},
|
|
5022
|
-
|
|
5213
|
+
enabled: !!q
|
|
5023
5214
|
});
|
|
5024
|
-
return parseJsonResponse3(response);
|
|
5025
5215
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5216
|
+
function getSearchApiInfiniteQueryOptions(q, sort, hideLow, since, votes) {
|
|
5217
|
+
return reactQuery.infiniteQueryOptions({
|
|
5218
|
+
queryKey: ["search", "api", q, sort, hideLow, since, votes],
|
|
5219
|
+
queryFn: async ({ pageParam }) => {
|
|
5220
|
+
const payload = { q, sort, hide_low: hideLow };
|
|
5221
|
+
if (since) {
|
|
5222
|
+
payload.since = since;
|
|
5223
|
+
}
|
|
5224
|
+
if (pageParam) {
|
|
5225
|
+
payload.scroll_id = pageParam;
|
|
5226
|
+
}
|
|
5227
|
+
if (votes !== void 0) {
|
|
5228
|
+
payload.votes = votes;
|
|
5229
|
+
}
|
|
5230
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search", {
|
|
5231
|
+
method: "POST",
|
|
5232
|
+
headers: {
|
|
5233
|
+
"Content-Type": "application/json"
|
|
5234
|
+
},
|
|
5235
|
+
body: JSON.stringify(payload)
|
|
5236
|
+
});
|
|
5237
|
+
if (!response.ok) {
|
|
5238
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
5239
|
+
}
|
|
5240
|
+
return response.json();
|
|
5241
|
+
},
|
|
5242
|
+
initialPageParam: void 0,
|
|
5243
|
+
getNextPageParam: (lastPage) => lastPage?.scroll_id,
|
|
5244
|
+
enabled: !!q
|
|
5034
5245
|
});
|
|
5035
|
-
return parseJsonResponse3(response);
|
|
5036
5246
|
}
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5247
|
+
function getSearchPathQueryOptions(q) {
|
|
5248
|
+
return reactQuery.queryOptions({
|
|
5249
|
+
queryKey: ["search", "path", q],
|
|
5250
|
+
queryFn: async () => {
|
|
5251
|
+
const response = await fetch(CONFIG.privateApiHost + "/search-api/search-path", {
|
|
5252
|
+
method: "POST",
|
|
5253
|
+
headers: {
|
|
5254
|
+
"Content-Type": "application/json"
|
|
5255
|
+
},
|
|
5256
|
+
body: JSON.stringify({ q })
|
|
5257
|
+
});
|
|
5258
|
+
if (!response.ok) {
|
|
5259
|
+
throw new Error(`Search path failed: ${response.status}`);
|
|
5260
|
+
}
|
|
5261
|
+
const data = await response.json();
|
|
5262
|
+
if (data?.length > 0) {
|
|
5263
|
+
return data;
|
|
5264
|
+
}
|
|
5265
|
+
return [q];
|
|
5266
|
+
}
|
|
5046
5267
|
});
|
|
5047
|
-
return parseJsonResponse3(response);
|
|
5048
5268
|
}
|
|
5049
|
-
|
|
5050
|
-
|
|
5269
|
+
|
|
5270
|
+
// src/modules/search/requests.ts
|
|
5271
|
+
async function parseJsonResponse3(response) {
|
|
5272
|
+
const parseBody = async () => {
|
|
5273
|
+
try {
|
|
5274
|
+
return await response.json();
|
|
5275
|
+
} catch {
|
|
5276
|
+
try {
|
|
5277
|
+
return await response.text();
|
|
5278
|
+
} catch {
|
|
5279
|
+
return void 0;
|
|
5280
|
+
}
|
|
5281
|
+
}
|
|
5282
|
+
};
|
|
5283
|
+
const data = await parseBody();
|
|
5284
|
+
if (!response.ok) {
|
|
5285
|
+
const error = new Error(`Request failed with status ${response.status}`);
|
|
5286
|
+
error.status = response.status;
|
|
5287
|
+
error.data = data;
|
|
5288
|
+
throw error;
|
|
5289
|
+
}
|
|
5290
|
+
if (data === void 0) {
|
|
5291
|
+
throw new Error("Response body was empty or invalid JSON");
|
|
5292
|
+
}
|
|
5293
|
+
return data;
|
|
5294
|
+
}
|
|
5295
|
+
async function search(q, sort, hideLow, since, scroll_id, votes) {
|
|
5296
|
+
const data = { q, sort, hide_low: hideLow };
|
|
5297
|
+
if (since) {
|
|
5298
|
+
data.since = since;
|
|
5299
|
+
}
|
|
5300
|
+
if (scroll_id) {
|
|
5301
|
+
data.scroll_id = scroll_id;
|
|
5302
|
+
}
|
|
5303
|
+
if (votes) {
|
|
5304
|
+
data.votes = votes;
|
|
5305
|
+
}
|
|
5051
5306
|
const fetchApi = getBoundFetch();
|
|
5052
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
5307
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/search-api/search", {
|
|
5053
5308
|
method: "POST",
|
|
5054
5309
|
headers: {
|
|
5055
5310
|
"Content-Type": "application/json"
|
|
@@ -5058,10 +5313,10 @@ async function addDraft(code, title, body, tags, meta) {
|
|
|
5058
5313
|
});
|
|
5059
5314
|
return parseJsonResponse3(response);
|
|
5060
5315
|
}
|
|
5061
|
-
async function
|
|
5062
|
-
const data = {
|
|
5316
|
+
async function searchAccount(q = "", limit = 20, random = 1) {
|
|
5317
|
+
const data = { q, limit, random };
|
|
5063
5318
|
const fetchApi = getBoundFetch();
|
|
5064
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
5319
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/search-api/search-account", {
|
|
5065
5320
|
method: "POST",
|
|
5066
5321
|
headers: {
|
|
5067
5322
|
"Content-Type": "application/json"
|
|
@@ -5070,10 +5325,10 @@ async function updateDraft(code, draftId, title, body, tags, meta) {
|
|
|
5070
5325
|
});
|
|
5071
5326
|
return parseJsonResponse3(response);
|
|
5072
5327
|
}
|
|
5073
|
-
async function
|
|
5074
|
-
const data = {
|
|
5328
|
+
async function searchTag(q = "", limit = 20, random = 0) {
|
|
5329
|
+
const data = { q, limit, random };
|
|
5075
5330
|
const fetchApi = getBoundFetch();
|
|
5076
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
5331
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/search-api/search-tag", {
|
|
5077
5332
|
method: "POST",
|
|
5078
5333
|
headers: {
|
|
5079
5334
|
"Content-Type": "application/json"
|
|
@@ -5082,83 +5337,86 @@ async function deleteDraft(code, draftId) {
|
|
|
5082
5337
|
});
|
|
5083
5338
|
return parseJsonResponse3(response);
|
|
5084
5339
|
}
|
|
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
|
-
}
|
|
5340
|
+
async function searchPath(q) {
|
|
5098
5341
|
const fetchApi = getBoundFetch();
|
|
5099
|
-
const response = await fetchApi(CONFIG.privateApiHost + "/
|
|
5342
|
+
const response = await fetchApi(CONFIG.privateApiHost + "/search-api/search-path", {
|
|
5100
5343
|
method: "POST",
|
|
5101
5344
|
headers: {
|
|
5102
5345
|
"Content-Type": "application/json"
|
|
5103
5346
|
},
|
|
5104
|
-
body: JSON.stringify(
|
|
5347
|
+
body: JSON.stringify({ q })
|
|
5105
5348
|
});
|
|
5106
|
-
|
|
5349
|
+
const data = await parseJsonResponse3(response);
|
|
5350
|
+
return data?.length > 0 ? data : [q];
|
|
5107
5351
|
}
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5352
|
+
function getBoostPlusPricesQueryOptions(accessToken) {
|
|
5353
|
+
return reactQuery.queryOptions({
|
|
5354
|
+
queryKey: ["promotions", "boost-plus-prices"],
|
|
5355
|
+
queryFn: async () => {
|
|
5356
|
+
if (!accessToken) {
|
|
5357
|
+
return [];
|
|
5358
|
+
}
|
|
5359
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/boost-plus-price", {
|
|
5360
|
+
method: "POST",
|
|
5361
|
+
headers: {
|
|
5362
|
+
"Content-Type": "application/json"
|
|
5363
|
+
},
|
|
5364
|
+
body: JSON.stringify({ code: accessToken })
|
|
5365
|
+
});
|
|
5366
|
+
if (!response.ok) {
|
|
5367
|
+
throw new Error(`Failed to fetch boost plus prices: ${response.status}`);
|
|
5368
|
+
}
|
|
5369
|
+
return await response.json();
|
|
5115
5370
|
},
|
|
5116
|
-
|
|
5371
|
+
staleTime: Infinity,
|
|
5372
|
+
refetchOnMount: true,
|
|
5373
|
+
enabled: !!accessToken
|
|
5117
5374
|
});
|
|
5118
|
-
return parseJsonResponse3(response);
|
|
5119
5375
|
}
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5376
|
+
function getPromotePriceQueryOptions(accessToken) {
|
|
5377
|
+
return reactQuery.queryOptions({
|
|
5378
|
+
queryKey: ["promotions", "promote-price"],
|
|
5379
|
+
queryFn: async () => {
|
|
5380
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/promote-price", {
|
|
5381
|
+
method: "POST",
|
|
5382
|
+
headers: {
|
|
5383
|
+
"Content-Type": "application/json"
|
|
5384
|
+
},
|
|
5385
|
+
body: JSON.stringify({ code: accessToken })
|
|
5386
|
+
});
|
|
5387
|
+
if (!response.ok) {
|
|
5388
|
+
throw new Error(`Failed to fetch promote prices: ${response.status}`);
|
|
5389
|
+
}
|
|
5390
|
+
return await response.json();
|
|
5127
5391
|
},
|
|
5128
|
-
|
|
5392
|
+
enabled: !!accessToken
|
|
5129
5393
|
});
|
|
5130
|
-
return parseJsonResponse3(response);
|
|
5131
5394
|
}
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5395
|
+
function getBoostPlusAccountPricesQueryOptions(account, accessToken) {
|
|
5396
|
+
return reactQuery.queryOptions({
|
|
5397
|
+
queryKey: ["promotions", "boost-plus-accounts", account],
|
|
5398
|
+
queryFn: async () => {
|
|
5399
|
+
if (!accessToken || !account) {
|
|
5400
|
+
return null;
|
|
5401
|
+
}
|
|
5402
|
+
const response = await fetch(CONFIG.privateApiHost + "/private-api/boosted-plus-account", {
|
|
5403
|
+
method: "POST",
|
|
5404
|
+
headers: {
|
|
5405
|
+
"Content-Type": "application/json"
|
|
5406
|
+
},
|
|
5407
|
+
body: JSON.stringify({ code: accessToken, account })
|
|
5408
|
+
});
|
|
5409
|
+
if (!response.ok) {
|
|
5410
|
+
throw new Error(`Failed to fetch boost plus account prices: ${response.status}`);
|
|
5411
|
+
}
|
|
5412
|
+
const responseData = await response.json();
|
|
5413
|
+
return responseData ? {
|
|
5414
|
+
account: responseData.account,
|
|
5415
|
+
expires: new Date(responseData.expires)
|
|
5416
|
+
} : null;
|
|
5139
5417
|
},
|
|
5140
|
-
|
|
5418
|
+
enabled: !!account && !!accessToken
|
|
5141
5419
|
});
|
|
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
5420
|
}
|
|
5163
5421
|
|
|
5164
5422
|
// src/modules/auth/requests.ts
|
|
@@ -5673,17 +5931,27 @@ exports.useAccountUpdate = useAccountUpdate;
|
|
|
5673
5931
|
exports.useAccountUpdateKeyAuths = useAccountUpdateKeyAuths;
|
|
5674
5932
|
exports.useAccountUpdatePassword = useAccountUpdatePassword;
|
|
5675
5933
|
exports.useAccountUpdateRecovery = useAccountUpdateRecovery;
|
|
5934
|
+
exports.useAddDraft = useAddDraft;
|
|
5676
5935
|
exports.useAddFragment = useAddFragment;
|
|
5936
|
+
exports.useAddImage = useAddImage;
|
|
5937
|
+
exports.useAddSchedule = useAddSchedule;
|
|
5677
5938
|
exports.useBookmarkAdd = useBookmarkAdd;
|
|
5678
5939
|
exports.useBookmarkDelete = useBookmarkDelete;
|
|
5679
5940
|
exports.useBroadcastMutation = useBroadcastMutation;
|
|
5941
|
+
exports.useDeleteDraft = useDeleteDraft;
|
|
5942
|
+
exports.useDeleteImage = useDeleteImage;
|
|
5943
|
+
exports.useDeleteSchedule = useDeleteSchedule;
|
|
5680
5944
|
exports.useEditFragment = useEditFragment;
|
|
5681
5945
|
exports.useGameClaim = useGameClaim;
|
|
5946
|
+
exports.useMarkNotificationsRead = useMarkNotificationsRead;
|
|
5947
|
+
exports.useMoveSchedule = useMoveSchedule;
|
|
5682
5948
|
exports.useRecordActivity = useRecordActivity;
|
|
5683
5949
|
exports.useRemoveFragment = useRemoveFragment;
|
|
5684
5950
|
exports.useSignOperationByHivesigner = useSignOperationByHivesigner;
|
|
5685
5951
|
exports.useSignOperationByKey = useSignOperationByKey;
|
|
5686
5952
|
exports.useSignOperationByKeychain = useSignOperationByKeychain;
|
|
5953
|
+
exports.useUpdateDraft = useUpdateDraft;
|
|
5954
|
+
exports.useUploadImage = useUploadImage;
|
|
5687
5955
|
exports.usrActivity = usrActivity;
|
|
5688
5956
|
exports.validatePostCreating = validatePostCreating;
|
|
5689
5957
|
exports.votingPower = votingPower;
|