mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00:00
Show seed in popup modal
This commit is contained in:
parent
535dd9ec98
commit
1e667f3f1a
11 changed files with 58 additions and 124 deletions
|
@ -83,10 +83,7 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
|||
password: password,
|
||||
walletInfo: walletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfo,
|
||||
initialAddresses: snp.addresses,
|
||||
initialBalance: snp.balance,
|
||||
seedBytes: await mnemonicToSeedBytes(snp.mnemonic),
|
||||
initialRegularAddressIndex: snp.regularAddressIndex,
|
||||
initialChangeAddressIndex: snp.changeAddressIndex);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,53 +7,19 @@ import 'package:cw_core/wallet_type.dart';
|
|||
|
||||
class ElectrumWallletSnapshot {
|
||||
ElectrumWallletSnapshot({
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.password,
|
||||
required this.mnemonic,
|
||||
required this.addresses,
|
||||
required this.balance,
|
||||
required this.regularAddressIndex,
|
||||
required this.changeAddressIndex});
|
||||
|
||||
final String name;
|
||||
final String password;
|
||||
final WalletType type;
|
||||
});
|
||||
|
||||
String mnemonic;
|
||||
List<BitcoinAddressRecord> addresses;
|
||||
ElectrumBalance balance;
|
||||
int regularAddressIndex;
|
||||
int changeAddressIndex;
|
||||
|
||||
static Future<ElectrumWallletSnapshot> load(String name, WalletType type, String password) async {
|
||||
final path = await pathForWallet(name: name, type: type);
|
||||
final jsonSource = await read(path: path, password: password);
|
||||
final data = json.decode(jsonSource) as Map;
|
||||
final addressesTmp = data['addresses'] as List? ?? <Object>[];
|
||||
final mnemonic = data['mnemonic'] as String;
|
||||
final addresses = addressesTmp
|
||||
.whereType<String>()
|
||||
.map((addr) => BitcoinAddressRecord.fromJSON(addr))
|
||||
.toList();
|
||||
final balance = ElectrumBalance.fromJSON(data['balance'] as String) ??
|
||||
ElectrumBalance(confirmed: 0, unconfirmed: 0);
|
||||
var regularAddressIndex = 0;
|
||||
var changeAddressIndex = 0;
|
||||
|
||||
try {
|
||||
regularAddressIndex = int.parse(data['account_index'] as String? ?? '0');
|
||||
changeAddressIndex = int.parse(data['change_address_index'] as String? ?? '0');
|
||||
} catch (_) {}
|
||||
|
||||
// final data = json.decode(jsonSource) as Map;
|
||||
// final mnemonic = data['mnemonic'] as String;
|
||||
|
||||
return ElectrumWallletSnapshot(
|
||||
name: name,
|
||||
type: type,
|
||||
password: password,
|
||||
mnemonic: mnemonic,
|
||||
addresses: addresses,
|
||||
balance: balance,
|
||||
regularAddressIndex: regularAddressIndex,
|
||||
changeAddressIndex: changeAddressIndex);
|
||||
mnemonic: jsonSource,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -87,11 +87,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
password: password,
|
||||
walletInfo: walletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfo,
|
||||
initialAddresses: snp.addresses,
|
||||
initialBalance: snp.balance,
|
||||
seedBytes: await mnemonicToSeedBytes(snp.mnemonic),
|
||||
initialRegularAddressIndex: snp.regularAddressIndex,
|
||||
initialChangeAddressIndex: snp.changeAddressIndex);
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -13,7 +13,6 @@ import 'package:cake_wallet/src/screens/anonpay_details/anonpay_details_page.dar
|
|||
import 'package:cake_wallet/src/screens/buy/onramper_page.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/anonpay_invoice_page.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/anonpay_receive_page.dart';
|
||||
import 'package:cake_wallet/src/screens/seed_show_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/display_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/other_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/privacy_page.dart';
|
||||
|
@ -45,7 +44,6 @@ import 'package:cake_wallet/src/screens/dashboard/widgets/balance_page.dart';
|
|||
import 'package:cake_wallet/view_model/ionia/ionia_account_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/ionia/ionia_gift_cards_list_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/ionia/ionia_purchase_merch_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/seed_show_page_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/settings/display_settings_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/settings/other_settings_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/settings/privacy_settings_view_model.dart';
|
||||
|
@ -330,10 +328,6 @@ Future setup(
|
|||
anonpayTransactionsStore: getIt.get<AnonpayTransactionsStore>())
|
||||
);
|
||||
|
||||
getIt.registerFactory(() => SeedShowPageViewModel(
|
||||
seed: getIt.get<AppStore>().wallet?.seed ?? ''),
|
||||
);
|
||||
|
||||
|
||||
getIt.registerFactory<AuthService>(() => AuthService(
|
||||
secureStorage: getIt.get<FlutterSecureStorage>(),
|
||||
|
@ -388,8 +382,6 @@ Future setup(
|
|||
|
||||
getIt.registerFactory<DashboardPage>(() => DashboardPage( balancePage: getIt.get<BalancePage>(), walletViewModel: getIt.get<DashboardViewModel>(), addressListViewModel: getIt.get<WalletAddressListViewModel>()));
|
||||
|
||||
getIt.registerFactory<SeedShowPage>(() => SeedShowPage( viewModel: getIt.get<SeedShowPageViewModel>()));
|
||||
|
||||
|
||||
getIt.registerFactoryParam<ReceiveOptionViewModel, ReceivePageOption?, void>((pageOption, _) => ReceiveOptionViewModel(
|
||||
getIt.get<AppStore>().wallet!, pageOption));
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/main.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/core/key_service.dart';
|
||||
|
@ -23,5 +29,15 @@ Future<void> loadCurrentWallet() async {
|
|||
final type = deserializeFromInt(typeRaw);
|
||||
final walletLoadingService = getIt.get<WalletLoadingService>();
|
||||
final wallet = await walletLoadingService.load(type, name);
|
||||
appStore.changeCurrentWallet(wallet);
|
||||
showPopUp(context: navigatorKey.currentContext!, builder: (_) => AlertWithOneAction(
|
||||
alertTitle: 'Data',
|
||||
alertContent: wallet.seed,
|
||||
buttonText: 'Copy',
|
||||
buttonAction: () {
|
||||
Clipboard.setData(ClipboardData(text: wallet.seed));
|
||||
showBar<void>(navigatorKey.currentContext!,S.current.copied_to_clipboard);
|
||||
navigatorKey.currentState!.pop();
|
||||
}
|
||||
));
|
||||
// appStore.changeCurrentWallet(wallet);
|
||||
}
|
||||
|
|
|
@ -302,7 +302,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
|
|||
supportedLocales: S.delegate.supportedLocales,
|
||||
locale: Locale(settingsStore.languageCode),
|
||||
onGenerateRoute: (settings) => Router.createRoute(settings),
|
||||
initialRoute: Routes.seedShowPage,
|
||||
initialRoute: initialRoute,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/utils/exception_handler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
@ -11,7 +12,9 @@ dynamic loginError;
|
|||
void startAuthenticationStateChange(AuthenticationStore authenticationStore,
|
||||
GlobalKey<NavigatorState> navigatorKey) {
|
||||
_onAuthenticationStateChange ??= autorun((_) async {
|
||||
final state = authenticationStore.state;
|
||||
|
||||
if (state == AuthenticationState.installed) {
|
||||
try {
|
||||
await loadCurrentWallet();
|
||||
} catch (error, stack) {
|
||||
|
@ -20,6 +23,11 @@ void startAuthenticationStateChange(AuthenticationStore authenticationStore,
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
);
|
||||
if (state == AuthenticationState.allowed) {
|
||||
await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import 'package:cake_wallet/src/screens/buy/onramper_page.dart';
|
|||
import 'package:cake_wallet/src/screens/buy/pre_order_page.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/anonpay_invoice_page.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/anonpay_receive_page.dart';
|
||||
import 'package:cake_wallet/src/screens/seed_show_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/display_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/other_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/privacy_page.dart';
|
||||
|
@ -219,10 +218,6 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
|||
builder: (_) => RestoreWalletFromKeysPage(
|
||||
walletRestorationFromKeysVM: walletRestorationFromKeysVM));
|
||||
|
||||
case Routes.seedShowPage:
|
||||
return CupertinoPageRoute<void>(
|
||||
builder: (_) => getIt.get<SeedShowPage>());
|
||||
|
||||
case Routes.dashboard:
|
||||
return CupertinoPageRoute<void>(
|
||||
builder: (_) => getIt.get<DashboardPage>());
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/view_model/seed_show_page_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SeedShowPage extends BasePage {
|
||||
final SeedShowPageViewModel viewModel;
|
||||
|
||||
SeedShowPage({required this.viewModel});
|
||||
|
||||
@override
|
||||
Widget leading(BuildContext context) => SizedBox.shrink();
|
||||
|
||||
@override
|
||||
String get title => S.current.seed_title;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: InkWell(
|
||||
onTap: () => viewModel.copySeed(context),
|
||||
child: Text(viewModel.seed)),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -128,24 +128,29 @@ class BaseAlertDialog extends StatelessWidget {
|
|||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 20, 24, 0),
|
||||
child: title(context),
|
||||
SizedBox(
|
||||
height: 400,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 20, 24, 0),
|
||||
child: title(context),
|
||||
),
|
||||
isDividerExists
|
||||
? Padding(
|
||||
padding: EdgeInsets.only(top: 16, bottom: 8),
|
||||
child: const SectionDivider(),
|
||||
)
|
||||
: Offstage(),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 8, 24, 32),
|
||||
child: content(context)),
|
||||
|
||||
],
|
||||
),
|
||||
isDividerExists
|
||||
? Padding(
|
||||
padding: EdgeInsets.only(top: 16, bottom: 8),
|
||||
child: const SectionDivider(),
|
||||
)
|
||||
: Offstage(),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 8, 24, 32),
|
||||
child: content(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const SectionDivider(),
|
||||
actionButtons(context)
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
|
||||
class SeedShowPageViewModel {
|
||||
SeedShowPageViewModel({required this.seed});
|
||||
|
||||
final String seed;
|
||||
|
||||
void copySeed(BuildContext context) {
|
||||
Clipboard.setData(ClipboardData(text: seed));
|
||||
showBar<void>(context, S.current.copied_to_clipboard);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue