Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
Merge pull request #1556 from ecency/feature/ecency-perks
Browse files Browse the repository at this point in the history
Feature/ecency perks
  • Loading branch information
feruzm authored Feb 26, 2024
2 parents 719a36a + 2bb9924 commit 14846a7
Show file tree
Hide file tree
Showing 96 changed files with 3,313 additions and 2,561 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@firebase/messaging": "^0.9.16",
"@hiveio/dhive": "^1.2.8",
"@hiveio/hivescript": "^1.2.7",
"@iconscout/react-unicons": "^2.0.2",
"@loadable/component": "^5.15.2",
"@loadable/server": "^5.15.2",
"@noble/secp256k1": "^1.7.1",
Expand Down
3 changes: 2 additions & 1 deletion src/common/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export const getCurrencyRate = (cur: string): Promise<number> => {
return axios
.get(u)
.then((r) => r.data)
.then((r) => r.hive_dollar[cur]);
.then((r) => r.hive_dollar[cur])
.catch((e) => {});
};

export const GIPHY_API_KEY = "DQ7mV4VsZ749GcCBZEunztICJ5nA4Vef";
Expand Down
41 changes: 41 additions & 0 deletions src/common/api/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,21 @@ export const promote = (
return hiveClient.broadcast.json(op, key);
};

export const boostPlus = (key: PrivateKey, user: string, account: string, duration: number) =>
hiveClient.broadcast.json(
{
id: "ecency_boost_plus",
json: JSON.stringify({
user,
account,
duration
}),
required_auths: [user],
required_posting_auths: []
},
key
);

