From 42f40209de6bee845b2757d13c1c073f0eebc712 Mon Sep 17 00:00:00 2001 From: yu23ki14 Date: Mon, 6 Jan 2025 20:44:29 +0900 Subject: [PATCH] add assist credit history --- .../routes/$treeId_.assistcredit-history.tsx | 38 ++++++++++ pkgs/frontend/app/routes/$treeId_.member.tsx | 2 +- pkgs/frontend/gql/gql.ts | 13 +++- pkgs/frontend/gql/graphql.ts | 76 ++++++++++++++++++- pkgs/frontend/hooks/useFractionToken.ts | 52 +++++++++++-- pkgs/frontend/hooks/useWorkspace.ts | 6 +- 6 files changed, 170 insertions(+), 17 deletions(-) create mode 100644 pkgs/frontend/app/routes/$treeId_.assistcredit-history.tsx diff --git a/pkgs/frontend/app/routes/$treeId_.assistcredit-history.tsx b/pkgs/frontend/app/routes/$treeId_.assistcredit-history.tsx new file mode 100644 index 00000000..6deafbc1 --- /dev/null +++ b/pkgs/frontend/app/routes/$treeId_.assistcredit-history.tsx @@ -0,0 +1,38 @@ +import { Box, Heading, List, Text } from "@chakra-ui/react"; +import { useParams } from "@remix-run/react"; +import { useGetTransferFractionTokens } from "hooks/useFractionToken"; +import { FC } from "react"; +import { abbreviateAddress } from "utils/wallet"; +import { StickyNav } from "~/components/StickyNav"; + +const WorkspaceMember: FC = () => { + const { treeId } = useParams(); + + const { data } = useGetTransferFractionTokens({ + where: { + workspaceId: treeId, + }, + }); + + return ( + <> + {/* Members */} + + Transaction History + + {data?.transferFractionTokens.map((token) => ( + + + {abbreviateAddress(token.from)} → {abbreviateAddress(token.to)}{" "} + : {token.amount} + + + ))} + + + + + ); +}; + +export default WorkspaceMember; diff --git a/pkgs/frontend/app/routes/$treeId_.member.tsx b/pkgs/frontend/app/routes/$treeId_.member.tsx index 20f2e921..a03475ac 100644 --- a/pkgs/frontend/app/routes/$treeId_.member.tsx +++ b/pkgs/frontend/app/routes/$treeId_.member.tsx @@ -135,7 +135,7 @@ const WorkspaceMember: FC = () => { All Contributors {assistantMembers.map((m, i) => ( - + ; and?: InputMaybe>>; + blockNumber?: InputMaybe; + blockNumber_gt?: InputMaybe; + blockNumber_gte?: InputMaybe; + blockNumber_in?: InputMaybe>; + blockNumber_lt?: InputMaybe; + blockNumber_lte?: InputMaybe; + blockNumber_not?: InputMaybe; + blockNumber_not_in?: InputMaybe>; + blockTimestamp?: InputMaybe; + blockTimestamp_gt?: InputMaybe; + blockTimestamp_gte?: InputMaybe; + blockTimestamp_in?: InputMaybe>; + blockTimestamp_lt?: InputMaybe; + blockTimestamp_lte?: InputMaybe; + blockTimestamp_not?: InputMaybe; + blockTimestamp_not_in?: InputMaybe>; hatId?: InputMaybe; hatId_gt?: InputMaybe; hatId_gte?: InputMaybe; @@ -104,6 +122,8 @@ export type InitializedFractionToken_Filter = { }; export enum InitializedFractionToken_OrderBy { + BlockNumber = 'blockNumber', + BlockTimestamp = 'blockTimestamp', HatId = 'hatId', Id = 'id', Wearer = 'wearer', @@ -261,6 +281,8 @@ export type SubscriptionWorkspacesArgs = { export type TransferFractionToken = { __typename?: 'TransferFractionToken'; amount: Scalars['BigInt']['output']; + blockNumber: Scalars['BigInt']['output']; + blockTimestamp: Scalars['BigInt']['output']; from: Scalars['String']['output']; hatId: Scalars['BigInt']['output']; id: Scalars['ID']['output']; @@ -282,6 +304,22 @@ export type TransferFractionToken_Filter = { amount_not?: InputMaybe; amount_not_in?: InputMaybe>; and?: InputMaybe>>; + blockNumber?: InputMaybe; + blockNumber_gt?: InputMaybe; + blockNumber_gte?: InputMaybe; + blockNumber_in?: InputMaybe>; + blockNumber_lt?: InputMaybe; + blockNumber_lte?: InputMaybe; + blockNumber_not?: InputMaybe; + blockNumber_not_in?: InputMaybe>; + blockTimestamp?: InputMaybe; + blockTimestamp_gt?: InputMaybe; + blockTimestamp_gte?: InputMaybe; + blockTimestamp_in?: InputMaybe>; + blockTimestamp_lt?: InputMaybe; + blockTimestamp_lte?: InputMaybe; + blockTimestamp_not?: InputMaybe; + blockTimestamp_not_in?: InputMaybe>; from?: InputMaybe; from_contains?: InputMaybe; from_contains_nocase?: InputMaybe; @@ -379,6 +417,8 @@ export type TransferFractionToken_Filter = { export enum TransferFractionToken_OrderBy { Amount = 'amount', + BlockNumber = 'blockNumber', + BlockTimestamp = 'blockTimestamp', From = 'from', HatId = 'hatId', Id = 'id', @@ -390,6 +430,8 @@ export enum TransferFractionToken_OrderBy { export type Workspace = { __typename?: 'Workspace'; + blockNumber: Scalars['BigInt']['output']; + blockTimestamp: Scalars['BigInt']['output']; creator: Scalars['String']['output']; hatsTimeFrameModule: Scalars['String']['output']; hatterHatId: Scalars['BigInt']['output']; @@ -402,6 +444,22 @@ export type Workspace_Filter = { /** Filter for the block changed event. */ _change_block?: InputMaybe; and?: InputMaybe>>; + blockNumber?: InputMaybe; + blockNumber_gt?: InputMaybe; + blockNumber_gte?: InputMaybe; + blockNumber_in?: InputMaybe>; + blockNumber_lt?: InputMaybe; + blockNumber_lte?: InputMaybe; + blockNumber_not?: InputMaybe; + blockNumber_not_in?: InputMaybe>; + blockTimestamp?: InputMaybe; + blockTimestamp_gt?: InputMaybe; + blockTimestamp_gte?: InputMaybe; + blockTimestamp_in?: InputMaybe>; + blockTimestamp_lt?: InputMaybe; + blockTimestamp_lte?: InputMaybe; + blockTimestamp_not?: InputMaybe; + blockTimestamp_not_in?: InputMaybe>; creator?: InputMaybe; creator_contains?: InputMaybe; creator_contains_nocase?: InputMaybe; @@ -490,6 +548,8 @@ export type Workspace_Filter = { }; export enum Workspace_OrderBy { + BlockNumber = 'blockNumber', + BlockTimestamp = 'blockTimestamp', Creator = 'creator', HatsTimeFrameModule = 'hatsTimeFrameModule', HatterHatId = 'hatterHatId', @@ -534,20 +594,28 @@ export enum _SubgraphErrorPolicy_ { Deny = 'deny' } +export type GetTransferFractionTokensQueryVariables = Exact<{ + where?: InputMaybe; +}>; + + +export type GetTransferFractionTokensQuery = { __typename?: 'Query', transferFractionTokens: Array<{ __typename?: 'TransferFractionToken', amount: any, from: string, to: string, tokenId: any, blockNumber: any, blockTimestamp: any, hatId: any, id: string, wearer: string, workspaceId: string }> }; + export type GetWorkspacesQueryVariables = Exact<{ where?: InputMaybe; }>; -export type GetWorkspacesQuery = { __typename?: 'Query', workspaces: Array<{ __typename?: 'Workspace', topHatId: any, splitCreator: string, id: string, hatterHatId: any, hatsTimeFrameModule: string, creator: string }> }; +export type GetWorkspacesQuery = { __typename?: 'Query', workspaces: Array<{ __typename?: 'Workspace', creator: string, topHatId: any, splitCreator: string, id: string, hatterHatId: any, hatsTimeFrameModule: string, blockTimestamp: any, blockNumber: any }> }; export type GetWorkspaceQueryVariables = Exact<{ workspaceId: Scalars['ID']['input']; }>; -export type GetWorkspaceQuery = { __typename?: 'Query', workspace?: { __typename?: 'Workspace', creator: string, hatsTimeFrameModule: string, hatterHatId: any, id: string, splitCreator: string, topHatId: any } | null }; +export type GetWorkspaceQuery = { __typename?: 'Query', workspace?: { __typename?: 'Workspace', creator: string, hatsTimeFrameModule: string, hatterHatId: any, id: string, splitCreator: string, topHatId: any, blockTimestamp: any, blockNumber: any } | null }; -export const GetWorkspacesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetWorkspaces"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Workspace_filter"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"workspaces"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"topHatId"}},{"kind":"Field","name":{"kind":"Name","value":"splitCreator"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hatterHatId"}},{"kind":"Field","name":{"kind":"Name","value":"hatsTimeFrameModule"}},{"kind":"Field","name":{"kind":"Name","value":"creator"}}]}}]}}]} as unknown as DocumentNode; -export const GetWorkspaceDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetWorkspace"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"workspaceId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"workspace"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"workspaceId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"creator"}},{"kind":"Field","name":{"kind":"Name","value":"hatsTimeFrameModule"}},{"kind":"Field","name":{"kind":"Name","value":"hatterHatId"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"splitCreator"}},{"kind":"Field","name":{"kind":"Name","value":"topHatId"}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file +export const GetTransferFractionTokensDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTransferFractionTokens"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"TransferFractionToken_filter"}},"defaultValue":{"kind":"ObjectValue","fields":[]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"transferFractionTokens"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"from"}},{"kind":"Field","name":{"kind":"Name","value":"to"}},{"kind":"Field","name":{"kind":"Name","value":"tokenId"}},{"kind":"Field","name":{"kind":"Name","value":"blockNumber"}},{"kind":"Field","name":{"kind":"Name","value":"blockTimestamp"}},{"kind":"Field","name":{"kind":"Name","value":"hatId"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"wearer"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceId"}}]}}]}}]} as unknown as DocumentNode; +export const GetWorkspacesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetWorkspaces"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Workspace_filter"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"workspaces"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"creator"}},{"kind":"Field","name":{"kind":"Name","value":"topHatId"}},{"kind":"Field","name":{"kind":"Name","value":"splitCreator"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hatterHatId"}},{"kind":"Field","name":{"kind":"Name","value":"hatsTimeFrameModule"}},{"kind":"Field","name":{"kind":"Name","value":"blockTimestamp"}},{"kind":"Field","name":{"kind":"Name","value":"blockNumber"}}]}}]}}]} as unknown as DocumentNode; +export const GetWorkspaceDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetWorkspace"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"workspaceId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"workspace"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"workspaceId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"creator"}},{"kind":"Field","name":{"kind":"Name","value":"hatsTimeFrameModule"}},{"kind":"Field","name":{"kind":"Name","value":"hatterHatId"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"splitCreator"}},{"kind":"Field","name":{"kind":"Name","value":"topHatId"}},{"kind":"Field","name":{"kind":"Name","value":"blockTimestamp"}},{"kind":"Field","name":{"kind":"Name","value":"blockNumber"}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file diff --git a/pkgs/frontend/hooks/useFractionToken.ts b/pkgs/frontend/hooks/useFractionToken.ts index dd71b572..0dc501ea 100644 --- a/pkgs/frontend/hooks/useFractionToken.ts +++ b/pkgs/frontend/hooks/useFractionToken.ts @@ -7,6 +7,13 @@ import { } from "./useContracts"; import { useActiveWallet } from "./useWallet"; import { publicClient } from "./useViem"; +import { gql } from "@apollo/client/core"; +import { useQuery } from "@apollo/client/react/hooks"; +import { + GetTransferFractionTokensQuery, + GetTransferFractionTokensQueryVariables, + TransferFractionToken_Filter, +} from "gql/graphql"; export const useTokenRecipients = ( params: { @@ -106,7 +113,6 @@ export const useBalanceOfFractionToken = ( */ export const useFractionToken = () => { const { wallet } = useActiveWallet(); - const [isLoading, setIsLoading] = useState(false); /** @@ -115,8 +121,6 @@ export const useFractionToken = () => { */ const getTokenRecipients = useCallback( async (params: { tokenId: bigint }) => { - if (!wallet) return; - setIsLoading(true); try { @@ -133,7 +137,7 @@ export const useFractionToken = () => { setIsLoading(false); } }, - [wallet] + [] ); /** @@ -143,8 +147,6 @@ export const useFractionToken = () => { */ const getTokenId = useCallback( async (params: { hatId: bigint; account: Address }) => { - if (!wallet) return; - setIsLoading(true); try { @@ -161,7 +163,7 @@ export const useFractionToken = () => { setIsLoading(false); } }, - [wallet] + [] ); const mintInitialSupplyFractionToken = useCallback( @@ -417,3 +419,39 @@ export const useTransferFractionToken = (hatId: bigint, wearer: Address) => { return { isLoading, transferFractionToken }; }; + +///////////////////////////////////// +/////// Start subgraph section ////// +///////////////////////////////////// + +const queryGetTransferFractionTokens = gql(` + query GetTransferFractionTokens($where: TransferFractionToken_filter = {}) { + transferFractionTokens(where: $where) { + amount + from + to + tokenId + blockNumber + blockTimestamp + hatId + id + wearer + workspaceId + } + } +`); + +export const useGetTransferFractionTokens = (params: { + where?: TransferFractionToken_Filter; +}) => { + const result = useQuery< + GetTransferFractionTokensQuery, + GetTransferFractionTokensQueryVariables + >(queryGetTransferFractionTokens, { + variables: { + where: params.where, + }, + }); + + return result; +}; diff --git a/pkgs/frontend/hooks/useWorkspace.ts b/pkgs/frontend/hooks/useWorkspace.ts index 67ea518d..780d471c 100644 --- a/pkgs/frontend/hooks/useWorkspace.ts +++ b/pkgs/frontend/hooks/useWorkspace.ts @@ -5,12 +5,14 @@ import { GetWorkspaceQuery, GetWorkspaceQueryVariables } from "gql/graphql"; const queryGetWorkspaces = gql(` query GetWorkspaces($where: Workspace_filter) { workspaces(where: $where) { + creator topHatId splitCreator id hatterHatId hatsTimeFrameModule - creator + blockTimestamp + blockNumber } } `); @@ -24,6 +26,8 @@ const queryGetWorkspace = gql(` id splitCreator topHatId + blockTimestamp + blockNumber } } `);