use of org.whispersystems.signalservice.api.payments.Money 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.whispersystems.signalservice.api.payments.Money in project Signal-Android by WhisperSystems.
the class BlockTransactionReconstructionTests method total_in_matches_total_out.
@Test
public void total_in_matches_total_out() {
Money net = unspentTransactionOutputs.sum().subtract(spentTransactionOutputs.sum());
TransactionReconstruction estimate = TransactionReconstruction.estimateBlockLevelActivity(spentTransactionOutputs.getMoney(), unspentTransactionOutputs.getMoney());
Money transactionIn = Money.MobileCoin.sum(toValueList(estimate.received()));
Money transactionOut = Money.MobileCoin.sum(toValueList(estimate.sent()));
Money netTransactions = transactionIn.subtract(transactionOut);
assertEquals(net, netTransactions);
}
use of org.whispersystems.signalservice.api.payments.Money in project Signal-Android by WhisperSystems.
the class BlockTransactionReconstructionTests method sum_of_all_transactions.
@Test
public void sum_of_all_transactions() {
Money net = unspentTransactionOutputs.sum().subtract(spentTransactionOutputs.sum());
TransactionReconstruction estimate = TransactionReconstruction.estimateBlockLevelActivity(spentTransactionOutputs.getMoney(), unspentTransactionOutputs.getMoney());
Money netValueWithDirections = Money.MobileCoin.sum(toValueListWithDirection(estimate.getAllTransactions()));
assertEquals(net, netValueWithDirections);
}
use of org.whispersystems.signalservice.api.payments.Money in project Signal-Android by WhisperSystems.
the class MoneyView method init.
public void init(@NonNull Context context, @Nullable AttributeSet attrs) {
FormatterOptions.Builder builder = FormatterOptions.builder(Locale.getDefault());
TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.MoneyView, 0, 0);
if (styledAttributes.getBoolean(R.styleable.MoneyView_always_show_sign, false)) {
builder.alwaysPrefixWithSign();
}
formatterOptions = builder.withoutSpaceBeforeUnit().build();
String value = styledAttributes.getString(R.styleable.MoneyView_money);
if (value != null) {
try {
setMoney(Money.parse(value));
} catch (Money.ParseException e) {
throw new AssertionError("Invalid money format", e);
}
}
styledAttributes.recycle();
}
use of org.whispersystems.signalservice.api.payments.Money 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);
});
}
Aggregations