Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,9 @@ class BinanceRepository implements CexRepository {
return false;
}
}

@override
void dispose() {
// No resources to dispose in this implementation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class MarketDataBootstrap {
if (config.enableCoinPaprika) {
container.registerSingletonAsync<ICoinPaprikaProvider>(
() async => config.coinPaprikaProvider ?? CoinPaprikaProvider(),
dispose: (provider) => provider.dispose(),
);
}

Expand Down Expand Up @@ -166,6 +167,7 @@ class MarketDataBootstrap {
coinPaprikaProvider: await container.getAsync<ICoinPaprikaProvider>(),
),
dependsOn: [ICoinPaprikaProvider],
dispose: (repository) => repository.dispose(),
);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/komodo_cex_market_data/lib/src/cex_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,10 @@ abstract class CexRepository {
QuoteCurrency fiatCurrency,
PriceRequestType requestType,
);

/// Releases any resources held by the repository.
///
/// Repositories that allocate resources such as HTTP clients or file handles
/// should override this method to dispose them when no longer needed.
void dispose() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,9 @@ class CoinGeckoRepository implements CexRepository {
// For paid plans with cutoff from 2013/2018, return a reasonable batch size
return daysSinceCutoff > 365 ? 365 : daysSinceCutoff;
}

@override
void dispose() {
// No resources to dispose in this implementation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ abstract class ICoinPaprikaProvider {

/// The current API plan with its limitations and features.
CoinPaprikaApiPlan get apiPlan;

/// Releases any resources held by the provider.
void dispose();
}

/// Implementation of CoinPaprika data provider using HTTP requests.
Expand All @@ -80,7 +83,8 @@ class CoinPaprikaProvider implements ICoinPaprikaProvider {
this.apiPlan = const CoinPaprikaApiPlan.free(),
http.Client? httpClient,
}) : _apiKey = apiKey,
_httpClient = httpClient ?? http.Client();
_httpClient = httpClient ?? http.Client(),
_ownsHttpClient = httpClient == null;

/// The base URL for the CoinPaprika API.
final String baseUrl;
Expand All @@ -97,6 +101,7 @@ class CoinPaprikaProvider implements ICoinPaprikaProvider {

/// The HTTP client for the CoinPaprika API.
final http.Client _httpClient;
final bool _ownsHttpClient;

static final Logger _logger = Logger('CoinPaprikaProvider');

Expand Down Expand Up @@ -514,4 +519,11 @@ class CoinPaprikaProvider implements ICoinPaprikaProvider {
: null,
);
}

