Skip to content
Open
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.3.0",
"react-flash-message": "^1.0.7",
"react-notification-system": "0.2.x",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
Expand Down
38 changes: 37 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const ERC20_DECIMALS = 18;
const monyaraContractAddress = "0xb68dF09062c055ff163645c428dcfc05b46812Cb";
const cUSDContractAddress = "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1";

import NotificationSystem from "react-notification-system";


function App() {
const [usdBalance, setUsdBalance] = useState(0);
const [contract, setcontract] = useState(null);
Expand All @@ -28,6 +31,8 @@ function App() {
const [loans, setLoans] = useState([]);
const [myLoans, setMyLoans] = useState([]);
const [isAdmin, setIsAdmin] = useState(false);
const notificationSystem = React.createRef();

// UseEffects
useEffect(() => {
connectWallet();
Expand Down Expand Up @@ -73,10 +78,10 @@ function App() {
};

const getUSDBalance = async () => {
const notification = notificationSystem.current;
try {
const balance = await kit.getTotalBalance(address);
const USDBalance = balance.cUSD.shiftedBy(-ERC20_DECIMALS).toFixed(2);
console.log(USDBalance);
const contract = new kit.web3.eth.Contract(
monyaraAbi,
monyaraContractAddress
Expand All @@ -85,6 +90,10 @@ function App() {
setUsdBalance(USDBalance);
} catch (error) {
console.log(error);
notification.addNotification({
message: "Error Occurred",
level: "error",
});
}
};

Expand All @@ -98,6 +107,7 @@ function App() {
_duration
) => {
const cUSDContract = new kit.web3.eth.Contract(IERC20, cUSDContractAddress);
const notification = notificationSystem.current;
try {
const loanRegistrationAmount = new BigNumber(1)
.shiftedBy(ERC20_DECIMALS)
Expand All @@ -121,10 +131,16 @@ function App() {
getLoans();
} catch (error) {
console.log(error);
notification.addNotification({
message: "Checking If Admin...Please wait",
level: "info",
});
}
};

const getLoans = async () => {
const notification = notificationSystem.current;

try {
const loanLength = await contract.methods.getLoanLength().call();
const _loans = [];
Expand All @@ -148,6 +164,10 @@ function App() {
timestamp: loan[10],
});
} catch (error) {
notification.addNotification({
message: "User is not admin",
level: "error",
});
console.log("User is not Admin");
}
});
Expand All @@ -173,6 +193,7 @@ function App() {
};

const verifyLoan = async (loan) => {
const notification = notificationSystem.current;
const cUSDContract = new kit.web3.eth.Contract(IERC20, cUSDContractAddress);
const loanAmount = new BigNumber(loan.amount)
.shiftedBy(ERC20_DECIMALS)
Expand All @@ -186,21 +207,31 @@ function App() {
.send({ from: address });
getLoans();
} catch (error) {
notification.addNotification({
message: "Could not verify loan",
level: "error",
});
console.log(error);
}
};
const unverifyLoan = async (loan) => {
const notification = notificationSystem.current;
try {
await contract.methods
.unVerifyApplicant(loan.index)
.send({ from: address });
getLoans();
} catch (error) {
notification.addNotification({
message: "Could not unverify Loan",
level: "error",
});
console.log(error);
}
};

const redeemLoan = async (loan) => {
const notification = notificationSystem.current;
try {
const cUSDContract = new kit.web3.eth.Contract(
IERC20,
Expand All @@ -217,6 +248,10 @@ function App() {
getLoans();
} catch (error) {
console.log(error);
notification.addNotification({
message: "Could not redeem Loan",
level: "error",
});
}
};

Expand Down Expand Up @@ -244,6 +279,7 @@ function App() {
)}
</Route>
</Switch>
<NotificationSystem ref={notificationSystem} />
</Router>
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/contracts/Monyara.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract Loan {
address internal bankAddress = 0xb7BF999D966F287Cd6A1541045999aD5f538D3c6;

modifier isAdmin(uint256 _id) {
require(msg.sender == bankAddress, "Accessible only to the admin");
require(msg.sender == address(this), "Accessible only to the admin");
_;
}

Expand All @@ -75,7 +75,7 @@ contract Loan {
require(
IERC20Token(cUsdTokenAddress).transferFrom(
msg.sender,
bankAddress,
address(this),
loanRegistrationAmount
),
"Error during Loan Registration"
Expand Down Expand Up @@ -135,7 +135,7 @@ contract Loan {
LoanDetails storage singleLoan = loan[_index];
require(
IERC20Token(cUsdTokenAddress).transferFrom(
bankAddress,
address(this),
singleLoan.borrowerAddress,
singleLoan.amount
),
Expand All @@ -154,7 +154,7 @@ contract Loan {
require(
IERC20Token(cUsdTokenAddress).transferFrom(
msg.sender,
bankAddress,
address(this),
(singleLoan.amount + singleLoan.amount * 1 / 10)
),
"Did not reedem loan"
Expand All @@ -163,7 +163,7 @@ contract Loan {
}

function isUserAdmin(address _address) public view returns (bool) {
if (_address == bankAddress) {
if (_address == address(this)) {
return true;
}
return false;
Expand Down