Skip to content

Commit

Permalink
refactor: Replace Sponsorship GraphQL query with Wagmi balance hook
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Mar 6, 2025
1 parent 0d70f27 commit ffce00f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 71 deletions.
6 changes: 3 additions & 3 deletions apps/api/src/routes/lens/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import catchedError from "src/helpers/catchedError";
import { heyWalletClient } from "src/helpers/heyWalletClient";
import { noBody } from "src/helpers/responses";
import trackEvent from "src/helpers/trackEvent";
import { type Address, checksumAddress } from "viem";
import { checksumAddress } from "viem";

const TYPES = {
SourceStamp: [
Expand All @@ -23,7 +23,7 @@ const DOMAIN = {
name: "Lens Source",
version: "1",
chainId: 37111,
verifyingContract: checksumAddress(HEY_APP as Address)
verifyingContract: checksumAddress(HEY_APP)
};

export const post = async (req: Request, res: Response) => {
Expand Down Expand Up @@ -56,7 +56,7 @@ export const post = async (req: Request, res: Response) => {
types: TYPES,
domain: DOMAIN,
message: {
source: checksumAddress(HEY_APP as Address),
source: checksumAddress(HEY_APP),
originalMsgSender: checksumAddress(account),
validator: checksumAddress(validator),
nonce,
Expand Down
5 changes: 2 additions & 3 deletions apps/web/src/components/Post/OpenAction/TipAction/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import usePreventScrollOnNumberInput from "src/hooks/usePreventScrollOnNumberInp
import useTransactionLifecycle from "src/hooks/useTransactionLifecycle";
import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import type { Address } from "viem";
import { formatUnits } from "viem";
import { useBalance } from "wagmi";

Expand All @@ -46,7 +45,7 @@ const Action: FC<ActionProps> = ({ closePopover, post }) => {
const { data: balanceData, isLoading: balanceLoading } = useBalance({
address: currentAccount?.address,
query: { refetchInterval: 2000 },
token: DEFAULT_COLLECT_TOKEN as Address
token: DEFAULT_COLLECT_TOKEN
});

const updateCache = () => {
Expand Down Expand Up @@ -123,7 +122,7 @@ const Action: FC<ActionProps> = ({ closePopover, post }) => {
post: post.id,
action: {
tipping: {
currency: DEFAULT_COLLECT_TOKEN as Address,
currency: DEFAULT_COLLECT_TOKEN,
value: cryptoRate.toString()
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Shared/Fund/FundAccount/Fund.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Fund: FC<FundProps> = ({ recipient, isHeyTip, onSuccess }) => {

const { data, isLoading } = useBalance({
address,
token: DEFAULT_COLLECT_TOKEN as Address,
token: DEFAULT_COLLECT_TOKEN,
query: { refetchInterval: 2000 }
});

Expand All @@ -66,7 +66,7 @@ const Fund: FC<FundProps> = ({ recipient, isHeyTip, onSuccess }) => {
await writeContractAsync({
abi: ABI,
functionName: "transfer",
address: DEFAULT_COLLECT_TOKEN as Address,
address: DEFAULT_COLLECT_TOKEN,
args: [recipient, parseEther(amount.toString())]
});

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Shared/Fund/FundAccount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DEFAULT_COLLECT_TOKEN, STATIC_IMAGES_URL } from "@hey/data/constants";
import { Image } from "@hey/ui";
import type { FC } from "react";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import { type Address, formatUnits } from "viem";
import { formatUnits } from "viem";
import { useBalance } from "wagmi";
import Loader from "../../Loader";
import Fund from "./Fund";
Expand All @@ -12,7 +12,7 @@ const FundAccount: FC = () => {

const { data, isLoading } = useBalance({
address: currentAccount?.address,
token: DEFAULT_COLLECT_TOKEN as Address,
token: DEFAULT_COLLECT_TOKEN,
query: { refetchInterval: 2000 }
});

Expand Down
21 changes: 8 additions & 13 deletions apps/web/src/components/Staff/Overview/Sponsorship.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
import Loader from "@components/Shared/Loader";
import { BLOCK_EXPLORER_URL, HEY_SPONSOR } from "@hey/data/constants";
import { useSponsorshipQuery } from "@hey/indexer";
import { Card, CardHeader, ErrorMessage, NumberedStat } from "@hey/ui";
import Link from "next/link";
import type { FC } from "react";
import { formatEther } from "viem";
import { useBalance } from "wagmi";

const Sponsorship: FC = () => {
const { data, loading, error } = useSponsorshipQuery({
variables: { request: { address: HEY_SPONSOR } },
pollInterval: 5000
const { data, isLoading, error } = useBalance({
address: HEY_SPONSOR,
query: { refetchInterval: 2000 }
});

return (
<Card>
<CardHeader title="Sponsorship" />
<div className="m-5">
{loading ? (
{isLoading ? (
<Loader className="my-10" message="Loading sponsorship..." />
) : error ? (
<ErrorMessage error={error} title="Failed to load sponsorship" />
) : (
<div className="space-y-5">
<div className="linkify font-bold">
<Link
href={`${BLOCK_EXPLORER_URL}/address/${data?.sponsorship?.address}`}
href={`${BLOCK_EXPLORER_URL}/address/${HEY_SPONSOR}`}
target="_blank"
>
Open Sponsorship Contract in Explorer
</Link>
</div>
<NumberedStat
count={data?.sponsorship?.balance}
count={formatEther(data?.value || BigInt(0))}
name="Balance"
suffix="GHO"
/>
{data?.sponsorship?.limits?.user && (
<NumberedStat
name="User limit"
suffix={`${data?.sponsorship?.limits?.user.limit} / ${data?.sponsorship?.limits?.user.window}`}
/>
)}
</div>
)}
</div>
Expand Down
10 changes: 5 additions & 5 deletions packages/data/utils/getEnvConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { MainnetContracts, TestnetContracts } from "../contracts";
import LensEndpoint from "../lens-endpoints";

const getEnvConfig = (): {
defaultCollectToken: string;
lensApiEndpoint: string;
appAddress: string;
sponsorAddress: string;
defaultCollectToken: `0x${string}`;
appAddress: `0x${string}`;
sponsorAddress: `0x${string}`;
} => {
switch (LENS_NETWORK) {
case "testnet":
return {
defaultCollectToken: TestnetContracts.DefaultToken,
lensApiEndpoint: LensEndpoint.Testnet,
defaultCollectToken: TestnetContracts.DefaultToken,
appAddress: TestnetContracts.App,
sponsorAddress: TestnetContracts.Sponsor
};
default:
return {
defaultCollectToken: MainnetContracts.DefaultToken,
lensApiEndpoint: LensEndpoint.Mainnet,
defaultCollectToken: MainnetContracts.DefaultToken,
appAddress: MainnetContracts.App,
sponsorAddress: MainnetContracts.Sponsor
};
Expand Down
16 changes: 0 additions & 16 deletions packages/indexer/documents/queries/sponsorship/Sponsorship.graphql

This file was deleted.

28 changes: 1 addition & 27 deletions packages/indexer/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ export type ActionMetadata = {
name: Scalars['String']['output'];
setDisabledParams: Array<KeyValuePair>;
source: Scalars['URI']['output'];
title: Scalars['String']['output'];
};

export type AddAccountManagerRequest = {
Expand Down Expand Up @@ -1865,7 +1864,6 @@ export type FeedMetadata = {
description?: Maybe<Scalars['String']['output']>;
id: Scalars['String']['output'];
name: Scalars['String']['output'];
title: Scalars['String']['output'];
};

export type FeedOneOf = {
Expand Down Expand Up @@ -2184,7 +2182,6 @@ export type GraphMetadata = {
description?: Maybe<Scalars['String']['output']>;
id: Scalars['String']['output'];
name: Scalars['String']['output'];
title: Scalars['String']['output'];
};

export type GraphOneOf = {
Expand Down Expand Up @@ -7896,13 +7893,6 @@ export type WhoReferencedPostQuery = { __typename?: 'Query', whoReferencedPost:
& PaginatedResultInfoFragment
) } };

export type SponsorshipQueryVariables = Exact<{
request: SponsorshipRequest;
}>;


export type SponsorshipQuery = { __typename?: 'Query', sponsorship?: { __typename?: 'Sponsorship', address: any, balance?: any | null, limits?: { __typename?: 'SponsorshipLimits', global?: { __typename?: 'SponsorshipRateLimit', limit: number, window: SponsorshipRateLimitWindow } | null, user?: { __typename?: 'SponsorshipRateLimit', limit: number, window: SponsorshipRateLimitWindow } | null } | null } | null };

export const PaginatedResultInfoFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"PaginatedResultInfo"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"PaginatedResultInfo"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prev"}},{"kind":"Field","name":{"kind":"Name","value":"next"}}]}}]} as unknown as DocumentNode;
export const GroupMetadataFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"GroupMetadata"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"GroupMetadata"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"coverPicture"}}]}}]} as unknown as DocumentNode;
export const PostGroupInfoFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"PostGroupInfo"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"PostGroupInfo"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"address"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"GroupMetadata"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"GroupMetadata"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"GroupMetadata"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"coverPicture"}}]}}]} as unknown as DocumentNode;
Expand Down Expand Up @@ -8801,20 +8791,4 @@ export function useWhoReferencedPostSuspenseQuery(baseOptions?: Apollo.SkipToken
}
export type WhoReferencedPostQueryHookResult = ReturnType<typeof useWhoReferencedPostQuery>;
export type WhoReferencedPostLazyQueryHookResult = ReturnType<typeof useWhoReferencedPostLazyQuery>;
export type WhoReferencedPostSuspenseQueryHookResult = ReturnType<typeof useWhoReferencedPostSuspenseQuery>;
export const SponsorshipDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Sponsorship"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"request"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SponsorshipRequest"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"sponsorship"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"request"},"value":{"kind":"Variable","name":{"kind":"Name","value":"request"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"address"}},{"kind":"Field","name":{"kind":"Name","value":"balance"}},{"kind":"Field","name":{"kind":"Name","value":"limits"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"global"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"limit"}},{"kind":"Field","name":{"kind":"Name","value":"window"}}]}},{"kind":"Field","name":{"kind":"Name","value":"user"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"limit"}},{"kind":"Field","name":{"kind":"Name","value":"window"}}]}}]}}]}}]}}]} as unknown as DocumentNode;
export function useSponsorshipQuery(baseOptions: Apollo.QueryHookOptions<SponsorshipQuery, SponsorshipQueryVariables> & ({ variables: SponsorshipQueryVariables; skip?: boolean; } | { skip: boolean; }) ) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<SponsorshipQuery, SponsorshipQueryVariables>(SponsorshipDocument, options);
}
export function useSponsorshipLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<SponsorshipQuery, SponsorshipQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<SponsorshipQuery, SponsorshipQueryVariables>(SponsorshipDocument, options);
}
export function useSponsorshipSuspenseQuery(baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<SponsorshipQuery, SponsorshipQueryVariables>) {
const options = baseOptions === Apollo.skipToken ? baseOptions : {...defaultOptions, ...baseOptions}
return Apollo.useSuspenseQuery<SponsorshipQuery, SponsorshipQueryVariables>(SponsorshipDocument, options);
}
export type SponsorshipQueryHookResult = ReturnType<typeof useSponsorshipQuery>;
export type SponsorshipLazyQueryHookResult = ReturnType<typeof useSponsorshipLazyQuery>;
export type SponsorshipSuspenseQueryHookResult = ReturnType<typeof useSponsorshipSuspenseQuery>;
export type WhoReferencedPostSuspenseQueryHookResult = ReturnType<typeof useWhoReferencedPostSuspenseQuery>;

0 comments on commit ffce00f

Please sign in to comment.