Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imprv: debug #9

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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
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 @@ -11,7 +11,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 @@ -22,31 +22,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];
}
}
Loading