use of org.signal.core.util.money.FiatMoney in project Signal-Android by WhisperSystems.
the class CreatePaymentViewModel method updateFiatAmount.
@NonNull
private InputState updateFiatAmount(@NonNull Context context, @NonNull InputState inputState, @NonNull AmountKeyboardGlyph glyph, @NonNull Currency currency) {
String newFiatAmount = updateAmountString(context, inputState.getFiatAmount(), glyph, currency.getDefaultFractionDigits());
FiatMoney newFiat = stringToFiatValueOrZero(newFiatAmount, currency);
Money newMoney = OptionalUtil.flatMap(inputState.getExchangeRate(), e -> e.exchange(newFiat)).get();
String newMoneyAmount;
if (newFiatAmount.equals("0")) {
newMoneyAmount = "0";
} else {
newMoneyAmount = newMoney.toString(FormatterOptions.builder().withoutUnit().build());
}
if (!withinMobileCoinBounds(newMoney.requireMobileCoin())) {
return inputState;
}
return inputState.updateAmount(newMoneyAmount, newFiatAmount, newMoney, Optional.of(newFiat));
}
use of org.signal.core.util.money.FiatMoney in project Signal-Android by signalapp.
the class CreatePaymentViewModel method clearAmount.
void clearAmount() {
inputState.update(s -> {
final Money money = Money.MobileCoin.ZERO;
final Optional<FiatMoney> fiat = OptionalUtil.flatMap(s.getExchangeRate(), r -> r.exchange(money));
return s.updateAmount("0", "0", Money.MobileCoin.ZERO, fiat);
});
}
use of org.signal.core.util.money.FiatMoney in project Signal-Android by signalapp.
the class CreatePaymentViewModel method updateFiatAmount.
@NonNull
private InputState updateFiatAmount(@NonNull Context context, @NonNull InputState inputState, @NonNull AmountKeyboardGlyph glyph, @NonNull Currency currency) {
String newFiatAmount = updateAmountString(context, inputState.getFiatAmount(), glyph, currency.getDefaultFractionDigits());
FiatMoney newFiat = stringToFiatValueOrZero(newFiatAmount, currency);
Money newMoney = OptionalUtil.flatMap(inputState.getExchangeRate(), e -> e.exchange(newFiat)).get();
String newMoneyAmount;
if (newFiatAmount.equals("0")) {
newMoneyAmount = "0";
} else {
newMoneyAmount = newMoney.toString(FormatterOptions.builder().withoutUnit().build());
}
if (!withinMobileCoinBounds(newMoney.requireMobileCoin())) {
return inputState;
}
return inputState.updateAmount(newMoneyAmount, newFiatAmount, newMoney, Optional.of(newFiat));
}
use of org.signal.core.util.money.FiatMoney in project Signal-Android by WhisperSystems.
the class CreatePaymentViewModel method clearAmount.
void clearAmount() {
inputState.update(s -> {
final Money money = Money.MobileCoin.ZERO;
final Optional<FiatMoney> fiat = OptionalUtil.flatMap(s.getExchangeRate(), r -> r.exchange(money));
return s.updateAmount("0", "0", Money.MobileCoin.ZERO, fiat);
});
}
use of org.signal.core.util.money.FiatMoney in project Signal-Android by WhisperSystems.
the class MainActivity method requestPayment.
private void requestPayment() {
donateButton.setClickable(false);
payApi.requestPayment(new FiatMoney(BigDecimal.valueOf(4.00), Currency.getInstance(Locale.getDefault())), "Test Purchase", 1);
}
Aggregations