diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dacd6ea1..be695aac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements +- [#900](https://github.com/alleslabs/celatone-frontend/pull/900) Refactor module details info +- [#899](https://github.com/alleslabs/celatone-frontend/pull/899) Refactor module details APIs - [#866](https://github.com/alleslabs/celatone-frontend/pull/866) Update upload code CTA to sticky bar - [#872](https://github.com/alleslabs/celatone-frontend/pull/872) Change Query/Execute page to Interact Contract - [#895](https://github.com/alleslabs/celatone-frontend/pull/895) Show collection address and creator on the collection list page diff --git a/src/lib/app-provider/env.ts b/src/lib/app-provider/env.ts index 7a9d33cad..9042fd08f 100644 --- a/src/lib/app-provider/env.ts +++ b/src/lib/app-provider/env.ts @@ -67,8 +67,6 @@ export enum CELATONE_QUERY_KEYS { PROPOSAL_VALIDATOR_VOTES = "CELATONE_QUERY_PROPOSAL_VALIDATOR_VOTES", PROPOSAL_ANSWER_COUNTS = "CELATONE_QUERY_PROPOSAL_ANSWER_COUNTS", RELATED_PROPOSALS_BY_CONTRACT_ADDRESS = "CELATONE_QUERY_RELATED_PROPOSALS_BY_CONTRACT_ADDRESS", - PROPOSALS_BY_MODULE_ID = "CELATONE_QUERY_PROPOSALS_BY_MODULE_ID", - PROPOSALS_COUNT_BY_MODULE_ID = "CELATONE_QUERY_PROPOSALS_COUNT_BY_MODULE_ID", PROPOSALS_BY_ADDRESS = "CELATONE_QUERY_PROPOSALS_BY_ADDRESS", PROPOSALS = "CELATONE_QUERY_PROPOSALS", PROPOSAL_PARAMS = "CELATONE_QUERY_PROPOSAL_PARAMS", @@ -106,13 +104,12 @@ export enum CELATONE_QUERY_KEYS { MODULE_VERIFICATION = "CELATONE_QUERY_MODULE_VERIFICATION", FUNCTION_VIEW = "CELATONE_QUERY_FUNCTION_VIEW", MODULE_DECODE = "CELATONE_QUERY_MODULE_DECODE", - MODULE_ID = "CELATONE_QUERY_MODULE_ID", + MODULE_TABLE_COUNTS = "CELATONE_QUERY_MODULE_TABLE_COUNTS", MODULE_TXS = "CELATONE_QUERY_MODULE_TXS", - MODULE_TXS_COUNT = "CELATONE_QUERY_MODULE_TXS_COUNT", MODULE_HISTORIES = "CELATONE_QUERY_MODULE_HISTORIES", - MODULE_HISTORIES_COUNT = "CELATONE_QUERY_MODULE_HISTORIES_COUNT", - MODULE_DETAILS = "CELATONE_QUERY_MODULE_DETAILS", + MODULE_PROPOSALS = "CELATONE_QUERY_MODULE_PROPOSALS", SCRIPT_DECODE = "CELATONE_QUERY_SCRIPT_DECODE", + MODULE_INFO = "CELATONE_QUERY_MODULE_INFO", // RESOURCE RESOURCES_BY_ADDRESS = "CELATONE_QUERY_RESOURCES_BY_ADDRESS", // NFTS diff --git a/src/lib/pages/module-details/components/ModuleInfo.tsx b/src/lib/pages/module-details/components/ModuleInfo.tsx index 372067d3e..97bf4e072 100644 --- a/src/lib/pages/module-details/components/ModuleInfo.tsx +++ b/src/lib/pages/module-details/components/ModuleInfo.tsx @@ -1,162 +1,38 @@ -import { chakra, Flex, Heading, Text } from "@chakra-ui/react"; +import { Flex, Heading, Text } from "@chakra-ui/react"; -import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; -import { LabelText } from "lib/components/LabelText"; -import { Loading } from "lib/components/Loading"; import { ModuleSourceCode } from "lib/components/module"; import type { ModuleVerificationInternal } from "lib/services/move/module"; import type { - IndexedModule, - ModuleInitialPublishInfo, -} from "lib/services/move/moduleService"; -import type { Nullable, Option } from "lib/types"; -import { dateFromNow, formatUTC } from "lib/utils"; - -const DetailsContainer = chakra(Flex, { - baseStyle: { - p: 4, - borderRadius: "8px", - border: "1px solid", - borderColor: "gray.700", - columnGap: 6, - "& > div": { flex: 1 }, - }, -}); - -interface ModuleInfoProps { - moduleDetails: Option; - upgradePolicy: IndexedModule["upgradePolicy"]; + HexAddr, + Nullable, + Option, + Proposal, + UpgradePolicy, +} from "lib/types"; + +import { ModuleInfoBody } from "./ModuleInfoBody"; + +export interface ModuleInfoProps { + vmAddress: HexAddr; + upgradePolicy: UpgradePolicy; + transaction: Option; + proposal: Nullable>; + isRepublished: boolean; + blockHeight: number; + blockTimestamp: Date; verificationData: Option>; - isLoading: boolean; } -const InitRender = ({ - initTxHash, - initProposalTitle, - initProposalId, - createdHeight, -}: { - initTxHash: ModuleInitialPublishInfo["initTxHash"]; - initProposalTitle: ModuleInitialPublishInfo["initProposalTitle"]; - initProposalId: ModuleInitialPublishInfo["initProposalId"]; - createdHeight: ModuleInitialPublishInfo["createdHeight"]; -}) => { - if (initTxHash) { - return ( - - - - ); - } - - if (createdHeight === 0) - return ( - - Genesis - - ); - - if (initProposalTitle && initProposalId) { - return ( - - - - ); - } - - return ( - - N/A - - ); -}; - -const ModuleInfoBody = ({ - moduleDetails, - isLoading, - upgradePolicy, -}: Omit) => { - if (isLoading) - return ( - - - - ); - if (!moduleDetails) - return ( - - - Error fetching data - - - ); - - const { - createdHeight, - createdTime, - publisherVmAddress, - initProposalId, - initProposalTitle, - initTxHash, - } = moduleDetails; - - return ( - - {upgradePolicy} - - {createdHeight !== undefined ? ( - - ) : ( - "N/A" - )} - - - - - - - ); -}; - export const ModuleInfo = ({ + vmAddress, + upgradePolicy, + transaction, + proposal, + isRepublished, + blockHeight, + blockTimestamp, verificationData, - ...details }: ModuleInfoProps) => ( @@ -173,7 +49,15 @@ export const ModuleInfo = ({ )} - + ); diff --git a/src/lib/pages/module-details/components/ModuleInfoBody.tsx b/src/lib/pages/module-details/components/ModuleInfoBody.tsx new file mode 100644 index 000000000..ceae34f5e --- /dev/null +++ b/src/lib/pages/module-details/components/ModuleInfoBody.tsx @@ -0,0 +1,84 @@ +import { Grid } from "@chakra-ui/react"; + +import { ExplorerLink } from "lib/components/ExplorerLink"; +import { LabelText } from "lib/components/LabelText"; +import { dateFromNow, formatUTC } from "lib/utils"; + +import type { ModuleInfoProps } from "./ModuleInfo"; + +const ModuleInfoBodyPublishedAndRepublished = ({ + transaction, + proposal, + isRepublished, +}: Pick) => { + const labelPrefix = isRepublished ? "Latest Republished" : "Published"; + + if (transaction) { + return ( + + + + ); + } + + if (proposal && proposal.id) { + return ( + + + + ); + } + + return Genesis; +}; + +export const ModuleInfoBody = ({ + vmAddress, + upgradePolicy, + transaction, + proposal, + isRepublished, + blockHeight, + blockTimestamp, +}: Omit) => ( + + {upgradePolicy} + + + + + {blockHeight ? ( + + ) : ( + "N/A" + )} + + + +); diff --git a/src/lib/pages/module-details/components/tables/ModuleRelatedProposalsTable.tsx b/src/lib/pages/module-details/components/tables/ModuleRelatedProposalsTable.tsx index 3c02a56a3..e42627507 100644 --- a/src/lib/pages/module-details/components/tables/ModuleRelatedProposalsTable.tsx +++ b/src/lib/pages/module-details/components/tables/ModuleRelatedProposalsTable.tsx @@ -1,25 +1,23 @@ -import type { ChangeEvent } from "react"; - import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { ProposalsTable, ViewMore } from "lib/components/table"; -import { useRelatedProposalsByModuleIdPagination } from "lib/services/proposalService"; -import type { Nullish, Option } from "lib/types"; +import { useModuleRelatedProposals } from "lib/services/move"; +import type { HexAddr, Option } from "lib/types"; interface ModuleRelatedProposalsTableProps { - moduleId: Nullish; + vmAddress: HexAddr; + moduleName: string; scrollComponentId: string; relatedProposalsCount: Option; - refetchCount: () => void; onViewMore?: () => void; } export const ModuleRelatedProposalsTable = ({ - moduleId, + vmAddress, + moduleName, scrollComponentId, relatedProposalsCount, - refetchCount, onViewMore, }: ModuleRelatedProposalsTableProps) => { const { @@ -29,6 +27,7 @@ export const ModuleRelatedProposalsTable = ({ pageSize, setPageSize, offset, + setTotalData, } = usePaginator({ total: relatedProposalsCount, initialState: { @@ -42,28 +41,20 @@ export const ModuleRelatedProposalsTable = ({ data: relatedProposals, isLoading, error, - } = useRelatedProposalsByModuleIdPagination( - moduleId, + } = useModuleRelatedProposals( + vmAddress, + moduleName, + onViewMore ? 5 : pageSize, offset, - onViewMore ? 5 : pageSize + { + onSuccess: (data) => setTotalData(data.total), + } ); - const onPageChange = (nextPage: number) => { - refetchCount(); - setCurrentPage(nextPage); - }; - - const onPageSizeChange = (e: ChangeEvent) => { - const size = Number(e.target.value); - refetchCount(); - setPageSize(size); - setCurrentPage(1); - }; - return ( <> { + const size = Number(e.target.value); + setPageSize(size); + setCurrentPage(1); + }} /> ))} diff --git a/src/lib/pages/module-details/components/tables/ModuleTxsTable.tsx b/src/lib/pages/module-details/components/tables/ModuleTxsTable.tsx index 2fcf88aba..717a701c4 100644 --- a/src/lib/pages/module-details/components/tables/ModuleTxsTable.tsx +++ b/src/lib/pages/module-details/components/tables/ModuleTxsTable.tsx @@ -1,4 +1,3 @@ -import type { ChangeEvent } from "react"; import { useEffect } from "react"; import { useCelatoneApp } from "lib/app-provider"; @@ -6,25 +5,23 @@ import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { TransactionsTable, ViewMore } from "lib/components/table"; -import { useTxsByModule } from "lib/services/txService"; +import { useModuleTxs } from "lib/services/move"; import type { HexAddr, Option } from "lib/types"; interface ModuleTxsTableProps { - address: HexAddr; + vmAddress: HexAddr; moduleName: string; txCount: Option; onViewMore?: () => void; scrollComponentId?: string; - refetchCount: () => void; } export const ModuleTxsTable = ({ - address, + vmAddress, moduleName, txCount, onViewMore, scrollComponentId, - refetchCount, }: ModuleTxsTableProps) => { const { currentChainId } = useCelatoneApp(); @@ -35,6 +32,7 @@ export const ModuleTxsTable = ({ pageSize, setPageSize, offset, + setTotalData, } = usePaginator({ total: txCount, initialState: { @@ -48,19 +46,9 @@ export const ModuleTxsTable = ({ data: moduleTxs, isLoading, error, - } = useTxsByModule(address, moduleName, offset, pageSize); - - const onPageChange = (nextPage: number) => { - refetchCount(); - setCurrentPage(nextPage); - }; - - const onPageSizeChange = (e: ChangeEvent) => { - const size = Number(e.target.value); - refetchCount(); - setPageSize(size); - setCurrentPage(1); - }; + } = useModuleTxs(vmAddress, moduleName, pageSize, offset, { + onSuccess: ({ total }) => setTotalData(total), + }); useEffect(() => { if (!onViewMore) setPageSize(10); @@ -96,8 +84,12 @@ export const ModuleTxsTable = ({ offset={offset} totalData={txCount} pageSize={pageSize} - onPageChange={onPageChange} - onPageSizeChange={onPageSizeChange} + onPageChange={setCurrentPage} + onPageSizeChange={(e) => { + const size = Number(e.target.value); + setPageSize(size); + setCurrentPage(1); + }} scrollComponentId={scrollComponentId} /> ))} diff --git a/src/lib/pages/module-details/components/tables/history/PublishedEventsTable.tsx b/src/lib/pages/module-details/components/tables/history/PublishedEventsTable.tsx index 417e59cd8..c692cf168 100644 --- a/src/lib/pages/module-details/components/tables/history/PublishedEventsTable.tsx +++ b/src/lib/pages/module-details/components/tables/history/PublishedEventsTable.tsx @@ -3,7 +3,8 @@ import { TableContainer } from "@chakra-ui/react"; import { useMobile } from "lib/app-provider"; import { Loading } from "lib/components/Loading"; import { MobileTableContainer } from "lib/components/table"; -import type { ModuleHistory, Option } from "lib/types"; +import type { ModuleHistory } from "lib/services/move/module"; +import type { Option } from "lib/types"; import { PublishedEventsTableHeader } from "./PublishedEventsTableHeader"; import { PublishedEventsTableMobileCard } from "./PublishedEventsTableMobileCard"; diff --git a/src/lib/pages/module-details/components/tables/history/PublishedEventsTableMobileCard.tsx b/src/lib/pages/module-details/components/tables/history/PublishedEventsTableMobileCard.tsx index 7db3a33b0..f7594051a 100644 --- a/src/lib/pages/module-details/components/tables/history/PublishedEventsTableMobileCard.tsx +++ b/src/lib/pages/module-details/components/tables/history/PublishedEventsTableMobileCard.tsx @@ -6,7 +6,7 @@ import { MobileLabel, RemarkRender, } from "lib/components/table"; -import type { ModuleHistory } from "lib/types"; +import type { ModuleHistory } from "lib/services/move/module"; import { dateFromNow, formatUTC } from "lib/utils"; import { PolicyChanges } from "./PublishedEventsTableRow"; diff --git a/src/lib/pages/module-details/components/tables/history/PublishedEventsTableRow.tsx b/src/lib/pages/module-details/components/tables/history/PublishedEventsTableRow.tsx index fa1d45a98..b00c487e4 100644 --- a/src/lib/pages/module-details/components/tables/history/PublishedEventsTableRow.tsx +++ b/src/lib/pages/module-details/components/tables/history/PublishedEventsTableRow.tsx @@ -5,7 +5,7 @@ import { capitalize } from "lodash"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; import { RemarkRender, TableRow } from "lib/components/table"; -import type { ModuleHistory } from "lib/types"; +import type { ModuleHistory } from "lib/services/move/module"; import { dateFromNow, formatUTC } from "lib/utils"; interface PublishedEventsTableRowProps { @@ -14,46 +14,42 @@ interface PublishedEventsTableRowProps { } export const PolicyChanges = ({ history }: { history: ModuleHistory }) => { - switch (history.previousPolicy) { - case undefined: - return ( - - Set as{" "} - - {capitalize(history.upgradePolicy)} - + const { upgradePolicy, previousPolicy } = history; + + if (!previousPolicy) + return ( + + Set as{" "} + + {capitalize(history.upgradePolicy)} - ); - case history.upgradePolicy: - return ( - - Remain as{" "} - - {capitalize(history.upgradePolicy)} - + + ); + + if (previousPolicy === upgradePolicy) + return ( + + Remain as{" "} + + {capitalize(history.upgradePolicy)} + + + ); + + return ( + + + Changed from{" "} + + {capitalize(previousPolicy)} - ); - default: - return ( - - - Changed from{" "} - - {capitalize(history.previousPolicy)} - - - - - {capitalize(history.upgradePolicy)} - - - ); - } + + + + {capitalize(history.upgradePolicy)} + + + ); }; export const PublishedEventsTableRow = ({ diff --git a/src/lib/pages/module-details/components/tables/history/index.tsx b/src/lib/pages/module-details/components/tables/history/index.tsx index 55a38e884..5fd8bc15e 100644 --- a/src/lib/pages/module-details/components/tables/history/index.tsx +++ b/src/lib/pages/module-details/components/tables/history/index.tsx @@ -1,4 +1,3 @@ -import type { ChangeEvent } from "react"; import { useEffect } from "react"; import { useCelatoneApp } from "lib/app-provider"; @@ -6,24 +5,24 @@ import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { ViewMore } from "lib/components/table"; -import { useModuleHistoriesByPagination } from "lib/services/move/moduleService"; -import type { Nullish, Option } from "lib/types"; +import { useModuleHistories } from "lib/services/move/moduleService"; +import type { HexAddr, Option } from "lib/types"; import { PublishedEventsTable } from "./PublishedEventsTable"; interface ModuleHistoryTableProps { - moduleId: Nullish; + vmAddress: HexAddr; + moduleName: string; historyCount: Option; scrollComponentId?: string; - refetchCount: () => void; onViewMore?: () => void; } export const ModuleHistoryTable = ({ - moduleId, + vmAddress, + moduleName, historyCount, scrollComponentId, - refetchCount, onViewMore, }: ModuleHistoryTableProps) => { const { currentChainId } = useCelatoneApp(); @@ -35,6 +34,7 @@ export const ModuleHistoryTable = ({ pageSize, setPageSize, offset, + setTotalData, } = usePaginator({ total: historyCount, initialState: { @@ -48,23 +48,15 @@ export const ModuleHistoryTable = ({ data: moduleHistories, isLoading, error, - } = useModuleHistoriesByPagination({ - moduleId, + } = useModuleHistories( + vmAddress, + moduleName, + onViewMore ? 5 : pageSize, offset, - pageSize: onViewMore ? 5 : pageSize, - }); - - const onPageChange = (nextPage: number) => { - refetchCount(); - setCurrentPage(nextPage); - }; - - const onPageSizeChange = (e: ChangeEvent) => { - const size = Number(e.target.value); - refetchCount(); - setPageSize(size); - setCurrentPage(1); - }; + { + onSuccess: ({ total }) => setTotalData(total), + } + ); useEffect(() => { if (!onViewMore) setPageSize(10); @@ -74,10 +66,10 @@ export const ModuleHistoryTable = ({ return ( <> ) : ( { + const size = Number(e.target.value); + setPageSize(size); + setCurrentPage(1); + }} scrollComponentId={scrollComponentId} /> ))} diff --git a/src/lib/pages/module-details/components/tables/index.tsx b/src/lib/pages/module-details/components/tables/index.tsx index 7edf3c5f3..4ec7264eb 100644 --- a/src/lib/pages/module-details/components/tables/index.tsx +++ b/src/lib/pages/module-details/components/tables/index.tsx @@ -11,7 +11,7 @@ import { useCallback } from "react"; import { AmpEvent, track } from "lib/amplitude"; import { useGovConfig } from "lib/app-provider"; import { CustomTab } from "lib/components/CustomTab"; -import type { HexAddr, Nullish, Option } from "lib/types"; +import type { HexAddr, Option } from "lib/types"; import { ModuleHistoryTable } from "./history"; import { ModuleRelatedProposalsTable } from "./ModuleRelatedProposalsTable"; @@ -24,26 +24,22 @@ export enum ModuleTablesTabIndex { } interface ModuleTablesProps { - address: HexAddr; + vmAddress: HexAddr; moduleName: string; - moduleId: Nullish; txsCount: Option; historiesCount: Option; relatedProposalsCount: Option; - refetchCount: () => void; tab: ModuleTablesTabIndex; setTab: (nextTab: ModuleTablesTabIndex) => void; onViewMore?: (nextTab: ModuleTablesTabIndex) => void; } export const ModuleTables = ({ - address, + vmAddress, moduleName, - moduleId, txsCount, historiesCount, relatedProposalsCount, - refetchCount, tab, setTab, onViewMore, @@ -116,19 +112,18 @@ export const ModuleTables = ({ ; -export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { +export const ModuleDetailsBody = ({ + moduleInfo, + moduleTableCounts, +}: ModuleDetailsBodyProps) => { const router = useRouter(); const navigate = useInternalNavigate(); - const { data: moduleId } = useModuleId( - moduleData.moduleName, - moduleData.address - ); - - const { data: moduleDetails, isLoading: moduleDetailsLoading } = - useModuleDetailsQuery(moduleId); + const moduleData = indexModuleResponse(moduleInfo); const { data: verificationData, isLoading: verificationLoading } = useVerifyModule({ - address: moduleData.address, - moduleName: moduleData.moduleName, + address: moduleInfo.address, + moduleName: moduleInfo.moduleName, }); - const { data: moduleTxsCount, refetch: refetchTxsCount } = - useModuleTxsCount(moduleId); - const { data: moduleHistoriesCount, refetch: refetchHistoriesCount } = - useModuleHistoriesCount(moduleId); - const { - data: moduleRelatedProposalsCount, - refetch: refetchRelatedProposalsCount, - } = useRelatedProposalsCountByModuleId(moduleId); - const refetchCount = () => { - refetchTxsCount(); - refetchHistoriesCount(); - refetchRelatedProposalsCount(); - }; - const tab = getFirstQueryParam(router.query.tab) as TabIndex; const [overviewTabIndex, setOverviewTabIndex] = useState( ModuleTablesTabIndex.Transactions @@ -90,8 +74,8 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { navigate({ pathname: "/modules/[address]/[moduleName]/[tab]", query: { - address: moduleData.address, - moduleName: moduleData.moduleName, + address: moduleInfo.address, + moduleName: moduleInfo.moduleName, tab: nextTab, ...(fnType && { type: fnType }), }, @@ -100,7 +84,7 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { }, }); }, - [moduleData.address, moduleData.moduleName, navigate, tab] + [moduleInfo.address, moduleInfo.moduleName, navigate, tab] ); useEffect(() => { @@ -109,8 +93,8 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { replace: true, pathname: "/modules/[address]/[moduleName]/[tab]", query: { - address: moduleData.address, - moduleName: moduleData.moduleName, + address: moduleInfo.address, + moduleName: moduleInfo.moduleName, tab: TabIndex.Overview, }, options: { @@ -122,8 +106,8 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { router.isReady, tab, navigate, - moduleData.address, - moduleData.moduleName, + moduleInfo.address, + moduleInfo.moduleName, ]); useEffect(() => { @@ -135,11 +119,11 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { }, [router.isReady, tab, verificationLoading, verificationData]); useEffect(() => { - if (moduleTxsCount === 0) { + if (moduleTableCounts.txs === 0) { setOverviewTabIndex(ModuleTablesTabIndex.PublishedEvents); setTableTabIndex(ModuleTablesTabIndex.PublishedEvents); } - }, [moduleTxsCount]); + }, [moduleTableCounts.txs]); return ( <> @@ -187,9 +171,9 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { viewFns={moduleData.viewFunctions.length} executeFns={moduleData.executeFunctions.length} allTxsCount={ - !isUndefined(moduleTxsCount) && - !isUndefined(moduleHistoriesCount) - ? moduleTxsCount + moduleHistoriesCount + !isNull(moduleTableCounts.txs) && + !isNull(moduleTableCounts.histories) + ? moduleTableCounts.txs + moduleTableCounts.histories : undefined } onSelectAction={( @@ -203,19 +187,21 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { }} /> { @@ -232,8 +218,8 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { { @@ -278,22 +262,28 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => { export const ModuleDetails = () => { const router = useRouter(); - const addr = getFirstQueryParam(router.query.address); const moduleName = getFirstQueryParam(router.query.moduleName); - const { data, isLoading } = useAccountModules({ - address: addr as Addr, - moduleName, - }); + const { data: moduleInfo, isLoading: isModuleInfoLoading } = useModuleInfo( + addr as HexAddr, + moduleName + ); + const { data: moduleTableCounts, isLoading: isMoudleTableCountsLoading } = + useModuleTableCounts(moduleName, addr as HexAddr); + + if (!router.isReady || isModuleInfoLoading || isMoudleTableCountsLoading) + return ; - if (!router.isReady || isLoading) return ; return ( - {data === undefined ? ( + {!moduleInfo || !moduleTableCounts ? ( ) : ( - + )} ); diff --git a/src/lib/query/index.ts b/src/lib/query/index.ts index 3ebf1ccb9..df43855ee 100644 --- a/src/lib/query/index.ts +++ b/src/lib/query/index.ts @@ -2,9 +2,7 @@ export * from "./block"; export * from "./code"; export * from "./contract"; export * from "./pool"; -export * from "./proposal"; export * from "./tx"; export * from "./account"; -export * from "./module"; export * from "./collection"; export * from "./nft"; diff --git a/src/lib/query/module.ts b/src/lib/query/module.ts deleted file mode 100644 index 496adb678..000000000 --- a/src/lib/query/module.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { graphql } from "lib/gql"; - -export const getModuleIdByNameAndVmAddressQueryDocument = graphql(` - query getModuleIdByNameAndVmAddressQuery( - $name: String! - $vmAddress: String! - ) { - modules( - where: { - name: { _eq: $name } - vm_address: { vm_address: { _eq: $vmAddress } } - } - ) { - id - } - } -`); - -export const getModuleHistoriesQueryDocument = graphql(` - query getModuleHistoriesQuery( - $moduleId: Int! - $pageSize: Int! - $offset: Int! - ) { - module_histories( - where: { module_id: { _eq: $moduleId } } - limit: $pageSize - offset: $offset - order_by: { block: { height: desc } } - ) { - remark - block { - height - timestamp - } - upgrade_policy - } - } -`); - -export const getModuleHistoriesCountQueryDocument = graphql(` - query getModuleHistoriesCountQuery($moduleId: Int!) { - module_histories_aggregate(where: { module_id: { _eq: $moduleId } }) { - aggregate { - count - } - } - } -`); - -export const getModuleInitialPublishInfoQueryDocument = graphql(` - query getModuleInitialPublishInfoQuery($moduleId: Int!, $isGov: Boolean!) { - modules(where: { id: { _eq: $moduleId } }) { - publisher_vm_address: vm_address { - vm_address - } - publish_transaction: transaction { - hash - } - module_proposals( - where: { - proposal: { type: { _in: ["/initia.move.v1.MsgGovPublish"] } } - } - order_by: { proposal_id: asc } - limit: 1 - ) @include(if: $isGov) { - proposal { - id - title - } - } - module_histories(order_by: { block: { timestamp: asc } }, limit: 1) { - block { - height - timestamp - } - } - } - } -`); diff --git a/src/lib/query/proposal.ts b/src/lib/query/proposal.ts deleted file mode 100644 index a2cf50601..000000000 --- a/src/lib/query/proposal.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { graphql } from "lib/gql"; - -export const getRelatedProposalsByModuleIdPagination = graphql(` - query getRelatedProposalsByModuleIdPagination( - $moduleId: Int! - $offset: Int! - $pageSize: Int! - ) { - module_proposals( - where: { module_id: { _eq: $moduleId } } - order_by: { proposal_id: desc } - offset: $offset - limit: $pageSize - ) { - proposal { - title - status - voting_end_time - deposit_end_time - type - account { - address - } - is_expedited - resolved_height - } - proposal_id - } - } -`); - -export const getRelatedProposalsCountByModuleId = graphql(` - query getRelatedProposalsCountByModuleId($moduleId: Int!) { - module_proposals_aggregate(where: { module_id: { _eq: $moduleId } }) { - aggregate { - count - } - } - } -`); diff --git a/src/lib/query/tx.ts b/src/lib/query/tx.ts index a8c837e0f..ee5342981 100644 --- a/src/lib/query/tx.ts +++ b/src/lib/query/tx.ts @@ -96,13 +96,3 @@ export const getBlockTransactionCountByHeightQueryDocument = graphql(` } } `); - -export const getModuleTransactionsCountQueryDocument = graphql(` - query getModuleTransactionsCountQuery($moduleId: Int!) { - module_transactions_aggregate(where: { module_id: { _eq: $moduleId } }) { - aggregate { - count - } - } - } -`); diff --git a/src/lib/services/move/module.ts b/src/lib/services/move/module.ts index 961d8ce6f..74a6d7de1 100644 --- a/src/lib/services/move/module.ts +++ b/src/lib/services/move/module.ts @@ -1,6 +1,8 @@ import axios from "axios"; import { z } from "zod"; +import { zProposal, zProposalsResponseItem } from "../proposal"; +import { zTxsResponseItem } from "../tx"; import type { AbiFormData, Addr, @@ -14,10 +16,17 @@ import type { ResponseModules, SnakeToCamelCaseNested, } from "lib/types"; -import { UpgradePolicy, zBechAddr, zHexAddr, zUtcDate } from "lib/types"; +import { + UpgradePolicy, + zBechAddr, + zHexAddr, + zRemark, + zUtcDate, +} from "lib/types"; import { libDecode, parseJsonABI, + parseTxHashOpt, parseWithError, serializeAbiData, snakeToCamel, @@ -191,3 +200,147 @@ export const getModules = async ( }, }) .then(({ data }) => parseWithError(zModulesResponse, data)); + +const zModuleInfoResponse = z + .object({ + abi: z.string(), + address: zHexAddr, + module_name: z.string(), + raw_bytes: z.string(), + upgrade_policy: z.nativeEnum(UpgradePolicy), + recent_publish_transaction: z.string().nullable(), + recent_publish_proposal: zProposal + .pick({ id: true, title: true }) + .nullable(), + is_republished: z.boolean(), + recent_publish_block_height: z.number().nonnegative(), + recent_publish_block_timestamp: zUtcDate, + }) + .transform((val) => ({ + ...snakeToCamel(val), + recentPublishTransaction: parseTxHashOpt( + val.recent_publish_transaction ?? undefined + ), + })); +export type ModuleInfoResponse = z.infer; + +export const getModuleInfo = async ( + endpoint: string, + vmAddress: HexAddr, + moduleName: string +): Promise => + axios + .get( + `${endpoint}/${encodeURIComponent(vmAddress)}/${encodeURIComponent(moduleName)}/info` + ) + .then(({ data }) => parseWithError(zModuleInfoResponse, data)); + +const zModuleTableCountsResponse = z.object({ + txs: z.number().nonnegative().nullable(), + histories: z.number().nonnegative().nullable(), + proposals: z.number().nonnegative().nullable(), +}); +export type ModuleTableCountsResponse = z.infer< + typeof zModuleTableCountsResponse +>; + +export const getModuleTableCounts = async ( + endpoint: string, + vmAddress: HexAddr, + moduleName: string +): Promise => + axios + .get( + `${endpoint}/${encodeURIComponent(vmAddress)}/${encodeURIComponent(moduleName)}/table-counts` + ) + .then(({ data }) => parseWithError(zModuleTableCountsResponse, data)); + +const zModuleTxsResponse = z.object({ + items: z.array(zTxsResponseItem), + total: z.number().nonnegative(), +}); +export type ModuleTxsResponse = z.infer; + +export const getModuleTxs = async ( + endpoint: string, + vmAddress: HexAddr, + moduleName: string, + limit: number, + offset: number, + isInitia: boolean +) => + axios + .get( + `${endpoint}/modules/${encodeURIComponent(vmAddress)}/${encodeURIComponent(moduleName)}/txs`, + { + params: { + limit, + offset, + is_initia: isInitia, + }, + } + ) + .then(({ data }) => parseWithError(zModuleTxsResponse, data)); + +const zModuleHistory = z + .object({ + remark: zRemark, + upgrade_policy: z.nativeEnum(UpgradePolicy), + height: z.number().nonnegative(), + timestamp: zUtcDate, + previous_policy: z.nativeEnum(UpgradePolicy).nullable(), + }) + .transform(snakeToCamel); +export type ModuleHistory = z.infer; + +const zModuleHistoriesResponse = z.object({ + items: z.array(zModuleHistory), + total: z.number().nonnegative(), +}); +export type ModuleHistoriesResponse = z.infer; + +export const getModuleHistories = async ( + endpoint: string, + vmAddress: HexAddr, + moduleName: string, + limit: number, + offset: number +) => + axios + .get( + `${endpoint}/modules/${encodeURIComponent(vmAddress)}/${encodeURIComponent(moduleName)}/histories`, + { + params: { + limit, + offset, + }, + } + ) + .then(({ data }) => parseWithError(zModuleHistoriesResponse, data)); + +const zModuleRelatedProposalsResponse = z.object({ + items: z.array(zProposalsResponseItem), + total: z.number().nonnegative(), +}); +export type ModuleRelatedProposalsResponse = z.infer< + typeof zModuleRelatedProposalsResponse +>; + +export const getModuleRelatedProposals = async ( + endpoint: string, + vmAddress: HexAddr, + moduleName: string, + limit: number, + offset: number +) => + axios + .get( + `${endpoint}/modules/${encodeURIComponent(vmAddress)}/${encodeURIComponent(moduleName)}/related-proposals`, + { + params: { + limit, + offset, + }, + } + ) + .then(({ data }) => parseWithError(zModuleRelatedProposalsResponse, data)); diff --git a/src/lib/services/move/moduleService.ts b/src/lib/services/move/moduleService.ts index 3ae63d723..eaea06de3 100644 --- a/src/lib/services/move/moduleService.ts +++ b/src/lib/services/move/moduleService.ts @@ -9,47 +9,45 @@ import type { AxiosError } from "axios"; import { CELATONE_QUERY_KEYS, useBaseApiRoute, - useCelatoneApp, - useGovConfig, + useInitia, useMoveConfig, } from "lib/app-provider"; -import { - getModuleHistoriesCountQueryDocument, - getModuleHistoriesQueryDocument, - getModuleIdByNameAndVmAddressQueryDocument, - getModuleInitialPublishInfoQueryDocument, -} from "lib/query"; import type { AbiFormData, Addr, ExposedFunction, HexAddr, InternalModule, - ModuleHistory, Nullable, Option, ResponseABI, RpcQueryError, UpgradePolicy, } from "lib/types"; -import { - parseDate, - parseDateOpt, - parseJsonABI, - parseTxHashOpt, - splitViewExecuteFunctions, - truncate, -} from "lib/utils"; +import { parseJsonABI, splitViewExecuteFunctions, truncate } from "lib/utils"; -import type { ModulesResponse, ModuleVerificationInternal } from "./module"; +import type { + ModuleHistoriesResponse, + ModuleInfoResponse, + ModuleRelatedProposalsResponse, + ModulesResponse, + ModuleTableCountsResponse, + ModuleTxsResponse, + ModuleVerificationInternal, +} from "./module"; import { decodeModule, decodeScript, getAccountModule, getAccountModules, getFunctionView, + getModuleHistories, + getModuleInfo, + getModuleRelatedProposals, getModules, getModulesByAddress, + getModuleTableCounts, + getModuleTxs, getModuleVerificationStatus, } from "./module"; @@ -61,7 +59,7 @@ export interface IndexedModule extends InternalModule { searchedFn: Option; } -const indexModuleResponse = ( +export const indexModuleResponse = ( module: InternalModule, functionName?: string ): IndexedModule => { @@ -242,106 +240,6 @@ export const useDecodeModule = ({ ); }; -export const useModuleId = (moduleName: string, vmAddress: HexAddr) => { - const { indexerGraphClient } = useCelatoneApp(); - const queryFn = async () => { - return indexerGraphClient - .request(getModuleIdByNameAndVmAddressQueryDocument, { - name: moduleName, - vmAddress, - }) - .then>(({ modules }) => modules[0]?.id ?? null); - }; - - return useQuery( - [CELATONE_QUERY_KEYS.MODULE_ID, indexerGraphClient, moduleName, vmAddress], - queryFn, - { - enabled: Boolean(moduleName && vmAddress), - retry: 1, - refetchOnWindowFocus: false, - } - ); -}; - -export const useModuleHistoriesByPagination = ({ - moduleId, - offset, - pageSize, -}: { - moduleId: Option>; - offset: number; - pageSize: number; -}): UseQueryResult => { - const { indexerGraphClient } = useCelatoneApp(); - - const queryFn = async () => { - if (!moduleId) return []; - return indexerGraphClient - .request(getModuleHistoriesQueryDocument, { - moduleId, - pageSize: pageSize + 1, - offset, - }) - .then(({ module_histories }) => - module_histories - .map((history, idx) => ({ - remark: history.remark, - upgradePolicy: history.upgrade_policy, - height: history.block.height, - timestamp: parseDate(history.block.timestamp), - previousPolicy: - idx === module_histories.length - 1 - ? undefined - : module_histories[idx + 1].upgrade_policy, - })) - .slice(0, pageSize) - ); - }; - - return useQuery( - [ - CELATONE_QUERY_KEYS.MODULE_HISTORIES, - indexerGraphClient, - moduleId, - pageSize, - offset, - ], - queryFn, - { - enabled: Boolean(moduleId), - retry: 1, - refetchOnWindowFocus: false, - } - ); -}; - -export const useModuleHistoriesCount = (moduleId: Option>) => { - const { indexerGraphClient } = useCelatoneApp(); - - const queryFn = async () => { - if (!moduleId) throw new Error("Module id not found"); - return indexerGraphClient - .request(getModuleHistoriesCountQueryDocument, { - moduleId, - }) - .then( - ({ module_histories_aggregate }) => - module_histories_aggregate.aggregate?.count - ); - }; - - return useQuery( - [CELATONE_QUERY_KEYS.MODULE_HISTORIES_COUNT, indexerGraphClient, moduleId], - queryFn, - { - enabled: Boolean(moduleId), - retry: 1, - refetchOnWindowFocus: false, - } - ); -}; - export interface ModuleInitialPublishInfo { publisherVmAddress: HexAddr; createdHeight: Option; @@ -351,42 +249,6 @@ export interface ModuleInitialPublishInfo { initProposalTitle: Option; } -export const useModuleDetailsQuery = ( - moduleId: Option> -): UseQueryResult => { - const { indexerGraphClient } = useCelatoneApp(); - const { enabled: isGov } = useGovConfig({ shouldRedirect: false }); - - const queryFn = async () => { - if (!moduleId) throw new Error("Module id not found"); - return indexerGraphClient - .request(getModuleInitialPublishInfoQueryDocument, { moduleId, isGov }) - .then(({ modules }) => { - const target = modules[0]; - if (!target) throw new Error(`Cannot find module with id ${moduleId}`); - return { - publisherVmAddress: target.publisher_vm_address.vm_address as HexAddr, - createdHeight: target.module_histories?.[0]?.block.height, - createdTime: parseDateOpt( - target.module_histories?.[0]?.block.timestamp - ), - initTxHash: parseTxHashOpt(target.publish_transaction?.hash), - initProposalId: target.module_proposals?.[0]?.proposal.id, - initProposalTitle: target.module_proposals?.[0]?.proposal.title, - }; - }); - }; - - return useQuery( - [CELATONE_QUERY_KEYS.MODULE_DETAILS, indexerGraphClient, moduleId], - queryFn, - { - enabled: Boolean(moduleId), - refetchOnWindowFocus: false, - } - ); -}; - export const useDecodeScript = ({ base64EncodedFile, options, @@ -430,3 +292,109 @@ export const useModules = ( { ...options, retry: 1, refetchOnWindowFocus: false } ); }; + +export const useModuleInfo = (vmAddress: HexAddr, moduleName: string) => { + const endpoint = useBaseApiRoute("modules"); + + return useQuery( + [CELATONE_QUERY_KEYS.MODULE_INFO, endpoint, vmAddress, moduleName], + async () => getModuleInfo(endpoint, vmAddress, moduleName), + { + retry: 1, + refetchOnWindowFocus: false, + } + ); +}; + +export const useModuleTableCounts = ( + moduleName: string, + vmAddress: HexAddr +) => { + const endpoint = useBaseApiRoute("modules"); + + return useQuery( + [CELATONE_QUERY_KEYS.MODULE_TABLE_COUNTS, endpoint, vmAddress, moduleName], + async () => getModuleTableCounts(endpoint, vmAddress, moduleName), + { + retry: 1, + refetchOnWindowFocus: false, + } + ); +}; + +export const useModuleTxs = ( + vmAddress: HexAddr, + moduleName: string, + limit: number, + offset: number, + options: Pick, "onSuccess"> = {} +) => { + const endpoint = useBaseApiRoute("move"); + const isInitia = useInitia(); + + return useQuery( + [ + CELATONE_QUERY_KEYS.MODULE_TXS, + endpoint, + vmAddress, + moduleName, + limit, + offset, + isInitia, + ], + async () => + getModuleTxs(endpoint, vmAddress, moduleName, limit, offset, isInitia), + { retry: 1, refetchOnWindowFocus: false, ...options } + ); +}; + +export const useModuleHistories = ( + vmAddress: HexAddr, + moduleName: string, + limit: number, + offset: number, + options: Pick, "onSuccess"> = {} +): UseQueryResult => { + const endpoint = useBaseApiRoute("move"); + + return useQuery( + [ + CELATONE_QUERY_KEYS.MODULE_HISTORIES, + endpoint, + vmAddress, + moduleName, + limit, + offset, + ], + async () => + getModuleHistories(endpoint, vmAddress, moduleName, limit, offset), + { retry: 1, refetchOnWindowFocus: false, ...options } + ); +}; + +export const useModuleRelatedProposals = ( + vmAddress: HexAddr, + moduleName: string, + limit: number, + offset: number, + options: Pick< + UseQueryOptions, + "onSuccess" + > = {} +): UseQueryResult => { + const endpoint = useBaseApiRoute("move"); + + return useQuery( + [ + CELATONE_QUERY_KEYS.MODULE_PROPOSALS, + endpoint, + vmAddress, + moduleName, + limit, + offset, + ], + async () => + getModuleRelatedProposals(endpoint, vmAddress, moduleName, limit, offset), + { retry: 1, refetchOnWindowFocus: false, ...options } + ); +}; diff --git a/src/lib/services/proposal.ts b/src/lib/services/proposal.ts index 5824b1cd8..e8fc1f15d 100644 --- a/src/lib/services/proposal.ts +++ b/src/lib/services/proposal.ts @@ -126,7 +126,8 @@ export const zProposal = z.object({ voting_end_time: zUtcDate.nullable(), }); -const zProposalsResponseItem = zProposal.transform(snakeToCamel); +export const zProposalsResponseItem = + zProposal.transform(snakeToCamel); const zProposalsResponse = z.object({ items: z.array(zProposalsResponseItem), diff --git a/src/lib/services/proposalService.ts b/src/lib/services/proposalService.ts index a15ae8691..fa827facb 100644 --- a/src/lib/services/proposalService.ts +++ b/src/lib/services/proposalService.ts @@ -4,24 +4,13 @@ import { useQuery } from "@tanstack/react-query"; import type Big from "big.js"; import { useCallback } from "react"; -import { - CELATONE_QUERY_KEYS, - useBaseApiRoute, - useCelatoneApp, -} from "lib/app-provider"; -import { - getRelatedProposalsByModuleIdPagination, - getRelatedProposalsCountByModuleId, -} from "lib/query"; -import { createQueryFnWithTimeout } from "lib/query-utils"; +import { CELATONE_QUERY_KEYS, useBaseApiRoute } from "lib/app-provider"; import { big } from "lib/types"; import type { BechAddr, BechAddr20, BechAddr32, - Nullish, Option, - Proposal, ProposalParams, ProposalStatus, ProposalType, @@ -35,7 +24,6 @@ import { deexponentify, formatTokenWithValue, getTokenLabel, - parseDate, } from "lib/utils"; import { useAssetInfos } from "./assetService"; @@ -170,81 +158,6 @@ export const useRelatedProposalsByContractAddress = ( ); }; -export const useRelatedProposalsByModuleIdPagination = ( - moduleId: Nullish, - offset: number, - pageSize: number -): UseQueryResult => { - const { indexerGraphClient } = useCelatoneApp(); - const queryFn = useCallback(async () => { - if (!moduleId) throw new Error("Module id not found"); - return indexerGraphClient - .request(getRelatedProposalsByModuleIdPagination, { - moduleId, - offset, - pageSize, - }) - .then(({ module_proposals }) => - module_proposals.map((proposal) => ({ - id: proposal.proposal_id, - title: proposal.proposal.title, - status: proposal.proposal.status as ProposalStatus, - votingEndTime: parseDate(proposal.proposal.voting_end_time), - depositEndTime: parseDate(proposal.proposal.deposit_end_time), - resolvedHeight: proposal.proposal.resolved_height ?? null, - // TODO: fix - types: [proposal.proposal.type as ProposalType], - proposer: proposal.proposal.account?.address as BechAddr, - isExpedited: Boolean(proposal.proposal.is_expedited), - })) - ); - }, [indexerGraphClient, moduleId, offset, pageSize]); - - return useQuery( - [ - CELATONE_QUERY_KEYS.PROPOSALS_BY_MODULE_ID, - moduleId, - indexerGraphClient, - offset, - pageSize, - ], - queryFn, - { - retry: 1, - refetchOnWindowFocus: false, - } - ); -}; - -export const useRelatedProposalsCountByModuleId = ( - moduleId: Nullish -): UseQueryResult> => { - const { indexerGraphClient } = useCelatoneApp(); - const queryFn = useCallback(async () => { - if (!moduleId) throw new Error("Module id not found"); - return indexerGraphClient - .request(getRelatedProposalsCountByModuleId, { - moduleId, - }) - .then( - ({ module_proposals_aggregate }) => - module_proposals_aggregate?.aggregate?.count - ); - }, [indexerGraphClient, moduleId]); - - return useQuery( - [ - CELATONE_QUERY_KEYS.PROPOSALS_COUNT_BY_MODULE_ID, - moduleId, - indexerGraphClient, - ], - createQueryFnWithTimeout(queryFn), - { - keepPreviousData: true, - } - ); -}; - export interface MinDeposit { amount: U>; denom: string; diff --git a/src/lib/services/tx.ts b/src/lib/services/tx.ts index fbc84599c..e2edcafcd 100644 --- a/src/lib/services/tx.ts +++ b/src/lib/services/tx.ts @@ -6,14 +6,7 @@ import type { Any } from "cosmjs-types/google/protobuf/any"; import { z } from "zod"; import type { TypeUrl } from "lib/data"; -import type { - BechAddr, - Fee, - HexAddr, - Option, - Transaction, - TxFilters, -} from "lib/types"; +import type { BechAddr, Fee, Option, Transaction, TxFilters } from "lib/types"; import { MsgFurtherAction, zBechAddr, zUtcDate } from "lib/types"; import { camelToSnake, @@ -132,29 +125,31 @@ const zBaseTxsResponseItem = z.object({ is_move_upgrade: z.boolean().optional(), }); -const zTxsResponseItem = zBaseTxsResponseItem.transform((val) => ({ - hash: parseTxHash(val.hash), - messages: snakeToCamel(val.messages), - sender: val.sender, - isSigner: false, - height: val.height, - created: val.created, - success: val.success, - actionMsgType: getActionMsgType([ - val.is_send, - val.is_execute, - val.is_instantiate, - val.is_store_code, - val.is_migrate, - val.is_update_admin, - val.is_clear_admin, - // TODO: implement Move msg type - ]), - furtherAction: MsgFurtherAction.NONE, - isIbc: val.is_ibc, - isOpinit: val.is_opinit ?? false, - isInstantiate: val.is_instantiate ?? false, -})); +export const zTxsResponseItem = zBaseTxsResponseItem.transform( + (val) => ({ + hash: parseTxHash(val.hash), + messages: snakeToCamel(val.messages), + sender: val.sender, + isSigner: false, + height: val.height, + created: val.created, + success: val.success, + actionMsgType: getActionMsgType([ + val.is_send, + val.is_execute, + val.is_instantiate, + val.is_store_code, + val.is_migrate, + val.is_update_admin, + val.is_clear_admin, + // TODO: implement Move msg type + ]), + furtherAction: MsgFurtherAction.NONE, + isIbc: val.is_ibc, + isOpinit: val.is_opinit ?? false, + isInstantiate: val.is_instantiate ?? false, + }) +); const zTxsResponse = z.object({ items: z.array(zTxsResponseItem), @@ -290,36 +285,6 @@ export const getTxsByBlockHeight = async ( }) .then(({ data }) => parseWithError(zBlockTxsResponse, data)); -const zModuleTxsResponse = z.object({ - items: z.array(zTxsResponseItem), -}); -export type ModuleTxsResponse = z.infer; - -export const getTxsByModule = async ( - endpoint: string, - address: HexAddr, - moduleName: string, - limit: number, - offset: number, - isWasm: boolean, - isMove: boolean, - isInitia: boolean -) => - axios - .get( - `${endpoint}/modules/${encodeURIComponent(address)}/${moduleName}/txs`, - { - params: { - limit, - offset, - is_wasm: isWasm, - is_move: isMove, - is_initia: isInitia, - }, - } - ) - .then(({ data }) => parseWithError(zModuleTxsResponse, data)); - const zTxsCountResponse = z .object({ count: z.number().nullish(), diff --git a/src/lib/services/txService.ts b/src/lib/services/txService.ts index e9c379264..0ade446e0 100644 --- a/src/lib/services/txService.ts +++ b/src/lib/services/txService.ts @@ -14,17 +14,11 @@ import { useMoveConfig, useWasmConfig, } from "lib/app-provider"; -import { - getModuleTransactionsCountQueryDocument, - getTxsByPoolIdPagination, - getTxsCountByPoolId, -} from "lib/query"; +import { getTxsByPoolIdPagination, getTxsCountByPoolId } from "lib/query"; import { createQueryFnWithTimeout } from "lib/query-utils"; import type { BechAddr, - HexAddr, Message, - Nullable, Option, PoolTxFilter, Transaction, @@ -43,7 +37,6 @@ import { usePoolTxExpression } from "./expression"; import type { AccountTxsResponse, BlockTxsResponse, - ModuleTxsResponse, TxResponse, TxsResponse, } from "./tx"; @@ -51,7 +44,6 @@ import { getTxs, getTxsByAddress, getTxsByBlockHeight, - getTxsByModule, getTxsCountByAddress, queryTxData, } from "./tx"; @@ -318,66 +310,3 @@ export const useTxsByBlockHeight = ( } ); }; - -export const useModuleTxsCount = (moduleId: Option>) => { - const { indexerGraphClient } = useCelatoneApp(); - - const queryFn = async () => { - if (!moduleId) throw new Error("Module id not found"); - return indexerGraphClient - .request(getModuleTransactionsCountQueryDocument, { - moduleId, - }) - .then( - ({ module_transactions_aggregate }) => - module_transactions_aggregate.aggregate?.count - ); - }; - - return useQuery( - [CELATONE_QUERY_KEYS.MODULE_TXS_COUNT, indexerGraphClient, moduleId], - queryFn, - { - enabled: Boolean(moduleId), - retry: 1, - refetchOnWindowFocus: false, - } - ); -}; - -export const useTxsByModule = ( - address: HexAddr, - moduleName: string, - offset: number, - limit: number -) => { - const endpoint = useBaseApiRoute("move"); - const { enabled: isWasm } = useWasmConfig({ shouldRedirect: false }); - const { enabled: isMove } = useMoveConfig({ shouldRedirect: false }); - const isInitia = useInitia(); - - return useQuery( - [ - CELATONE_QUERY_KEYS.MODULE_TXS, - endpoint, - address, - moduleName, - limit, - offset, - isWasm, - isMove, - ], - async () => - getTxsByModule( - endpoint, - address, - moduleName, - limit, - offset, - isWasm, - isMove, - isInitia - ), - { retry: 1, refetchOnWindowFocus: false } - ); -}; diff --git a/src/lib/types/move/module.ts b/src/lib/types/move/module.ts index 059d4c854..ab21a4184 100644 --- a/src/lib/types/move/module.ts +++ b/src/lib/types/move/module.ts @@ -1,12 +1,4 @@ -import type { BechAddr, Option, Remark, UpgradePolicy } from "lib/types"; - -export interface ModuleHistory { - remark: Remark; - upgradePolicy: UpgradePolicy; - height: number; - timestamp: Date; - previousPolicy: Option; -} +import type { BechAddr } from "lib/types"; export interface ModuleInfo { // NOTE: can also be an ica or a contract