Skip to content

Commit

Permalink
Integrate data sharing UI for registration flow
Browse files Browse the repository at this point in the history
  • Loading branch information
lijogeorgep authored and josmilan committed Nov 14, 2023
1 parent 86a418e commit c84521c
Show file tree
Hide file tree
Showing 12 changed files with 582 additions and 100 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ dependencies {
implementation platform('com.google.firebase:firebase-bom:28.0.1')
implementation 'com.google.firebase:firebase-dynamic-links-ktx'
// implementation 'com.github.L3-iGrant:mobileSDK-android:2.5.2'
implementation 'com.github.decentralised-dataexchange:bb-consent-android-privacy-dashboard:2023.11.2'
implementation 'com.github.decentralised-dataexchange:bb-consent-android-privacy-dashboard:2023.11.3'
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
implementation 'com.cocosw:bottomsheet:1.5.0'
implementation 'com.github.markomilos:paginate:1.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import io.igrant.data_wallet.utils.DataWalletConfigurations
import io.igrant.data_wallet.utils.InitializeWalletCallback
import io.igrant.data_wallet.utils.InitializeWalletState
import io.igrant.data_wallet.utils.dataAgreement.DataAgreementUtils
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

class MainActivity : FlutterActivity() {

Expand Down Expand Up @@ -66,7 +68,7 @@ class MainActivity : FlutterActivity() {
val userId: String?= call.argument("userId")
PrivacyDashboard.showPrivacyDashboard().withApiKey(apiKey ?: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY0ZjA5Zjc3OGU1ZjM4MDAwMTRhODc5YSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTBhZTFmYmJlMWViNDAwMDE3MTFkODciLCJleHAiOjE3MzAyMjMyODh9.DlU8DjykYr3eBmbgsKLR4dnaChiRqXdxofKOuk4LiRM")
.withUserId(userId ?: "653fe90efec9f34efed23619")
.withOrgId(orgId ?: "64f09f778e5f3800014a879a")
// .withOrgId(orgId ?: "64f09f778e5f3800014a879a")
.withBaseUrl(baseUrl ?: "https://demo-consent-bb-api.igrant.io/")
// .enableUserRequest()
// .enableAskMe()
Expand All @@ -92,6 +94,28 @@ class MainActivity : FlutterActivity() {
val data = DataWallet.queryCredentials(credDefId, schemaId)
result.success(data)
}
"DataSharing" -> {
val accessToken: String? = call.argument("accessToken")
val dataAgreementID: String? = call.argument("dataAgreementID")
val baseUrl: String? = call.argument("baseUrl")
var data:String? = null
print("access token passes as :$accessToken")
GlobalScope.launch {
data = PrivacyDashboard.optInToDataAgreement(
dataAgreementId = dataAgreementID ?:"",
baseUrl = baseUrl ?: "",
accessToken = accessToken ?: ""
)
println("response received1:$data");
if(data !=null){
result.success(data)
}
else{
result.error("CUSTOM_ERROR_CODE", "Error occurred. Data: $data", null)
}

}
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions lib/app/modules/dataSharing/binding/dataAgreement_binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart';
import 'package:get/get.dart';
import 'package:get/get_instance/src/bindings_interface.dart';

class DataAgreementBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<DataAgreementContoller>(
() => DataAgreementContoller(),
fenix: true,
);


}
}
206 changes: 206 additions & 0 deletions lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import 'dart:convert';
import 'dart:ui';

import 'package:Data4Diabetes/app/core/base/base_controller.dart';
import 'package:Data4Diabetes/app/modules/Register/controllers/register_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../../login/views/login_view.dart';

class DataAgreementContoller extends BaseController {
final RegisterController _registerController = Get.find();
WebViewController? controller;
var platform = const MethodChannel('io.igrant.data4diabetes.channel');
var dataAgreementId = "654cf0db9684ed907ce07c5";

var thirdPartyOrgName = "Data4Diabetes";
String? accessToken;
var redirectUrl = "https://www.govstack.global/";
// invokeDataAgreement() {
// controller = WebViewController()
// ..setJavaScriptMode(JavaScriptMode.unrestricted)
// ..setBackgroundColor(const Color(0x00000000))
// ..setNavigationDelegate(
// NavigationDelegate(
// onProgress: (int progress) {
// // if (progress != maxProgressValue) {
// // showLoading();
// // } else {
// // hideLoading();
// // }
//
// return;
// },
// onPageStarted: (String url) {
// /// show progress on loading
// // showLoading();
//
// return;
// },
// onPageFinished: (String url) {
// /// stop progress after loading
// // hideLoading();
//
// return;
// },
// onWebResourceError: (WebResourceError error) {
// return;
// },
// onNavigationRequest: (NavigationRequest request) async {
// if (request.url.startsWith('https://www.govstack.global/')) {
// final uri = Uri.parse(request.url);
// print('the response uri:${uri.queryParameters}');
// if (uri.queryParameters.containsKey('error')) {
// // Handle error response
// String? error = uri.queryParameters['error'];
// String? errorDescription = uri.queryParameters['errorDescription'];
// print('Error: $error, Description: $errorDescription');
// GetSnackToast(message: errorDescription??"something went wrong");
// Get.off(LoginView());
// } else if (uri.queryParameters.containsKey('credentials')) {
// // Decode the base64-encoded credentials
// print('got scueess data');
// String? credentialsBase64 = uri.queryParameters['credentials'];
// // Ensure that the base64 string has the correct length and padding
// String paddedCredentialsBase64 = credentialsBase64! + '=' * (4 - credentialsBase64.length % 4);
//
// // Decode the padded base64 string
// List<int> bytes = base64.decode(paddedCredentialsBase64);
// String decodedCredentialsJson = utf8.decode(bytes);
//
// Map<String, dynamic> decodedCredentials = json.decode(decodedCredentialsJson);
//
// // Accessing user information
// Map<String, dynamic> userInfo = decodedCredentials['userInfo'];
// String subject = userInfo['subject'];
// String email = userInfo['email'];
// bool emailVerified = userInfo['emailVerified'];
//
// print('Subject: $subject');
// print('Email: $email');
// print('Email Verified: $emailVerified');
//
// // Accessing token information
// Map<String, dynamic> token = decodedCredentials['token'];
// String accessToken = token['accessToken'];
// int expiresIn = token['expiresIn'];
// String refreshToken = token['refreshToken'];
//
// print('Access Token: $accessToken');
// print('Expires In: $expiresIn');
// print('Refresh Token: $refreshToken');
//
// SharedPreferences _prefs = await SharedPreferences.getInstance();
// await _prefs.setString('dataSharingAccessToken',accessToken );
// await _prefs.setInt('dataSharingTokenExpiresIn',expiresIn );
// await _prefs.setString('dataSharingRefreshToken',refreshToken );
// Get.back();
// int index = _registerController.selectedPage.value + 1;
// _registerController.pageController.animateToPage(index,
// duration: const Duration(milliseconds: 500),
// curve: Curves.ease);
//
//
// GetSnackToast(message: 'Authorized successfully',color: Colors.green);
// }
//
// return NavigationDecision.navigate;
// }
//
// return NavigationDecision.navigate;
// },
// ),
// )
// ..loadRequest(Uri.parse(
// 'https://staging-consent-bb-iam.igrant.io/realms/3pp-application/protocol/openid-connect/auth?client_id=3pp&response_type=code&redirect_uri=https%3A%2F%2Fstaging-consent-bb-api.igrant.io%2Fv2%2Fservice%2Fdata-sharing%3FdataAgreementId%3D654cf0db9684ed907ce07c5f%26thirdPartyOrgName%3DData4Diabetes%26dataSharingUiRedirectUrl%3Dhttps%3A%2F%2Fwww.govstack.global%2F'));
// }

invokeDataAgreement() {
controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(const Color(0x00000000))
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
return;
},
onPageStarted: (String url) {
/// show progress on loading
return;
},
onPageFinished: (String url) {
/// stop progress after loading
return;
},
onWebResourceError: (WebResourceError error) {
return;
},
onNavigationRequest: (NavigationRequest request) async {
if (request.url.startsWith(redirectUrl)) {
final uri = Uri.parse(request.url);
if (uri.queryParameters.containsKey('error')) {
// Handle error response
String? error = uri.queryParameters['error'];
String? errorDescription =
uri.queryParameters['errorDescription'];
GetSnackToast(
message: errorDescription ?? "something went wrong");
Get.off(LoginView());
_registerController.firstNameController.clear();
_registerController.mobileNumberController.clear();
} else if (uri.queryParameters.containsKey('credentials')) {
// Decode the base64-encoded credentials
String? credentialsBase64 = uri.queryParameters['credentials'];
// Ensure that the base64 string has the correct length and padding
String paddedCredentialsBase64 = credentialsBase64! +
'=' * (4 - credentialsBase64.length % 4);
// Decode the padded base64 string
List<int> bytes = base64.decode(paddedCredentialsBase64);
String decodedCredentialsJson = utf8.decode(bytes);
Map<String, dynamic> decodedCredentials =
json.decode(decodedCredentialsJson);
// Accessing user information
// Map<String, dynamic> userInfo = decodedCredentials['userInfo'];
// String subject = userInfo['subject'];
// String email = userInfo['email'];
// bool emailVerified = userInfo['emailVerified'];
// Accessing token information
Map<String, dynamic> token = decodedCredentials['token'];
accessToken = token['accessToken'];
// int expiresIn = token['expiresIn'];
// String refreshToken = token['refreshToken'];
SharedPreferences _prefs =
await SharedPreferences.getInstance();
await _prefs.setString('dataSharingAccessToken', accessToken!);
var response = await platform.invokeMethod('DataSharing', {
"accessToken": token,
"dataAgreementID": "65530f3507a0b7e06bdd9383",
"baseUrl": "https://staging-consent-bb-api.igrant.io/v2/"
});
Map<String, dynamic> responseMap = json.decode(response);
if (responseMap['optIn'] == true) {
Get.back();
int index = _registerController.selectedPage.value + 1;
_registerController.pageController.animateToPage(index,
duration: const Duration(milliseconds: 500),
curve: Curves.ease);
} else {
GetSnackToast(message: 'something went wrong');
}
}

return NavigationDecision.navigate;
}

return NavigationDecision.navigate;
},
),
)
..loadRequest(Uri.parse(
'https://staging-consent-bb-iam.igrant.io/realms/3pp-application/protocol/openid-connect/auth?client_id=3pp&response_type=code&redirect_uri=https%3A%2F%2Fstaging-consent-bb-api.igrant.io%2Fv2%2Fservice%2Fdata-sharing%3FdataAgreementId%3D654cf0db9684ed907ce07c5f%26thirdPartyOrgName%3DData4Diabetes%26dataSharingUiRedirectUrl%3Dhttps%3A%2F%2Fwww.govstack.global%2F'));
}
}
46 changes: 46 additions & 0 deletions lib/app/modules/dataSharing/views/dataAgreement_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../../../Constants/Palette.dart';
import '../../../core/base/base_view.dart';

