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 #1410 from ecency/feature/activity-points-queries
Browse files Browse the repository at this point in the history
Feature/activity points queries
  • Loading branch information
feruzm authored Jul 19, 2023
2 parents d8f84c5 + 297835f commit 90256b0
Show file tree
Hide file tree
Showing 35 changed files with 276 additions and 722 deletions.
15 changes: 15 additions & 0 deletions src/common/api/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useMutation } from "@tanstack/react-query";
import { usrActivity } from "./private-api";

interface Params {
bl?: string | number;
tx?: string | number;
}

export function useUserActivity(username: string | undefined, ty: number) {
return useMutation(["user-activity", username, ty], async (params: Params | undefined) => {
if (username) {
await usrActivity(username, ty, params?.bl, params?.tx);
}
});
}
3 changes: 0 additions & 3 deletions src/common/api/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import hs from "hivesigner";

import {
AccountUpdateOperation,
Authority,
CustomJsonOperation,
KeyRole,
Operation,
OperationName,
VirtualOperationName,
PrivateKey,
TransactionConfirmation
} from "@hiveio/dhive";
Expand Down
18 changes: 8 additions & 10 deletions src/common/api/private-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,23 +408,21 @@ export const deleteFragment = (username: string, fragmentId: string): Promise<an
return axios.post(apiBase(`/private-api/fragments-delete`), data).then((resp) => resp.data);
};

