Skip to content

Commit 2ba4823

Browse files
committed
docs(coin-app): Add crypto icons
1 parent 758f391 commit 2ba4823

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

examples/coin-app/src/pages/AssetDetail/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export default function AssetDetail({ id }: { id: string }) {
1111
return (
1212
<>
1313
<header>
14-
<h1>{currency.name}</h1>
14+
<h1>
15+
<img src={currency.icon} /> {currency.name}
16+
</h1>
1517
<h2>
1618
<AssetPrice product_id={`${currency.id}-USD`} />
1719
</h2>

examples/coin-app/src/pages/Home/CurrencyList.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default function CurrencyList() {
2222
<table>
2323
<thead>
2424
<tr>
25+
<th></th>
2526
<th align="left">Name</th>
2627
<th>Volume 30d</th>
2728
<th align="right">Price</th>
@@ -30,6 +31,11 @@ export default function CurrencyList() {
3031
<tbody>
3132
{currencies.slice(0, 25).map(currency => (
3233
<tr key={currency.pk()}>
34+
<td>
35+
{currency.icon && (
36+
<img src={currency.icon} width="20" height="20" />
37+
)}
38+
</td>
3339
<td align="left">
3440
<Link name="AssetDetail" props={{ id: currency.id }}>
3541
{currency.name}

examples/coin-app/src/resources/Currency.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Entity, createResource, schema } from '@data-client/rest';
22

3+
import { iconTable } from './cryptoIconTable';
34
import { Stats } from './Stats';
45

56
export class Currency extends Entity {
@@ -31,6 +32,10 @@ export class Currency extends Entity {
3132
// faked for client-side join
3233
stats = Stats.fromJS();
3334

35+
get icon() {
36+
return iconTable[this.id]?.img_url;
37+
}
38+
3439
pk(): string {
3540
return this.id;
3641
}

examples/coin-app/src/resources/cryptoIcon.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cryptoIcon from './cryptoIcon.json';
2+
3+
export const iconTable: Record<string, any> = {};
4+
cryptoIcon.forEach(crypto => {
5+
if (!(crypto.symbol in iconTable)) {
6+
iconTable[crypto.symbol] = crypto;
7+
}
8+
});

0 commit comments

Comments
 (0)