Skip to content

Commit f768b97

Browse files
authored
Merge pull request #7 from MXCzkEVM/checkver
imprv: github version check
2 parents f83d6bd + 024419d commit f768b97

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

logic/lib/src/domain/const/urls.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ class Urls {
3636
static const String dapp =
3737
'https://raw.githubusercontent.com/MXCzkEVM/MEP-1759-DApp-store/main/dapp_store';
3838

39-
static String getLatestVersion(String appSecret, String groupId) =>
40-
'https://api.appcenter.ms/v0.1/public/sdk/apps/$appSecret/distribution_groups/$groupId/releases/latest';
39+
// Remove the following method:
40+
// static String getLatestVersion(String appSecret, String groupId) =>
41+
// 'https://api.appcenter.ms/v0.1/public/sdk/apps/$appSecret/distribution_groups/$groupId/releases/latest';
42+
43+
// Add this new static constant:
44+
static const String latestVersionYaml = 'https://raw.githubusercontent.com/MXCzkEVM/moonchain-wallet/refs/heads/main/pubspec.yaml';
4145

4246
static String getApiBaseUrl(int chainId) =>
4347
MXCFunctionHelpers.mxcChainsSeparatedFunctions(
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:http/http.dart';
22
import 'package:mxc_logic/mxc_logic.dart';
3+
import 'package:yaml/yaml.dart';
34
import 'package:mxc_logic/src/data/api/client/web3_client.dart';
45
import 'package:mxc_logic/src/domain/const/urls.dart';
56

@@ -11,22 +12,31 @@ class AppVersionRepository {
1112
final DatadashClient _web3Client;
1213
final Client _restClient;
1314

14-
Future<bool> checkLatestVersion(
15-
String appSecret,
16-
String groupId,
17-
String appVersion,
18-
) async {
15+
Future<bool> checkLatestVersion(String appVersion) async {
1916
final res = await _restClient.get(
20-
Uri.parse(
21-
Urls.getLatestVersion(appSecret, groupId),
22-
),
23-
headers: {'accept': 'application/json'},
17+
Uri.parse(Urls.latestVersionYaml),
18+
headers: {'accept': 'text/plain'},
2419
);
2520

26-
final app = AppVersion.fromJson(res.body);
27-
final latestVersion = int.parse(app.version!);
28-
final currentVersion = int.parse(appVersion);
21+
if (res.statusCode != 200) {
22+
throw Exception('Failed to fetch version information');
23+
}
2924

30-
return latestVersion > currentVersion;
25+
final yamlDoc = loadYaml(res.body);
26+
final latestVersion = yamlDoc['version'] as String;
27+
28+
return _isNewVersionAvailable(latestVersion, appVersion);
29+
}
30+
31+
bool _isNewVersionAvailable(String latestVersion, String currentVersion) {
32+
final latest = latestVersion.split('.').map(int.parse).toList();
33+
final current = currentVersion.split('.').map(int.parse).toList();
34+
35+
for (int i = 0; i < 3; i++) {
36+
if (latest[i] > current[i]) return true;
37+
if (latest[i] < current[i]) return false;
38+
}
39+
40+
return false;
3141
}
3242
}

0 commit comments

Comments
 (0)