Skip to content

Commit

Permalink
Merge branch 'avive:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
avive authored Aug 8, 2023
2 parents d1e0450 + 1a2a4f7 commit 0cb684d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 43 deletions.
1 change: 1 addition & 0 deletions lib/logic/account_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ abstract class AccountLogicInterface {
bool validateDataForNewKarmCoinUser();
bool validateDataForPhoneVerification();
bool validateDataForNewUserTransaction();
bool numberVerified();

// Set received FCM push note token
Future<void> setFCMPushNoteToken(String token);
Expand Down
18 changes: 11 additions & 7 deletions lib/logic/account_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,10 @@ class AccountLogic extends AccountLogicInterface with TrnasactionGenerator {
try {
debugPrint('calling verifier.verifyNumber()...');
VerifyNumberResponse response = await verifier.verifierServiceClient
.verifyNumberEx(requestData.request
/*,
options: CallOptions(
compression: const GzipCodec(),
timeout: const Duration(seconds: 30),
),*/
);
.verifyNumberEx(requestData.request);

debugPrint(
'Verification result: ${response.userVerificationData.verificationResult}');

userVerificationData = response.userVerificationData;
} catch (e) {
Expand Down Expand Up @@ -641,6 +638,13 @@ class AccountLogic extends AccountLogicInterface with TrnasactionGenerator {
return karmaCoinUser.value != null;
}

@override
bool numberVerified() {
return _userVerificationData?.verificationResult != null &&
_userVerificationData!.verificationResult ==
VerificationResult.VERIFICATION_RESULT_VERIFIED;
}

@override
bool validateDataForNewKarmCoinUser() {
debugPrint(
Expand Down
6 changes: 6 additions & 0 deletions lib/logic/account_setup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum AccountSetupStatus {
signedUp, // signup tx confirmed on chain
accountAlreadyExists, // there's already an on-chain account for that accountId
missingData,
incorrectVerificationCode,
}

/// Drives the sign-up interactive process in an app session once user provided all
Expand Down Expand Up @@ -67,6 +68,11 @@ class AccountSetupController extends ChangeNotifier {
return;
}

if (!accountLogic.numberVerified()) {
setStatus(AccountSetupStatus.incorrectVerificationCode);
return;
}

await submitSignupTransaction();
}

Expand Down
24 changes: 15 additions & 9 deletions lib/ui/screens/phone_number_input.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:karma_coin/common/platform_info.dart';
import 'package:karma_coin/common_libs.dart';
import 'package:karma_coin/services/api/verifier.pbgrpc.dart';
Expand All @@ -10,7 +8,6 @@ import 'package:status_alert/status_alert.dart';
import 'package:flutter_native_contact_picker/flutter_native_contact_picker.dart'
as contact_picker;
import 'package:email_validator/email_validator.dart';
import 'package:http/http.dart' as http;

const _privacyUrl = 'https://karmaco.in/docs/privacy';

Expand All @@ -28,7 +25,7 @@ class _PhoneInputScreenState extends State<PhoneInputScreen> {
TextEditingController emailController = TextEditingController();
late PhoneNumberInputValidator validator;
bool outlineBorder = false;
bool mobileOnly = true;
bool mobileOnly = false;
bool shouldFormat = true;
bool isCountryChipPersistent = false;
bool withLabel = false;
Expand All @@ -49,12 +46,22 @@ class _PhoneInputScreenState extends State<PhoneInputScreen> {
super.initState();
isSigninIn = false;

String defaultNuber = settingsLogic.devMode ? "549805381" : "";
String defaultNumber = settingsLogic.devMode ? "549805381" : "";
IsoCode code = settingsLogic.devMode ? IsoCode.IL : IsoCode.US;

try {
// ignore: deprecated_member_use
String? countryCode = WidgetsBinding.instance.window.locale.countryCode;
if (countryCode != null) {
code = IsoCode.fromJson(countryCode.toUpperCase());
}
} catch (e) {
debugPrint('failed to get country code from locale: $e');
}

phoneController =
PhoneController(PhoneNumber(isoCode: code, nsn: defaultNuber));
validator = PhoneValidator.validMobile();
PhoneController(PhoneNumber(isoCode: code, nsn: defaultNumber));
validator = PhoneValidator.valid();

if (PlatformInfo.isMobile) {
// contact picker only available in native mobile iOs or Android
Expand All @@ -74,8 +81,7 @@ class _PhoneInputScreenState extends State<PhoneInputScreen> {
isSigninIn = true;
});

bool isValid =
phoneController.value?.isValid(type: PhoneNumberType.mobile) ?? false;
bool isValid = phoneController.value?.isValid() ?? false;

if (!isValid) {
StatusAlert.show(
Expand Down
4 changes: 4 additions & 0 deletions lib/ui/screens/user_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class _SetUserNameScreenState extends State<SetUserNameScreen> {
text = 'Signing up...';
showIndicator = true;
break;
case AccountSetupStatus.incorrectVerificationCode:
text =
'Incorrect verification code. Please go back and enter the correct code.';
break;
case AccountSetupStatus.transactionSubmitted:
text = 'Transaction submitted';
showIndicator = true;
Expand Down
12 changes: 11 additions & 1 deletion lib/ui/widgets/appreciate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class _AppreciateWidgetState extends State<AppreciateWidget> {
late PhoneController phoneController;
late final TraitsPickerWidget traitsPicker;
bool outlineBorder = false;
bool mobileOnly = true;
bool mobileOnly = false;
bool shouldFormat = true;
bool isCountryChipPersistent = false;
bool withLabel = true;
Expand All @@ -62,6 +62,16 @@ class _AppreciateWidgetState extends State<AppreciateWidget> {
String defaultNumber = settingsLogic.devMode ? "549805380" : "";
IsoCode code = settingsLogic.devMode ? IsoCode.IL : IsoCode.US;

// set default country code from user's mobile number's country code
try {
PhoneNumber userNumber = PhoneNumber.parse(
accountLogic.karmaCoinUser.value!.mobileNumber.value.number);

code = userNumber.isoCode;
} catch (e) {
debugPrint('error parsing user mobile number: $e');
}

if (widget.communityId == 0) {
traitsPicker =
TraitsPickerWidget(null, GenesisConfig.personalityTraits, 6);
Expand Down
11 changes: 11 additions & 0 deletions lib/ui/widgets/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ class _SendWidgetState extends State<SendWidget> {
String defaultNumber = settingsLogic.devMode ? "549805380" : "";
IsoCode code = settingsLogic.devMode ? IsoCode.IL : IsoCode.US;

// set default country code from user's mobile number's country code

try {
PhoneNumber userNumber = PhoneNumber.parse(
accountLogic.karmaCoinUser.value!.mobileNumber.value.number);

code = userNumber.isoCode;
} catch (e) {
debugPrint('error parsing user mobile number: $e');
}

phoneController =
PhoneController(PhoneNumber(isoCode: code, nsn: defaultNumber));
}
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/widgets/send_destination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class _SendDestinationState extends State<SendDestination> {
PhoneNumberInputValidator? _getValidator() {
List<PhoneNumberInputValidator> validators = [];
validators.add(PhoneValidator.validMobile());
validators.add(PhoneValidator.validFixedLine());

return validators.isNotEmpty ? PhoneValidator.compose(validators) : null;
}
}
28 changes: 6 additions & 22 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ packages:
dependency: transitive
description:
name: circle_flags
sha256: "87102c61b777dcae56d29c6f1d2b2126d98dd09dd904618ccc04a0943ac95924"
sha256: cac0fe72ad731cae5984e30be536814d7df37eeb7efc388ba76fdb84dab47ac4
url: "https://pub.dev"
source: hosted
version: "1.0.4"
version: "3.0.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -233,14 +233,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.10"
dart_countries:
dependency: transitive
description:
name: dart_countries
sha256: c42fc90c38d57c857960b793c45d9cf2ba227f5eeb43c69d25d9ea47a9d44553
url: "https://pub.dev"
source: hosted
version: "3.0.3"
desktop_window:
dependency: "direct main"
description:
Expand Down Expand Up @@ -922,26 +914,18 @@ packages:
dependency: "direct main"
description:
name: phone_form_field
sha256: cf36bf7c444ca179d480115a47480d1c8b019abbaba1a63fe35e185bfd48e872
url: "https://pub.dev"
source: hosted
version: "7.1.0"
phone_number_metadata:
dependency: transitive
description:
name: phone_number_metadata
sha256: "33df62bd25d8aa3fe245e928047f803a2c3af21a911965ff17c3b53f5824e6c7"
sha256: "0e02d5548b73b51c47ee3e68b6fc0752cfb6f2f59c1ff9b531dcead0083ccd74"
url: "https://pub.dev"
source: hosted
version: "5.0.5"
version: "8.1.0"
phone_numbers_parser:
dependency: "direct main"
description:
name: phone_numbers_parser
sha256: a3659911edc70e13da02a4d4374e4600b0862f8a56b94ba6a9d67afa9aba830d
sha256: "3b809c0190e7d1272a831f12a67ae5b329ef889d3a9e6da7a59fe86a471576e5"
url: "https://pub.dev"
source: hosted
version: "7.0.2"
version: "8.0.0"
pinput:
dependency: "direct main"
description:
Expand Down
7 changes: 3 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.2.9+43
version: 1.2.9+44

environment:
sdk: '>=3.0.6 <4.0.0'
Expand Down Expand Up @@ -56,7 +56,6 @@ dependencies:
firebase_messaging: ^14.6.5
cloud_firestore: ^4.8.3
cloud_functions: ^4.3.4

hex: ^0.2.0
path_provider: ^2.0.11
quiver: ^3.2.1
Expand All @@ -65,8 +64,8 @@ dependencies:
hive_flutter: ^1.1.0
keyboard_dismisser: ^3.0.0
currency_text_input_formatter: ^2.1.8
phone_form_field: ^7.1.0
phone_numbers_parser: ^7.0.2
phone_form_field: ^8.1.0
phone_numbers_parser: ^8.0.0
intl: ^0.18.0
status_alert: ^1.0.1
font_awesome_flutter: ^10.4.0
Expand Down

0 comments on commit 0cb684d

Please sign in to comment.