Skip to content

Commit

Permalink
docs(cbdc-example): remove unused variables and unused code
Browse files Browse the repository at this point in the history
* Created new Docker Image and updated README.md

Signed-off-by: André Augusto <[email protected]>
  • Loading branch information
AndreAugusto11 authored and RafaelAPB committed Sep 17, 2024
1 parent 47bc45e commit 3ad9c6c
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 262 deletions.
6 changes: 6 additions & 0 deletions examples/cactus-example-cbdc-bridging-frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
rules: {
"@typescript-eslint/no-explicit-any": "off",
},
};
17 changes: 12 additions & 5 deletions examples/cactus-example-cbdc-bridging-frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@

### Using a pre-built image

`docker run -p 2000:2000 aaugusto11/cactus-example-cbdc-bridging-frontend`
`docker run -p 2000:2000 aaugusto11/cactus-example-cbdc-bridging-frontend:v2`

### Building the image
### Building the image locally

```docker build -t cbdc-app-frontend .
docker run -p 2000:2000 cbdc-app-frontend```
```
docker build -t cbdc-app-frontend .
## `npm start`
docker run -p 2000:2000 cbdc-app-frontend
```

### Running in debug mode

```
npm start
```

Runs the app in the development mode.\
Open [http://localhost:2000](http://localhost:2000) to view it in the browser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import CryptoMaterial from "../crypto-material/crypto-material.json";
import { getEthAddress, getEthUserPrKey } from "./common";

const BESU_CONTRACT_CBDC_ERC20_NAME = "SATPContract";
const BESU_CONTRACT_WRAPPER_NAME = "SATPWrapperContract";

export async function authorizeNTokensBesu(
frontendUserFrom: string,
Expand Down Expand Up @@ -94,122 +93,6 @@ export async function transferTokensBesu(
}
}

/*
export async function escrowTokensBesu(
frontendUserFrom: string,
amount: number,
assetRefID: string,
) {
const from = getEthAddress(frontendUserFrom);
await axios.post(
"http://localhost:4100/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract",
{
contractName: BESU_CONTRACT_CBDC_ERC20_NAME,
invocationType: "SEND",
methodName: "escrow",
gas: 1000000,
params: [amount, assetRefID],
signingCredential: {
ethAccount: from,
secret: getEthUserPrKey(frontendUserFrom),
type: "PRIVATE_KEY_HEX",
},
keychainId: CryptoMaterial.keychains.keychain2.id,
},
);
}
*/

export async function getAssetReferencesBesu(frontendUser: string) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const from = getEthAddress(frontendUser);
try {
const response = await axios.post(
"http://localhost:4100/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract",
{
contractName: BESU_CONTRACT_WRAPPER_NAME,
invocationType: "CALL",
methodName: "getAllAssets",
gas: 1000000,
params: [],
signingCredential: {
ethAccount: CryptoMaterial.accounts.bridge.ethAddress,
secret: getEthUserPrKey("bridge"),
type: "PRIVATE_KEY_HEX",
},
keychainId: CryptoMaterial.keychains.keychain2.id,
},
);

return response.data.callOutput.map((asset: any) => {
return {
id: asset[2],
numberTokens: asset[4],
owner: getUserFromEthAddress(asset[3]),
};
});
} catch (error) {
console.error(error);
return [];
}
}

