prepareUpdateRate method

ExchangeRate prepareUpdateRate(
  1. String base,
  2. String currency,
  3. {bool rateLimit = false}
)

Called before requesting updated basecurrency.

Implementation

ExchangeRate prepareUpdateRate(String base, String currency,
    {bool rateLimit = false}) {
  ExchangeRate rate = data[base];
  if (rate == null) rate = data[base] = ExchangeRate(base);
  if (rate.to[currency] == null) {
    rate.to[currency] = ExchangeRateTo(null);
  } else {
    ExchangeRateTo rateTo = rate.to[currency];
    DateTime now = DateTime.now();
    if (rateLimit && now.isBefore(rateTo.updated.add(updateDuration))) {
      return null;
    }
    rateTo.updated = now;
  }
  return rate;
}