Skip to content

Commit

Permalink
fix(assets): Add ticker-safe asset lookup
Browse files Browse the repository at this point in the history
Add ticker-safe asset lookup that returns null if no assets are found for a given string ticker. When non-null it will always return one or more assets.
  • Loading branch information
CharlVS committed Feb 7, 2025
1 parent 0d2f45a commit 02e3ea9
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ extension AssetTickerIndexExtension on AssetManager {
return Set<Asset>.unmodifiable(_tickerIndex[ticker] ?? {});
}

/// Returns all assets matching the given ticker symbol.
///
/// If no assets are found, returns `null`.
///
/// Currently all assets have unique tickers, but this has not always been
/// the case, and may not be in the future.
@Deprecated(_deprecatedMessage)
Set<Asset>? maybeAssetsFromTicker(String ticker) {
assert(
_isInitialized,
'Ticker index not initialized. Call initTickerIndex() first.',
);
final assets = _tickerIndex[ticker];
return assets?.isEmpty == true ? null : Set<Asset>.unmodifiable(assets!);
}

/// Cleans up the ticker index. Call when the manager is no longer needed.
void dispose() {
_tickerIndex.clear();
Expand Down

0 comments on commit 02e3ea9

Please sign in to comment.