export const getPoints = (
username: string
export const getPoints = async (
username: string,
usePrivate?: boolean
): Promise<{
points: string;
unclaimed_points: string;
}> => {
if (window.usePrivate) {
if (usePrivate ?? window.usePrivate) {
const data = { username };
return axios.post(apiBase(`/private-api/points`), data).then((resp) => resp.data);
}

return new Promise((resolve) => {
resolve({
points: "0.000",
unclaimed_points: "0.000"
});
});
return {
points: "0.000",
unclaimed_points: "0.000"
};
};

export const getPointTransactions = (
Expand Down
37 changes: 37 additions & 0 deletions src/common/api/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useQuery } from "@tanstack/react-query";
import { QueryIdentifiers } from "../core";
import { getPoints, getPointTransactions } from "./private-api";
import { useMappedStore } from "../store/use-mapped-store";

const DEFAULT = {
points: "0.000",
uPoints: "0.000",
transactions: []
};

export function usePointsQuery(username: string, filter = 0) {
const { global } = useMappedStore();

return useQuery(
[QueryIdentifiers.POINTS, username, filter],
async () => {
const name = username.replace("@", "");

try {
const points = await getPoints(name, global.usePrivate);
const transactions = await getPointTransactions(name, filter);
return {
points: points.points,
uPoints: points.unclaimed_points,
transactions
};
} catch (e) {
return DEFAULT;
}
},
{
initialData: DEFAULT,
retryDelay: 30000
}
);
}
14 changes: 8 additions & 6 deletions src/common/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import React, { useEffect, useState } from "react";
import { Route, Switch } from "react-router-dom";
import EntryIndexContainer from "./pages/index";
import { EntryScreen } from "./pages/entry";
import { SearchPageContainer, SearchMorePageContainer } from "./pages/search";
import { ProposalsIndexContainer, ProposalDetailContainer } from "./pages/proposals";
import { SearchMorePageContainer, SearchPageContainer } from "./pages/search";
import { ProposalDetailContainer, ProposalsIndexContainer } from "./pages/proposals";
import NotFound from "./components/404";
import Tracker from "./tracker";
import {
AboutPage,
GuestPostPage,
ContributePage,
ContributorsPage,
FaqPage,
GuestPostPage,
PrivacyPage,
WhitePaperPage,
TosPage,
FaqPage,
ContributorsPage
WhitePaperPage
} from "./pages/static";
import routes from "./routes";
import * as ls from "./util/local-storage";
Expand All @@ -26,6 +26,7 @@ import Announcement from "./components/announcement";
import FloatingFAQ from "./components/floating-faq";
import { useMappedStore } from "./store/use-mapped-store";
import { EntriesCacheManager } from "./core";
import { UserActivityRecorder } from "./components/user-activity-recorder";

// Define lazy pages
const ProfileContainer = loadable(() => import("./pages/profile-functional"));
Expand Down Expand Up @@ -94,6 +95,7 @@ const App = (props: any) => {
{/*Excluded from production*/}
{/*<ReactQueryDevtools initialIsOpen={false} />*/}
<Tracker />
<UserActivityRecorder />
<Switch>
<Route exact={true} path={routes.HOME} component={EntryIndexContainer} />
<Route exact={true} strict={true} path={routes.FILTER} component={EntryIndexContainer} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { _t } from "../../../i18n";
import { History } from "history";
import { UserDeckGridItem } from "../types";
import "./_deck-wallet-balance-column.scss";
import { getCurrencyTokenRate, getPoints } from "../../../api/private-api";
import { getCurrencyTokenRate } from "../../../api/private-api";
import { Spinner } from "react-bootstrap";
import FormattedCurrency from "../../formatted-currency";
import { useMappedStore } from "../../../store/use-mapped-store";
Expand All @@ -19,6 +19,7 @@ import { getHiveEngineTokenBalances, getMetrics } from "../../../api/hive-engine
import { getSpkWallet } from "../../../api/spk-api";
import { getEstimatedBalance } from "../../wallet-spk/util";
import { DeckGridContext } from "../deck-manager";
import { usePointsQuery } from "../../../api/queries";

interface Props {
id: string;
Expand Down Expand Up @@ -60,9 +61,11 @@ export const DeckWalletBalanceColumn = ({
const [account, setAccount] = useState<FullAccount | null>(null);

// Ecency wallet
const [points, setPoints] = useState("0");
const [pointsLoading, setPointsLoading] = useState(false);
const [estimatedValue, setEstimatedValue] = useState(0);
const {
data: { points }
} = usePointsQuery(username);

// Hive wallet
const [hive, setHive] = useState("0");
Expand Down Expand Up @@ -124,10 +127,8 @@ export const DeckWalletBalanceColumn = ({
setPointsLoading(true);

try {
const { points } = await getPoints(username);
const estimatedValue = await getCurrencyTokenRate("usd", "estm");

setPoints(points);
setEstimatedValue(estimatedValue);
} catch (e) {
} finally {
Expand Down
7 changes: 3 additions & 4 deletions src/common/components/entry-tip-btn/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import React from "react";
import EntryTipBtn, { TippingDialog } from "./index";

import {
globalInstance,
dynamicPropsIntance1,
UiInstance,
entryInstance1,
fullAccountInstance
fullAccountInstance,
globalInstance,
UiInstance
} from "../../helper/test-helper";
import { withStore } from "../../tests/with-store";

Expand Down Expand Up @@ -53,7 +53,6 @@ it("(2) Dialog", async () => {
deleteUser: () => {},
toggleUIProp: () => {},
setSigningKey: () => {},
fetchPoints: () => {},
updateWalletValues: () => {},
onHide: () => {}
};
Expand Down
4 changes: 1 addition & 3 deletions src/common/components/entry-tip-btn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useMappedStore } from "../../store/use-mapped-store";

import { giftOutlineSvg } from "../../img/svg";
import "./_index.scss";

interface Props {
global: Global;
dynamicProps: DynamicProps;
Expand All @@ -29,7 +30,6 @@ interface Props {
entry: Entry;
signingKey: string;
account: Account;
fetchPoints: (username: string, type?: number) => void;
updateWalletValues: () => void;
addAccount: (data: Account) => void;
setActiveUser: (username: string | null) => void;
Expand Down Expand Up @@ -158,7 +158,6 @@ export default ({
global,
activeUser,
signingKey,
fetchPoints,
addAccount,
setActiveUser,
updateActiveUser,
Expand All @@ -176,7 +175,6 @@ export default ({
activeUser: activeUser,
entry: entry,
signingKey: signingKey,
fetchPoints: fetchPoints,
updateWalletValues: updateWalletValues,
setTipDialogMounted: setTipDialogMounted,
handleClickAway: handleClickAway,
Expand Down
3 changes: 1 addition & 2 deletions src/common/components/profile-referrals/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { StaticRouter } from "react-router-dom";

import { ProfileReferrals } from "./index";

import { globalInstance, allOver, dynamicPropsIntance1 } from "../../helper/test-helper";
import { allOver, dynamicPropsIntance1, globalInstance } from "../../helper/test-helper";
import { initialState as transactionsInitialState } from "../../store/transactions/index";

jest.mock("../../api/bridge", () => ({
Expand Down Expand Up @@ -82,7 +82,6 @@ it("(1) Default render - With data.", async () => {
updateActiveUser: () => {},
setSigningKey: () => {},
fetchTransactions: () => {},
fetchPoints: () => {},
updateWalletValues: () => {}
};

Expand Down
9 changes: 3 additions & 6 deletions src/common/components/profile-referrals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import BaseComponent from "../base";
import UserAvatar from "../user-avatar";
import ProfileLink from "../profile-link";
import MyPagination from "../pagination";
import Transfer, { TransferMode, TransferAsset } from "../transfer";
import Transfer, { TransferAsset, TransferMode } from "../transfer";
import LinearProgress from "../linear-progress";
import { shareVariantSvg } from "../../img/svg";
import { getReferrals, ReferralItem, getReferralsStats, ReferralStat } from "../../api/private-api";
import { getReferrals, getReferralsStats, ReferralItem, ReferralStat } from "../../api/private-api";
// import clipboard from '../../util/clipboard';

import { _t } from "../../i18n";
import { success } from "../feedback";
import { Tsx } from "../../i18n/helper";
Expand All @@ -36,7 +35,6 @@ interface Props {
updateActiveUser: (data?: Account) => void;
setSigningKey: (key: string) => void;
fetchTransactions: (username: string, group?: OperationGroup | "") => void;
fetchPoints: (username: string, type?: number) => void;
updateWalletValues: () => void;
}

Expand Down Expand Up @@ -305,8 +303,7 @@ export default (p: Props) => {
addAccount: p.addAccount,
updateActiveUser: p.updateActiveUser,
setSigningKey: p.setSigningKey,
fetchTransactions: p.fetchTransactions,
fetchPoints: p.fetchPoints
fetchTransactions: p.fetchTransactions
};

return <ProfileReferrals {...props} />;
Expand Down
5 changes: 2 additions & 3 deletions src/common/components/purchase/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React from "react";
import { Purchase } from "./index";

import {
globalInstance,
allOver,
dynamicPropsIntance1,
fullAccountInstance,
allOver
globalInstance
} from "../../helper/test-helper";

import { initialState as transactionsInitialState } from "../../store/transactions/index";
Expand Down Expand Up @@ -47,7 +47,6 @@ const defProps = {
updateActiveUser: () => {},
setSigningKey: () => {},
onHide: () => {},
fetchPoints: () => {},
updateWalletValues: () => {}
};

Expand Down
3 changes: 1 addition & 2 deletions src/common/components/purchase/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from "react";

import { Form, FormControl, Modal, Button } from "react-bootstrap";
import { Button, Form, FormControl, Modal } from "react-bootstrap";

import { Global } from "../../store/global/types";
import { DynamicProps } from "../../store/dynamic-props/types";
Expand All @@ -26,7 +26,6 @@ interface Props {
transactions: Transactions;
signingKey: string;
account: Account;
fetchPoints: (username: string, type?: number) => void;
updateWalletValues: () => void;
addAccount: (data: Account) => void;
updateActiveUser: (data?: Account) => void;
Expand Down
7 changes: 3 additions & 4 deletions src/common/components/transfer-he/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { Transfer, TransferMode } from "./index";
import { initialState as transactionsInitialState } from "../../store/transactions/index";

import {
globalInstance,
dynamicPropsIntance1,
fullAccountInstance
fullAccountInstance,
globalInstance
} from "../../helper/test-helper";

import TestRenderer, { ReactTestInstance } from "react-test-renderer";
import { ReactTestInstance } from "react-test-renderer";
import { withStore } from "../../tests/with-store";

jest.mock("moment", () => () => ({
Expand Down Expand Up @@ -41,7 +41,6 @@ const defProps = {
addAccount: () => {},
updateActiveUser: () => {},
setSigningKey: () => {},
fetchPoints: () => {},
updateWalletValues: () => {},
onHide: () => {}
};
Expand Down
Loading

0 comments on commit 90256b0

Please sign in to comment.