Skip to content

Commit

Permalink
Merge branch 'main' into 5837-cert-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jschill authored Jan 22, 2024
2 parents 0595c85 + 190c715 commit 2943d96
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 19 deletions.
70 changes: 70 additions & 0 deletions cosmwasm/schema/plastic-credit-marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,37 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"price"
],
"properties": {
"price": {
"type": "object",
"required": [
"denom",
"number_of_credits_to_buy",
"owner"
],
"properties": {
"denom": {
"type": "string"
},
"number_of_credits_to_buy": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"owner": {
"$ref": "#/definitions/Addr"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
Expand Down Expand Up @@ -647,6 +678,45 @@
"type": "string"
}
}
},
"price": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PriceResponse",
"type": "object",
"required": [
"fee",
"total_price"
],
"properties": {
"fee": {
"$ref": "#/definitions/Coin"
},
"total_price": {
"$ref": "#/definitions/Coin"
}
},
"additionalProperties": false,
"definitions": {
"Coin": {
"type": "object",
"required": [
"amount",
"denom"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"denom": {
"type": "string"
}
}
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
}
}
}
2 changes: 1 addition & 1 deletion frontend/empowerjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@empower-plastic/empowerjs",
"version": "0.0.19",
"version": "0.0.20",
"description": "Typescript types for EmpowerChain",
"author": "empower <[email protected]>",
"homepage": "https://github.com/EmpowerPlastic/empowerchain/tree/main/frontend/empowerjs#readme",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { StdFee } from "@cosmjs/amino";
import { InstantiateMsg, ExecuteMsg, Uint64, Addr, Uint128, Decimal, Coin, Share, QueryMsg, Config, ListingResponse, Listing, ListingsResponse } from "./PlasticCreditMarketplace.types";
import { InstantiateMsg, ExecuteMsg, Uint64, Addr, Uint128, Decimal, Coin, Share, QueryMsg, Config, ListingResponse, Listing, ListingsResponse, PriceResponse } from "./PlasticCreditMarketplace.types";
export interface PlasticCreditMarketplaceReadOnlyInterface {
contractAddress: string;
listings: ({
Expand All @@ -24,6 +24,15 @@ export interface PlasticCreditMarketplaceReadOnlyInterface {
owner: Addr;
}) => Promise<ListingResponse>;
feeSplitConfig: () => Promise<Config>;
price: ({
denom,
numberOfCreditsToBuy,
owner
}: {
denom: string;
numberOfCreditsToBuy: number;
owner: Addr;
}) => Promise<PriceResponse>;
}
export class PlasticCreditMarketplaceQueryClient implements PlasticCreditMarketplaceReadOnlyInterface {
client: CosmWasmClient;
Expand All @@ -35,6 +44,7 @@ export class PlasticCreditMarketplaceQueryClient implements PlasticCreditMarketp
this.listings = this.listings.bind(this);
this.listing = this.listing.bind(this);
this.feeSplitConfig = this.feeSplitConfig.bind(this);
this.price = this.price.bind(this);
}

listings = async ({
Expand Down Expand Up @@ -70,6 +80,23 @@ export class PlasticCreditMarketplaceQueryClient implements PlasticCreditMarketp
fee_split_config: {}
});
};
price = async ({
denom,
numberOfCreditsToBuy,
owner
}: {
denom: string;
numberOfCreditsToBuy: number;
owner: Addr;
}): Promise<PriceResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
price: {
denom,
number_of_credits_to_buy: numberOfCreditsToBuy,
owner
}
});
};
}
export interface PlasticCreditMarketplaceInterface extends PlasticCreditMarketplaceReadOnlyInterface {
contractAddress: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export type QueryMsg = {
};
} | {
fee_split_config: {};
} | {
price: {
denom: string;
number_of_credits_to_buy: number;
owner: Addr;
};
};
export interface Config {
fee_percentage: Decimal;
Expand All @@ -106,4 +112,8 @@ export interface Listing {
}
export interface ListingsResponse {
listings: Listing[];
}
export interface PriceResponse {
fee: Coin;
total_price: Coin;
}
2 changes: 1 addition & 1 deletion frontend/marketplace/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ VITE_ROLLBAR_ACCESS_TOKEN="0791c0b34f844b61aba669c0ad4469d5"
VITE_GOOGLE_MAPS_API_KEY="AIzaSyBezM4SJJO5t2bS5j2CPOdWJm_kHsdN4n0"
VITE_LOGTO_ENDPOINT="https://h3cwf8.logto.app/"
VITE_LOGTO_APP_ID="ilv0vuqy1u4zi05nyesgc"
VITE_PC_BACKEND_ENDPOINT="https://pc-backend-public-qa-xv5zwi25ya-ew.a.run.app"
VITE_PC_BACKEND_ENDPOINT="https://api.qa.empower.eco/api/v1/pc-backend-public"

8 changes: 4 additions & 4 deletions frontend/marketplace/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/marketplace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"prettier": "^3.1.0",
"tailwindcss": "^3.3.5",
"typescript": "~5.3.3",
"vite": "^5.0.10",
"vite": "^5.0.12",
"vitest": "^0.34.6",
"vue-tsc": "^1.8.25"
},
Expand Down
6 changes: 3 additions & 3 deletions frontend/marketplace/src/pages/AuctionPaymentSuccessful.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ onMounted(async () => {
v-if="auctionStatus === PaymentStatus.COMPLETE"
class="font-Inter text-white text-title18"
>
Your plastic credit purchase was successful and Plastic Credit Offset
Certificate has been generated for you.
Your plastic credit purchase was successful and a Plastic Credit
Offset Certificate has been generated for you.
</span>
<span
v-else-if="auctionStatus === PaymentStatus.ERROR"
Expand All @@ -115,7 +115,7 @@ onMounted(async () => {
<a
class="mt-5 text-white btn btn-ghost btn-block normal-case bg-greenPrimary hover:bg-greenDark text-title24 lg:text-title32 lg:btn-lg p-0 px-12 font-normal md:max-w-lg"
href="/certificate"
>See your plastic credits</a
>See your certificates</a
>
</div>
</div>
Expand Down
82 changes: 74 additions & 8 deletions frontend/marketplace/src/pdfGenerator/pdfGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
leaf1,
horizontalLeafs,
verticalLeafs,
greenLogo,
} from "../pdfGenerator/AssetsBase64";
import {
addTextWithSpacing,
Expand Down Expand Up @@ -79,9 +80,48 @@ export const generatePDF = (
creditData,
applicantDataDescription,
);
addFinalPage(doc);
doc.save("certificate.pdf");
};

const addFinalPage = (doc: IjsPDF) => {
doc.addPage("a4", "portrait");
addGrayPadding(doc);
doc.addImage(verticalLeafs, "png", 0, 0, 210, 297);
doc.addImage(leaf1, "png", 30, 23, 10, 8);

doc.setFontSize(12);
doc.setTextColor(35, 31, 32);
doc.setFont("Open Sans", "normal");

doc.text(
`
This certificate is issued by Empower.
Blockchain technology ensures the transparency and integrity of this certificate.
Each transaction is recorded on a decentralized and immutable ledger, providing a
clear audit trail. This guarantees that each credit is unique, cannot be
double-counted, and its environmental impact is accurately represented.
Read more at https://www.empower.eco
`,
doc.internal.pageSize.width / 2,
doc.internal.pageSize.height / 2 - 72,
{
align: "center",
},
);

doc.addImage(
greenLogo,
"png",
doc.internal.pageSize.width / 2 - 5,
60,
10,
10,
);
};

const addGrayPadding = (doc: IjsPDF) => {
const paddingInMM = 10.58;
const pageWidth = doc.internal.pageSize.getWidth();
Expand All @@ -99,10 +139,12 @@ const addGreenRectanglePage1 = (doc: IjsPDF) => {

doc.setFillColor(219, 231, 214);

const x = 40;
const y = 60;
const x = 80.58;
const y = 56;
const paddingToTheLeft = 80.58;
const paddingToTheRight = 10.58;

const rectWidth = pageWidth;
const rectWidth = pageWidth - paddingToTheLeft - paddingToTheRight;
const rectHeight = 90;

doc.rect(x, y, rectWidth, rectHeight, "F");
Expand Down Expand Up @@ -143,14 +185,34 @@ const addCertificateHolderPage1 = (
addTextWithSpacing(doc, "PROUDLY PRESENTED TO", 142, 75, 0.5);

const name = certificateData.retiringEntityName || "N/A";
const yPos = 95;
const yPos = 91;

const { xPos, fontSize } = calculateTextProperties(name);

doc.setFontSize(fontSize);
doc.setTextColor(88, 185, 71);
doc.setFont("Open Sans", "bold");
doc.setFont("Open Sans", "normal");
doc.text(name, xPos, yPos);

doc.setFontSize(10);
doc.setTextColor(35, 31, 32);
const logoWidth = 5;
doc.text(
"Certificate issued by Empower",
doc.internal.pageSize.width / 2 + 35 - logoWidth - 4,
doc.internal.pageSize.height - 12,
{
align: "center",
},
);
doc.addImage(
greenLogo,
"png",
doc.internal.pageSize.width / 2 + 35 + 10 + logoWidth,
doc.internal.pageSize.height - 17,
logoWidth,
logoWidth,
);
};

const addHorizontalLongLinePage1 = (doc: IjsPDF) => {
Expand Down Expand Up @@ -198,15 +260,19 @@ const addCirularImagePage1 = (
ID: string,
qrCodeUrl: string | undefined,
) => {
doc.addImage(circular, "png", 160, 155, 40, 40);
const startY = 151;
const textY = startY + 20;
const qrY = startY + 9;

doc.addImage(circular, "png", 160, startY, 40, 40);
doc.setFontSize(15);
doc.setTextColor(0, 0, 0);
doc.setFont("Open Sans", "bold");
doc.text(ID, 174, 175);
doc.text(ID, 174, textY);
doc.setTextColor(88, 185, 71);
doc.setFontSize(12);
if (qrCodeUrl) {
doc.addImage(qrCodeUrl, "svg", 168, 164, 23, 23);
doc.addImage(qrCodeUrl, "svg", 168, qrY, 23, 23);
}
};

Expand Down

0 comments on commit 2943d96

Please sign in to comment.