Search in sources :

Example 1 with CurrencyExchange

use of org.thoughtcrime.securesms.payments.currency.CurrencyExchange in project Signal-Android by WhisperSystems.

the class Payments method getCurrencyExchange.

@WorkerThread
@NonNull
public synchronized CurrencyExchange getCurrencyExchange(boolean refreshIfAble) throws IOException {
    if (currencyConversions == null || shouldRefresh(refreshIfAble, currencyConversions.getTimestamp())) {
        Log.i(TAG, "Currency conversion data is unavailable or a refresh was requested and available");
        CurrencyConversions newCurrencyConversions = ApplicationDependencies.getSignalServiceAccountManager().getCurrencyConversions();
        if (currencyConversions == null || (newCurrencyConversions != null && newCurrencyConversions.getTimestamp() > currencyConversions.getTimestamp())) {
            currencyConversions = newCurrencyConversions;
        }
    }
    if (currencyConversions != null) {
        for (CurrencyConversion currencyConversion : currencyConversions.getCurrencies()) {
            if ("MOB".equals(currencyConversion.getBase())) {
                return new CurrencyExchange(currencyConversion.getConversions(), currencyConversions.getTimestamp());
            }
        }
    }
    throw new IOException("Unable to retrieve currency conversions");
}
Also used : CurrencyConversion(org.whispersystems.signalservice.api.payments.CurrencyConversion) CurrencyConversions(org.whispersystems.signalservice.api.payments.CurrencyConversions) CurrencyExchange(org.thoughtcrime.securesms.payments.currency.CurrencyExchange) IOException(java.io.IOException) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 IOException (java.io.IOException)1 CurrencyExchange (org.thoughtcrime.securesms.payments.currency.CurrencyExchange)1 CurrencyConversion (org.whispersystems.signalservice.api.payments.CurrencyConversion)1 CurrencyConversions (org.whispersystems.signalservice.api.payments.CurrencyConversions)1