Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update with trustvc libs #966

Merged
merged 9 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# FROM synthetixio/docker-e2e:18.16-ubuntu as base
FROM synthetixio/docker-e2e@sha256:d46dd0c38a4a6cf44355dbf583f3bb83c60e445c5508c10d7680c5a30dc81d8a as base

# Download and install Google Chrome
# Test and replace chrome version, value can be found in the link below
# https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-stable
# ENV CHROME_VERSION=130.0.6723.91-1
# RUN wget -q https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb
# RUN apt-get install -y ./google-chrome-stable_${CHROME_VERSION}_amd64.deb

RUN mkdir /app
WORKDIR /app

Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let config = {
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining",
"macros",
"@babel/plugin-transform-class-static-block",
],
env: {
test: {
Expand Down
287 changes: 150 additions & 137 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"integration:testcafe": "run-s blockchain:contracts:testcafe build:test integration:testcafe:prod",
"integration:testcafe:ci": "concurrently -k -s first \"npm:blockchain\" \"npm:integration:testcafe\"",
"integration:metamask": "run-s wait blockchain:contracts:synpress integration:synpress",
"integration:synpress": "cross-env METAMASK_VERSION=11.15.6 CYPRESS_RESOURCES_WAIT=1 STABLE_MODE=true SECRET_WORDS='indicate swing place chair flight used hammer soon photo region volume shuffle' NETWORK_NAME='localhost' RPC_URL=http://localhost:8545 CHAIN_ID=1337 SYMBOL=ETH IS_TESTNET=true synpress run --configFile='./synpress.config.js'",
"integration:synpress": "node ./scripts/fix_synpress.js && cross-env METAMASK_VERSION=11.15.6 CYPRESS_RESOURCES_WAIT=1 STABLE_MODE=true SECRET_WORDS='indicate swing place chair flight used hammer soon photo region volume shuffle' NETWORK_NAME='localhost' RPC_URL=http://localhost:8545 CHAIN_ID=1337 SYMBOL=ETH IS_TESTNET=true synpress run --configFile='./synpress.config.js'",
"integration:local": "cross-env NET=local npm run dev",
"integration:local:static": "cross-env NET=local npm run build:test && npm run serve-static",
"integration:headful": "concurrently -k -s first \"npm:blockchain\" \"npm:integration:local:static\" \"npm:integration:metamask\"",
Expand All @@ -56,12 +56,8 @@
"@reduxjs/toolkit": "^1.6.1",
"@tradetrust-tt/decentralized-renderer-react-components": "^3.14.3",
"@tradetrust-tt/document-store": "^4.1.0",
"@tradetrust-tt/token-registry": "^5.1.0",
"@tradetrust-tt/tradetrust": "^6.9.7",
"@tradetrust-tt/tradetrust-ui-components": "^3.0.0",
"@tradetrust-tt/tradetrust-utils": "^2.1.1",
"@tradetrust-tt/tt-verify": "^9.2.0",
"@trustvc/trustvc": "^1.0.0",
"@trustvc/trustvc": "^1.0.4",
"@types/gtag.js": "0.0.8",
"buffer": "^6.0.3",
"cross-env": "^7.0.3",
Expand Down Expand Up @@ -93,6 +89,7 @@
"devDependencies": {
"@babel/core": "^7.23.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-transform-class-static-block": "^7.26.0",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.23.3",
Expand Down
8 changes: 8 additions & 0 deletions scripts/fix_synpress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const fs = require("fs");

const synpressConfigPath = "./node_modules/@synthetixio/synpress/commands/playwright.js";

const playwright = fs.readFileSync(synpressConfigPath, { encoding: "utf8" });
const overwrite = playwright.replace(").split(': ')[1];", ").split(': ')[1].replace(/(\\n| )/g, '');");

fs.writeFileSync(synpressConfigPath, overwrite, { encoding: "utf8" });
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { constants } from "@tradetrust-tt/token-registry";
import { TitleEscrow, TradeTrustToken } from "@tradetrust-tt/token-registry/contracts";
import { v5SupportInterfaceIds } from "@trustvc/trustvc";
import { v5Contracts } from "@trustvc/trustvc";
import React, { createContext, FunctionComponent, useCallback, useContext, useEffect, useState } from "react";
import { BurnAddress } from "../../../constants/chain-info";
import { ContractFunctionState, useContractFunctionHook } from "../../hooks/useContractFunctionHook";
Expand All @@ -8,7 +8,9 @@ import { useSupportsInterface } from "../../hooks/useSupportsInterface";
import { useTitleEscrowContract } from "../../hooks/useTitleEscrowContract";
import { useTokenRegistryContract } from "../../hooks/useTokenRegistryContract";
import { useProviderContext } from "../provider";
const { contractInterfaceId } = constants;
const contractInterfaceId = v5SupportInterfaceIds;
type TitleEscrow = v5Contracts.TitleEscrow;
type TradeTrustToken = v5Contracts.TradeTrustToken;

export enum TokenRegistryVersion {
V2 = "V2",
Expand All @@ -26,9 +28,9 @@ interface TokenInformationContext {
remark?: string;
documentOwner?: string;
approvedBeneficiary?: string;
changeHolder: TitleEscrow["transferHolder"];
changeHolder: v5Contracts.TitleEscrow["transferHolder"];
changeHolderState: ContractFunctionState;
returnToIssuer: TitleEscrow["returnToIssuer"];
returnToIssuer: v5Contracts.TitleEscrow["returnToIssuer"];
returnToIssuerState: ContractFunctionState;
endorseBeneficiary: TitleEscrow["transferBeneficiary"];
endorseBeneficiaryState: ContractFunctionState;
Expand Down
2 changes: 1 addition & 1 deletion src/common/contexts/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers, providers } from "ethers";
import React, { createContext, FunctionComponent, useCallback, useContext, useEffect, useRef, useState } from "react";
import { INFURA_API_KEY } from "../../config";
import { ProviderDetails, utils } from "@tradetrust-tt/tt-verify";
import { ProviderDetails, utils } from "@trustvc/trustvc";
import { magic } from "./helpers";
import { ChainId, ChainInfo, ChainInfoObject } from "../../constants/chain-info";
import { UnsupportedNetworkError } from "../errors";
Expand Down
7 changes: 4 additions & 3 deletions src/common/hooks/useContractFunctionHook.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { TitleEscrow, TradeTrustToken } from "@tradetrust-tt/token-registry/dist/contracts";
import { TypedContractMethod } from "@tradetrust-tt/token-registry/dist/contracts/common";
import { v5Contracts } from "@trustvc/trustvc";
import { TypedContractMethod } from "@trustvc/trustvc";
import { BaseContract, ContractReceipt, ContractTransaction } from "ethers";
import { useCallback, useState } from "react";

export type ContractFunctionState = "UNINITIALIZED" | "INITIALIZED" | "PENDING_CONFIRMATION" | "CONFIRMED" | "ERROR";
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;

type TitleEscrow = v5Contracts.TitleEscrow;
type TradeTrustToken = v5Contracts.TradeTrustToken;
// Todo
// Deploy
// Deploy & Initialize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { providers } from "ethers";
import { ChainId, ChainInfo } from "../../../constants/chain-info";
import { ChainId } from "../../../constants/chain-info";
import { useProviderContext } from "../../contexts/provider";
import { fetchEscrowTransfersV5 } from "./fetchEscrowTransfer";

jest.mock("../../contexts/provider");

const amoyProvider = new providers.JsonRpcProvider(ChainInfo[ChainId.Amoy].rpcUrl);
const amoyProvider = new providers.JsonRpcProvider("https://rpc-amoy.polygon.technology", ChainId.Amoy);

const mockUseProviderContext = useProviderContext as jest.Mock;

Expand Down
5 changes: 3 additions & 2 deletions src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TitleEscrow, TitleEscrow__factory } from "@tradetrust-tt/token-registry/contracts";
import { v5Contracts } from "@trustvc/trustvc";
import { providers } from "ethers";
import { EventFragment, Result } from "ethers/lib/utils";
import {
Expand All @@ -7,7 +7,8 @@ import {
TokenTransferEventType,
TransferBaseEvent,
} from "../../../types";

const { TitleEscrow__factory } = v5Contracts;
type TitleEscrow = v5Contracts.TitleEscrow;
export const fetchEscrowTransfersV5 = async (
provider: providers.Provider,
address: string
Expand Down
5 changes: 3 additions & 2 deletions src/common/hooks/useEndorsementChain/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { providers } from "ethers";
import { useProviderContext } from "../../contexts/provider";
import { TradeTrustToken__factory } from "@tradetrust-tt/token-registry/dist/contracts";
// import { TradeTrustToken__factory } from "@tradetrust-tt/token-registry/dist/contracts";
import { v5Contracts } from "@trustvc/trustvc";
import { fetchEventTime, getHolderOwner, mergeTransfers, sortLogChain } from "./helpers";
import { TransferBaseEvent } from "../../../types";
import { retrieveTitleEscrowAddressOnFactory } from "../useTitleEscrowContract";
import { ChainId, ChainInfo } from "../../../constants/chain-info";

jest.mock("../../contexts/provider");

const { TradeTrustToken__factory } = v5Contracts;
const amoyProvider = new providers.JsonRpcProvider(ChainInfo[ChainId.Amoy].rpcUrl);

const mockUseProviderContext = useProviderContext as jest.Mock;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { act, renderHook } from "@testing-library/react-hooks";
import { providers } from "ethers";
import { ChainId, ChainInfo } from "../../../constants/chain-info";
import { ChainId } from "../../../constants/chain-info";
import { TokenInformationContextProvider, useTokenInformationContext } from "../../contexts/TokenInformationContext";
import { useProviderContext } from "../../contexts/provider";
import { useEndorsementChain } from "./useEndorsementChain";

jest.mock("../../contexts/provider");

const amoyProvider = new providers.JsonRpcProvider(ChainInfo[ChainId.Amoy].rpcUrl, ChainId.Amoy);
const amoyProvider = new providers.JsonRpcProvider("https://rpc-amoy.polygon.technology", ChainId.Amoy);

const mockUseProviderContext = useProviderContext as jest.Mock;

Expand Down Expand Up @@ -47,10 +47,10 @@ describe("useEndorsementChain|integration", () => {
expect(result.current.endorsementChain).toBe(undefined);
expect(result.current.pending).toBe(false);
},
{ timeout: 60000 }
{ timeout: 120_000 }
);
});
}, 60000);
}, 120_000);

it("should work correctly for a given tokenRegistryAddress + tokenId with Transfer, Surrender, Burnt events", async () => {
const { result } = renderHook(
Expand All @@ -68,11 +68,10 @@ describe("useEndorsementChain|integration", () => {
},
{ wrapper }
);

await act(async () => {
await waitFor(
() => {
expect(result.current.endorsementChain).toBeTruthy();
// expect(result.current.endorsementChain).toBeTruthy();
expect(result.current.endorsementChain).toStrictEqual([
{
type: "INITIAL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const useEndorsementChain = (
setError("");
try {
let transferEvents: TransferBaseEvent[] = [];

if (tokenRegistryVersion === TokenRegistryVersion.V5) {
const titleEscrowAddress = await retrieveTitleEscrowAddressOnFactory(tokenRegistry, tokenId, providerOrSigner);
const titleEscrowLogs = await fetchEscrowTransfersV5(provider, titleEscrowAddress);
Expand Down
4 changes: 2 additions & 2 deletions src/common/hooks/useRestoreToken.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TradeTrustToken } from "@tradetrust-tt/token-registry/contracts";
import { v5Contracts } from "@trustvc/trustvc";
import { providers, Signer } from "ethers";
import { useCallback, useEffect, useState } from "react";
import { getLogger } from "../../utils/logger";
import { UnsupportedNetworkError } from "../errors";
import { ContractFunctionState } from "./useContractFunctionHook";

const { error: errorLogger } = getLogger("services:userestoretoken");

type TradeTrustToken = v5Contracts.TradeTrustToken;
export const useRestoreToken = (
provider: providers.Provider | Signer | undefined,
contractInstance?: TradeTrustToken,
Expand Down
4 changes: 3 additions & 1 deletion src/common/hooks/useSupportsInterface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { TitleEscrow, TradeTrustToken } from "@tradetrust-tt/token-registry/dist/contracts";
import { v5Contracts } from "@trustvc/trustvc";
import { Contract } from "ethers";
import { useEffect, useState } from "react";
import { getLogger } from "../../utils/logger";
import { useContractFunctionHook } from "./useContractFunctionHook";

const { error } = getLogger("services:usesupportsinterface");
type TitleEscrow = v5Contracts.TitleEscrow;
type TradeTrustToken = v5Contracts.TradeTrustToken;

interface Erc165Contract extends Contract {
supportsInterface: (interfaceId: []) => Promise<boolean> | undefined;
Expand Down
8 changes: 4 additions & 4 deletions src/common/hooks/useTitleEscrowContract.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState, useEffect, useCallback } from "react";
import { providers, Signer } from "ethers";
import { TitleEscrowFactory__factory, TitleEscrow__factory } from "@tradetrust-tt/token-registry/contracts";
import { TitleEscrow } from "@tradetrust-tt/token-registry/contracts";
import { TradeTrustToken } from "@tradetrust-tt/token-registry/contracts";
import { v5Contracts } from "@trustvc/trustvc";
import { BurnAddress } from "../../constants/chain-info";

const { TitleEscrowFactory__factory, TitleEscrow__factory } = v5Contracts;
type TitleEscrow = v5Contracts.TitleEscrow;
type TradeTrustToken = v5Contracts.TradeTrustToken;
interface useTitleEscrowContractProps {
titleEscrow?: TitleEscrow;
documentOwner?: string;
Expand Down
4 changes: 3 additions & 1 deletion src/common/hooks/useTokenRegistryContract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { TradeTrustToken, TradeTrustToken__factory } from "@tradetrust-tt/token-registry/contracts";
import { v5Contracts } from "@trustvc/trustvc";
import { providers, Signer } from "ethers";
import { useEffect, useState } from "react";
const { TradeTrustToken__factory } = v5Contracts;
type TradeTrustToken = v5Contracts.TradeTrustToken;

export const useTokenRegistryContract = (
address?: string,
Expand Down
5 changes: 3 additions & 2 deletions src/common/hooks/useTokenRegistryRole.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { TradeTrustToken } from "@tradetrust-tt/token-registry/dist/contracts";
import { v5Contracts } from "@trustvc/trustvc";

import { BytesLike } from "ethers";
import { useEffect, useState } from "react";
import { useContractFunctionHook } from "./useContractFunctionHook";

type TradeTrustToken = v5Contracts.TradeTrustToken;
export const useTokenRegistryRole = ({
account,
role,
Expand Down
48 changes: 48 additions & 0 deletions src/common/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export const validateGtag = function () {
const isInit = typeof gtag === "function";
if (!isInit) console.warn("gtag is not initialised");
return isInit;
};
export interface GAEvent {
action: string;
category?: string;
label?: string;
value?: number;
}

export const validatePageViewEvent = function (gaEvent: GAEvent) {
const action = gaEvent.action;
if (!action) console.error("Action is required");
if (action && typeof action !== "string") console.error("Action must be a string");
};
export const gaPageView = function (gaEvent: GAEvent, gaId: string) {
if (!validateGtag()) return;
validatePageViewEvent(gaEvent);
const action: string = gaEvent.action;
gtag("event", action, {
send_to: gaId,
});
};
export const validateGaEvent = function (gaEvent: GAEvent) {
const action = gaEvent.action,
category = gaEvent.category,
label = gaEvent.label,
value = gaEvent.value;
if (!category) console.error("Category is required");
if (!action) console.error("Action is required");
if (label && typeof label !== "string") console.error("Label must be a string");
if (value && typeof value !== "number") console.error("Value must be a number");
};
export const gaEvent = function (eventData: GAEvent) {
if (!validateGtag()) return;
validateGaEvent(eventData);
const action = eventData.action,
category = eventData.category,
label = eventData.label,
value = eventData.value;
gtag("event", action, {
event_category: category,
event_label: label,
value: value,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AssetManagementActions } from "../AssetManagementActions";
import { AssetManagementForm } from "../AssetManagementForm";
import { AssetManagementTags } from "../AssetManagementTags";
import { DocumentStatus } from "../../DocumentStatus";
import { constants } from "@tradetrust-tt/token-registry";
import { v5RoleHash } from "@trustvc/trustvc";
import { useTokenRegistryRole } from "../../../common/hooks/useTokenRegistryRole";
import { AssetInformationPanel } from "../AssetInformationPanel";

Expand Down Expand Up @@ -62,12 +62,12 @@ export const AssetManagementApplication: FunctionComponent<AssetManagementApplic
const { hasRole: hasAccepterRole } = useTokenRegistryRole({
tokenRegistry,
account,
role: constants.roleHash.AccepterRole,
role: v5RoleHash.AccepterRole,
});
const { hasRole: hasRestorerRole } = useTokenRegistryRole({
tokenRegistry,
account,
role: constants.roleHash.RestorerRole,
role: v5RoleHash.RestorerRole,
});

const onDestroyToken = (remark: string = "0x") => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { act, fireEvent, render, within } from "@testing-library/react";
import React from "react";
import { whenDocumentValidAndIssuedByDns } from "../../../../../test/fixture/verifier-responses";
import { ActionSelectionForm } from "./ActionSelectionForm";
import { VerificationFragment } from "@tradetrust-tt/tt-verify";
import { VerificationFragment } from "@trustvc/trustvc";
import { WrappedOrSignedOpenAttestationDocument } from "../../../../../utils/shared";

const defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "swiper/css";
import "swiper/css/navigation";
import "swiper/css/pagination";
import { GaAction, GaCategory } from "../../types";
import { gaEvent } from "@tradetrust-tt/tradetrust-utils";
import { gaEvent } from "../../common/utils/analytics";
import { isExternalLink } from "../../utils";

interface PageLink {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CertificateDropZone } from "./CertificateDropZone";
import { Provider } from "react-redux";
import { configureStore } from "../../store";
import { states } from "../../reducers/certificate";
import { CONSTANTS } from "@tradetrust-tt/tradetrust-utils";
import { errorMessages } from "@trustvc/trustvc";
import {
whenDocumentHashInvalidAndNotIssued,
whenDocumentHashInvalid,
Expand Down Expand Up @@ -49,7 +49,7 @@ const RenderWithStore = ({ children, ...props }: any) => {
);
};

const { TYPES } = CONSTANTS;
const { TYPES } = errorMessages;

export default {
title: "Dropzone/CertificateDropZone",
Expand Down
Loading
Loading