import { Injectable } from '@angular/core' ; import { BLOCKCHAIN_NAME } from '@shared/models/blockchain/blockchain-name' ; import { HttpService } from 'src/app/core/services/http/http.service' ; import { Observable , of } from 'rxjs' ; import { Cacheable } from 'ts-cacheable' ; import { TO_BACKEND_BLOCKCHAINS , ToBackendBlockchain } from '@shared/constants/blockchain/backend-blockchains' ; import { catchError , map } from 'rxjs/operators' ; import BigNumber from 'bignumber.js' ; import { FROM_TEST_BLOCKCHAINS } from '@shared/constants/blockchain/test-blockchains' ; @ Injectable ( { providedIn : 'root' } ) export class GasApiService { constructor ( private readonly httpService ) { } param blockchain return @ Cacheable ( { maxAge : 15000 } ) public getMinGasPriceInBlockchain ( blockchain ) { const backendBlockchain = TO_BACKEND_BLOCKCHAINS [ FROM_TEST_BLOCKCHAINS [ blockchain ] as ToBackendBlockchain ] ; return this . httpService . get < { [ backendBlockchain ] : number ; } > ( 'min_gas_price' , { blockchain : backendBlockchain } ) . pipe ( map ( minGasPrice => { return new BigNumber ( minGasPrice [ backendBlockchain ] ) . multipliedBy ( 10 ** 9 ) ; } ) , catchError ( ( ) => { return of ( null ) ; } ) ) ; } }