diff --git a/README.md b/README.md index a3dff81..67f4cac 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,11 @@ - [Questions](#Questions) ## About the Project +In this project, we created an application that helps inexperienced investors to learn investing without risking their hard earned money. To be able to use the app, a user has to sign up first. Up on sign up, a user will be given $10,000 fake free money that can be used to buy shares. A user will have access to the latest business news to be able to make decision of buying or selling. A user also can search companies by name to be able to get detailed information about the company a user would wish to search. If a user wouldn't like to buy, he/she will be given an option to put the company under a watch list. Any company under a watchlist can be removed when a user wishes to do so. +For each purchased share, the app shows current price, todays share price movement in graph and the gain or loss of money from owning that share. + +The app also displays, total money a user has from owning shares. The trend for the combined investin money is also displayed for different time spans. ## Usage Run the following commands in your terminal diff --git a/client/src/components/Form/index.js b/client/src/components/Form/index.js index abc272c..5e5ba9b 100644 --- a/client/src/components/Form/index.js +++ b/client/src/components/Form/index.js @@ -14,6 +14,8 @@ export default function PurchaseForm() { const [currentPrice, setCurrentPrice] = useState(); const [buyOrSell, setbuyOrSell] = useState("buy"); const [error, setError] = useState(); + const [success, setSuccess] = useState(); + const [message, setMessage] = useState(); const [userBalance, setUserBalance] = useState(0) const [stocksPortfolio, setStocksPortfolio] = useState([]) const [foundStock, setfoundStock] = useState("") @@ -41,7 +43,7 @@ export default function PurchaseForm() { setFormObject({ ...formObject, [name]: value }) // GetCurrentPrice(formObject.symbol) let newArr = stocksPortfolio.filter(stock => { - console.log(stock.symbol === formObject.symbol.toUpperCase().trim()) + // console.log(stock.symbol === formObject.symbol.toUpperCase().trim()) return stock.symbol === formObject.symbol.toUpperCase().trim() }); if (newArr.length) { @@ -78,7 +80,7 @@ export default function PurchaseForm() { console.log(stocksPortfolio) if (buyOrSell === "buy") { if (calculateTotal() > userBalance) { - setError(`You don't have enough money. Your balance is ${userBalance}`) + setMessage(`You don't have enough money. Your balance is ${userBalance}`) } else { API.saveBuyTransaction({ @@ -90,17 +92,18 @@ export default function PurchaseForm() { .then(res => console.log(res)) .catch(err => console.log(err)) - history.push("/gamestock/user") + setMessage(`Successfully bought ${formObject.amount} ${formObject.symbol.toUpperCase().trim()} shares`) + // history.push("/gamestock/user") } } if (buyOrSell === "sell") { console.log(foundStock) console.log(numberOfStocks) if (foundStock === "") { - setError(`You don't own any ${formObject.symbol.toUpperCase().trim()} shares`) + setMessage(`You don't own any ${formObject.symbol.toUpperCase().trim()} shares`) } else if (parseInt(formObject.amount) > parseInt(numberOfStocks)) { - setError(`You only have ${numberOfStocks} ${formObject.symbol.toUpperCase().trim()} shares to sell`) + setMessage(`You only have ${numberOfStocks} ${formObject.symbol.toUpperCase().trim()} shares to sell`) } else { API.saveSellTransaction({ email: currentUser.email, @@ -110,8 +113,8 @@ export default function PurchaseForm() { }) .then(data => console.log("selling info", data)) .catch(err => console.log(err)) - - history.push("/gamestock/user") + setMessage(`Successfully sold ${formObject.amount} ${formObject.symbol.toUpperCase().trim()} shares`) + // history.push("/gamestock/user") } } } @@ -121,7 +124,7 @@ export default function PurchaseForm() {

Trading Desk: Trade Shares Here

- {error && {error}} + {message && {message}}
Symbol @@ -137,7 +140,7 @@ export default function PurchaseForm() { name="amount" onChange={handleInputChange} /> -
Total: {calculateTotal()}
+
Total: {formObject.symbol && formObject.amount ? calculateTotal(): ""}