diff --git a/src/pages/send/confirm/confirm.html b/src/pages/send/confirm/confirm.html index e257286604e..c3974245728 100644 --- a/src/pages/send/confirm/confirm.html +++ b/src/pages/send/confirm/confirm.html @@ -162,7 +162,7 @@ {{requiredFee | satToUnit: getChain(tx.coin)}}
- {{requiredFee | satToFiat: getChain(tx.coin)}} + {{requiredFee | satToFiat: getChain(tx.coin):tx.paypro && tx.paypro.exchangeRates}}
@@ -172,7 +172,7 @@ {{tx.txp[wallet.id].fee | satToUnit: getChain(tx.coin)}}
- {{tx.txp[wallet.id].fee | satToFiat: getChain(tx.coin)}} + {{tx.txp[wallet.id].fee | satToFiat: getChain(tx.coin):tx.paypro && tx.paypro.exchangeRates}} · @@ -409,7 +409,7 @@
- {{tx.amount | satToFiat: tx.coin}} + {{tx.amount | satToFiat: tx.coin:tx.paypro && tx.paypro.exchangeRates}} {{tx.amount - tx.txp[wallet.id].fee | satToFiat: tx.coin}}
@@ -436,7 +436,7 @@
- {{totalAmount | satToFiat: tx.coin}} + {{totalAmount | satToFiat: tx.coin:tx.paypro && tx.paypro.exchangeRates}}
diff --git a/src/pipes/satToFiat.ts b/src/pipes/satToFiat.ts index f582350b1ac..404de288e06 100644 --- a/src/pipes/satToFiat.ts +++ b/src/pipes/satToFiat.ts @@ -17,11 +17,19 @@ export class SatToFiatPipe implements PipeTransform { ) { this.walletSettings = this.configProvider.get().wallet.settings; } - transform(amount: number, coin: string) { + transform(amount: number, coin: string, exchangeRates?: any) { + const lowercaseKeys = obj => { + return Object.keys(obj).reduce((destination, key) => { + destination[key.toLowerCase()] = obj[key]; + return destination; + }, {}); + }; + let amount_ = this.rateProvider.toFiat( amount, this.walletSettings.alternativeIsoCode, - coin.toLowerCase() + coin.toLowerCase(), + { rates: exchangeRates && lowercaseKeys(exchangeRates) } ); return ( this.decimalPipe.transform(amount_ || 0, '1.2-2') + diff --git a/src/providers/invoice/invoice.ts b/src/providers/invoice/invoice.ts index f41b13b281e..ede446cde51 100644 --- a/src/providers/invoice/invoice.ts +++ b/src/providers/invoice/invoice.ts @@ -54,6 +54,19 @@ export class InvoiceProvider { return res.data; } + public async getBitPayInvoiceWithNetwork(id: string, network: string) { + const host = network === 'testnet' ? 'test.bitpay.com' : 'bitpay.com'; + const res: any = await this.http + .get(`https://${host}/invoices/${id}`) + .toPromise() + .catch(err => { + this.logger.error('BitPay Get Invoice: ERROR ' + err.error.message); + throw err.error.message; + }); + this.logger.info('BitPay Get Invoice: SUCCESS'); + return res.data; + } + public emailIsValid(email: string): boolean { const validEmail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test( email diff --git a/src/providers/paypro/paypro.ts b/src/providers/paypro/paypro.ts index 864aca8ffb4..97fd7b056c7 100644 --- a/src/providers/paypro/paypro.ts +++ b/src/providers/paypro/paypro.ts @@ -4,6 +4,7 @@ import { Logger } from '../../providers/logger/logger'; // providers import { BwcProvider } from '../bwc/bwc'; import { CurrencyProvider } from '../currency/currency'; +import { InvoiceProvider } from '../invoice/invoice'; import { OnGoingProcessProvider } from '../on-going-process/on-going-process'; @Injectable() @@ -12,7 +13,8 @@ export class PayproProvider { private logger: Logger, private bwcProvider: BwcProvider, private currencyProvider: CurrencyProvider, - private onGoingProcessProvider: OnGoingProcessProvider + private onGoingProcessProvider: OnGoingProcessProvider, + private invoiceProvider: InvoiceProvider ) { this.logger.debug('PayproProvider initialized'); } @@ -85,6 +87,18 @@ export class PayproProvider { } }); if (!disableLoader) this.onGoingProcessProvider.clear(); + // workaround for getting invoice exchange rates + if (payDetails && !payDetails.exchangeRates) { + const invoiceId = payDetails.payProUrl.split('i/')[1]; + const network = payDetails.payProUrl.includes('test') + ? 'testnet' + : 'livenet'; + const invoice = await this.invoiceProvider.getBitPayInvoiceWithNetwork( + invoiceId, + network + ); + payDetails.exchangeRates = invoice.exchangeRates; + } this.logger.info('PayPro Details: SUCCESS', JSON.stringify(payDetails)); return payDetails; }