Skip to content

Change contract model #164

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

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion packages/gridproxy_client/lib/models/contracts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ContractInfo {
String state;
int twin_id;
String type;
int? nodeId;

ContractInfo({
required this.contract_id,
Expand All @@ -98,6 +99,7 @@ class ContractInfo {
required this.state,
required this.twin_id,
required this.type,
this.nodeId,
});

factory ContractInfo.fromJson(Map<String, dynamic> json) {
Expand All @@ -122,6 +124,7 @@ class ContractInfo {

return ContractInfo(
contract_id: json['contract_id'] ?? 0,
nodeId: json['details']['nodeId'] ?? '',
created_at: json['created_at'] ?? 0,
details: details,
state: json['state'] ?? '',
Expand Down Expand Up @@ -201,7 +204,7 @@ class ContractInfoQueryParams {
int? node_id;
String? name;
ContractTypes? type;
ContractState? state;
List<ContractState>? state;
String? deployment_data;
String? deployment_hash;
int? number_of_public_ips;
Expand Down
23 changes: 15 additions & 8 deletions packages/gridproxy_client/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,36 @@ class GridProxyClient {
Future<dynamic> getRequest(
String path, Map<String, dynamic>? queryParameters) async {
try {
final convertedQueryParameters = queryParameters
?.map((key, value) => MapEntry(key, value?.toString() ?? ''));
final Map<String, String> encodedQueryParams = {};
queryParameters?.forEach((key, value) {
if (value is List) {
encodedQueryParams[key] = value.map((e) => e.toString()).join(',');
} else if (value != null) {
encodedQueryParams[key] = value.toString();
}
});

final uri = Uri.parse(baseUrl);
final scheme = uri.scheme;
final host = uri.host;

final requestUri = convertedQueryParameters != null &&
convertedQueryParameters.isNotEmpty
final requestUri = encodedQueryParams.isNotEmpty
? (scheme == 'https'
? Uri.https(host, path, convertedQueryParameters)
: Uri.http(host, path, convertedQueryParameters))
? Uri.https(host, path, encodedQueryParams)
: Uri.http(host, path, encodedQueryParams))
: (scheme == 'https' ? Uri.https(host, path) : Uri.http(host, path));

final response = await http.get(requestUri);

if (response.statusCode == 200) {
final jsonData = json.decode(response.body);
return jsonData;
} else {
throw Exception('Failed to load data got: ${response.body}');
throw Exception(
'Failed to load data. Status: ${response.statusCode}, Body: ${response.body}');
}
} catch (e) {
throw Exception('Error: $e');
throw Exception('Error during GET request to $path: $e');
}
}
}