Skip to content

Instantly share code, notes, and snippets.

@Gbuomprisco
Last active June 29, 2019 12:27
Show Gist options
  • Save Gbuomprisco/005aad97d10bb6497f97dec7890110ce to your computer and use it in GitHub Desktop.
Save Gbuomprisco/005aad97d10bb6497f97dec7890110ce to your computer and use it in GitHub Desktop.
const BASE_PRICES = {
bitcoin: 11000,
litecoin: 130,
ethereum: 300
};
const randomize = (price: number) => {
return (Math.random() * 2) + price;
};
@Injectable()
export class MockPriceApiService implements PriceApi {
static latency = 250;
private unsubsciptions$ = new Subject();
public getPrice(currency: string): Observable<string> {
return timer(0, MockPriceApiService.latency).pipe(
delay(1000),
map(() => BASE_PRICES[currency]),
map((price: number) => randomize(price)),
map((price: number) => price.toFixed(5)),
takeUntil(this.unsubsciptions$),
)
}
public unsubscribe() {
this.unsubsciptions$.next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment