diff --git a/carbonmark/.generated/carbonmark-api-sdk/clients/getActivities.ts b/carbonmark/.generated/carbonmark-api-sdk/clients/getActivities.ts new file mode 100644 index 0000000000..ae0d01f78e --- /dev/null +++ b/carbonmark/.generated/carbonmark-api-sdk/clients/getActivities.ts @@ -0,0 +1,25 @@ +import type { ResponseConfig } from "../client"; +import client from "../client"; +import type { + GetActivitiesQueryParams, + GetActivitiesQueryResponse, +} from "../types/GetActivities"; + +/** + * @description Retrieve an array of activities related to a carbon project + * @summary List project activities + * @link /activities + */ +export async function getActivities( + params?: GetActivitiesQueryParams, + options: Partial[0]> = {} +): Promise["data"]> { + const { data: resData } = await client({ + method: "get", + url: `/activities`, + params, + ...options, + }); + + return resData; +} diff --git a/carbonmark/.generated/carbonmark-api-sdk/clients/getProjectsIdActivity.ts b/carbonmark/.generated/carbonmark-api-sdk/clients/getProjectsIdActivity.ts new file mode 100644 index 0000000000..49779222e3 --- /dev/null +++ b/carbonmark/.generated/carbonmark-api-sdk/clients/getProjectsIdActivity.ts @@ -0,0 +1,29 @@ +import type { ResponseConfig } from "../client"; +import client from "../client"; +import type { + GetProjectsIdActivityPathParams, + GetProjectsIdActivityQueryParams, + GetProjectsIdActivityQueryResponse, +} from "../types/GetProjectsIdActivity"; + +/** + * @description Retrieve an array of activities related to a carbon project + * @summary List project activities + * @link /projects/:id/activity + */ +export async function getProjectsIdActivity< + TData = GetProjectsIdActivityQueryResponse, +>( + id: GetProjectsIdActivityPathParams["id"], + params?: GetProjectsIdActivityQueryParams, + options: Partial[0]> = {} +): Promise["data"]> { + const { data: resData } = await client({ + method: "get", + url: `/projects/${id}/activity`, + params, + ...options, + }); + + return resData; +} diff --git a/carbonmark/.generated/carbonmark-api-sdk/clients/index.ts b/carbonmark/.generated/carbonmark-api-sdk/clients/index.ts index f13f6a0f62..cd274caa22 100644 --- a/carbonmark/.generated/carbonmark-api-sdk/clients/index.ts +++ b/carbonmark/.generated/carbonmark-api-sdk/clients/index.ts @@ -1,7 +1,9 @@ +export * from "./getActivities"; export * from "./getCategories"; export * from "./getCountries"; export * from "./getProjects"; export * from "./getProjectsId"; +export * from "./getProjectsIdActivity"; export * from "./getPurchasesId"; export * from "./getUsersWalletorhandle"; export * from "./getVintages"; diff --git a/carbonmark/.generated/carbonmark-api-sdk/clients/operations.ts b/carbonmark/.generated/carbonmark-api-sdk/clients/operations.ts index 0f75e06c81..fc88781b79 100644 --- a/carbonmark/.generated/carbonmark-api-sdk/clients/operations.ts +++ b/carbonmark/.generated/carbonmark-api-sdk/clients/operations.ts @@ -1,7 +1,8 @@ export const operations = { + get_activities: { path: "/activities", method: "get" }, get_categories: { path: "/categories", method: "get" }, - get_projects: { path: "/projects", method: "get" }, get_countries: { path: "/countries", method: "get" }, + get_projects: { path: "/projects", method: "get" }, "get_users-walletorhandle": { path: "/users/:walletOrHandle", method: "get" }, post_users: { path: "/users", method: "post" }, "put_users-wallet": { path: "/users/:wallet", method: "put" }, @@ -9,5 +10,6 @@ export const operations = { "get_projects-id": { path: "/projects/:id", method: "get" }, "get_purchases-id": { path: "/purchases/:id", method: "get" }, "post_users-login": { path: "/users/login", method: "post" }, + "get_projects-id-activity": { path: "/projects/:id/activity", method: "get" }, "post_users-login-verify": { path: "/users/login/verify", method: "post" }, } as const; diff --git a/carbonmark/.generated/carbonmark-api-sdk/hooks/index.ts b/carbonmark/.generated/carbonmark-api-sdk/hooks/index.ts index 4952884e23..19ef548493 100644 --- a/carbonmark/.generated/carbonmark-api-sdk/hooks/index.ts +++ b/carbonmark/.generated/carbonmark-api-sdk/hooks/index.ts @@ -1,7 +1,9 @@ +export * from "./useGetActivities"; export * from "./useGetCategories"; export * from "./useGetCountries"; export * from "./useGetProjects"; export * from "./useGetProjectsId"; +export * from "./useGetProjectsIdActivity"; export * from "./useGetPurchasesId"; export * from "./useGetUsersWalletorhandle"; export * from "./useGetVintages"; diff --git a/carbonmark/.generated/carbonmark-api-sdk/hooks/useGetActivities.ts b/carbonmark/.generated/carbonmark-api-sdk/hooks/useGetActivities.ts new file mode 100644 index 0000000000..09515bb122 --- /dev/null +++ b/carbonmark/.generated/carbonmark-api-sdk/hooks/useGetActivities.ts @@ -0,0 +1,60 @@ +import type { SWRConfiguration, SWRResponse } from "swr"; +import useSWR from "swr"; +import client from "../../../lib/api/client"; +import type { + GetActivitiesQueryParams, + GetActivitiesQueryResponse, +} from "../types/GetActivities"; + +export function getActivitiesQueryOptions< + TData = GetActivitiesQueryResponse, + TError = unknown, +>( + params?: GetActivitiesQueryParams, + options: Partial[0]> = {} +): SWRConfiguration { + return { + fetcher: () => { + return client({ + method: "get", + url: `/activities`, + + params, + + ...options, + }).then((res) => res.data); + }, + }; +} + +/** + * @description Retrieve an array of activities related to a carbon project + * @summary List project activities + * @link /activities + */ + +export function useGetActivities< + TData = GetActivitiesQueryResponse, + TError = unknown, +>( + params?: GetActivitiesQueryParams, + options?: { + query?: SWRConfiguration; + client?: Partial>[0]>; + shouldFetch?: boolean; + } +): SWRResponse { + const { + query: queryOptions, + client: clientOptions = {}, + shouldFetch = true, + } = options ?? {}; + + const url = shouldFetch ? `/activities` : null; + const query = useSWR(url, { + ...getActivitiesQueryOptions(params, clientOptions), + ...queryOptions, + }); + + return query; +} diff --git a/carbonmark/.generated/carbonmark-api-sdk/hooks/useGetProjectsIdActivity.ts b/carbonmark/.generated/carbonmark-api-sdk/hooks/useGetProjectsIdActivity.ts new file mode 100644 index 0000000000..08fc4f6074 --- /dev/null +++ b/carbonmark/.generated/carbonmark-api-sdk/hooks/useGetProjectsIdActivity.ts @@ -0,0 +1,67 @@ +import type { SWRConfiguration, SWRResponse } from "swr"; +import useSWR from "swr"; +import client from "../../../lib/api/client"; +import type { + GetProjectsIdActivityPathParams, + GetProjectsIdActivityQueryParams, + GetProjectsIdActivityQueryResponse, +} from "../types/GetProjectsIdActivity"; + +export function getProjectsIdActivityQueryOptions< + TData = GetProjectsIdActivityQueryResponse, + TError = unknown, +>( + id: GetProjectsIdActivityPathParams["id"], + params?: GetProjectsIdActivityQueryParams, + options: Partial[0]> = {} +): SWRConfiguration { + return { + fetcher: () => { + return client({ + method: "get", + url: `/projects/${id}/activity`, + + params, + + ...options, + }).then((res) => res.data); + }, + }; +} + +/** + * @description Retrieve an array of activities related to a carbon project + * @summary List project activities + * @link /projects/:id/activity + */ + +export function useGetProjectsIdActivity< + TData = GetProjectsIdActivityQueryResponse, + TError = unknown, +>( + id: GetProjectsIdActivityPathParams["id"], + params?: GetProjectsIdActivityQueryParams, + options?: { + query?: SWRConfiguration; + client?: Partial>[0]>; + shouldFetch?: boolean; + } +): SWRResponse { + const { + query: queryOptions, + client: clientOptions = {}, + shouldFetch = true, + } = options ?? {}; + + const url = shouldFetch ? `/projects/${id}/activity` : null; + const query = useSWR(url, { + ...getProjectsIdActivityQueryOptions( + id, + params, + clientOptions + ), + ...queryOptions, + }); + + return query; +} diff --git a/carbonmark/.generated/carbonmark-api-sdk/types/GetActivities.ts b/carbonmark/.generated/carbonmark-api-sdk/types/GetActivities.ts new file mode 100644 index 0000000000..45c3ca563f --- /dev/null +++ b/carbonmark/.generated/carbonmark-api-sdk/types/GetActivities.ts @@ -0,0 +1,51 @@ +import type { Def1 } from "./Def1"; + +/** + * @description List of project activities + */ +export type GetActivitiesQueryResponse = { + /** + * @type string + */ + id: string; + amount?: string | null; + previousAmount?: string | null; + price?: string | null; + previousPrice?: string | null; + timeStamp?: string | null; + activityType?: string | null; + seller?: { + /** + * @type string + */ + id: string; + handle?: string | null; + } | null; + buyer?: { + /** + * @type string + */ + id: string; + handle?: string | null; + } | null; +}[]; + +export type GetActivitiesQueryParams = { + network?: Def1; + /** + * @description Filter returned activities by project + * @type string | undefined + */ + projectId?: string; + /** + * @type array | undefined + */ + activityType?: ( + | "CreatedListing" + | "DeletedListing" + | "Purchase" + | "Sold" + | "UpdatedPrice" + | "UpdatedQuantity" + )[]; +}; diff --git a/carbonmark/.generated/carbonmark-api-sdk/types/GetProjectsIdActivity.ts b/carbonmark/.generated/carbonmark-api-sdk/types/GetProjectsIdActivity.ts new file mode 100644 index 0000000000..e6d9e34e7e --- /dev/null +++ b/carbonmark/.generated/carbonmark-api-sdk/types/GetProjectsIdActivity.ts @@ -0,0 +1,59 @@ +import type { Def1 } from "./Def1"; + +export type GetProjectsIdActivityPathParams = { + /** + * @description Project id & vintage + * @type string + */ + id: string; +}; + +/** + * @description List of project activities + */ +export type GetProjectsIdActivityQueryResponse = { + /** + * @type string + */ + id: string; + amount?: string | null; + previousAmount?: string | null; + price?: string | null; + previousPrice?: string | null; + timeStamp?: string | null; + activityType?: string | null; + seller?: { + /** + * @type string + */ + id: string; + handle?: string | null; + } | null; + buyer?: { + /** + * @type string + */ + id: string; + handle?: string | null; + } | null; +}[]; + +export type GetProjectsIdActivityQueryParams = { + network?: Def1; + /** + * @description Filter returned activities by project + * @type string | undefined + */ + projectId?: string; + /** + * @type array | undefined + */ + activityType?: ( + | "CreatedListing" + | "DeletedListing" + | "Purchase" + | "Sold" + | "UpdatedPrice" + | "UpdatedQuantity" + )[]; +}; diff --git a/carbonmark/.generated/carbonmark-api-sdk/types/index.ts b/carbonmark/.generated/carbonmark-api-sdk/types/index.ts index 7a276a2e9b..609bb1a59a 100644 --- a/carbonmark/.generated/carbonmark-api-sdk/types/index.ts +++ b/carbonmark/.generated/carbonmark-api-sdk/types/index.ts @@ -5,10 +5,12 @@ export * from "./Country"; export * from "./Def0"; export * from "./Def1"; export * from "./DetailedProject"; +export * from "./GetActivities"; export * from "./GetCategories"; export * from "./GetCountries"; export * from "./GetProjects"; export * from "./GetProjectsId"; +export * from "./GetProjectsIdActivity"; export * from "./GetPurchasesId"; export * from "./GetUsersWalletorhandle"; export * from "./GetVintages"; diff --git a/carbonmark/.generated/carbonmark-api.schema.json b/carbonmark/.generated/carbonmark-api.schema.json index 52d1620791..11b91257b3 100644 --- a/carbonmark/.generated/carbonmark-api.schema.json +++ b/carbonmark/.generated/carbonmark-api.schema.json @@ -2,7 +2,7 @@ "openapi": "3.0.3", "info": { "title": "Carbonmark REST API", - "description": "\nWelcome to the API Reference docs for **version 2.0.2** of the Carbonmark REST API.\n\nUse this API to view assets, prices, supply, activity and more.\n\nLooking for the latest version? Visit our [GitHub Releases page](https://github.com/KlimaDAO/klimadao/releases).\n\n## Quick start\nBe sure to prefix a version number, otherwise your application will be exposed to breaking changes.\n\n~~~ts\nconst res = await fetch(\"https://v2.0.2.api.carbonmark.com/projects\");\nconst projects = await res.json();\n~~~\n\nFor a developer guides and example implementations, or to learn more about Carbonmark and Digital Carbon Market, view our product knowledge base at docs.carbonmark.com.\n## \n", + "description": "\nWelcome to the API Reference docs for **version 2.1.0** of the Carbonmark REST API.\n\nUse this API to view assets, prices, supply, activity and more.\n\nLooking for the latest version? Visit our [GitHub Releases page](https://github.com/KlimaDAO/klimadao/releases).\n\n## Quick start\nBe sure to prefix a version number, otherwise your application will be exposed to breaking changes.\n\n~~~ts\nconst res = await fetch(\"https://v2.1.0.api.carbonmark.com/projects\");\nconst projects = await res.json();\n~~~\n\nFor a developer guides and example implementations, or to learn more about Carbonmark and Digital Carbon Market, view our product knowledge base at docs.carbonmark.com.\n## \n", "termsOfService": "https://www.carbonmark.com/blog/terms-of-use", "contact": { "name": "Support", @@ -12,7 +12,7 @@ "name": "MIT", "url": "https://github.com/KlimaDAO/klimadao/blob/main/LICENSE" }, - "version": "2.0.2" + "version": "2.1.0" }, "components": { "schemas": { @@ -2184,6 +2184,221 @@ } }, "paths": { + "/activities": { + "get": { + "summary": "List project activities", + "tags": [ + "Activities" + ], + "description": "Retrieve an array of activities related to a carbon project", + "parameters": [ + { + "schema": { + "$ref": "#/components/schemas/def-1" + }, + "in": "query", + "name": "network", + "required": false + }, + { + "schema": { + "type": "string" + }, + "in": "query", + "name": "projectId", + "required": false, + "description": "Filter returned activities by project" + }, + { + "schema": { + "type": "array", + "items": { + "anyOf": [ + { + "type": "string", + "enum": [ + "CreatedListing" + ] + }, + { + "type": "string", + "enum": [ + "DeletedListing" + ] + }, + { + "type": "string", + "enum": [ + "Purchase" + ] + }, + { + "type": "string", + "enum": [ + "Sold" + ] + }, + { + "type": "string", + "enum": [ + "UpdatedPrice" + ] + }, + { + "type": "string", + "enum": [ + "UpdatedQuantity" + ] + } + ] + } + }, + "in": "query", + "name": "activityType", + "required": false + } + ], + "responses": { + "200": { + "description": "List of project activities", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "amount": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "previousAmount": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "price": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "previousPrice": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "timeStamp": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "activityType": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "seller": { + "anyOf": [ + { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "handle": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "id" + ] + }, + { + "type": "null" + } + ] + }, + "buyer": { + "anyOf": [ + { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "handle": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "id" + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "id" + ] + } + } + } + } + } + } + } + }, "/categories": { "get": { "summary": "Categories", @@ -2226,6 +2441,48 @@ } } }, + "/countries": { + "get": { + "summary": "Countries", + "description": "Retrieve an array containing the countries that carbon projects originate from", + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ] + } + }, + "examples": [ + [ + { + "id": "Brazil" + }, + { + "id": "Bulgaria" + }, + { + "id": "China" + } + ] + ] + } + } + } + } + } + }, "/projects": { "get": { "summary": "List projects", @@ -2701,48 +2958,6 @@ } } }, - "/countries": { - "get": { - "summary": "Countries", - "description": "Retrieve an array containing the countries that carbon projects originate from", - "responses": { - "200": { - "description": "Successful response", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "type": "object", - "properties": { - "id": { - "type": "string" - } - }, - "required": [ - "id" - ] - } - }, - "examples": [ - [ - { - "id": "Brazil" - }, - { - "id": "Bulgaria" - }, - { - "id": "China" - } - ] - ] - } - } - } - } - } - }, "/users/{walletOrHandle}": { "get": { "summary": "User details", @@ -4397,7 +4612,7 @@ }, "/projects/{id}/activity": { "get": { - "summary": "List project acitivities", + "summary": "List project activities", "tags": [ "Activities" ], @@ -4405,43 +4620,68 @@ "parameters": [ { "schema": { - "default": "polygon", - "anyOf": [ - { - "type": "string", - "enum": [ - "polygon" - ] - }, - { - "type": "string", - "enum": [ - "mumbai" - ] - } - ] - }, - "examples": { - "polygon": { - "value": "polygon" - }, - "mumbai": { - "value": "mumbai" - } + "$ref": "#/components/schemas/def-1" }, "in": "query", "name": "network", - "required": false, - "description": "Optional. Desired blockchain network. Default is `polygon` (mainnet)." + "required": false }, { "schema": { "type": "string" }, "in": "query", - "name": "activityType", + "name": "projectId", "required": false, - "description": "Desired types of the project activities" + "description": "Filter returned activities by project" + }, + { + "schema": { + "type": "array", + "items": { + "anyOf": [ + { + "type": "string", + "enum": [ + "CreatedListing" + ] + }, + { + "type": "string", + "enum": [ + "DeletedListing" + ] + }, + { + "type": "string", + "enum": [ + "Purchase" + ] + }, + { + "type": "string", + "enum": [ + "Sold" + ] + }, + { + "type": "string", + "enum": [ + "UpdatedPrice" + ] + }, + { + "type": "string", + "enum": [ + "UpdatedQuantity" + ] + } + ] + } + }, + "in": "query", + "name": "activityType", + "required": false }, { "schema": { @@ -4652,7 +4892,7 @@ }, "servers": [ { - "url": "https://v2.0.2.api.carbonmark.com" + "url": "https://v2.1.0.api.carbonmark.com" } ], "externalDocs": { diff --git a/carbonmark/components/pages/Project/index.tsx b/carbonmark/components/pages/Project/index.tsx index 5083e9eee0..9db61212e9 100644 --- a/carbonmark/components/pages/Project/index.tsx +++ b/carbonmark/components/pages/Project/index.tsx @@ -1,14 +1,13 @@ -import { useGetProjectsId } from ".generated/carbonmark-api-sdk/hooks"; +import { useGetProjectsId, useGetProjectsIdActivity } from ".generated/carbonmark-api-sdk/hooks"; import { cx } from "@emotion/css"; import { fetcher } from "@klimadao/carbonmark/lib/fetcher"; import { Anchor } from "@klimadao/lib/components"; import { REGISTRIES } from "@klimadao/lib/constants"; import { useWeb3 } from "@klimadao/lib/utils"; -import { t, Trans } from "@lingui/macro"; +import { Trans, t } from "@lingui/macro"; import InfoOutlined from "@mui/icons-material/InfoOutlined"; import LaunchIcon from "@mui/icons-material/Launch"; import { Activities } from "components/Activities"; -import { ActivityActions } from "components/Activities/Activities.constants"; import Carousel from "components/Carousel/Carousel"; import { Category } from "components/Category"; import { Layout } from "components/Layout"; @@ -19,7 +18,6 @@ import { Stats } from "components/Stats"; import { Text } from "components/Text"; import { TextInfoTooltip } from "components/TextInfoTooltip"; import { Vintage } from "components/Vintage"; -import { useFetchProjectActivities } from "hooks/useFetchProjectActivities"; import { urls } from "lib/constants"; import { formatList, formatToPrice } from "lib/formatNumbers"; import { getActiveListings, getAllListings } from "lib/listingsGetter"; @@ -47,14 +45,10 @@ export type PageProps = { const Page: NextPage = (props) => { const { data: project } = useGetProjectsId(props.projectID); - const { activities } = useFetchProjectActivities({ - query: { - activityType: Object.keys(ActivityActions) - .filter((a) => a != "Sold") - .join(","), - }, - params: { id: props.projectID }, - }); + const { data: activities } = useGetProjectsIdActivity(props.projectID, { + activityType: [ "CreatedListing", "DeletedListing", "Purchase", "UpdatedPrice", "UpdatedQuantity"] + } + ); const [isExpanded, setIsExpanded] = useState(false); const bestPrice = project?.price; diff --git a/carbonmark/hooks/useFetchProjectActivities.ts b/carbonmark/hooks/useFetchProjectActivities.ts deleted file mode 100644 index b58f996e6b..0000000000 --- a/carbonmark/hooks/useFetchProjectActivities.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { ClientT, client } from "lib/api/client"; -import { urls } from "lib/constants"; -import type { SWRConfiguration } from "swr"; -import useSWR from "swr"; - -type GetProjectActivitiesFnT = ClientT["/projects/{id}/activity"]["get"]; - -export const useFetchProjectActivities = ( - args: Parameters[0], - options?: { - initOpts: Parameters[1]; - swrOpts: SWRConfiguration; - } -) => { - const fetchProjectActivities = async () => - ( - await client["/projects/{id}/activity"].get(args, options?.initOpts) - ).json(); - - const { data, ...rest } = useSWR( - fetchProjectActivitiesURL(args), - fetchProjectActivities, - options?.swrOpts - ); - return { activities: data || [], ...rest }; -}; - -/** - * Construct stable URL as key for SWR. When this key changes, data is re-fetched. - * Always includes network default 'polygon' - */ -export const fetchProjectActivitiesURL = ( - args: Parameters[0] -) => { - const url = new URL( - `${urls.api.projects}/${args.params.id.toLowerCase()}/activity` - ); - - const { network = "polygon", ...query } = args.query || {}; - url.searchParams.set("network", network?.toLowerCase()); - - for (const queryParam in query) { - const value = query[queryParam as keyof typeof query]; - if (value) { - url.searchParams.set(queryParam, value); - } - } - - return url.toString(); -}; diff --git a/package-lock.json b/package-lock.json index 72014ad53a..59c21645a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -588,7 +588,7 @@ }, "carbonmark-api": { "name": "@klimadao/carbonmark-api", - "version": "2.0.1", + "version": "2.1.0", "license": "ISC", "dependencies": { "@fastify/autoload": "^5.0.0",