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

View file

@ -6,10 +6,12 @@ import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.address.InvalidAddressException; import com.sparrowwallet.drongo.address.InvalidAddressException;
import com.sparrowwallet.drongo.wallet.*; import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.CurrencyRate;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.*; import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.*; import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.io.ExchangeSource;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
@ -52,6 +54,9 @@ public class SendController extends WalletFormController implements Initializabl
@FXML @FXML
private ComboBox<BitcoinUnit> amountUnit; private ComboBox<BitcoinUnit> amountUnit;
@FXML
private FiatLabel fiatAmount;
@FXML @FXML
private Button maxButton; private Button maxButton;
@ -94,6 +99,13 @@ public class SendController extends WalletFormController implements Initializabl
utxoSelectorProperty.setValue(null); utxoSelectorProperty.setValue(null);
} }
Long recipientValueSats = getRecipientValueSats();
if(recipientValueSats != null) {
setFiatAmount(AppController.getFiatCurrencyExchangeRate(), recipientValueSats);
} else {
fiatAmount.setText("");
}
updateTransaction(); updateTransaction();
} }
}; };
@ -440,6 +452,12 @@ public class SendController extends WalletFormController implements Initializabl
updateTransaction(true); updateTransaction(true);
} }
private void setFiatAmount(CurrencyRate currencyRate, long amount) {
if(currencyRate != null && currencyRate.isAvailable()) {
fiatAmount.set(currencyRate, amount);
}
}
public void clear(ActionEvent event) { public void clear(ActionEvent event) {
address.setText(""); address.setText("");
label.setText(""); label.setText("");
@ -508,4 +526,17 @@ public class SendController extends WalletFormController implements Initializabl
amountUnit.getSelectionModel().select(BitcoinUnit.BTC.equals(unit) ? 0 : 1); amountUnit.getSelectionModel().select(BitcoinUnit.BTC.equals(unit) ? 0 : 1);
feeAmountUnit.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());
}
} }

View file

@ -19,6 +19,7 @@
<?import javafx.scene.chart.NumberAxis?> <?import javafx.scene.chart.NumberAxis?>
<?import com.sparrowwallet.sparrow.control.TransactionDiagram?> <?import com.sparrowwallet.sparrow.control.TransactionDiagram?>
<?import com.sparrowwallet.drongo.BitcoinUnit?> <?import com.sparrowwallet.drongo.BitcoinUnit?>
<?import com.sparrowwallet.sparrow.control.FiatLabel?>
<BorderPane stylesheets="@send.css, @wallet.css, @../script.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.SendController"> <BorderPane stylesheets="@send.css, @wallet.css, @../script.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.SendController">
<center> <center>
@ -54,6 +55,8 @@
</items> </items>
</ComboBox> </ComboBox>
<Region style="-fx-pref-width: 20" /> <Region style="-fx-pref-width: 20" />
<FiatLabel fx:id="fiatAmount" />
<Region style="-fx-pref-width: 20" />
<Button fx:id="maxButton" text="Max" onAction="#setMaxInput" /> <Button fx:id="maxButton" text="Max" onAction="#setMaxInput" />
</Field> </Field>
</Fieldset> </Fieldset>