-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect to api for price tickers in nav bar
- Loading branch information
1 parent
a18941c
commit 2a70ab9
Showing
3 changed files
with
63 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,60 @@ | ||
import React from 'react'; | ||
// import {getCurrentPrice} from "../actions/index"; | ||
// import {connect} from 'react-redux'; | ||
|
||
import './nav-bar.css'; | ||
|
||
export function NavBar() { | ||
return ( | ||
<nav className="nav-container"> | ||
<div className="nav-content"> | ||
<div className="nav-title">the creative crypto</div> | ||
<div className="nav-right"> | ||
<div className="steem-price"> | ||
<span className="steem-label">STEEM</span> ∧ $ 2.90 | ||
</div> | ||
<div className="sbd-price"> | ||
<span className="sbd-label">SBD</span> ∨ $ 1.05 | ||
export class NavBar extends React.Component { | ||
state = { | ||
steemPrice: 0, | ||
steemDirection: '\u2303', | ||
sbdPrice: 0, | ||
sbdDirection: '\u2303' | ||
}; | ||
|
||
async componentDidMount() { | ||
const steemPriceData = await this.getPrice('steem'); | ||
const steemDirection = parseFloat(steemPriceData[0].percent_change_1h) < 0 ? '\u2304' : '\u2303'; | ||
const steemPrice = parseFloat(steemPriceData[0].price_usd).toFixed(2); | ||
|
||
const sbdPriceData = await this.getPrice('steem-dollars'); | ||
const sbdDirection = parseFloat(sbdPriceData[0].percent_change_1h) < 0 ? '\u2304' : '\u2303'; | ||
const sbdPrice = parseFloat(sbdPriceData[0].price_usd).toFixed(2); | ||
|
||
this.setState({ | ||
steemPrice, | ||
sbdPrice | ||
}) | ||
} | ||
|
||
async getPrice(name) { | ||
const response = await fetch(`https://api.coinmarketcap.com/v1/ticker/${name}/`); | ||
const data = await response.json(); | ||
return data; | ||
} | ||
|
||
render() { | ||
return ( | ||
<nav className="nav-container"> | ||
<div className="nav-content"> | ||
<div className="nav-title">the creative crypto</div> | ||
<div className="nav-right"> | ||
<div className="steem-price"> | ||
<span className="steem-label">STEEM</span> {this.state.steemDirection} $ {this.state.steemPrice} | ||
</div> | ||
<div className="sbd-price"> | ||
<span className="sbd-label">SBD</span> {this.state.sbdDirection} $ {this.state.sbdPrice} | ||
</div> | ||
<div className="question-button">?</div> | ||
</div> | ||
<div className="question-button">?</div> | ||
</div> | ||
</div> | ||
</nav> | ||
) | ||
} | ||
</nav> | ||
) | ||
} | ||
} | ||
|
||
// const mapDispatchToProps = { | ||
// getCurrentPrice | ||
// }; | ||
// | ||
// export const ConnectedNavBar = connect(mapDispatchToProps)(NavBar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters