From 0889182f4dd1de28b33d2ec78d9c798e3236506c Mon Sep 17 00:00:00 2001 From: Daniel Ogbuti Date: Thu, 31 Mar 2022 15:42:16 +0100 Subject: [PATCH] changed files --- src/App.js | 49 ++++++++++++++++++++++++++----------------- src/contract/card.sol | 3 +++ src/index.js | 1 - 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/App.js b/src/App.js index dcb7fc8..e219f97 100644 --- a/src/App.js +++ b/src/App.js @@ -104,20 +104,26 @@ export default function App() { await contract.methods .createCard(number, description, image, price) .send({ from: address }); + getBalance() + getCards() } catch (error) { console.log(error); } }; const buyCard = async (_index) => { - const amount = cards[_index].amount / ( 10 ** 18); + const amount = cards[_index].amount / 10 ** 18; console.log(amount); - const price = new BigNumber(amount * 3).shiftedBy(ERC20_DECIMALS).toString(); + const price = new BigNumber(amount * 3) + .shiftedBy(ERC20_DECIMALS) + .toString(); try { await cUSDContract.methods .approve(contractAddress, price) .send({ from: address }); await contract.methods.buyCard(_index).send({ from: address }); + getBalance() + getCards() } catch (error) { console.log(error); } @@ -129,6 +135,7 @@ export default function App() { await contract.methods .giftCard(_index, giftAddress) .send({ from: address }); + getCards() } catch (error) { console.log(error); } @@ -185,7 +192,7 @@ export default function App() {
diff --git a/src/contract/card.sol b/src/contract/card.sol index 67d77f8..18d6fe3 100644 --- a/src/contract/card.sol +++ b/src/contract/card.sol @@ -56,7 +56,9 @@ contract GiftCard{ cardLength++; } + function buyCard(uint _index)public payable{ + require(msg.sender != cards[_index].owner, "Cannot be owner"); require( IERC20Token(cUsdTokenAddress).transferFrom( msg.sender, @@ -69,6 +71,7 @@ contract GiftCard{ } function giftCard(uint _index, address _address)public payable{ + require(msg.sender == cards[_index].owner, "must be be owner"); cards[_index].owner = payable(_address); } diff --git a/src/index.js b/src/index.js index 0ffd837..62adcf3 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; -import reportWebVitals from './reportWebVitals'; ReactDOM.render(