Search in sources :

Example 6 with ExchangeRateEntry

use of de.schildbach.wallet.exchangerate.ExchangeRateEntry in project bitcoin-wallet by bitcoin-wallet.

the class ExchangeRatesAdapter method buildListItems.

public static List<ListItem> buildListItems(final List<ExchangeRateEntry> exchangeRates, final Coin balance, final BlockchainState blockchainState, final String defaultCurrency, final Coin rateBase) {
    final List<ListItem> items = new ArrayList<>(exchangeRates.size());
    for (final ExchangeRateEntry exchangeRate : exchangeRates) {
        final ExchangeRate rate = exchangeRate.exchangeRate();
        final String source = exchangeRate.getSource();
        final String currencyCode = rate.fiat.currencyCode;
        final Fiat baseRateAsFiat = rate.coinToFiat(rateBase);
        final int baseRateMinDecimals = !rateBase.isLessThan(Coin.COIN) ? 2 : 4;
        final Fiat balanceAsFiat = balance != null && (blockchainState == null || !blockchainState.replaying) ? rate.coinToFiat(balance) : null;
        final boolean isDefault = currencyCode.equals(defaultCurrency);
        items.add(new ListItem(source, currencyCode, baseRateAsFiat, baseRateMinDecimals, balanceAsFiat, isDefault));
    }
    return items;
}
Also used : ExchangeRateEntry(de.schildbach.wallet.exchangerate.ExchangeRateEntry) ExchangeRate(org.bitcoinj.utils.ExchangeRate) Fiat(org.bitcoinj.utils.Fiat) ArrayList(java.util.ArrayList)

Aggregations

ExchangeRateEntry (de.schildbach.wallet.exchangerate.ExchangeRateEntry)6 Coin (org.bitcoinj.core.Coin)4 ExchangeRatesRepository (de.schildbach.wallet.exchangerate.ExchangeRatesRepository)2 Fiat (org.bitcoinj.utils.Fiat)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 Stopwatch (com.google.common.base.Stopwatch)1 SelectedExchangeRateLiveData (de.schildbach.wallet.data.SelectedExchangeRateLiveData)1 WalletBalanceLiveData (de.schildbach.wallet.data.WalletBalanceLiveData)1 WalletLiveData (de.schildbach.wallet.data.WalletLiveData)1 BlockchainState (de.schildbach.wallet.service.BlockchainState)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 BlockChain (org.bitcoinj.core.BlockChain)1 BlockStoreException (org.bitcoinj.store.BlockStoreException)1