mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-23 20:36:44 +00:00
introduce currencyrate to hold fiat rate
This commit is contained in:
parent
c477d31d3d
commit
d6218f2a58
5 changed files with 53 additions and 23 deletions
|
@ -104,7 +104,7 @@ public class AppController implements Initializable {
|
|||
|
||||
private static Map<Integer, Double> targetBlockFeeRates;
|
||||
|
||||
private static Map<Currency, Double> fiatCurrencyExchangeRate;
|
||||
private static CurrencyRate fiatCurrencyExchangeRate;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
@ -397,7 +397,7 @@ public class AppController implements Initializable {
|
|||
return targetBlockFeeRates;
|
||||
}
|
||||
|
||||
public static Map<Currency, Double> getFiatCurrencyExchangeRate() {
|
||||
public static CurrencyRate getFiatCurrencyExchangeRate() {
|
||||
return fiatCurrencyExchangeRate;
|
||||
}
|
||||
|
||||
|
@ -879,6 +879,6 @@ public class AppController implements Initializable {
|
|||
|
||||
@Subscribe
|
||||
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
|
||||
fiatCurrencyExchangeRate = Map.of(event.getSelectedCurrency(), event.getRate());
|
||||
fiatCurrencyExchangeRate = event.getCurrencyRate();
|
||||
}
|
||||
}
|
25
src/main/java/com/sparrowwallet/sparrow/CurrencyRate.java
Normal file
25
src/main/java/com/sparrowwallet/sparrow/CurrencyRate.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package com.sparrowwallet.sparrow;
|
||||
|
||||
import java.util.Currency;
|
||||
|
||||
public class CurrencyRate {
|
||||
private final Currency currency;
|
||||
private final Double btcRate;
|
||||
|
||||
public CurrencyRate(Currency currency, Double btcRate) {
|
||||
this.currency = currency;
|
||||
this.btcRate = btcRate;
|
||||
}
|
||||
|
||||
public Currency getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return btcRate != null && btcRate > 0.0;
|
||||
}
|
||||
|
||||
public Double getBtcRate() {
|
||||
return btcRate;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
import com.sparrowwallet.sparrow.CurrencyRate;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
|
@ -70,6 +71,10 @@ public class FiatLabel extends CopyableLabel {
|
|||
this.currencyProperty.set(currency);
|
||||
}
|
||||
|
||||
public final void set(CurrencyRate currencyRate, long value) {
|
||||
set(currencyRate.getCurrency(), currencyRate.getBtcRate(), value);
|
||||
}
|
||||
|
||||
public final void set(Currency currency, double btcRate, long value) {
|
||||
setValue(value);
|
||||
setBtcRate(btcRate);
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.sparrow.CurrencyRate;
|
||||
|
||||
import java.util.Currency;
|
||||
|
||||
public class ExchangeRatesUpdatedEvent {
|
||||
private final Currency selectedCurrency;
|
||||
private final Double rate;
|
||||
private final Currency currency;
|
||||
private final Double btcRate;
|
||||
|
||||
public ExchangeRatesUpdatedEvent(Currency selectedCurrency, Double rate) {
|
||||
this.selectedCurrency = selectedCurrency;
|
||||
this.rate = rate;
|
||||
public ExchangeRatesUpdatedEvent(Currency currency, Double btcRate) {
|
||||
this.currency = currency;
|
||||
this.btcRate = btcRate;
|
||||
}
|
||||
|
||||
public Currency getSelectedCurrency() {
|
||||
return selectedCurrency;
|
||||
public Currency getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
public Double getRate() {
|
||||
return rate;
|
||||
public Double getBtcRate() {
|
||||
return btcRate;
|
||||
}
|
||||
|
||||
public CurrencyRate getCurrencyRate() {
|
||||
return new CurrencyRate(currency, btcRate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.wallet;
|
|||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.sparrowwallet.sparrow.AppController;
|
||||
import com.sparrowwallet.sparrow.CurrencyRate;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.BalanceChart;
|
||||
import com.sparrowwallet.sparrow.control.CoinLabel;
|
||||
|
@ -16,8 +17,6 @@ import javafx.scene.control.TreeItem;
|
|||
import javafx.scene.input.MouseEvent;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Currency;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class TransactionsController extends WalletFormController implements Initializable {
|
||||
|
@ -61,13 +60,9 @@ public class TransactionsController extends WalletFormController implements Init
|
|||
});
|
||||
}
|
||||
|
||||
private void setFiatBalance(Map<Currency, Double> fiatCurrencyExchangeRate, long balance) {
|
||||
if(fiatCurrencyExchangeRate != null && !fiatCurrencyExchangeRate.isEmpty()) {
|
||||
Currency currency = fiatCurrencyExchangeRate.keySet().iterator().next();
|
||||
Double rate = fiatCurrencyExchangeRate.get(currency);
|
||||
if(rate != null) {
|
||||
fiatBalance.set(currency, rate, balance);
|
||||
}
|
||||
private void setFiatBalance(CurrencyRate currencyRate, long balance) {
|
||||
if(currencyRate != null && currencyRate.isAvailable()) {
|
||||
fiatBalance.set(currencyRate, balance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,8 +119,7 @@ public class TransactionsController extends WalletFormController implements Init
|
|||
|
||||
@Subscribe
|
||||
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
|
||||
Map<Currency, Double> fiatRate = Map.of(event.getSelectedCurrency(), event.getRate());
|
||||
setFiatBalance(fiatRate, getWalletForm().getWalletTransactionsEntry().getBalance());
|
||||
setFiatBalance(event.getCurrencyRate(), getWalletForm().getWalletTransactionsEntry().getBalance());
|
||||
}
|
||||
|
||||
//TODO: Remove
|
||||
|
|
Loading…
Reference in a new issue