From 59cbabe95fb72f8a32280e6d9eba3964352f6584 Mon Sep 17 00:00:00 2001 From: Piranavan Shanmugavadivelu Date: Fri, 19 Jan 2024 11:47:40 +0530 Subject: [PATCH] plastic credit collection page (#1135) * plastic credit collection page * collection page query changes * rename query function --------- Co-authored-by: Johannes Schill --- .../marketplace/src/graphql/queries/index.ts | 1 + .../src/graphql/queries/marketPlaceListing.ts | 61 ++++++ .../src/pages/CreditCollectionPage.vue | 193 ++++++++++++++++++ frontend/marketplace/src/router/index.ts | 6 + .../src/utils/formatAuctionDetails.ts | 60 ++++++ 5 files changed, 321 insertions(+) create mode 100644 frontend/marketplace/src/graphql/queries/marketPlaceListing.ts create mode 100644 frontend/marketplace/src/pages/CreditCollectionPage.vue create mode 100644 frontend/marketplace/src/utils/formatAuctionDetails.ts diff --git a/frontend/marketplace/src/graphql/queries/index.ts b/frontend/marketplace/src/graphql/queries/index.ts index 5608737e..f269c121 100644 --- a/frontend/marketplace/src/graphql/queries/index.ts +++ b/frontend/marketplace/src/graphql/queries/index.ts @@ -1,3 +1,4 @@ export * from "./creditCollections"; export * from "./creditOffsetCertificates"; export * from "./creditOffsetCertificate"; +export * from "./marketPlaceListing"; diff --git a/frontend/marketplace/src/graphql/queries/marketPlaceListing.ts b/frontend/marketplace/src/graphql/queries/marketPlaceListing.ts new file mode 100644 index 00000000..1dbbf58a --- /dev/null +++ b/frontend/marketplace/src/graphql/queries/marketPlaceListing.ts @@ -0,0 +1,61 @@ +import gql from "graphql-tag"; + +export const GET_MARKETPLACE_LISTING = gql` + query GetMarketplaceListing($id: String!) { + marketplaceListings(filter: { id: { equalTo: $id } }) { + totalCount + nodes { + id + amount + initialAmount + denom + owner + pricePerCreditAmount + pricePerCreditDenom + creditCollection { + activeAmount + retiredAmount + creditType + creditData { + nodes { + mediaFiles { + nodes { + name + url + } + } + binaryFiles { + nodes { + name + url + } + } + eventData { + nodes { + magnitude + registrationDate + amount + country + latitude + longitude + material { + nodes { + key + value + } + } + } + } + applicantDataByCreditDataId { + nodes { + name + description + } + } + } + } + } + } + } + } +`; diff --git a/frontend/marketplace/src/pages/CreditCollectionPage.vue b/frontend/marketplace/src/pages/CreditCollectionPage.vue new file mode 100644 index 00000000..2f376717 --- /dev/null +++ b/frontend/marketplace/src/pages/CreditCollectionPage.vue @@ -0,0 +1,193 @@ + + + diff --git a/frontend/marketplace/src/router/index.ts b/frontend/marketplace/src/router/index.ts index 36cf29c7..0945631c 100644 --- a/frontend/marketplace/src/router/index.ts +++ b/frontend/marketplace/src/router/index.ts @@ -8,6 +8,7 @@ import CallbackView from "@/pages/CallbackView.vue"; import UserProfile from "@/pages/UserProfile.vue"; import AuctionPaymentSuccessful from "@/pages/AuctionPaymentSuccessful.vue"; import AuctionPaymentCancelled from "@/pages/AuctionPaymentCancelled.vue"; +import CreditCollectionPage from "@/pages/CreditCollectionPage.vue"; const router = createRouter({ scrollBehavior: () => { @@ -62,6 +63,11 @@ const router = createRouter({ name: "AuctionPaymentCancelled", component: AuctionPaymentCancelled, }, + { + path: "/registry/:denom", + name: "CreditCollectionPage", + component: CreditCollectionPage, + }, // { // path: "/payment-cancelled/:id", // name: "AuctionPaymentCancelled", diff --git a/frontend/marketplace/src/utils/formatAuctionDetails.ts b/frontend/marketplace/src/utils/formatAuctionDetails.ts new file mode 100644 index 00000000..a0926540 --- /dev/null +++ b/frontend/marketplace/src/utils/formatAuctionDetails.ts @@ -0,0 +1,60 @@ +import type { MaterialProperty } from "@/types/GraphqlSchema"; +import { + convertIPFStoHTTPS, + findPlasticTypeInMaterial, + uniqueMaterials, +} from "@/utils/utils"; + +export const formatAuctionDetails = (data: any, materialVolume: number) => { + const applicantArray: string[] = []; + const locationArray: string[] = []; + const locationPointersArray: { + lat: number; + lng: number; + }[] = []; + const imageArray: string[] = []; + const fileArray: { url: string; name: string }[] = []; + const materialArray: MaterialProperty[][] = []; + const volume = materialVolume; + const registrationDateArray: string[] = []; + + data?.map((item: any) => { + item.applicantDataByCreditDataId.nodes.map((node: any) => { + applicantArray.push(node.name); + }); + + item.eventData.nodes.map((node: any) => { + locationArray.push(node.country); + locationPointersArray.push({ lat: node.latitude, lng: node.longitude }); + materialArray.push(node.material.nodes); + registrationDateArray.push( + new Date(node.registrationDate).toLocaleDateString(), + ); + }); + + item.mediaFiles.nodes.map((node: any) => { + imageArray.push(convertIPFStoHTTPS(node.url)); + }); + item.binaryFiles.nodes.map((node: any) => { + fileArray.push({ + url: convertIPFStoHTTPS(node.url), + name: node.name, + }); + }); + }); + const uniqueMaterialArray = uniqueMaterials(materialArray); + const plasticType = + findPlasticTypeInMaterial(uniqueMaterialArray[0])?.value ?? ""; + + return { + applicant: applicantArray[0], + location: Array.from(new Set(locationArray)), + material: uniqueMaterialArray, + volume: volume, + image: imageArray, + file: fileArray, + locationPointers: locationPointersArray, + registrationDate: registrationDateArray[0], + plasticType: plasticType, + }; +};