From 368041e7d477dc66904314c2d9d66f0024d576a3 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 16 Jan 2023 11:05:30 -0600 Subject: [PATCH] Use selected currency in app-amount component --- .../src/app/components/amount/amount.component.html | 2 +- .../src/app/components/amount/amount.component.ts | 13 +++++++++++-- frontend/src/app/fiat/fiat.component.html | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/components/amount/amount.component.html b/frontend/src/app/components/amount/amount.component.html index c4946ddf8..3526b554b 100644 --- a/frontend/src/app/components/amount/amount.component.html +++ b/frontend/src/app/components/amount/amount.component.html @@ -1,5 +1,5 @@ - {{ addPlus && satoshis >= 0 ? '+' : '' }}{{ conversions.USD * (satoshis / 100000000) | currency:'USD':'symbol':'1.2-2' }} + {{ addPlus && satoshis >= 0 ? '+' : '' }}{{ (conversions ? conversions[currency] : 0) * satoshis / 100000000 | fiatCurrency : digitsInfo : currency }} diff --git a/frontend/src/app/components/amount/amount.component.ts b/frontend/src/app/components/amount/amount.component.ts index f9bba4318..cfdc50468 100644 --- a/frontend/src/app/components/amount/amount.component.ts +++ b/frontend/src/app/components/amount/amount.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, Input, ChangeDetectionStrategy } from '@angular/core'; +import { Component, OnInit, OnDestroy, Input, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; import { StateService } from '../../services/state.service'; import { Observable, Subscription } from 'rxjs'; @@ -10,10 +10,12 @@ import { Observable, Subscription } from 'rxjs'; }) export class AmountComponent implements OnInit, OnDestroy { conversions$: Observable; + currency: string; viewFiat$: Observable; network = ''; stateSubscription: Subscription; + currencySubscription: Subscription; @Input() satoshis: number; @Input() digitsInfo = '1.8-8'; @@ -22,7 +24,13 @@ export class AmountComponent implements OnInit, OnDestroy { constructor( private stateService: StateService, - ) { } + private cd: ChangeDetectorRef, + ) { + this.currencySubscription = this.stateService.fiatCurrency$.subscribe((fiat) => { + this.currency = fiat; + this.cd.markForCheck(); + }); + } ngOnInit() { this.viewFiat$ = this.stateService.viewFiat$.asObservable(); @@ -34,6 +42,7 @@ export class AmountComponent implements OnInit, OnDestroy { if (this.stateSubscription) { this.stateSubscription.unsubscribe(); } + this.currencySubscription.unsubscribe(); } } diff --git a/frontend/src/app/fiat/fiat.component.html b/frontend/src/app/fiat/fiat.component.html index 1adde8120..99a177cc0 100644 --- a/frontend/src/app/fiat/fiat.component.html +++ b/frontend/src/app/fiat/fiat.component.html @@ -1 +1 @@ -{{ (conversions$ | async)[currency] * value / 100000000 | fiatCurrency : digitsInfo : currency }} \ No newline at end of file +{{ (conversions ? conversions[currency] : 0) * value / 100000000 | fiatCurrency : digitsInfo : currency }} \ No newline at end of file