/*
export async function bridgeBackTokensBesu(
frontendUser: string,
amount: number,
assetRefID: string,
) {
const address = getEthAddress(frontendUser);
const fabricID = getFabricId(frontendUser);
const assetProfile = {
expirationDate: new Date(2060, 11, 24).toString(),
issuer: "CB1",
assetCode: "CBDC1",
// since there is no link with the asset information,
// we are just passing the asset parameters like this
// [amountBeingTransferred, fabricID, ethAddress]
keyInformationLink: [amount.toString(), fabricID, address],
};
await axios.post(
"http://localhost:4100/api/v1/@hyperledger/cactus-plugin-satp-hermes/clientrequest",
{
clientGatewayConfiguration: {
apiHost: `http://localhost:4100`,
},
serverGatewayConfiguration: {
apiHost: `http://localhost:4000`,
},
version: "0.0.0",
loggingProfile: "dummyLoggingProfile",
accessControlProfile: "dummyAccessControlProfile",
applicationProfile: "dummyApplicationProfile",
payloadProfile: {
assetProfile,
capabilities: "",
},
assetProfile: assetProfile,
assetControlProfile: "dummyAssetControlProfile",
beneficiaryPubkey: "dummyPubKey",
clientDltSystem: "DLT2",
originatorPubkey: "dummyPubKey",
recipientGatewayDltSystem: "DLT1",
recipientGatewayPubkey: CryptoMaterial.gateways["gateway1"].publicKey,
serverDltSystem: "DLT1",
sourceGatewayDltSystem: "DLT2",
clientIdentityPubkey: "",
serverIdentityPubkey: "",
maxRetries: 5,
maxTimeout: 5000,
sourceLedgerAssetID: assetRefID,
recipientLedgerAssetID: "FABRIC_ASSET_ID",
},
);
}
*/
export async function getBesuBalance(frontendUser: string) {
const userEthAddress = getEthAddress(frontendUser);

Expand Down Expand Up @@ -261,7 +144,7 @@ export async function mintTokensBesu(user: string, amount: number) {
}
}

function getUserFromEthAddress(ethAddress: string) {
export function getUserFromEthAddress(ethAddress: string) {
switch (ethAddress) {
case CryptoMaterial.accounts["userA"].ethAddress:
return "Alice";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export async function getFabricBalance(frontendUser: string) {
},
);
} catch (error) {
//TODO fix
console.error(error.msg);
return -1;
}

Expand Down Expand Up @@ -83,86 +81,7 @@ export async function transferTokensFabric(
console.error(error);
}
}
/*
export async function escrowTokensFabric(
frontendUser: string,
amount: string,
assetRefID: string,
) {
const response = await axios.post(
"http://localhost:4000/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/run-transaction",
{
contractName: FABRIC_CONTRACT_CBDC_ERC20_NAME,
channelName: FABRIC_CHANNEL_NAME,
params: [amount.toString(), assetRefID],
methodName: "Escrow",
invocationType: "FabricContractInvocationType.SEND",
signingCredential: {
keychainId: CryptoMaterial.keychains.keychain1.id,
keychainRef: getUserFromPseudonim(frontendUser),
},
},
);

if (response.status === 200) {
// throw error
}
}*/
/*
export async function bridgeOutTokensFabric(
frontendUser: string,
amount: string,
assetRefID: string,
) {
const fabricID = getFabricId(frontendUser);
const address = getEthAddress(frontendUser);
const assetProfile = {
expirationDate: new Date(2060, 11, 24).toString(),
issuer: "CB1",
assetCode: "CBDC1",
// since there is no link with the asset information,
// we are just passing the asset parameters like this
// [amountBeingTransferred, fabricID, ethAddress]
keyInformationLink: [amount.toString(), fabricID, address],
};
await axios.post(
"http://localhost:4000/api/v1/@hyperledger/cactus-plugin-satp-hermes/clientrequest",
{
clientGatewayConfiguration: {
apiHost: `http://localhost:4000`,
},
serverGatewayConfiguration: {
apiHost: `http://localhost:4100`,
},
version: "0.0.0",
loggingProfile: "dummyLoggingProfile",
accessControlProfile: "dummyAccessControlProfile",
applicationProfile: "dummyApplicationProfile",
payloadProfile: {
assetProfile,
capabilities: "",
},
assetProfile: assetProfile,
assetControlProfile: "dummyAssetControlProfile",
beneficiaryPubkey: "dummyPubKey",
clientDltSystem: "DLT1",
originatorPubkey: "dummyPubKey",
recipientGatewayDltSystem: "DLT2",
recipientGatewayPubkey: CryptoMaterial.gateways["gateway2"].publicKey,
serverDltSystem: "DLT2",
sourceGatewayDltSystem: "DLT1",
clientIdentityPubkey: "",
serverIdentityPubkey: "",
maxRetries: 5,
maxTimeout: 5000,
sourceLedgerAssetID: assetRefID,
recipientLedgerAssetID: "FABRIC_ASSET_ID",
},
);
}
*/
export async function getAssetReferencesFabric(
frontendUser: string,
): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import axios from "axios";
import CryptoMaterial from "../crypto-material/crypto-material.json";
import { getEthAddress, getEthUserPrKey } from "./common";
import { getUserFromPseudonim, getFabricId } from "./common";
import { getEthAddress, getFabricId } from "./common";
import {
createSessionReference,
SessionReference,
} from "../models/SessionReference";