class DataAgreementView extends BaseView<DataAgreementContoller> {
@override
PreferredSizeWidget? appBar(BuildContext context) {
return AppBar(
backgroundColor: Colors.transparent,
//centerTitle: true,
elevation: 0,
automaticallyImplyLeading: true,
leading: IconButton(
onPressed: (){
Get.back();
},
icon: const Icon(Icons.arrow_back_ios),
),
);
}
final DataAgreementContoller _dataAgreementContoller = Get.find();
@override
Widget body(BuildContext context) {
return FutureBuilder<String>(
future:_dataAgreementContoller. invokeDataAgreement(),
builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
// Display a loading spinner while waiting for the future to complete
return Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
// Display an error message if the future throws an error
return Text('Error: ${snapshot.error}');
} else {
// Display the fetched data
return WebViewWidget(controller:_dataAgreementContoller. controller!);
}
},
);
}
}
5 changes: 5 additions & 0 deletions lib/app/modules/launcher/bindings/launcher_binding.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:Data4Diabetes/app/modules/Dexcom/controllers/dexcom_controller.dart';
import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart';
import 'package:Data4Diabetes/app/modules/insights/controllers/insights_controller.dart';
import 'package:Data4Diabetes/app/modules/launcher/controller/launcher_controller.dart';
import 'package:Data4Diabetes/app/modules/privacyPolicy/controllers/privacyPolicy_controller.dart';
Expand Down Expand Up @@ -83,5 +84,9 @@ class LauncherBinding extends Bindings {
() => DexcomCredentailController(),
fenix: true,
);
Get.lazyPut<DataAgreementContoller>(
() => DataAgreementContoller(),
fenix: true,
);
}
}
5 changes: 5 additions & 0 deletions lib/app/modules/login/bindings/login_binding.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:Data4Diabetes/app/data/remote/user_remote_data_source.dart';
import 'package:Data4Diabetes/app/modules/Otp/controllers/otp_controller.dart';
import 'package:Data4Diabetes/app/modules/Register/controllers/register_controller.dart';
import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart';
import 'package:Data4Diabetes/app/modules/insights/controllers/insights_controller.dart';
import 'package:Data4Diabetes/app/modules/login/controllers/login_controller.dart';
import 'package:Data4Diabetes/app/modules/privacyPolicy/controllers/privacyPolicy_controller.dart';
Expand Down Expand Up @@ -77,5 +78,9 @@ class LoginBinding extends Bindings {
() => DexcomCredentailController(),
fenix: true,
);
Get.lazyPut<DataAgreementContoller>(
() => DataAgreementContoller(),
fenix: true,
);
}
}
Loading

0 comments on commit c84521c

Please sign in to comment.