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
// in a real app could be environment.useMocks ? | |
const useMocks = true; | |
@NgModule({ | |
imports: [BrowserModule, CommonModule], | |
declarations: [AppComponent, CryptoSelectorComponent], | |
bootstrap: [AppComponent], | |
providers: [ | |
{ | |
provide: PriceApiService, |
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
const WEB_SOCKET_ENDPOINT = 'wss://ws.coincap.io/prices/'; | |
@Injectable() | |
export class PriceApiService implements PriceApi { | |
private webSocket: WebSocket; | |
public getPrice(currency: string): Observable<string> { | |
return this.connectToPriceStream(currency); | |
} |
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
const BASE_PRICES = { | |
bitcoin: 11000, | |
litecoin: 130, | |
ethereum: 300 | |
}; | |
const randomize = (price: number) => { | |
return (Math.random() * 2) + price; | |
}; |
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
import { Observable } from 'rxjs'; | |
export interface PriceApi { | |
getPrice(currency: string): Observable<string>; | |
unsubscribe(): void; | |
} |
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
<div class="price-container"> | |
<div class="price" | |
*ngIf="(price$ | async) as price; else showEmptyState" | |
[ngClass]="{ | |
'trend-up': (trend$ | async) === trends.Up, | |
'trend-down': (trend$ | async) === trends.Down | |
}" | |
> | |
${{ price }} | |
</div> |
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
@Component({ | |
selector: 'cf-asset-pricer', | |
templateUrl: './asset-pricer.component.html', | |
styleUrls: ['./asset-pricer.component.scss'], | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class AssetPricerComponent implements OnInit { | |
@Input() | |
public asset: string; |
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
<mat-form-field> | |
<mat-label> | |
Select Asset | |
</mat-label> | |
<mat-select (selectionChange)="assetSelected.next($event.value)"> | |
<mat-option *ngFor="let asset of (assets$ | async)" [value]="asset.id"> | |
{{ asset.name }} | |
</mat-option> | |
</mat-select> |
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
@Component({ | |
selector: 'cf-asset-selector', | |
templateUrl: './asset-selector.component.html', | |
styleUrls: ['./asset-selector.component.scss'], | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class AssetSelectorComponent { | |
@Output() assetSelected = new EventEmitter<string>(); | |
public assets$ = this.assetsFacade.assets$; |
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
@Injectable() | |
export class PricesFacadeServiceImpl implements PricesFacadeService { | |
subscribedAssets$: Observable<string[]> = this.store.select( | |
selectSubscribedAssets | |
); | |
constructor(private store: Store<EntityState<PriceState>>) {} | |
public createPriceSubscription(assetId: string) { | |
this.addInitialPrice(assetId); |
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
<div [ngSwitch]="tile.assetId" fxLayout="column"> | |
<div class="tile-header"> | |
<div class="tile-heading" *ngSwitchDefault> | |
{{ tile.assetId | titlecase }} | |
</div> | |
<cf-asset-selector | |
*ngSwitchCase="undefined" | |
(assetSelected)="updateTile($event)" | |
></cf-asset-selector> |