2020-09-11 15:52:55 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
|
|
|
import 'package:cake_wallet/palette.dart';
|
2020-09-25 10:26:08 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
2020-09-11 15:52:55 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:esys_flutter_share/esys_flutter_share.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/view_model/wallet_seed_view_model.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
class WalletSeedPage extends BasePage {
|
2020-09-11 15:52:55 +00:00
|
|
|
WalletSeedPage(this.walletSeedViewModel, {@required this.isNewWalletCreated});
|
2020-01-08 12:26:34 +00:00
|
|
|
|
2020-06-09 18:43:55 +00:00
|
|
|
static final imageLight = Image.asset('assets/images/crypto_lock_light.png');
|
|
|
|
static final imageDark = Image.asset('assets/images/crypto_lock.png');
|
2020-01-08 12:26:34 +00:00
|
|
|
|
|
|
|
@override
|
2020-01-04 19:31:52 +00:00
|
|
|
String get title => S.current.seed_title;
|
|
|
|
|
2020-09-11 15:52:55 +00:00
|
|
|
final bool isNewWalletCreated;
|
2020-07-06 20:09:03 +00:00
|
|
|
final WalletSeedViewModel walletSeedViewModel;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
@override
|
2020-09-25 10:26:08 +00:00
|
|
|
void onClose(BuildContext context) async {
|
|
|
|
if (isNewWalletCreated) {
|
|
|
|
final confirmed = await showDialog<bool>(context: context, builder: (BuildContext context) {
|
|
|
|
// FIXME: add translations
|
|
|
|
return AlertWithTwoActions(
|
|
|
|
alertTitle: 'Attention',
|
|
|
|
alertContent: 'Have you written it down? The seed is the only way to recover your wallet.',
|
|
|
|
leftButtonText: 'Not yet',
|
|
|
|
rightButtonText: 'Yes, I have',
|
|
|
|
actionLeftButton: () => Navigator.of(context).pop(false),
|
|
|
|
actionRightButton: () => Navigator.of(context).pop(true));
|
|
|
|
}) ?? false;
|
|
|
|
|
|
|
|
if (confirmed) {
|
|
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
2020-07-06 20:09:03 +00:00
|
|
|
Widget leading(BuildContext context) =>
|
2020-09-11 15:52:55 +00:00
|
|
|
isNewWalletCreated ? Offstage() : super.leading(context);
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-04-24 17:34:32 +00:00
|
|
|
@override
|
|
|
|
Widget trailing(BuildContext context) {
|
2020-09-11 15:52:55 +00:00
|
|
|
return isNewWalletCreated
|
2020-04-24 17:34:32 +00:00
|
|
|
? GestureDetector(
|
2020-09-25 10:26:08 +00:00
|
|
|
onTap: () => onClose(context),
|
|
|
|
child: Container(
|
|
|
|
width: 100,
|
|
|
|
height: 32,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
margin: EdgeInsets.only(left: 10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(16)),
|
|
|
|
color: Theme
|
|
|
|
.of(context)
|
|
|
|
.accentTextTheme
|
|
|
|
.caption
|
|
|
|
.color),
|
|
|
|
child: Text(
|
|
|
|
S
|
|
|
|
.of(context)
|
|
|
|
.seed_language_next,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: Palette.blueCraiola),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2020-04-24 17:34:32 +00:00
|
|
|
: Offstage();
|
|
|
|
}
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) {
|
2020-09-21 11:50:26 +00:00
|
|
|
final image =
|
2020-09-25 10:26:08 +00:00
|
|
|
getIt
|
|
|
|
.get<SettingsStore>()
|
|
|
|
.isDarkTheme ? imageDark : imageLight;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
return Container(
|
2020-07-06 20:09:03 +00:00
|
|
|
padding: EdgeInsets.all(24),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Flexible(
|
|
|
|
flex: 2,
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1,
|
|
|
|
child: FittedBox(child: image, fit: BoxFit.fill))),
|
|
|
|
Flexible(
|
|
|
|
flex: 3,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 33),
|
|
|
|
child: Observer(builder: (_) {
|
2020-06-09 18:43:55 +00:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
2020-07-06 20:09:03 +00:00
|
|
|
walletSeedViewModel.name,
|
2020-06-09 18:43:55 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
2020-09-11 15:52:55 +00:00
|
|
|
fontWeight: FontWeight.w600,
|
2020-09-25 10:26:08 +00:00
|
|
|
color: Theme
|
|
|
|
.of(context)
|
2020-07-06 20:09:03 +00:00
|
|
|
.primaryTextTheme
|
|
|
|
.title
|
|
|
|
.color),
|
2020-04-24 17:34:32 +00:00
|
|
|
),
|
2020-06-09 18:43:55 +00:00
|
|
|
Padding(
|
2020-09-21 11:50:26 +00:00
|
|
|
padding:
|
2020-09-25 10:26:08 +00:00
|
|
|
EdgeInsets.only(top: 20, left: 16, right: 16),
|
2020-06-09 18:43:55 +00:00
|
|
|
child: Text(
|
2020-07-06 20:09:03 +00:00
|
|
|
walletSeedViewModel.seed,
|
2020-06-09 18:43:55 +00:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
2020-09-11 15:52:55 +00:00
|
|
|
fontWeight: FontWeight.normal,
|
2020-09-25 10:26:08 +00:00
|
|
|
color: Theme
|
|
|
|
.of(context)
|
2020-07-06 20:09:03 +00:00
|
|
|
.primaryTextTheme
|
|
|
|
.caption
|
|
|
|
.color),
|
2020-06-09 18:43:55 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
2020-07-06 20:09:03 +00:00
|
|
|
}),
|
|
|
|
),
|
2020-09-11 15:52:55 +00:00
|
|
|
Column(
|
2020-07-06 20:09:03 +00:00
|
|
|
children: <Widget>[
|
2020-09-11 15:52:55 +00:00
|
|
|
isNewWalletCreated
|
2020-09-21 11:50:26 +00:00
|
|
|
? Padding(
|
2020-09-25 10:26:08 +00:00
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: 52, left: 43, right: 43),
|
|
|
|
child: Text(
|
|
|
|
S
|
|
|
|
.of(context)
|
|
|
|
.seed_reminder,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
color: Theme
|
|
|
|
.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.overline
|
|
|
|
.color),
|
|
|
|
),
|
|
|
|
)
|
2020-09-21 11:50:26 +00:00
|
|
|
: Offstage(),
|
2020-09-11 15:52:55 +00:00
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: <Widget>[
|
|
|
|
Flexible(
|
|
|
|
child: Container(
|
2020-09-25 10:26:08 +00:00
|
|
|
padding: EdgeInsets.only(right: 8.0),
|
|
|
|
child: PrimaryButton(
|
|
|
|
onPressed: () =>
|
|
|
|
Share.text(
|
|
|
|
S
|
|
|
|
.of(context)
|
|
|
|
.seed_share,
|
|
|
|
walletSeedViewModel.seed,
|
|
|
|
'text/plain'),
|
|
|
|
text: S
|
|
|
|
.of(context)
|
|
|
|
.save,
|
|
|
|
color: Colors.green,
|
|
|
|
textColor: Colors.white),
|
|
|
|
)),
|
2020-09-11 15:52:55 +00:00
|
|
|
Flexible(
|
|
|
|
child: Container(
|
2020-09-25 10:26:08 +00:00
|
|
|
padding: EdgeInsets.only(left: 8.0),
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) =>
|
|
|
|
PrimaryButton(
|
|
|
|
onPressed: () {
|
|
|
|
Clipboard.setData(ClipboardData(
|
|
|
|
text: walletSeedViewModel
|
|
|
|
.seed));
|
|
|
|
Scaffold.of(context)
|
|
|
|
.showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(S
|
|
|
|
.of(context)
|
|
|
|
.copied_to_clipboard),
|
|
|
|
backgroundColor: Colors
|
|
|
|
.green,
|
|
|
|
duration:
|
|
|
|
Duration(
|
|
|
|
milliseconds: 1500),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
text: S
|
|
|
|
.of(context)
|
|
|
|
.copy,
|
|
|
|
color: Theme
|
|
|
|
.of(context)
|
|
|
|
.accentTextTheme
|
|
|
|
.body2
|
|
|
|
.color,
|
|
|
|
textColor: Colors.white)),
|
|
|
|
))
|
2020-09-11 15:52:55 +00:00
|
|
|
],
|
|
|
|
)
|
2020-07-06 20:09:03 +00:00
|
|
|
],
|
2020-06-09 18:43:55 +00:00
|
|
|
)
|
|
|
|
],
|
2020-07-06 20:09:03 +00:00
|
|
|
))
|
|
|
|
],
|
|
|
|
));
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
}
|