diff --git a/app/lib/screens/identity_verification_screen.dart b/app/lib/screens/identity_verification_screen.dart index 3acd24a7c..8dfcecafa 100644 --- a/app/lib/screens/identity_verification_screen.dart +++ b/app/lib/screens/identity_verification_screen.dart @@ -922,8 +922,8 @@ class _IdentityVerificationScreenState if (Globals().hidePhoneButton.value == true) { return; } - - await addPhoneNumberDialog(context); + await addPhoneNumberDialog(context, + newPhone: false, oldPhone: phone); var phoneMap = (await getPhone()); if (phoneMap.isEmpty || !phoneMap.containsKey('phone')) { @@ -1116,6 +1116,18 @@ class _IdentityVerificationScreenState if (step == 1) { return _changeEmailDialog(false); } + if (step == 2) { + await addPhoneNumberDialog(context, + newPhone: false, oldPhone: phone); + var phoneMap = (await getPhone()); + String? phoneNumber = phoneMap['phone']; + if (phone != phoneNumber) { + setState(() { + phone = phoneNumber!; + }); + } + return; + } // Only make this section clickable if it is Identity Verification + Current Phase if (step != 3) { return; @@ -1183,6 +1195,18 @@ class _IdentityVerificationScreenState ), ]) : const Column(), + step == 2 + ? const Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: EdgeInsets.only(left: 15), + child: Icon( + Icons.edit, + ), + ), + ]) + : const Column(), step == 3 ? const Column( mainAxisAlignment: MainAxisAlignment.center, @@ -1650,7 +1674,7 @@ class _IdentityVerificationScreenState color: Theme.of(context).colorScheme.onSurface)) : Text( - 'Changing your email will require you to go through the email verification process again.', + 'Changing your email will require re-verification.', style: Theme.of(context) .textTheme .bodyLarge! @@ -1828,7 +1852,7 @@ class _IdentityVerificationScreenState } if (phone.isEmpty) { - await addPhoneNumberDialog(context); + await addPhoneNumberDialog(context, newPhone: true, oldPhone: phone); var phoneMap = (await getPhone()); if (phoneMap.isEmpty || !phoneMap.containsKey('phone')) { @@ -1846,9 +1870,15 @@ class _IdentityVerificationScreenState FlutterPkid client = await getPkidClient(); client.setPKidDoc('phone', json.encode({'phone': phone})); + startPhoneNumberCounter(); + return; + } else { + PhoneAlertDialogState().sendPhoneVerification(); return; } + } + void startPhoneNumberCounter() { int currentTime = DateTime.now().millisecondsSinceEpoch; if (globals.tooManySmsAttempts && globals.lockedSmsUntil > currentTime) { globals.sendSmsAttempts = 0; diff --git a/app/lib/widgets/phone_widget.dart b/app/lib/widgets/phone_widget.dart index 35c5480f0..16878621f 100644 --- a/app/lib/widgets/phone_widget.dart +++ b/app/lib/widgets/phone_widget.dart @@ -5,7 +5,6 @@ import 'package:flutter_pkid/flutter_pkid.dart'; import 'package:http/http.dart'; import 'package:intl_phone_field/countries.dart'; import 'package:intl_phone_field/intl_phone_field.dart'; -import 'package:intl_phone_field/phone_number.dart'; import 'package:threebotlogin/helpers/globals.dart'; import 'package:threebotlogin/services/open_kyc_service.dart'; import 'package:threebotlogin/services/phone_service.dart'; @@ -14,15 +13,18 @@ import 'package:threebotlogin/services/shared_preference_service.dart'; import 'custom_dialog.dart'; -Future addPhoneNumberDialog(context) async { +Future addPhoneNumberDialog(context, + {required bool newPhone, required String oldPhone}) async { Response res = await getCountry(); var countryCode = res.body.replaceAll('\n', ''); await showDialog( context: context, barrierDismissible: false, - builder: (BuildContext context) => - PhoneAlertDialog(defaultCountryCode: countryCode), + builder: (BuildContext context) => PhoneAlertDialog( + defaultCountryCode: countryCode, + newPhone: newPhone, + oldPhone: oldPhone), ); } @@ -48,8 +50,14 @@ phoneSendDialog(context) { class PhoneAlertDialog extends StatefulWidget { final String defaultCountryCode; + final bool newPhone; + final String oldPhone; - const PhoneAlertDialog({Key? key, required this.defaultCountryCode}) + const PhoneAlertDialog( + {Key? key, + required this.defaultCountryCode, + required this.newPhone, + required this.oldPhone}) : super(key: key); @override @@ -76,53 +84,74 @@ class PhoneAlertDialogState extends State { Widget build(BuildContext context) { return CustomDialog( image: Icons.phone, - title: 'Add phone number', - widgetDescription: SizedBox( - height: 100, - child: Row( - children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: IntlPhoneField( - initialCountryCode: widget.defaultCountryCode, - decoration: const InputDecoration( - labelText: 'Phone Number', - border: OutlineInputBorder( - borderSide: BorderSide(), - ), - ), - style: Theme.of(context).textTheme.bodyMedium!.copyWith( - color: Theme.of(context).colorScheme.onSurface), - dropdownTextStyle: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: Theme.of(context).colorScheme.onSurface), - onChanged: (phone) { - PhoneNumber p = phone; - setState(() { - if (phone.number.length >= _country.minLength && - phone.number.length <= _country.maxLength) { - valid = true; - verificationPhoneNumber = p.completeNumber; - } else { - valid = false; - } - }); - }, - onCountryChanged: (country) { - if (_country != country) { - valid = false; - } - _country = country; - setState(() {}); - }, + title: widget.newPhone ? 'Add phone number' : 'Change phone number', + widgetDescription: Column( + mainAxisSize: MainAxisSize.min, + children: [ + if (!widget.newPhone) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Text( + 'Changing your phone will require re-verification', + style: Theme.of(context) + .textTheme + .bodyLarge! + .copyWith(color: Theme.of(context).colorScheme.onSurface), + ), + ), + if (!widget.newPhone) + const SizedBox( + height: 30, + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: IntlPhoneField( + initialCountryCode: widget.defaultCountryCode, + decoration: const InputDecoration( + labelText: 'Phone Number', + border: OutlineInputBorder( + borderSide: BorderSide(), ), ), + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith(color: Theme.of(context).colorScheme.onSurface), + dropdownTextStyle: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith(color: Theme.of(context).colorScheme.onSurface), + validator: (phone) { + if (phone!.completeNumber == widget.oldPhone) { + setState(() { + valid = false; + }); + return 'Please enter a different number'; + } else if (phone.number.length >= _country.minLength && + phone.number.length <= _country.maxLength) { + setState(() { + valid = true; + }); + verificationPhoneNumber = phone.completeNumber; + return null; + } else { + setState(() { + valid = false; + }); + return 'Invalid Mobile Number'; + } + }, + disableLengthCheck: true, + onCountryChanged: (country) { + if (_country != country) { + valid = false; + } + _country = country; + setState(() {}); + }, ), - ], - ), + ), + ], ), actions: [ TextButton(