From 22e1dce1d0bc41c6b63948738ab74d0d2a1dfa6b Mon Sep 17 00:00:00 2001 From: John Williams Date: Tue, 1 Oct 2024 12:02:01 -0400 Subject: [PATCH] feat(explored): add contractRevisions APIs --- .changeset/curly-queens-work.md | 7 +++++++ libs/explored-js/src/api.ts | 9 +++++++++ libs/explored-react/src/hooks.ts | 12 ++++++++++++ libs/explored-types/src/api.ts | 6 ++++++ 4 files changed, 34 insertions(+) create mode 100644 .changeset/curly-queens-work.md diff --git a/.changeset/curly-queens-work.md b/.changeset/curly-queens-work.md new file mode 100644 index 000000000..98575441a --- /dev/null +++ b/.changeset/curly-queens-work.md @@ -0,0 +1,7 @@ +--- +'@siafoundation/explored-js': minor +'@siafoundation/explored-react': minor +'@siafoundation/explored-types': minor +--- + +Added contractionRevisions API. diff --git a/libs/explored-js/src/api.ts b/libs/explored-js/src/api.ts index e052fb2d5..098c53f41 100644 --- a/libs/explored-js/src/api.ts +++ b/libs/explored-js/src/api.ts @@ -24,6 +24,10 @@ import { ConsensusNetworkParams, ConsensusNetworkPayload, ConsensusNetworkResponse, + ContractRevisionsParams, + ContractRevisionsPayload, + ContractRevisionsResponse, + contractRevisionsRoute, consensusStateRoute, ConsensusStateParams, ConsensusStatePayload, @@ -239,6 +243,11 @@ export function Explored({ ContractByPubkeyPayload, ContractByPubkeyResponse >(axios, 'get', contractByPubkeyRoute), + contractRevisions: buildRequestHandler< + ContractRevisionsParams, + ContractRevisionsPayload, + ContractRevisionsResponse + >(axios, 'get', contractRevisionsRoute), // Metrics metrics: buildRequestHandler< MetricsParams, diff --git a/libs/explored-react/src/hooks.ts b/libs/explored-react/src/hooks.ts index 47e0a01fb..d23bc488a 100644 --- a/libs/explored-react/src/hooks.ts +++ b/libs/explored-react/src/hooks.ts @@ -23,6 +23,9 @@ import { ContractByPubkeyParams, ContractByPubkeyResponse, contractByPubkeyRoute, + ContractRevisionsParams, + ContractRevisionsResponse, + contractRevisionsRoute, ContractsByIDsParams, ContractsByIDsPayload, ContractsByIDsResponse, @@ -310,6 +313,15 @@ export function useContractByPubkey( }) } +export function useContractRevisions( + args: HookArgsSwr +) { + return useGetSwr({ + ...args, + route: contractRevisionsRoute, + }) +} + // Metrics export function useMetrics(args: HookArgsSwr) { diff --git a/libs/explored-types/src/api.ts b/libs/explored-types/src/api.ts index 1dd0ffc40..992bea390 100644 --- a/libs/explored-types/src/api.ts +++ b/libs/explored-types/src/api.ts @@ -194,6 +194,12 @@ export type ContractByPubkeyParams = { key: number } export type ContractByPubkeyPayload = void export type ContractByPubkeyResponse = ExplorerFileContract +// Returns all the revisions of the contract with the specified ID. +export const contractRevisionsRoute = '/contracts/:id/revisions' +export type ContractRevisionsParams = { id: FileContractID } +export type ContractRevisionsPayload = void +export type ContractRevisionsResponse = ExplorerFileContract[] + // Metrics // Returns the most recent metrics about Sia.