Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add shareReplay #157

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface TableData {
})
export class PoolsComponent {
protected cryptoService = inject(CryptoService);
protected tokens = toSignal(this.cryptoService.getTokens());
protected tokens = toSignal(this.cryptoService.tokens);
protected tableData: Signal<TableData[]> = computed(() => {
const tokens = this.tokens() || [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {CryptoService} from '../../../../../services/crypto.service';
})
export class PriceListComponent {
protected pricesService = inject(CryptoService);
protected tokens$ = this.pricesService.getTokens();
protected tokens$ = this.pricesService.tokens;

protected showTokens = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {CoinIconPipe} from '../../pipes/coin-icon.pipe';
export class StakingComponent {
private readonly dialogs = inject(TuiDialogService);
private readonly cryptoService = inject(CryptoService);
protected tokens = toSignal(this.cryptoService.getTokens());
protected tokens = toSignal(this.cryptoService.tokens);
protected price = computed(
() =>
this.amount() *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {CryptoService} from '../../../../services/crypto.service';
})
export class SwapComponent {
protected readonly cryptoService = inject(CryptoService);
protected readonly tokens = toSignal(this.cryptoService.getTokens());
protected readonly tokens = toSignal(this.cryptoService.tokens);
protected readonly priceFrom = computed(() => this.getPrice(this.tokenFrom()));

protected readonly priceTo = computed(() => this.getPrice(this.tokenTo()));
Expand Down
8 changes: 6 additions & 2 deletions apps/taiga-lumbermill/src/services/crypto.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HttpClient} from '@angular/common/http';
import {inject, Injectable, InjectionToken} from '@angular/core';
import {map, type Observable} from 'rxjs';
import {map, type Observable, shareReplay} from 'rxjs';

export interface PricesData {
readonly id: string;
Expand Down Expand Up @@ -36,9 +36,13 @@ export class CryptoService {
private readonly http = inject(HttpClient);

private readonly API = inject(CryptoApi);
public readonly tokens = this.getTokens();

public getTokens(): Observable<PricesData[]> {
return this.http.get<ResponseData>(this.API).pipe(map((info) => info.data));
return this.http
.get<ResponseData>(this.API)
.pipe(map((info) => info.data))
.pipe(shareReplay({bufferSize: 1, refCount: true}));
}

public getHistory(id: string, interval: string): Observable<HistoryData[]> {
Expand Down
Loading