export const promoteHot = (user: string, author: string, permlink: string, duration: number) => {
const params = {
authority: "active",
Expand All @@ -1224,6 +1239,22 @@ export const promoteHot = (user: string, author: string, permlink: string, durat
hotSign("custom-json", params, `@${user}/points`);
};

export const boostPlusHot = (user: string, account: string, duration: number) => {
const params = {
authority: "active",
required_auths: `["${user}"]`,
required_posting_auths: "[]",
id: "ecency_boost_plus",
json: JSON.stringify({
user,
account,
duration
})
};

hotSign("custom-json", params, `@${user}/points`);
};

export const promoteKc = (user: string, author: string, permlink: string, duration: number) => {
const json = JSON.stringify({
user,
Expand All @@ -1235,6 +1266,16 @@ export const promoteKc = (user: string, author: string, permlink: string, durati
return keychain.customJson(user, "ecency_promote", "Active", json, "Promote");
};

export const boostPlusKc = (user: string, account: string, duration: number) => {
const json = JSON.stringify({
user,
account,
duration
});

return keychain.customJson(user, "ecency_boost_plus", "Active", json, "Boost Plus");
};

export const boost = (
key: PrivateKey,
user: string,
Expand Down
17 changes: 17 additions & 0 deletions src/common/api/private-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,22 @@ export const getPromotePrice = (username: string): Promise<PromotePrice[]> => {
return axios.post(apiBase(`/private-api/promote-price`), data).then((resp) => resp.data);
};

export const getBoostPlusPrice = (username: string): Promise<PromotePrice[]> => {
const data = { code: getAccessToken(username) };
return axios.post(apiBase(`/private-api/boost-plus-price`), data).then((resp) => resp.data);
};

export const getBoostPlusAccounts = (
username: string,
account: string
): Promise<{
expires: string;
account: string;
}> => {
const data = { code: getAccessToken(username), account };
return axios.post(apiBase("/private-api/boosted-plus-account"), data).then((resp) => resp.data);
};

export const getPromotedPost = (
username: string,
author: string,
Expand Down Expand Up @@ -601,6 +617,7 @@ export const getAnnouncementsData = async (): Promise<Announcement[]> => {
throw error;
}
};

export interface Recoveries {
username: string;
email: string;
Expand Down
50 changes: 48 additions & 2 deletions src/common/api/queries.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { useQueries, useQuery, UseQueryOptions } from "@tanstack/react-query";
import { EntriesCacheContext, QueryIdentifiers } from "../core";
import { getPoints, getPointTransactions } from "./private-api";
import {
getBoostPlusAccounts,
getBoostPlusPrice,
getPoints,
getPointTransactions
} from "./private-api";
import { useMappedStore } from "../store/use-mapped-store";
import axios from "axios";
import { catchPostImage } from "@ecency/render-helper";
import { Entry } from "../store/entries/types";
import { getAccountFull, getFollowing } from "./hive";
import { getAccountPosts, getDiscussion } from "./bridge";
import { SortOrder } from "../store/discussion/types";
import { useContext } from "react";
import { useContext, useState } from "react";
import { sortDiscussions } from "../util/sort-discussions";
import { apiBase } from "./helper";
import useDebounce from "react-use/lib/useDebounce";

const DEFAULT = {
points: "0.000",
Expand Down Expand Up @@ -170,3 +176,43 @@ export function useBotsQuery() {
initialData: []
});
}

export function useGetBoostPlusPricesQuery() {
const { activeUser } = useMappedStore();
return useQuery({
queryKey: [QueryIdentifiers.GET_BOOST_PLUS_PRICES],
queryFn: () => getBoostPlusPrice(activeUser!.username),
initialData: []
});
}

export function useGetBoostPlusAccountPricesQuery(account: string) {
const { activeUser } = useMappedStore();

const [query, setQuery] = useState("");

useDebounce(
() => {
if (account) {
setQuery(account);
}
},
300,
[account]
);

return useQuery({
queryKey: [QueryIdentifiers.GET_BOOST_PLUS_ACCOUNTS, query],
queryFn: () =>
getBoostPlusAccounts(activeUser!.username, query).then((data) =>
data
? ({
...data,
expires: new Date(data.expires)
} as { account?: string; expires?: Date })
: {}
),
initialData: {},
enabled: !!query
});
}
2 changes: 2 additions & 0 deletions src/common/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const PurchaseContainer = loadable(() => import("./pages/purchase"));
const PurchasePage = (props: any) => <PurchaseContainer {...props} />;

const DecksPage = loadable(() => import("./pages/decks"));
const EcencyPerksPage = loadable(() => import("./features/perks/screens/main"));

const App = (props: any) => {
const { global, activeUser } = useMappedStore();
Expand Down Expand Up @@ -221,6 +222,7 @@ const App = (props: any) => {
path={routes.CONTRIBUTORS}
component={ContributorsPage}
/>
<Route exact={true} strict={true} path={routes.PERKS} component={EcencyPerksPage} />
<Route
exact={true}
strict={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`(1) Default render 1`] = `
Set Beneficiaries
</div>
<div
className="flex justify-center items-center w-5 h-5 [&>svg]:w-5 [&>svg]:h-5 "
className="flex justify-center items-center min-w-[1.25rem] min-h-[1.25rem] max-w-[1.25rem] max-h-[1.25rem] [&>svg]:min-w-[1.25rem] [&>svg]:min-h-[1.25rem] [&>svg]:max-w-[1.25rem] [&>svg]:max-h-[1.25rem] "
>
<svg
viewBox="0 0 24 24"
Expand Down Expand Up @@ -46,7 +46,7 @@ exports[`(2) Default render with author 1`] = `
Set Beneficiaries (1)
</div>
<div
className="flex justify-center items-center w-5 h-5 [&>svg]:w-5 [&>svg]:h-5 "
className="flex justify-center items-center min-w-[1.25rem] min-h-[1.25rem] max-w-[1.25rem] max-h-[1.25rem] [&>svg]:min-w-[1.25rem] [&>svg]:min-h-[1.25rem] [&>svg]:max-w-[1.25rem] [&>svg]:max-h-[1.25rem] "
>
<svg
viewBox="0 0 24 24"
Expand Down Expand Up @@ -76,7 +76,7 @@ exports[`(3) DialogBody 1`] = `
Set Beneficiaries (1)
</div>
<div
className="flex justify-center items-center w-5 h-5 [&>svg]:w-5 [&>svg]:h-5 "
className="flex justify-center items-center min-w-[1.25rem] min-h-[1.25rem] max-w-[1.25rem] max-h-[1.25rem] [&>svg]:min-w-[1.25rem] [&>svg]:min-h-[1.25rem] [&>svg]:max-w-[1.25rem] [&>svg]:max-h-[1.25rem] "
>
<svg
viewBox="0 0 24 24"
Expand Down Expand Up @@ -106,7 +106,7 @@ exports[`(4) DialogBody with author 1`] = `
Set Beneficiaries (1)
</div>
<div
className="flex justify-center items-center w-5 h-5 [&>svg]:w-5 [&>svg]:h-5 "
className="flex justify-center items-center min-w-[1.25rem] min-h-[1.25rem] max-w-[1.25rem] max-h-[1.25rem] [&>svg]:min-w-[1.25rem] [&>svg]:min-h-[1.25rem] [&>svg]:max-w-[1.25rem] [&>svg]:max-h-[1.25rem] "
>
<svg
viewBox="0 0 24 24"
Expand Down
Loading

0 comments on commit 14846a7

Please sign in to comment.