fiat amount on send

This commit is contained in:
Craig Raw
2020-07-11 10:03:11 +02:00
parent 9b43429de9
commit a37028b53f
2 changed files with 34 additions and 0 deletions
@@ -6,10 +6,12 @@ import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.address.InvalidAddressException;
import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.CurrencyRate;
import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.io.ExchangeSource;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
@@ -52,6 +54,9 @@ public class SendController extends WalletFormController implements Initializabl
@FXML
private ComboBox<BitcoinUnit> amountUnit;
@FXML
private FiatLabel fiatAmount;
@FXML
private Button maxButton;
@@ -94,6 +99,13 @@ public class SendController extends WalletFormController implements Initializabl
utxoSelectorProperty.setValue(null);
}
Long recipientValueSats = getRecipientValueSats();
if(recipientValueSats != null) {
setFiatAmount(AppController.getFiatCurrencyExchangeRate(), recipientValueSats);
} else {
fiatAmount.setText("");
}
updateTransaction();
}
};
@@ -440,6 +452,12 @@ public class SendController extends WalletFormController implements Initializabl
updateTransaction(true);
}
private void setFiatAmount(CurrencyRate currencyRate, long amount) {
if(currencyRate != null && currencyRate.isAvailable()) {
fiatAmount.set(currencyRate, amount);
}
}
public void clear(ActionEvent event) {
address.setText("");
label.setText("");
@@ -508,4 +526,17 @@ public class SendController extends WalletFormController implements Initializabl
amountUnit.getSelectionModel().select(BitcoinUnit.BTC.equals(unit) ? 0 : 1);
feeAmountUnit.getSelectionModel().select(BitcoinUnit.BTC.equals(unit) ? 0 : 1);
}
@Subscribe
public void fiatCurrencySelected(FiatCurrencySelectedEvent event) {
if(event.getExchangeSource() == ExchangeSource.NONE) {
fiatAmount.setCurrency(null);
fiatAmount.setBtcRate(0.0);
}
}
@Subscribe
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
setFiatAmount(event.getCurrencyRate(), getRecipientValueSats());
}
}