25-4-29/1

This commit is contained in:
Hamza-Ayed
2025-04-29 15:36:15 +03:00
parent 0126011f0e
commit 801f26eb18
19 changed files with 416 additions and 401 deletions

View File

@@ -71,6 +71,8 @@ class CRUD {
Map<String, dynamic>? payload,
}) async {
var s = await LoginController().getJwtWallet();
final hmac = box.read(BoxName.hmac);
// Log.print('hmac: ${hmac}');
var url = Uri.parse(
link,
);
@@ -79,7 +81,8 @@ class CRUD {
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer $s'
'Authorization': 'Bearer $s',
'X-HMAC-Auth': hmac.toString(),
},
);
// print('req: ${response.request}');
@@ -87,6 +90,7 @@ class CRUD {
// Log.print('payload: ${payload}');
if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
Log.print('jsonData: $jsonData');
if (jsonData['status'] == 'success') {
return response.body;
}
@@ -139,7 +143,7 @@ class CRUD {
return jsonData['status'];
}
} catch (e) {
addError(e.toString(), 'crud().post - JSON decoding');
// addError(e.toString(), 'crud().post - JSON decoding');
return 'failure';
}
} else if (response.statusCode == 401) {
@@ -162,16 +166,16 @@ class CRUD {
return 'token_expired'; // Return a specific value for token expiration
} else {
// Other 401 errors
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
// addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
addError('Non-200 response code: ${response.statusCode}',
'crud().post - Other');
// addError('Non-200 response code: ${response.statusCode}',
// 'crud().post - Other');
return 'failure';
}
} catch (e) {
addError('HTTP request error: $e', 'crud().post - HTTP');
// addError('HTTP request error: $e', 'crud().post - HTTP');
return 'failure';
}
}
@@ -179,6 +183,9 @@ class CRUD {
Future<dynamic> postWallet(
{required String link, Map<String, dynamic>? payload}) async {
var s = await LoginController().getJwtWallet();
final hmac = box.read(BoxName.hmac);
var url = Uri.parse(link);
try {
var response = await http.post(
@@ -186,7 +193,8 @@ class CRUD {
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer $s'
'Authorization': 'Bearer $s',
'X-HMAC-Auth': hmac.toString(),
},
);
// print('req: ${response.request}');
@@ -224,16 +232,16 @@ class CRUD {
return 'token_expired'; // Return a specific value for token expiration
} else {
// Other 401 errors
addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
// addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
addError('Non-200 response code: ${response.statusCode}',
'crud().post - Other');
// addError('Non-200 response code: ${response.statusCode}',
// 'crud().post - Other');
return 'failure';
}
} catch (e) {
addError('HTTP request error: $e', 'crud().post - HTTP');
// addError('HTTP request error: $e', 'crud().post - HTTP');
return 'failure';
}
}