diff --git a/package.json b/package.json index 5d4a79c..624e626 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/App.js b/src/App.js index 0948b97..56cfe80 100644 --- a/src/App.js +++ b/src/App.js @@ -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); @@ -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(); @@ -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 @@ -85,6 +90,10 @@ function App() { setUsdBalance(USDBalance); } catch (error) { console.log(error); + notification.addNotification({ + message: "Error Occurred", + level: "error", + }); } }; @@ -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) @@ -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 = []; @@ -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"); } }); @@ -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) @@ -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, @@ -217,6 +248,10 @@ function App() { getLoans(); } catch (error) { console.log(error); + notification.addNotification({ + message: "Could not redeem Loan", + level: "error", + }); } }; @@ -244,6 +279,7 @@ function App() { )} + ); } diff --git a/src/contracts/Monyara.sol b/src/contracts/Monyara.sol index 88a2905..fb059ed 100644 --- a/src/contracts/Monyara.sol +++ b/src/contracts/Monyara.sol @@ -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"); _; } @@ -75,7 +75,7 @@ contract Loan { require( IERC20Token(cUsdTokenAddress).transferFrom( msg.sender, - bankAddress, + address(this), loanRegistrationAmount ), "Error during Loan Registration" @@ -135,7 +135,7 @@ contract Loan { LoanDetails storage singleLoan = loan[_index]; require( IERC20Token(cUsdTokenAddress).transferFrom( - bankAddress, + address(this), singleLoan.borrowerAddress, singleLoan.amount ), @@ -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" @@ -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;