Skip to content

Commit 88ee798

Browse files
committed
Add prices on home page and 24 hour change difference
1 parent 2e68f45 commit 88ee798

4 files changed

Lines changed: 119 additions & 75 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.chains-home {
2+
width: 100%;
3+
font-size: 1.2em;
4+
text-align: center;
5+
}
6+
7+
.chains-home img {
8+
width: 32px;
9+
height: 32px;
10+
}
11+
12+
.chains-home li {
13+
margin-left: 0.5em;
14+
width: 180px;
15+
}
16+
17+
.chains-home {
18+
padding: 2rem;
19+
}
20+
21+
.chains-home > ul {
22+
display: grid;
23+
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
24+
grid-gap: 1em;
25+
list-style-type: none;
26+
}
27+
28+
.chains-home > ul > li {
29+
margin: 0.5em;
30+
}
31+
32+
.chain-home-link:hover {
33+
text-decoration: underline;
34+
}
35+
36+
.chains-home > ul > li > a {
37+
white-space: nowrap;
38+
text-decoration: none !important;
39+
}
40+
41+
.chain-home-item {
42+
display: grid;
43+
grid-template-columns: 32px 1fr;
44+
grid-template-rows: 1fr 1fr;
45+
margin-bottom: 1em;
46+
column-gap: 10px;
47+
row-gap: 0px;
48+
}
49+
50+
.chain-home-ticker {
51+
clear: both;
52+
display: block;
53+
place-self: start;
54+
white-space: nowrap;
55+
color: var(--foreground-alternative);
56+
font-size: 0.8em;
57+
}
58+
59+
.chain-home-link {
60+
height: 32px;
61+
line-height: 32px;
62+
place-self: start;
63+
}
64+
65+
.chain-home-link img {
66+
margin-right: 0.2em;
67+
}
68+
69+
.chain-home-link:hover {
70+
text-decoration: none;
71+
}
72+
73+
.chain-home-ticker-change {
74+
margin-left: 0.2em;
75+
}

src/Blockcore.Explorer/ClientApp/src/app/home/home.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
<ul>
55
<li class="chain-home-item" *ngFor="let chain of setup.chains">
66
<a class="chain-home-link" [routerLink]="[chain.symbol.toLowerCase()]"><img [ngClass]="{'mode-aware': chain.filter}" [src]="chain.icon"></a>
7-
<a class="chain-home-link" [routerLink]="[chain.symbol.toLowerCase()]">{{chain.name}}</a>
7+
<a class="chain-home-link" [routerLink]="[chain.symbol.toLowerCase()]">
8+
{{chain.name}}
9+
</a><br>
10+
<div class="chain-home-ticker" *ngIf="tickers && chain.coin">
11+
{{ tickers[chain.coin].btc }} <i class="fab fa-btc"></i> <span *ngIf="tickers[chain.coin].btc_24h_change" class="chain-home-ticker-change" [ngClass]="getChangeClass(tickers[chain.coin].btc_24h_change)">{{tickers[chain.coin].btc_24h_change.toFixed(2)}}%</span>
12+
</div>
813
</li>
914
</ul>
1015
</div>
Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,51 @@
1-
import { Component, HostBinding } from '@angular/core';
1+
import { Component, HostBinding, OnInit } from '@angular/core';
22
import { SetupService } from '../services/setup.service';
33
import { Router } from '@angular/router';
4+
import { ApiService } from '../services/api.service';
45

56
@Component({
67
selector: 'app-home',
78
templateUrl: './home.component.html',
9+
styleUrls: ['./home.component.css']
810
})
9-
export class HomeComponent {
11+
export class HomeComponent implements OnInit {
1012
// @HostBinding('class.content-centered') hostClass = true;
13+
tickers: any;
1114

12-
constructor(public setup: SetupService, private router: Router) {
15+
constructor(
16+
public setup: SetupService,
17+
private api: ApiService,
18+
private router: Router) {
1319
// When we are not in multichain mode, redirect to chain-home.
1420
if (!setup.multiChain) {
1521
router.navigate(['/' + setup.current.toLowerCase()]);
1622
}
1723
}
24+
25+
async ngOnInit() {
26+
await this.updateTicker();
27+
}
28+
29+
getChangeClass(value: number) {
30+
if (value < 0) {
31+
return 'negative';
32+
} else {
33+
return 'positive';
34+
}
35+
}
36+
37+
async updateTicker() {
38+
39+
try {
40+
const coins = this.setup.chains.map(c => c.coin).filter((c) => c != null);;
41+
const coinList = coins.join('%2C');
42+
const url = `https://api.coingecko.com/api/v3/simple/price?ids=${coinList}&vs_currencies=btc&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true`
43+
44+
const request = await this.api.download(url);
45+
this.tickers = request;
46+
}
47+
catch (err) {
48+
console.error(err);
49+
}
50+
}
1851
}

src/Blockcore.Explorer/ClientApp/src/styles/blockcore.scss

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -198,75 +198,6 @@ header a:hover {
198198
z-index: 1;
199199
}
200200

201-
.chains-home {
202-
width: 100%;
203-
// margin: 2em;
204-
// padding: 1em;
205-
// border-radius: 10px;
206-
// top: 1em;
207-
// left: 5em;
208-
font-size: 1.2em;
209-
text-align: center;
210-
}
211-
212-
.chains-home img {
213-
width: 32px;
214-
height: 32px;
215-
}
216-
217-
// .chains-home ul {
218-
// display: inline-block;
219-
// list-style-type: none;
220-
// margin: 0;
221-
// padding: 0;
222-
// }
223-
224-
.chains-home li {
225-
margin-left: 0.5em;
226-
width: 180px;
227-
}
228-
229-
.chains-home {
230-
padding: 2rem;
231-
}
232-
233-
.chains-home > ul {
234-
display: grid;
235-
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
236-
grid-gap: 1em;
237-
}
238-
239-
.chains-home > ul > li {
240-
margin: 0.5em;
241-
}
242-
243-
.chain-home-link:hover {
244-
text-decoration: underline;
245-
}
246-
247-
.chains-home > ul > li > a {
248-
white-space: nowrap;
249-
text-decoration: none !important;
250-
}
251-
252-
.chain-home-item {
253-
display: flex;
254-
margin-bottom: 1em;
255-
}
256-
257-
.chain-home-link {
258-
height: 32px;
259-
line-height: 32px;
260-
}
261-
262-
.chain-home-link img {
263-
margin-right: 0.2em;
264-
}
265-
266-
.chain-home-link:hover {
267-
text-decoration: none;
268-
}
269-
270201
.chains {
271202
background-color: var(--box-background);
272203
border-radius: 6px;
@@ -683,8 +614,8 @@ footer {
683614
width: 100%;
684615
font-family: "Manrope", sans-serif;
685616
font-family: "Raleway", sans-serif;
686-
}
687-
617+
}
618+
688619
.search-global {
689620
display: flex;
690621
flex-direction: row;

0 commit comments

Comments
 (0)