Skip to content

Commit

Permalink
Merge pull request #913 from Prime-Holding/feature/upgrade-widget_too…
Browse files Browse the repository at this point in the history
…lkit_pin-dependency

Upgrade widget_toolkit_pin to 0.3.0
  • Loading branch information
JvnSlv authored Dec 12, 2024
2 parents e824a6b + 5936dd6 commit 996119e
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class MfaPinCodeService extends PinCodeService {
Future<int> getPinLength() => _pinCodeRepository.getPinLength();

@override
Future<bool> isPinCodeInSecureStorage() async {
return await _pinCodeRepository.readPinFromStorage(key: storedPin) != null;
}
Future<bool> savePinCodeInSecureStorage(String pinCode) async => false;

@override
Future<String> encryptPinCode(String pinCode) async =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MfaPinBiometricsPage extends StatelessWidget {
.pop(Result<MfaResponse>.success(response));
}
}, // Handle error states
autoBiometricAuth: true,
autoPromptBiometric: true,
biometricsLocalDataSource:
context.read<BiometricsLocalDataSource>(),
pinCodeService: context.read<MfaPinCodeService>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ class CreatePinCodeService implements PinCodeService {
}

@override
Future<bool> isPinCodeInSecureStorage() async {
if (firstPin != null) {
return true;
}
return null != await _pinCodeRepository.readPinFromStorage(key: _storedPin);
Future<bool> savePinCodeInSecureStorage(String pinCode) async {
await _pinCodeRepository.writePinToStorage(_storedPin, pinCode);
return true;
}

Future<bool> checkIsPinCreated() async =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class VerifyPinCodeService implements PinCodeService {
}

@override
Future<bool> isPinCodeInSecureStorage() async =>
await pinCodeRepository.readPinFromStorage(key: storedPin) != null;
Future<bool> savePinCodeInSecureStorage(String pinCode) async {
return false;
}

Future<bool> checkIsPinCreated() async =>
await pinCodeRepository.getPinCode() != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class VerifyPinCodePage extends StatelessWidget {
children: [
Expanded(
child: PinCodeKeyboard(
autoBiometricAuth: true,
autoPromptBiometric: true,
mapBiometricMessageToString: (message) =>
_exampleMapMessageToString(message, context),
pinCodeService: context.read<VerifyPinCodeService>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
String? encryptedPinCode,
bool isPinCorrect = false,
bool isPinCreated = false,
bool isPinCodeInSecureStorage = false,
bool savePinCodeInSecureStorage = false,
bool isPinDeleted = false,
}) {
when(coordinatorStates.userLoggedIn)
Expand All @@ -33,8 +33,8 @@ void main() {
when(createPinCodeService.checkIsPinCreated())
.thenAnswer((_) => Future.value(isPinCreated));

when(createPinCodeService.isPinCodeInSecureStorage())
.thenAnswer((_) => Future.value(isPinCodeInSecureStorage));
when(createPinCodeService.savePinCodeInSecureStorage(pinCode ?? ''))
.thenAnswer((_) => Future.value(savePinCodeInSecureStorage));

if (pinCode != null) {
if (encryptedPinCode != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void main() {
String? encryptedPinCode,
bool isPinCorrect = false,
bool isPinCreated = false,
bool isPinCodeInSecureStorage = false,
bool savePinCodeInSecureStorage = false,
bool isPinDeleted = false,
}) {
when(coordinatorStates.userLoggedIn)
Expand All @@ -47,8 +47,8 @@ void main() {
when(verifyPinCodeService.checkIsPinCreated())
.thenAnswer((_) => Future.value(isPinCreated));

when(verifyPinCodeService.isPinCodeInSecureStorage())
.thenAnswer((_) => Future.value(isPinCodeInSecureStorage));
when(verifyPinCodeService.savePinCodeInSecureStorage(pinCode ?? ''))
.thenAnswer((_) => Future.value(false));

if (pinCode != null) {
if (encryptedPinCode != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ UpdatePinCodeService updatePinCodeServiceMockFactory({
}) {
final mockUpdatePinCodeService = MockUpdatePinCodeService();

when(mockUpdatePinCodeService.isPinCodeInSecureStorage())
when(mockUpdatePinCodeService.savePinCodeInSecureStorage('1234'))
.thenAnswer((_) async => showBiometricsButton);

when(mockUpdatePinCodeService.getPinLength()).thenAnswer((_) async => 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ VerifyPinCodeService verifyPinCodeServiceMockFactory({
}) {
final mockVerifyPinCodeService = MockVerifyPinCodeService();

when(mockVerifyPinCodeService.isPinCodeInSecureStorage())
when(mockVerifyPinCodeService.savePinCodeInSecureStorage('1234'))
.thenAnswer((_) async => showBiometricsButton);

when(mockVerifyPinCodeService.getPinLength()).thenAnswer((_) async => 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ void main() {
verify(repository.getPinCode()).called(1);
});

test('isPinCodeInSecureStorage should return true', () async {
test('savePinCodeInSecureStorage should return true', () async {
const pinKey = VerifyPinCodeService.storedPin;

when(repository.readPinFromStorage(key: pinKey))
when(repository.writePinToStorage(pinKey, Stubs.pin))
.thenAnswer((_) async => Stubs.pin);

final result = await permissionsService.isPinCodeInSecureStorage();
final result =
await permissionsService.savePinCodeInSecureStorage(Stubs.pin);

expect(result, true);
verify(repository.readPinFromStorage(key: pinKey)).called(1);
verify(repository.writePinToStorage(pinKey, Stubs.pin)).called(1);
});

test('isPinCodeInSecureStorage should return false', () async {
test('savePinCodeInSecureStorage should return false', () async {
const pinKey = VerifyPinCodeService.storedPin;

when(repository.readPinFromStorage(key: pinKey))
.thenAnswer((_) async => null);

final result = await permissionsService.isPinCodeInSecureStorage();
final result =
await permissionsService.savePinCodeInSecureStorage(pinKey);

expect(result, false);
verify(repository.readPinFromStorage(key: pinKey)).called(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,17 @@ void main() {
.called(1);
});

test('isPinCodeInSecureStorage should return true', () async {
test('savePinCodeInSecureStorage should return false', () async {
const pinKey = VerifyPinCodeService.storedPin;
const pin = Stubs.pin;

when(repository.readPinFromStorage(key: pinKey))
when(repository.writePinToStorage(pinKey, pin))
.thenAnswer((_) async => pin);

final result = await service.isPinCodeInSecureStorage();

expect(result, true);
verify(repository.readPinFromStorage(key: pinKey)).called(1);
});

test('isPinCodeInSecureStorage should return false', () async {
const pinKey = VerifyPinCodeService.storedPin;

when(repository.readPinFromStorage(key: pinKey))
.thenAnswer((_) async => null);

final result = await service.isPinCodeInSecureStorage();
final result = await service.savePinCodeInSecureStorage(pin);

expect(result, false);
verify(repository.readPinFromStorage(key: pinKey)).called(1);
verifyNever(repository.writePinToStorage(pinKey, pin));
});

test('checkIsPinCreated should return true', () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,10 @@ class RouterBloc extends $RouterBloc {

@override
ConnectableStream<void> _mapToNavigationPathState() => Rx.merge([
_$goEvent
.throttleTime(const Duration(seconds: 1))
.switchMap((routeData) => _go(routeData).asResultStream()),
_$pushEvent
.throttleTime(const Duration(seconds: 1))
.switchMap((routeData) => _push(routeData).asResultStream()),
_$goEvent.switchMap((routeData) => _go(routeData).asResultStream()),
_$pushEvent.switchMap((routeData) => _push(routeData).asResultStream()),
_$goToLocationEvent.doOnData(_router.go).asResultStream(),
_$pushReplaceEvent
.throttleTime(const Duration(seconds: 1))
.switchMap((routeData) => _pushReplace(routeData).asResultStream()),
_$pushReplaceEvent.switchMap((routeData) => _pushReplace(routeData).asResultStream()),
_$popEvent.doOnData(_pop).asResultStream(),
]).setErrorStateHandler(this).whereSuccess().publish();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SplashBloc extends $SplashBloc {

{{#enable_pin_code}}
if (await _authService.isAuthenticated()) {
if(await _pinCodeService.isPinCodeInSecureStorage()) {
if (await _pinCodeService.getPinCode() == null) {
return _navigationBloc.events.go(const VerifyPinCodeRoute(),
extra: const PinCodeArguments(title: 'Enter Pin Code'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies: {{#enable_dev_menu}}
widget_toolkit: ^0.2.0 {{#enable_pin_code}}
widget_toolkit_biometrics: ^0.1.0 {{/enable_pin_code}} {{#enable_feature_otp}}
widget_toolkit_otp: ^0.1.0{{/enable_feature_otp}}{{#enable_pin_code}}
widget_toolkit_pin: ^0.2.1{{/enable_pin_code}}{{#enable_feature_qr_scanner}}
widget_toolkit_pin: ^0.3.0{{/enable_pin_code}}{{#enable_feature_qr_scanner}}
widget_toolkit_qr: ^0.2.0{{/enable_feature_qr_scanner}}


Expand All @@ -73,13 +73,6 @@ dev_dependencies:
rx_bloc_generator: ^8.0.0
rx_bloc_test: ^5.0.0
test: any {{#enable_patrol}}

dependency_overrides:
widget_toolkit_pin:
git:
url: https://github.com/Prime-Holding/widget_toolkit.git
path: packages/widget_toolkit_pin
ref: feature/auto-biometrics-option

patrol:
app_name: {{project_name}}
Expand Down

0 comments on commit 996119e

Please sign in to comment.