Skip to content

Commit

Permalink
Merge pull request #9 from MXCzkEVM/checkyaml
Browse files Browse the repository at this point in the history
imprv: debug
  • Loading branch information
sheenhx authored Sep 26, 2024
2 parents cbcaeec + f50a4bc commit 1e255c6
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions logic/lib/src/domain/repositories/wallet/app_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AppVersionRepository {
final DatadashClient _web3Client;
final Client _restClient;

Future<bool> checkLatestVersion(String appVersion) async {
Future<bool> checkLatestVersion(String currentVersion) async {
try {
final res = await _restClient.get(
Uri.parse(Urls.latestVersionYaml),
Expand All @@ -23,31 +23,28 @@ class AppVersionRepository {
throw Exception('Failed to fetch version information. Status code: ${res.statusCode}');
}

print('YAML content: ${res.body}'); // Debug log

final yamlDoc = loadYaml(res.body);
print('Parsed YAML: $yamlDoc'); // Debug log

final latestVersion = yamlDoc['version'] as String;
print('Latest version: $latestVersion'); // Debug log

return _isNewVersionAvailable(latestVersion, appVersion);
print('Comparing versions - Latest: $latestVersion, Current: $currentVersion');

return _isNewVersionAvailable(latestVersion, currentVersion);
} catch (e) {
print('Error checking app version: $e');
return false;
}
}

bool _isNewVersionAvailable(String latestVersion, String currentVersion) {
print('Comparing versions - Latest: $latestVersion, Current: $currentVersion'); // Debug log
final latest = latestVersion.split('.').map(int.parse).toList();
final current = currentVersion.split('.').map(int.parse).toList();
// Convert the semantic version to a comparable integer
int latestCode = _versionToCode(latestVersion);
int currentCode = int.parse(currentVersion);

for (int i = 0; i < 3; i++) {
if (latest[i] > current[i]) return true;
if (latest[i] < current[i]) return false;
}
return latestCode > currentCode;
}

return false;
int _versionToCode(String version) {
List<int> parts = version.split('.').map(int.parse).toList();
return parts[0] * 10000 + parts[1] * 100 + parts[2];
}
}

0 comments on commit 1e255c6

Please sign in to comment.