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

Invest #3

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
18,150 changes: 100 additions & 18,050 deletions frontend/package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@date-io/date-fns": "^2.13.1",
"@emotion/react": "^11.8.2",
"@emotion/styled": "^11.8.1",
"@material-ui/core": "^4.12.3",
Expand All @@ -12,14 +13,15 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.4",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.26.1",
"ethers": "^5.6.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "^5.3.0",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.4",
"react-webcam": "^7.0.1",
"recharts": "^2.1.9",
"ethers": "^5.6.2",
"axios": "^0.21.1"
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
Binary file added frontend/public/Arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/close-bracket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/crypto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/devi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/done.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/indianWomen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/planet-earth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/rupee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/sand-timer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/smart-contracts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/target.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/thumbsUp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/us-flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/utilities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/woman-riding-a-motorbike.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/woman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion frontend/src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import LoadingScreen from "./sakti/loadingScreen/LoadingScreen";
import LocationPermission from "./sakti/locationPermission/LocationPermission";
import Overview from "./tinlake/components/overview/Overview";
import Test from "./tinlake/Test";
import SignIn from "./user/SignIn";
import DashboardMain from "./user/DashboardMain";
import Logout from "./user/Logout";
import DashboardRepayment from "./user/DashboardRepayment";
import LoanStatement from "./user/LoanStatement";
import DashboardReview from "./user/DashboardReview";
import Welcome from "./sakti/welcome/Welcome";
import LandingPage from "./investor/LandingPage";
import CompanyInfo from "./investor/CompanyInfo";
import KYC from "./investor/KYC";
import Wallet from "./investor/Wallet";
import Dashboard from "./investor/Dashboard";
import Disbursement from "./investor/Disbursement";

