Skip to content

Commit 1e255c6

Browse files
authored
Merge pull request #9 from MXCzkEVM/checkyaml
imprv: debug
2 parents cbcaeec + f50a4bc commit 1e255c6

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

logic/lib/src/domain/repositories/wallet/app_version.dart

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AppVersionRepository {
1212
final DatadashClient _web3Client;
1313
final Client _restClient;
1414

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

26-
print('YAML content: ${res.body}'); // Debug log
27-
2826
final yamlDoc = loadYaml(res.body);
29-
print('Parsed YAML: $yamlDoc'); // Debug log
30-
3127
final latestVersion = yamlDoc['version'] as String;
32-
print('Latest version: $latestVersion'); // Debug log
3328

34-
return _isNewVersionAvailable(latestVersion, appVersion);
29+
print('Comparing versions - Latest: $latestVersion, Current: $currentVersion');
30+
31+
return _isNewVersionAvailable(latestVersion, currentVersion);
3532
} catch (e) {
3633
print('Error checking app version: $e');
3734
return false;
3835
}
3936
}
4037

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

46-
for (int i = 0; i < 3; i++) {
47-
if (latest[i] > current[i]) return true;
48-
if (latest[i] < current[i]) return false;
49-
}
43+
return latestCode > currentCode;
44+
}
5045

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

0 commit comments

Comments
 (0)