Skip to content

Commit

Permalink
standalone balance query
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-justin committed Dec 20, 2023
1 parent 570a08e commit dad4241
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/pages/Admin/Charity/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { PropsWithChildren } from "react";
import { useAdminContext } from "pages/Admin/Context";
import { useProfileQuery } from "services/aws/aws";
import { useEndowBalanceQuery } from "services/apes";
import ContentLoader from "components/ContentLoader";
import QueryLoader from "components/QueryLoader";
import Seo from "../Seo";
import Balance from "./Balance";

export default function Dashboard() {
const { id } = useAdminContext();
const queryState = useProfileQuery({ endowId: id }, { skip: !id });
const queryState = useEndowBalanceQuery(id, { skip: !id });

return (
<div className="@container w-full max-w-4xl grid content-start mt-6">
Expand Down
9 changes: 7 additions & 2 deletions src/pages/Profile/Body/GeneralInfo/DetailsColumn/Balances.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { useProfileContext } from "pages/Profile/ProfileContext";
import { useEndowBalanceQuery } from "services/apes";
import { humanize } from "helpers";

export default function Balances() {
const { totalContributions } = useProfileContext();
const { id } = useProfileContext();
const { data } = useEndowBalanceQuery(id);

return (
<div className="flex flex-col items-center gap-4 w-full">
<Balance title="Total Contributions" amount={totalContributions || 0} />
<Balance
title="Total Contributions"
amount={data?.totalContributions ?? 0}
/>
</div>
);
}
Expand Down
7 changes: 6 additions & 1 deletion src/services/apes/apes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { Token } from "types/aws";
import { EndowmentBalances, Token } from "types/aws";
import { ChainID } from "types/chain";
import { appRoutes } from "constants/routes";
import { APIs } from "constants/urls";
Expand Down Expand Up @@ -37,12 +37,17 @@ export const apes = createApi({
}),
}
),
endowBalance: builder.query<EndowmentBalances, number>({
providesTags: ["balance"],
query: (endowId) => `${v(1)}/balances/${endowId}`,
}),
}),
});

export const {
useTokensQuery,
useStripeSessionURLMutation,
useEndowBalanceQuery,
util: {
invalidateTags: invalidateApesTags,
updateQueryData: updateApesQueryData,
Expand Down
2 changes: 1 addition & 1 deletion src/services/apes/tags.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const tags = ["chain", "donations", "tokens"] as const;
export const tags = ["chain", "donations", "tokens", "balance"] as const;
12 changes: 1 addition & 11 deletions src/types/aws/ap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ import { APIEnvironment, EndowmentType, UNSDG_NUMS } from "../../lists";

export type EndowmentTierNum = 1 | 2 | 3;

type EndowmentBalances = {
contributionsCount: number;
donationsBal: number;
payoutsMade: number;
payoutsPending: number;
sustainabilityFundBal: number;
totalContributions: number;
totalEarnings: number;
};

export type MileStone = {
milestone_date: string; //isoDate
milestone_description: string;
Expand Down Expand Up @@ -68,7 +58,7 @@ export type EndowmentProfile = EndowmentBase & {
street_address: string; //or empty
url: string;
wise_recipient_id: number;
} & EndowmentBalances;
};

export type EndowmentCard = EndowmentBase & {
endow_type: EndowmentType;
Expand Down
10 changes: 10 additions & 0 deletions src/types/aws/apes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ export type Token = {
coingecko_denom: string;
type: TokenType;
};

export type EndowmentBalances = {
contributionsCount: number;
donationsBal: number;
payoutsMade: number;
payoutsPending: number;
sustainabilityFundBal: number;
totalContributions: number;
totalEarnings: number;
};

0 comments on commit dad4241

Please sign in to comment.