Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Sep 26, 2024
2 parents f0eb777 + f768b97 commit fa83fb9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
8 changes: 6 additions & 2 deletions logic/lib/src/domain/const/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ class Urls {
static const String dapp =
'https://raw.githubusercontent.com/MXCzkEVM/MEP-1759-DApp-store/main/dapp_store';

static String getLatestVersion(String appSecret, String groupId) =>
'https://api.appcenter.ms/v0.1/public/sdk/apps/$appSecret/distribution_groups/$groupId/releases/latest';
// Remove the following method:
// static String getLatestVersion(String appSecret, String groupId) =>
// 'https://api.appcenter.ms/v0.1/public/sdk/apps/$appSecret/distribution_groups/$groupId/releases/latest';

// Add this new static constant:
static const String latestVersionYaml = 'https://raw.githubusercontent.com/MXCzkEVM/moonchain-wallet/refs/heads/main/pubspec.yaml';

static String getApiBaseUrl(int chainId) =>
MXCFunctionHelpers.mxcChainsSeparatedFunctions(
Expand Down
36 changes: 23 additions & 13 deletions logic/lib/src/domain/repositories/wallet/app_version.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:http/http.dart';
import 'package:mxc_logic/mxc_logic.dart';
import 'package:yaml/yaml.dart';
import 'package:mxc_logic/src/data/api/client/web3_client.dart';
import 'package:mxc_logic/src/domain/const/urls.dart';

Expand All @@ -11,22 +12,31 @@ class AppVersionRepository {
final DatadashClient _web3Client;
final Client _restClient;

Future<bool> checkLatestVersion(
String appSecret,
String groupId,
String appVersion,
) async {
Future<bool> checkLatestVersion(String appVersion) async {
final res = await _restClient.get(
Uri.parse(
Urls.getLatestVersion(appSecret, groupId),
),
headers: {'accept': 'application/json'},
Uri.parse(Urls.latestVersionYaml),
headers: {'accept': 'text/plain'},
);

final app = AppVersion.fromJson(res.body);
final latestVersion = int.parse(app.version!);
final currentVersion = int.parse(appVersion);
if (res.statusCode != 200) {
throw Exception('Failed to fetch version information');
}

return latestVersion > currentVersion;
final yamlDoc = loadYaml(res.body);
final latestVersion = yamlDoc['version'] as String;

return _isNewVersionAvailable(latestVersion, appVersion);
}

bool _isNewVersionAvailable(String latestVersion, String currentVersion) {
final latest = latestVersion.split('.').map(int.parse).toList();
final current = currentVersion.split('.').map(int.parse).toList();

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

return false;
}
}

0 comments on commit fa83fb9

Please sign in to comment.