@override
void dispose() {
if (_ownsHttpClient) {
_httpClient.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ class CoinPaprikaRepository implements CexRepository {
CoinPaprikaRepository({
required this.coinPaprikaProvider,
bool enableMemoization = true,
bool ownsProvider = false,
}) : _idResolutionStrategy = CoinPaprikaIdResolutionStrategy(),
_enableMemoization = enableMemoization;
_enableMemoization = enableMemoization,
_ownsProvider = ownsProvider;

/// The CoinPaprika provider to use for fetching data.
final ICoinPaprikaProvider coinPaprikaProvider;
final IdResolutionStrategy _idResolutionStrategy;
final bool _enableMemoization;
final bool _ownsProvider;

final AsyncMemoizer<List<CexCoin>> _coinListMemoizer = AsyncMemoizer();
Set<String>? _cachedQuoteCurrencies;
Expand Down Expand Up @@ -437,4 +440,11 @@ class CoinPaprikaRepository implements CexRepository {
return false;
}
}

@override
void dispose() {
if (_ownsProvider) {
coinPaprikaProvider.dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class SparklineRepository with RepositoryFallbackMixin {
factory SparklineRepository.defaultInstance() {
return SparklineRepository([
BinanceRepository(binanceProvider: const BinanceProvider()),
CoinPaprikaRepository(coinPaprikaProvider: CoinPaprikaProvider()),
CoinPaprikaRepository(
coinPaprikaProvider: CoinPaprikaProvider(),
ownsProvider: true,
),
CoinGeckoRepository(coinGeckoProvider: CoinGeckoCexProvider()),
], selectionStrategy: DefaultRepositorySelectionStrategy());
}
Expand Down Expand Up @@ -174,6 +177,28 @@ class SparklineRepository with RepositoryFallbackMixin {
return future;
}

/// Releases held resources such as HTTP clients and Hive boxes.
Future<void> dispose() async {
for (final repository in _repositories) {
try {
repository.dispose();
} catch (e, st) {
_logger.severe('Error disposing repository: $repository', e, st);
}
}

final box = _box;
if (box != null && box.isOpen) {
try {
await box.close();
} catch (e, st) {
_logger.severe('Error closing Hive box', e, st);
}
}
_box = null;
isInitialized = false;
}

/// Internal method to perform the actual sparkline fetch
///
/// This is separated from fetchSparkline to enable proper request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ class TestUnknownRepository implements CexRepository {
) async {
return false;
}

@override
void dispose() {
// No resources to dispose in mock
}
}

void main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class MockSupportingRepository implements CexRepository {
@override
bool canHandleAsset(AssetId assetId) => true;

@override
void dispose() {
// No resources to dispose in mock
}

@override
String toString() => 'MockRepository($name)';
}
Expand Down Expand Up @@ -170,6 +175,11 @@ class MockFailingRepository implements CexRepository {
@override
bool canHandleAsset(AssetId assetId) => true;

@override
void dispose() {
// No resources to dispose in mock
}

@override
String toString() => 'MockFailingRepository';
}
Expand Down Expand Up @@ -420,6 +430,11 @@ class MockGeckoStyleRepository implements CexRepository {
@override
bool canHandleAsset(AssetId assetId) => true;

@override
void dispose() {
// No resources to dispose in mock
}

@override
String toString() => 'MockGeckoStyleRepository';
}
Expand Down Expand Up @@ -488,6 +503,11 @@ class MockPaprikaStyleRepository implements CexRepository {
@override
bool canHandleAsset(AssetId assetId) => true;

@override
void dispose() {
// No resources to dispose in mock
}

@override
String toString() => 'MockPaprikaStyleRepository';
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by the `index_generator` package with the `index_generator.yaml` configuration file.

library;
library _coins_config;

export 'asset_parser.dart';
export 'coin_config_provider.dart';
Expand Down
22 changes: 11 additions & 11 deletions packages/komodo_defi_framework/app_build/build_config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"api": {
"api_commit_hash": "96023711777feda55990a7510c352485d8a5c7a5",
"branch": "staging",
"fetch_at_build_enabled": true,
"api_commit_hash": "9aa41b4c741907d59e4887db08cf84fb78e967e0",
"branch": "dev",
"fetch_at_build_enabled": false,
"concurrent_downloads_enabled": true,
"source_urls": [
"https://api.github.com/repos/KomodoPlatform/komodo-defi-framework",
Expand All @@ -13,14 +13,14 @@
"web": {
"matching_pattern": "^(?:kdf_[a-f0-9]{7,40}-wasm|mm2_[a-f0-9]{7,40}-wasm|mm2-[a-f0-9]{7,40}-wasm)\\.zip$",
"valid_zip_sha256_checksums": [
"37738eb7d487aefa125ffed8e2de0be0d4279752234cfb90c94542d6a054d6f3"
"f92d61595317c16b8f8294c038c7c9215aca94187e22aedc7e0adeba93c94d82"
],
"path": "web/kdf/bin"
},
"ios": {
"matching_pattern": "^(?:kdf_[a-f0-9]{7,40}-ios-aarch64|mm2_[a-f0-9]{7,40}-ios-aarch64|mm2-[a-f0-9]{7,40}-ios-aarch64-CI)\\.zip$",
"valid_zip_sha256_checksums": [
"eef4d2f5ddd000d9c6be7b9b1afcd6e1265096ca4d31664b2481ea89493d1a72"
"4f18e9e82ca16e7b1133cabd898d7503f925be1b7d06693f687c34866617da2e"
],
"path": "ios"
},
Expand All @@ -31,35 +31,35 @@
"mac-arm64"
],
"valid_zip_sha256_checksums": [
"3943c7ad8cab1e7263eb9693936909df87ae60816f09d16435d7122411895624"
"169db9b1410888d7da9f6a0ead2e1a05834528982cebbb70a2e2e3d01e220b69"
],
"path": "macos/bin"
},
"windows": {
"matching_pattern": "^(?:kdf_[a-f0-9]{7,40}-win-x86-64|mm2_[a-f0-9]{7,40}-win-x86-64|mm2-[a-f0-9]{7,40}-Win64)\\.zip$",
"valid_zip_sha256_checksums": [
"c875dac3a4e850dffd68a16036350acfbdde21285f35f0889e4b8abd7c75b67f"
"d4f5954071df5c2c23016a69074bf19d3daeba10ab413fda2fce8205ee32184c"
],
"path": "windows/bin"
},
"android-armv7": {
"matching_pattern": "^(?:kdf_[a-f0-9]{7,40}-android-armv7|mm2_[a-f0-9]{7,40}-android-armv7|mm2-[a-f0-9]{7,40}-android-armv7-CI)\\.zip$",
"valid_zip_sha256_checksums": [
"4125917ceacfbc9da6856bf84281e48768e8a6d7f537019575c751ec1cab0164"
"d964f608787683de67ddde7d827dee88185509cc5ffeb6e85d5f7e2aeba84f08"
],
"path": "android/app/src/main/cpp/libs/armeabi-v7a"
},
"android-aarch64": {
"matching_pattern": "^(?:kdf_[a-f0-9]{7,40}-android-aarch64|mm2_[a-f0-9]{7,40}-android-aarch64|mm2-[a-f0-9]{7,40}-android-aarch64-CI)\\.zip$",
"valid_zip_sha256_checksums": [
"c99c96c08c02b9d0ebe91c5dbad57aeda3d0b39d0b960343f8831fd70e0af032"
"32927dfa36a283d344c34cd1514ca8ea3233f20752ec15b7929309cf4df969c2"
],
"path": "android/app/src/main/cpp/libs/arm64-v8a"
},
"linux": {
"matching_pattern": "^(?:kdf_[a-f0-9]{7,40}-linux-x86-64|mm2_[a-f0-9]{7,40}-linux-x86-64|mm2-[a-f0-9]{7,40}-Linux-Release)\\.zip$",
"valid_zip_sha256_checksums": [
"04f57689eba9c7d9a901bae3da7c954f2cfa248140a0112df1ab5920871d2926"
"e3315a46cb9e1957206b36036954bce51d61d8c4784ed878cc93360b9d01c1cb"
],
"path": "linux/bin"
}
Expand All @@ -68,7 +68,7 @@
"coins": {
"fetch_at_build_enabled": true,
"update_commit_on_build": true,
"bundled_coins_repo_commit": "3d23cb5dcc82d4bb8c88f8ebf67ad3fb51ed3b6b",
"bundled_coins_repo_commit": "5344c5ab44a153020ea2bb3893a752f19df927d0",
"coins_repo_api_url": "https://api.github.com/repos/KomodoPlatform/coins",
"coins_repo_content_url": "https://raw.githubusercontent.com/KomodoPlatform/coins",
"coins_repo_branch": "master",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SharedWorker script that forwards messages to all connected ports.
/* eslint-disable no-restricted-globals */

const connections = [];

onconnect = function (e) {
const port = e.ports[0];
connections.push(port);
port.start();
Comment thread
CharlVS marked this conversation as resolved.

port.onmessage = function (msgEvent) {
try {
const data = msgEvent.data;
for (const p of connections) {
try { p.postMessage(data); } catch (_) { }
}
} catch (_) { }
};
Comment thread
CharlVS marked this conversation as resolved.
};
Loading
Loading