Skip to content

Commit

Permalink
Use CC Proxy for Price Data (#20)
Browse files Browse the repository at this point in the history
* new enpoint, attempt to use new format

* Change date-time format

* Remove extra console log

* Fix xmr graph date-time formatting

* Fix graph media queries

* Rename variable & update type
  • Loading branch information
dternyak authored Jun 4, 2018
1 parent 043e1da commit a67d235
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/app/details/block-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export class BlockDetailsClass extends React.Component<Props, State> {
<div className="Details-header">
<h1 className="Details-header-title">Block Details</h1>
<div className="flex-spacer" />
<p className="Details-header-timestamp">{formatApiDateStrings(block.timestamp)}</p>
<p className="Details-header-timestamp">
{formatApiDateStrings(block.timestamp_utc)}
</p>
</div>
<div className="Details-body">
<div className="Details-body-section">
Expand Down
2 changes: 1 addition & 1 deletion src/app/details/details.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
font-size: 1.1rem;
&:first-child {
color: $blue-gray-light;
font-size: .9rem;
font-size: 0.9rem;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/details/tx-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class TxDetailsClass extends React.Component<Props, State> {
<Tag type="coinbase" text="COINBASE" />
) : null}
<div className="Details-header-timestamp">
{formatApiDateStrings(transaction.timestamp)}
{formatApiDateStrings(transaction.timestamp_utc)}
</div>
</div>
<div className="Details-body">
Expand Down
4 changes: 2 additions & 2 deletions src/app/home/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
display: block;
font-size: 1rem;
font-weight: 500;
color: #72BAC4;
color: #72bac4;
}
&-graph {
margin: 0.5rem 0;
Expand All @@ -47,7 +47,7 @@
width: 133%;
}

@media screen and (max-width: 900px) {
@media screen and (max-width: 1016px) {
flex-wrap: wrap;
flex-direction: column-reverse;

Expand Down
4 changes: 2 additions & 2 deletions src/app/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export class Home extends React.Component {
const clientWidth = document.documentElement.clientWidth;
// take rem into account when adjusting width for padding
const width =
clientWidth < 900 ? (clientWidth > 600 ? clientWidth - 32 : clientWidth - 26) : 400;
const height = clientWidth > 600 && clientWidth < 900 ? 150 : 100;
clientWidth <= 1016 ? (clientWidth > 600 ? clientWidth - 64 : clientWidth - 26) : 400;
const height = clientWidth > 600 && clientWidth <= 1016 ? 150 : 100;
// adjust for border width
this.setState({ width: width - 2, height });
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/line-graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export class LineGraph extends React.Component<Props, State> {
);

public getDate = (point: Point) => {
return moment(point[2]).format('MMM DD, LT');
const date = point[2];
return moment.unix(date).format('MMM DD, LT');
};

public render() {
Expand Down
12 changes: 6 additions & 6 deletions src/components/line-graph/xmr/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class MoneroGraph extends React.Component<Props, State> {

public fetchData = () => {
this.setState({ fetchingData: true });
fetchAsync('https://coincap.io/history/1day/XMR')
fetchAsync('https://proxy.mycryptoapi.com/mv')
.then((json: any) => {
if (json) {
this.setState({ fetchingData: false });
this.setState({ data: this.formatRawData(json.price) });
this.setState({ data: this.formatRawData(json.Data) });
} else {
throw new Error('Failed to fetch XMR data');
}
Expand All @@ -41,8 +41,8 @@ export class MoneroGraph extends React.Component<Props, State> {
};

public formatRawData = (data: any) => {
return data.map((arr: number[], i: number) => {
return [i, arr[1], arr[0]];
return data.map((point: { [key: string]: number }, i: number) => {
return [i, point.close, point.time];
});
};

Expand All @@ -62,7 +62,7 @@ export class MoneroGraph extends React.Component<Props, State> {
<div className="xmr-price-header">
<p className="title">Monero Price</p>
<div className="flex-spacer" />
<p className="time">24h</p>
<p className="time">7d</p>
</div>
<div className="xmr-price-data">
<div className="left">
Expand Down Expand Up @@ -113,7 +113,7 @@ export class MoneroGraph extends React.Component<Props, State> {
<div className="xmr-price-header">
<p className="title">Monero Price</p>
<div className="flex-spacer" />
<p className="time">24h</p>
<p className="time">7d</p>
</div>
<div className="xmr-price-data" aria-hidden={true}>
<div className="left">
Expand Down
2 changes: 1 addition & 1 deletion src/sass/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ span {
margin-bottom: 3rem;
}

@media screen and (max-width: 900px) {
@media screen and (max-width: 1016px) {
padding: 1rem 1.5rem;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export const toKB = (bytes: number | string) => {
};

export const formatApiDateStrings = (str: string) => {
return moment
.unix(parseInt(str, 10))
.utc()
.format('YYYY / MM / DD – HH:MM UTC');
return moment(str).format('YYYY / MM / DD HH:mm UTC');
};

export const createReducer = (initialState: any, handlers: any) => {
Expand Down

0 comments on commit a67d235

Please sign in to comment.