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