Last active
June 29, 2019 12:27
-
-
Save Gbuomprisco/005aad97d10bb6497f97dec7890110ce to your computer and use it in GitHub Desktop.
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; | |
}; | |
@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