Skip to content

Commit

Permalink
Resolve issue when doing reset and recover of wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkbee1 committed Jun 8, 2022
1 parent c69fe7e commit ab915cc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 36 deletions.
13 changes: 13 additions & 0 deletions lib/did/cubit/did_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ class DIDCubit extends Cubit<DIDState> {
did: did, didMethod: didMethod, didMethodName: didMethodName));
log.info('successfully Loaded');
}

Future<void> reset() async {
final log = Logger('talao-wallet/DID/delete');

emit(DIDStateWorking());
await secureStorageProvider.delete(SecureStorageKeys.did);
await secureStorageProvider.delete(SecureStorageKeys.didMethod);
await secureStorageProvider.delete(SecureStorageKeys.verificationMethod);
await secureStorageProvider.delete(SecureStorageKeys.didMethodName);
emit(DIDState());

log.info('successfully Deleted did information');
}
}
2 changes: 2 additions & 0 deletions lib/drawer/profile/view/profile_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:talao/app/shared/widget/confirm_dialog.dart';
import 'package:talao/did/cubit/did_cubit.dart';
import 'package:talao/drawer/drawer.dart';
import 'package:talao/issuer_websites_page/view/issuer_websites_page.dart';
import 'package:talao/l10n/l10n.dart';
Expand Down Expand Up @@ -116,6 +117,7 @@ class ProfileView extends StatelessWidget {
false;
if (confirm) {
await context.read<WalletCubit>().resetWallet();
await context.read<DIDCubit>().reset();
}
},
),
Expand Down
99 changes: 63 additions & 36 deletions lib/onboarding/recovery/view/onboarding_recovery.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import 'package:bip39/bip39.dart' as bip39;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:talao/app/interop/didkit/didkit.dart';
import 'package:talao/app/interop/key_generation.dart';
import 'package:talao/app/interop/secure_storage/secure_storage.dart';
import 'package:talao/app/shared/widget/back_leading_button.dart';
import 'package:talao/app/shared/widget/base/button.dart';
import 'package:talao/app/shared/widget/base/page.dart';
import 'package:talao/app/shared/widget/base/text_field.dart';
import 'package:flutter/material.dart';
import 'package:talao/did/cubit/did_cubit.dart';
import 'package:talao/drawer/profile/models/profile.dart';
import 'package:talao/l10n/l10n.dart';
import 'package:talao/onboarding/onboarding.dart';
import 'package:talao/personal/personal.dart';

class OnBoardingRecoveryPage extends StatefulWidget {
static Route route() => MaterialPageRoute(
builder: (context) => OnBoardingRecoveryPage(),
builder: (context) => BlocProvider(
create: (context) => OnBoardingGenPhraseCubit(
secureStorageProvider: SecureStorageProvider.instance,
didCubit: context.read<DIDCubit>(),
didKitProvider: DIDKitProvider.instance,
keyGeneration: KeyGeneration(),
),
child: OnBoardingRecoveryPage(),
),
settings: RouteSettings(name: '/onBoardingKeyPage'),
);

Expand Down Expand Up @@ -58,41 +71,55 @@ class _OnBoardingRecoveryPageState extends State<OnBoardingRecoveryPage> {
titleLeading: BackLeadingButton(),
scrollView: false,
padding: EdgeInsets.zero,
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
OnBoardingRecoveryPage._padHorizontal(Text(
l10n.recoveryText,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
)),
const SizedBox(height: 24.0),
BaseTextField(
label: l10n.recoveryMnemonicHintText,
controller: mnemonicController,
error: edited && !buttonEnabled ? l10n.recoveryMnemonicError : null,
),
const SizedBox(height: 24.0),
OnBoardingRecoveryPage._padHorizontal(BaseButton.primary(
context: context,
onPressed: buttonEnabled
? () async {
await SecureStorageProvider.instance.set(
'mnemonic',
mnemonicController.text,
);
await Navigator.of(context).pushReplacement(
PersonalPage.route(
isFromOnBoarding: true,
profileModel: ProfileModel.empty()),
);
}
: null,
child: Text(l10n.onBoardingRecoveryButton),
)),
const SizedBox(height: 32.0),
],
body: BlocConsumer<OnBoardingGenPhraseCubit, OnBoardingGenPhraseState>(
listener: (context, state) async {
if (state.status == OnBoardingGenPhraseStatus.success) {
await Navigator.of(context).pushReplacement(
PersonalPage.route(
isFromOnBoarding: true, profileModel: ProfileModel.empty()),
);
}
if (state.status == OnBoardingGenPhraseStatus.failure) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
backgroundColor: state.message!.color!,
content: Text(state.message?.getMessage(context) ?? ''),
));
}
},
builder: (context, state) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
OnBoardingRecoveryPage._padHorizontal(Text(
l10n.recoveryText,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle1,
)),
const SizedBox(height: 24.0),
BaseTextField(
label: l10n.recoveryMnemonicHintText,
controller: mnemonicController,
error: edited && !buttonEnabled
? l10n.recoveryMnemonicError
: null,
),
const SizedBox(height: 24.0),
OnBoardingRecoveryPage._padHorizontal(BaseButton.primary(
context: context,
onPressed: buttonEnabled
? () async {
await context
.read<OnBoardingGenPhraseCubit>()
.generateKey(context, state.mnemonic);
}
: null,
child: Text(l10n.onBoardingRecoveryButton),
)),
const SizedBox(height: 32.0),
],
);
},
),
);
}
Expand Down

0 comments on commit ab915cc

Please sign in to comment.