import { Injectable } from '@angular/core' ; import { StorageCacheService } from '@app/cache' ; import { Language , TradeStaticHttpResultId } from '@data/poe/schema' ; import { TradeHttpService } from '@data/poe/service' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { Currency } from './currency' ; const CACHE_EXPIRY = 1000 * 60 * 60 ; @ Injectable ( { providedIn : 'root' } ) export class CurrenciesProvider { constructor ( private readonly trade , private readonly cache ) { } public provide ( language ) { const key = `currencies_${ language }` ; return this . cache . proxy ( key , ( ) => this . fetch ( language ) , CACHE_EXPIRY ) ; } private fetch ( language ) { return this . trade . getStatics ( language ) . pipe ( map ( ( { result } ) => { const currencyGroup = result . find ( group => group . id === TradeStaticHttpResultId . Currency ) ; if ( ! currencyGroup ?. entries ) { return [ ] ; } return currencyGroup . entries . map ( entry => { const currency = { id : entry . id , nameType : entry . text , image : entry . image } ; return currency ; } ) ; } ) ) ; } }