Skip to content

Commit

Permalink
Merge pull request #175 from seattletrade/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Myau5x authored Feb 27, 2021
2 parents af10dce + f28527f commit 64b2194
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions client/src/components/Form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand All @@ -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")
}
}
}
Expand All @@ -121,7 +124,7 @@ export default function PurchaseForm() {
<Card>
<Card.Body>
<h1 className="text-center mb-4 text-white" style={{ backgroundColor: "#FD0000" }}>Trading Desk: Trade Shares Here</h1>
{error && <Alert variant="danger">{error}</Alert>}
{message && <Alert variant="info">{message}</Alert>}
<Form >
<Form.Group id="symbol">
<Form.Label>Symbol</Form.Label>
Expand All @@ -137,7 +140,7 @@ export default function PurchaseForm() {
name="amount"
onChange={handleInputChange}
/>
<div id="previewTotal" className="form-text text-muted">Total: {calculateTotal()}</div>
<div id="previewTotal" className="form-text text-muted">Total: {formObject.symbol && formObject.amount ? calculateTotal(): ""}</div>
</Form.Group>

<label>
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Nav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export default function Nav() {
.then(data => setNickname(data.data.nickName))
}
// console.log(currentUser)
}, [])
}, [currentUser])

useEffect(() => {

}, [nickname]
)
}, [nickname])


const handleLogout = async () => {
setError('')
Expand Down

0 comments on commit 64b2194

Please sign in to comment.