Skip to content

Commit

Permalink
feat: allow v5 minting (#351)
Browse files Browse the repository at this point in the history
* feat: allow v5 minting

* chore: fix package-lock

* fix: template generation error
  • Loading branch information
nghaninn authored Dec 4, 2024
1 parent 11ec913 commit a03aa22
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 40 deletions.
3 changes: 3 additions & 0 deletions config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module.exports = function override(config) {
...config,
resolve: {
...config.resolve,
alias: {
process: "process/browser",
},
extensions: [...config.resolve.extensions, ".ts", ".tsx", ".js"],
fallback: nodejsPolyfillWebpack.fallback(config),
},
Expand Down
125 changes: 96 additions & 29 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"ethers": "^5.4.0",
"file-saver": "^2.0.5",
"json-2-csv": "^3.14.1",
"json-schema-library": "^5.3.0",
"json-schema-library": "^9.3.5",
"jszip": "^3.6.0",
"lodash": "^4.17.21",
"pretty-bytes": "^5.6.0",
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ajv from "ajv";
import { saveAs } from "file-saver";
import converter, { csv2jsonAsync } from "json-2-csv";
import { JSONSchema } from "json-schema-library";
import { JsonSchema } from "json-schema-library";
import { ChainId, ChainInfo, ChainInfoObject } from "../constants/chainInfo";
import { FormErrors, Network, NetworkObject, WalletOptions } from "../types";

Expand Down Expand Up @@ -183,7 +183,7 @@ export const getDataToValidate: any = (data: any) => {
}
};

export const validateData = (schema: JSONSchema, data: unknown): { isValid: boolean; ajvErrors: FormErrors } => {
export const validateData = (schema: JsonSchema, data: unknown): { isValid: boolean; ajvErrors: FormErrors } => {
const ajv = new Ajv({ allErrors: true });
const isValid = ajv.validate(schema, data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { FunctionComponent, useState } from "react";
import { readFileAsCsv, readFileAsJson, downloadCsvDataFile, downloadJsonDataFile } from "../../../common/utils";
import { getLogger } from "../../../utils/logger";
import { FormErrorBanner } from "./../FormErrorBanner";
import { Draft04 as Core, JSONSchema } from "json-schema-library";
import { Draft04 as Core, JsonSchema } from "json-schema-library";
import { ToolTip } from "../../UI/ToolTip";
import { StyledDropZone } from "../../UI/StyledDropZone";
import { validateData, getDataToValidate } from "./../../../common/utils";
Expand Down Expand Up @@ -32,7 +32,7 @@ type DataFileUpload = DataFileDefault | DataFileCsv;

interface DataFileButton {
onDataFile: (dataFile: unknown) => void;
schema: JSONSchema;
schema: JsonSchema;
}

interface GetDataFileBasedOnExtension {
Expand Down Expand Up @@ -85,8 +85,8 @@ export const DataFileButton: FunctionComponent<DataFileButton> = ({ onDataFile,
}
};

const core = new Core();
const jsonTemplate = core.getTemplate({}, schema);
const core = new Core(schema);
const jsonTemplate = core.getTemplate(undefined, undefined, { addOptionalProps: true });

const defaultStyle = "bg-yellow-50";
const activeStyle = "bg-yellow-100";
Expand Down
1 change: 1 addition & 0 deletions src/services/publishing/publishing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const mockDocumentStore = {

const mockTokenRegistry = {
mint: mockTokenRegistryMint,
supportsInterface: jest.fn().mockResolvedValue(true),
};

const mockTransactionReceipt = {
Expand Down
25 changes: 21 additions & 4 deletions src/services/publishing/publishing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
v2,
} from "@tradetrust-tt/tradetrust";
import { TradeTrustToken__factory } from "@tradetrust-tt/token-registry/contracts";
import { Signer, Wallet } from "ethers";
import { constants } from "@tradetrust-tt/token-registry";
import { ethers, Signer, Wallet } from "ethers";
import { ConnectedSigner, PublishingJob } from "../../types";
import { assertAddressIsSmartContract, getConnectedDocumentStore } from "../common";
import { fetchGasPriceSuggestions } from "./gas-price";
Expand Down Expand Up @@ -52,9 +53,25 @@ export const publishTransferableRecordJob = async (job: PublishingJob, signer: S
const { beneficiaryAddress, holderAddress } = payload.ownership;
const tokenRegistryContract = TradeTrustToken__factory.connect(contractAddress, signer);
const suggestedGasPrice = await fetchGasPriceSuggestions(await signer.getChainId());
const mintingReceipt = await tokenRegistryContract.mint(beneficiaryAddress, holderAddress, `0x${merkleRoot}`, {
...suggestedGasPrice,
});

const mintableSupportInterfaceId = constants.contractInterfaceId.TradeTrustTokenMintable;
const isV4TT = await tokenRegistryContract.supportsInterface(mintableSupportInterfaceId);

let mintingReceipt;
if (isV4TT) {
mintingReceipt = await tokenRegistryContract.mint(beneficiaryAddress, holderAddress, `0x${merkleRoot}`, {
...suggestedGasPrice,
});
} else {
const tokenRegistryV5Contract = new ethers.Contract(
contractAddress,
'[{"inputs":[{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"address","name":"holder","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_remark","type":"bytes"}],"name":"mint","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"}]',
signer
);
mintingReceipt = await tokenRegistryV5Contract.mint(beneficiaryAddress, holderAddress, `0x${merkleRoot}`, "0x", {
...suggestedGasPrice,
});
}
const mintingTx = await mintingReceipt.wait();
if (!mintingTx.transactionHash) throw new Error(`Tx hash not available: ${JSON.stringify(mintingTx)}`);
return mintingTx.transactionHash;
Expand Down

0 comments on commit a03aa22

Please sign in to comment.