findByCode method

Currency? findByCode(
  1. String monetaryAmount
)

Searches for the matching registered Currency by comparing the currency codes in a monetaryAmount.

Implementation

Currency? findByCode(String monetaryAmount) {
  Currency? match;
  var longToShort = <Currency>[];

  longToShort = _directory.values.toList()
    ..sort((lhs, rhs) => lhs.isoCode.length - rhs.isoCode.length);

  for (final currency in longToShort) {
    if (monetaryAmount.contains(currency.isoCode)) {
      match = currency;
      break;
    }
  }
  return match;
}