import BesuSATPInteraction from "../ontology/besu-erc20-ontology.json";
import FabricSATPInteraction from "../ontology/fabric-erc20-ontology.json";
import { uuidV4 } from "web3-utils";

const FABRIC_CHANNEL_NAME = "mychannel";
const CONTRACT_CBDC_ERC20_NAME = "SATPContract";
const CONTRACT_WRAPPER_NAME = "SATPWrapperContract";

export async function getSessionReferencesBridge(port: string): Promise<any> {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { useState, useEffect } from "react";
import Paper from "@mui/material/Paper";
import Grid from "@mui/material/Grid";
Expand All @@ -13,36 +12,6 @@ import { SessionReference } from "../models/SessionReference";
import { NormalButton } from "./buttons/NormalButton";
import { CriticalButton } from "./buttons/CriticalButton";

// const NormalButton = styled(Button)<ButtonProps>(({ theme }) => ({
// margin: "auto",
// width: "100%",
// fontSize: "13px",
// textTransform: "none",
// background: "#2B9BF6",
// color: "#FFFFFF",
// border: "0.5px solid #000000",
// "&:disabled": {
// border: "0",
// },
// }));

// const CriticalButton = styled(Button)<ButtonProps>(({ theme }) => ({
// margin: "auto",
// width: "100%",
// fontSize: "13px",
// textTransform: "none",
// background: "#FF584B",
// color: "#FFFFFF",
// border: "0.5px solid #000000",
// "&:hover": {
// backgroundColor: "#444444",
// color: "#FFFFFF",
// },
// "&:disabled": {
// border: "0",
// },
// }));

export interface IActionsContainerOptions {
user: string;
ledger: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CircularProgress from "@mui/material/CircularProgress";
import { getSessionReferencesBridge } from "../api-calls/gateway-api";
import { fetchAmountApprovedToBridge as fetchAmountApprovedToBridgeFabric } from "../api-calls/fabric-api";
import { fetchAmountApprovedToBridge as fetchAmountApprovedToBridgeBesu } from "../api-calls/besu-api";
import AssetReferencesTable from "./AssetReferencesTable";
import SessionReferencesTable from "./SessionReferencesTable";
import ApprovalsTable from "./ApprovalsTable";

export interface ILedgerOptions {
Expand Down Expand Up @@ -92,7 +92,7 @@ export default function Ledger(props: ILedgerOptions) {
/>
)}
<p>Sessions Status</p>
<AssetReferencesTable
<SessionReferencesTable
ledger={props.ledger}
sessionRefs={sessionReferences}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { useState, useEffect } from "react";
import Grid from "@mui/material/Grid";
import Ledger from "../components/Ledger";
import {
checkApiServer1Connection,
checkApiServer2Connection,
} from "../api-calls/common";
// import {
// checkApiServer1Connection,
// checkApiServer2Connection,
// } from "../api-calls/common";
import IconButton from "@mui/material/IconButton";
import HelpIcon from "@mui/icons-material/Help";
import ConnectionErrorDialog from "../components/dialogs/ConnectionErrorDialog";

export default function HomePage() {
const [errorDialog, setErrorDialog] = useState<boolean>(false);

/*useEffect(() => {
const checkConnection = async () => {
await checkApiServer1Connection()
.then(() => setErrorDialog(false))
.catch(() => setErrorDialog(true));
await checkApiServer2Connection()
.then(() => setErrorDialog(false))
.catch(() => setErrorDialog(true));
};
checkConnection();
}, []);*/
useEffect(() => {
// const checkConnection = async () => {
// await checkApiServer1Connection()
// .then(() => setErrorDialog(false))
// .catch(() => setErrorDialog(true));
// await checkApiServer2Connection()
// .then(() => setErrorDialog(false))
// .catch(() => setErrorDialog(true));
// };
// checkConnection();
}, []);

return (
<div style={{ width: "95%", margin: "4rem auto" }}>
Expand Down

Large diffs are not rendered by default.

0 comments on commit 3ad9c6c

Please sign in to comment.