mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-29 22:16:05 +00:00
Fix parsing of json to Map<String, dynamic> for ionia api. Update sing in and verify email methods for ionia api. (#604)
This commit is contained in:
parent
0a0f9e80fd
commit
8981ebad56
3 changed files with 16 additions and 22 deletions
|
@ -36,8 +36,8 @@ class IoniaApi {
|
|||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final bodyJson = json.decode(response.body) as Map<String, Object>;
|
||||
final data = bodyJson['Data'] as Map<String, Object>;
|
||||
final bodyJson = json.decode(response.body) as Map<String, dynamic>;
|
||||
final data = bodyJson['Data'] as Map<String, dynamic>;
|
||||
final isSuccessful = bodyJson['Successful'] as bool;
|
||||
|
||||
if (!isSuccessful) {
|
||||
|
@ -50,13 +50,11 @@ class IoniaApi {
|
|||
// Verify email
|
||||
|
||||
Future<IoniaUserCredentials> verifyEmail({
|
||||
required String username,
|
||||
required String email,
|
||||
required String code,
|
||||
required String clientId}) async {
|
||||
final headers = <String, String>{
|
||||
'clientId': clientId,
|
||||
'username': username,
|
||||
'EmailAddress': email};
|
||||
final query = <String, String>{'verificationCode': code};
|
||||
final uri = verifyEmailUri.replace(queryParameters: query);
|
||||
|
@ -66,8 +64,8 @@ class IoniaApi {
|
|||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final bodyJson = json.decode(response.body) as Map<String, Object>;
|
||||
final data = bodyJson['Data'] as Map<String, Object>;
|
||||
final bodyJson = json.decode(response.body) as Map<String, dynamic>;
|
||||
final data = bodyJson['Data'] as Map<String, dynamic>;
|
||||
final isSuccessful = bodyJson['Successful'] as bool;
|
||||
|
||||
if (!isSuccessful) {
|
||||
|
@ -75,13 +73,13 @@ class IoniaApi {
|
|||
}
|
||||
|
||||
final password = data['password'] as String;
|
||||
username = data['username'] as String;
|
||||
final username = data['username'] as String;
|
||||
return IoniaUserCredentials(username, password);
|
||||
}
|
||||
|
||||
// Sign In
|
||||
|
||||
Future<String> signIn(String email, {required String clientId}) async {
|
||||
Future<void> signIn(String email, {required String clientId}) async {
|
||||
final headers = <String, String>{'clientId': clientId};
|
||||
final query = <String, String>{'emailAddress': email};
|
||||
final uri = signInUri.replace(queryParameters: query);
|
||||
|
@ -91,15 +89,13 @@ class IoniaApi {
|
|||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final bodyJson = json.decode(response.body) as Map<String, Object>;
|
||||
final data = bodyJson['Data'] as Map<String, Object>;
|
||||
final bodyJson = json.decode(response.body) as Map<String, dynamic>;
|
||||
final data = bodyJson['Data'] as Map<String, dynamic>;
|
||||
final isSuccessful = bodyJson['Successful'] as bool;
|
||||
|
||||
if (!isSuccessful) {
|
||||
throw Exception(data['ErrorMessage'] as String);
|
||||
}
|
||||
|
||||
return data['username'] as String;
|
||||
}
|
||||
|
||||
// Get virtual card
|
||||
|
@ -118,15 +114,15 @@ class IoniaApi {
|
|||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final bodyJson = json.decode(response.body) as Map<String, Object>;
|
||||
final data = bodyJson['Data'] as Map<String, Object>;
|
||||
final bodyJson = json.decode(response.body) as Map<String, dynamic>;
|
||||
final data = bodyJson['Data'] as Map<String, dynamic>;
|
||||
final isSuccessful = bodyJson['Successful'] as bool;
|
||||
|
||||
if (!isSuccessful) {
|
||||
throw Exception(data['message'] as String);
|
||||
}
|
||||
|
||||
final virtualCard = data['VirtualCard'] as Map<String, Object>;
|
||||
final virtualCard = data['VirtualCard'] as Map<String, dynamic>;
|
||||
return IoniaVirtualCard.fromMap(virtualCard);
|
||||
}
|
||||
|
||||
|
@ -146,8 +142,8 @@ class IoniaApi {
|
|||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final bodyJson = json.decode(response.body) as Map<String, Object>;
|
||||
final data = bodyJson['Data'] as Map<String, Object>;
|
||||
final bodyJson = json.decode(response.body) as Map<String, dynamic>;
|
||||
final data = bodyJson['Data'] as Map<String, dynamic>;
|
||||
final isSuccessful = bodyJson['Successful'] as bool? ?? false;
|
||||
|
||||
if (!isSuccessful) {
|
||||
|
|
|
@ -31,9 +31,8 @@ class IoniaService {
|
|||
// Verify email
|
||||
|
||||
Future<void> verifyEmail(String code) async {
|
||||
final username = (await secureStorage.read(key: ioniaUsernameStorageKey))!;
|
||||
final email = (await secureStorage.read(key: ioniaEmailStorageKey))!;
|
||||
final credentials = await ioniaApi.verifyEmail(email: email, username: username, code: code, clientId: clientId);
|
||||
final credentials = await ioniaApi.verifyEmail(email: email, code: code, clientId: clientId);
|
||||
await secureStorage.write(key: ioniaPasswordStorageKey, value: credentials.password);
|
||||
await secureStorage.write(key: ioniaUsernameStorageKey, value: credentials.username);
|
||||
}
|
||||
|
@ -41,9 +40,8 @@ class IoniaService {
|
|||
// Sign In
|
||||
|
||||
Future<void> signIn(String email) async {
|
||||
final username = await ioniaApi.signIn(email, clientId: clientId);
|
||||
await ioniaApi.signIn(email, clientId: clientId);
|
||||
await secureStorage.write(key: ioniaEmailStorageKey, value: email);
|
||||
await secureStorage.write(key: ioniaUsernameStorageKey, value: username);
|
||||
}
|
||||
|
||||
Future<String> getUserEmail() async {
|
||||
|
|
|
@ -11,7 +11,7 @@ class IoniaVirtualCard {
|
|||
required this.fundsLimit,
|
||||
required this.spendLimit});
|
||||
|
||||
factory IoniaVirtualCard.fromMap(Map<String, Object> source) {
|
||||
factory IoniaVirtualCard.fromMap(Map<String, dynamic> source) {
|
||||
final created = source['created'] as String;
|
||||
final createdAt = DateTime.tryParse(created);
|
||||
|
||||
|
|
Loading…
Reference in a new issue