const Routes = () => {
return (
Expand All @@ -21,7 +34,14 @@ const Routes = () => {
<Route exact path="/token" component={Token} />
<Route exact path="/test" component={Test} />
<Route exact path="/overview" component={Overview} />
<Route exact path="/sale" component={Mobile} />
<Route exact path="/sale" component={Welcome} />
<Route exact path="/sign" component={DashboardMain} />
<Route exact path="/landing" component={LandingPage} />
<Route exact path="/info" component={CompanyInfo} />
<Route exact path="/kyc" component={KYC} />
<Route exact path="/wallet" component={Wallet} />
<Route exact path="/disbursement" component={Disbursement} />
<Route exact path="/dashboard" component={Dashboard} />
</Switch>
</BrowserRouter>
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/charts/BorrowChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const BorrowChart = () => {
return React.createElement(
AreaChart,
{
width: 450,
height: 250,
width: 400,
height: 200,
data: data,
margin: {
top: 10,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/charts/StakeChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const StakeChart = () => {
return React.createElement(
AreaChart,
{
width: 450,
height: 250,
width: 400,
height: 200,
data: data,
margin: {
top: 10,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/navbar/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const NavBar = () => {
<>
<section className="nav">
<Link to="/">
<Button variant="outlined">{" Home"}</Button>
{/* <Button variant="outlined">{" Home"}</Button> */}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this line commented?

</Link>
<Button
variant="outlined"
Expand Down
27 changes: 23 additions & 4 deletions frontend/src/components/transaction/TransactionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@ import dygnifyStaking from "../../artifacts/contracts/DygnifyStaking.sol/Dygnify
import dygnifyToken from "../../artifacts/contracts/DygnifyToken.sol/DygnifyToken.json";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add try catch in all the functions in this file

import { requestAccount } from "../navbar/NavBarHelper";

const dygnifyStakingAddress = "0xf79B8AF0D963124444A6443331D9Ba00bCfED855";
const token = "0x1546A8e7389B47d2Cf1bacE7C0ad3e0A91CAae94";
const dygnifyStakingAddress = "0x043c0B0385870AaFe42d98A2817DDA81E462Ccc9";
const token = "0x420d23b5D7B70fFEF09A6076B7Db1176472BaA37";

export async function approve(amount) {
if (amount <= 0 || amount <= "0" ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amount <= "0" this check is not correct

console.log("Amount must be greater than 0");
} else if (typeof window.ethereum !== "undefined") {
await requestAccount();
const provider = new ethers.providers.Web3Provider(window.ethereum);
console.log({ provider });
const signer = provider.getSigner();
const contract2 = new ethers.Contract(
token,
dygnifyToken.abi,
signer
);
const transaction = await contract2.approve(dygnifyStakingAddress,amount);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to use the return from approve function and proceed accordingly

await transaction.wait()
}
}

export async function stake(amount) {
if (amount <= 0 || amount <= "0" ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above regarding condition

Expand All @@ -19,8 +37,9 @@ export async function stake(amount) {
dygnifyStaking.abi,
signer
);
const transaction = await contract.stake(amount);
await transaction.wait();
const transaction1 = await contract.stake(amount);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improper naming of variable 'transaction1', variable naming needs to be corrected

await transaction1.wait();

}
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Home = () => {
const form = () => {
return (
<div className="box">

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary line addition, please remove

<Sidebar></Sidebar>
<aside className="right">
<NavBar />
Expand Down
133 changes: 121 additions & 12 deletions frontend/src/home/Token.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import { useState } from 'react';
import { ethers } from 'ethers'
import dygToken from "../artifacts/contracts/DygnifyToken.sol/DygnifyToken.json";
import NFTMinter from "../artifacts/contracts/NFT_minter.sol/NFTMinter.json";
import axiosHttpService from '../services/axioscall';
import uploadFileToIPFS from '../services/PinataIPFSOptions';
import { uploadFileToIPFS } from '../services/PinataIPFSOptions';
import { amlCheck } from '../services/OFACAxiosOptions';
import axios from 'axios';

const tokenAddress = "0x1546A8e7389B47d2Cf1bacE7C0ad3e0A91CAae94"
const NFT_minter = "0xbEfC9040e1cA8B224318e4f9BcE9E3e928471D37"

//metadata to ipfs
const pinJSONToIPFS = async (JSONBody) => {
const url = `https://api.pinata.cloud/pinning/pinJSONToIPFS`;
//making axios POST request to Pinata ⬇️
return axios
.post(url, JSONBody, {
headers: {
pinata_api_key: process.env.REACT_APP_PINATA_API_KEY,
pinata_secret_api_key: process.env.REACT_APP_PINATA_API_SECRET,
}
})
.then(function (response) {
return {
success: true,
pinataUrl: "https://gateway.pinata.cloud/ipfs/" + response.data.IpfsHash
};
})
.catch(function (error) {
console.log(error)
return {
success: false,
message: error.message,
}

});
};

function Token() {
const [userAccount, setUserAccount] = useState();
const [amount, setAmount] = useState();
const [selectedFile, setSelectedFile] = useState();
const [tokenURI, setTokenURI] = useState("");
const [nameForAMLCheck, setNameForAMLCheck] = useState("");

async function requestAccount() {
await window.ethereum.request({ method: 'eth_requestAccounts' });
Expand Down Expand Up @@ -49,15 +82,81 @@ function Token() {
}
}

async function mint_NFT(tokenURI) {
if (typeof window.ethereum !== 'undefined') {
await requestAccount()
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const contract = new ethers.Contract(NFT_minter, NFTMinter.abi, signer);
const transaction = await contract.mint(tokenURI);
await transaction.wait();
console.log(`${tokenURI} has minted sucessfully.`);
alert(`${tokenURI} has minted sucessfully.`);
}
}

// On file upload (click the upload button)
async function onFileUpload () {
try {
console.log("Upload called");
let ipfsUploadRes = await axiosHttpService(uploadFileToIPFS(selectedFile));
console.log(ipfsUploadRes);
} catch (error) {
console.log(error);
async function onFileUpload() {
try {
console.log("Upload called");
let ipfsUploadRes = await axiosHttpService(uploadFileToIPFS(selectedFile));
console.log(ipfsUploadRes);
//make metadata
const metadata = new Object();
metadata.imageHash = ipfsUploadRes.res.IpfsHash;
metadata.PinSize = ipfsUploadRes.res.PinSize;
metadata.Timestamp = ipfsUploadRes.res.Timestamp;

//make pinata call
const pinataResponse = await pinJSONToIPFS(metadata);
if (!pinataResponse.success) {
return {
success: false,
status: "😢 Something went wrong while uploading your tokenURI.",
}
}
const tokenURI = pinataResponse.pinataUrl;
console.log(tokenURI)
setTokenURI(tokenURI)
} catch (error) {
console.log(error);
}
};

async function onCheckAML(name) {
try {
console.log("onCheckAML called");
if (!name) {
return;
}
let amlCheckRes = await axiosHttpService(amlCheck(name));
console.log("Status " + amlCheckRes.code);
console.log("Body" + amlCheckRes.res);
console.log("Error " + amlCheckRes.res["error"]);
if (amlCheckRes.code === 200 && amlCheckRes.res["error"] === false) {
if (amlCheckRes.res["matches"][name][0] &&
amlCheckRes.res["matches"][name][0]["score"] >= process.env.REACT_APP_OFAC_MIN_SCORE) {
return true;
} else {
return false;
}
} else {
return;
}
} catch (error) {
console.log(error);
}
}

// On file upload (click the upload button)
async function onFileUpload() {
try {
console.log("Upload called");
let ipfsUploadRes = await axiosHttpService(uploadFileToIPFS(selectedFile));
console.log(ipfsUploadRes);
} catch (error) {
console.log(error);
}
};

return (
Expand All @@ -69,10 +168,20 @@ function Token() {
<input onChange={e => setUserAccount(e.target.value)} placeholder="Account ID" />
<input onChange={e => setAmount(e.target.value)} placeholder="Amount" />
<button onClick={approveSendCoins}>Approve</button>
<input type="file" onChange={ (event) => setSelectedFile(event.target.files[0]) }/>
<button onClick={onFileUpload}>
Upload!
</button>
<input type="file" onChange={(event) => setSelectedFile(event.target.files[0])} />
<button onClick={onFileUpload}>
Upload
</button>
<h5 style={{ textAlign: "center" }}>{tokenURI === "" ? <h5 >Upload your NFT before minting</h5> : tokenURI}</h5>
<input type="text" onChange={(event) => setTokenURI(event.target.value)} />
<button onClick={() => mint_NFT(tokenURI)}>
Mint
</button>
<br />
<input type="text" onChange={(event) => setNameForAMLCheck(event.target.value)} />
<button onClick={() => onCheckAML(nameForAMLCheck)}>
Check
</button>
</header>
</div>
);
Expand Down
Loading