Skip to content

Commit

Permalink
Merge pull request #26 from peercoin/v0.2.0
Browse files Browse the repository at this point in the history
V0.2.0
  • Loading branch information
Willy authored Apr 8, 2021
2 parents 1bfaaec + 2173934 commit 6e4b71e
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 95 deletions.
7 changes: 5 additions & 2 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
"setup_pin": "Please set a PIN before you continue.",
"setup_create_pin": "Create PIN",
"setup_securebox_fail": "We are very sorry.\nYour device does not support a secure enough way of storing keys.",
"setup_seed_slider_label": "Slide to change the number of words",
"setup_pin_title": "Security",
"setup_welcome": "Welcome to Peercoin Wallet",
"create_wallet_new_seed": "Create wallet with new seed",
"create_wallet_or": "or",
"create_wallet_existing_seed": "Import existing seed",
"import_seed": "Please enter the seed you wish to import.",
"import_seed_button": "Import seed",
"import_seed_error_1": "Must be 12 words or more",
"import_seed_error_2": "Invalid seed",
"label_wallet_seed": "This is your wallet seed:",
"label_keep_seed_safe": "Make sure to keep it safe.\nTreat it like a password.\nThose 12 simple words give full access to your wallet.",
"label_wallet_seed": "Your wallet seed",
"label_keep_seed_safe": "Make sure to keep it safe.\nTreat it like a password.\nThose $numberOfWords simple words give full access to your wallet.",
"continue": "Continue",
"export_now": "Export now",
"transaction_details": "Transaction details",
Expand Down
4 changes: 2 additions & 2 deletions lib/providers/activewallets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class ActiveWallets with ChangeNotifier {
return bip39.mnemonicToSeed(words);
}

Future<void> createPhrase([String providedPhrase]) async {
Future<void> createPhrase([String providedPhrase, int strength = 128]) async {
if (providedPhrase == null) {
var mnemonicSeed = bip39.generateMnemonic();
var mnemonicSeed = bip39.generateMnemonic(strength: strength);
await _vaultBox.put('mnemonicSeed', mnemonicSeed);
_seedPhrase = mnemonicSeed;
} else {
Expand Down
54 changes: 32 additions & 22 deletions lib/screens/setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,36 @@ class _SetupScreenState extends State<SetupScreen> {
color: Theme.of(context).primaryColor,
child: Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
"assets/icon/ppc-icon-white-256.png",
width: 50,
),
SizedBox(height: 60),
Padding(
padding: EdgeInsets.symmetric(horizontal: 50),
child: Text(
AppLocalizations.instance.translate('setup_files_for_wallet'),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white),
),
),
SizedBox(height: 30),
_loading
? LoadingIndicator()
: Column(
child: _loading
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
LinearProgressIndicator(
backgroundColor: Colors.white,
),
],
)
: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Image.asset(
"assets/icon/ppc-icon-white-256.png",
width: 50,
),
Text(
AppLocalizations.instance.translate('setup_welcome'),
style: TextStyle(color: Colors.white, fontSize: 24),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 50),
child: Text(
AppLocalizations.instance
.translate('setup_files_for_wallet'),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
Expand Down Expand Up @@ -79,8 +89,8 @@ class _SetupScreenState extends State<SetupScreen> {
)
],
)
],
),
],
),
),
),
);
Expand Down
9 changes: 5 additions & 4 deletions lib/screens/setup_pin_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ class _SetupPinCodeScreenState extends State<SetupPinCodeScreen> {
padding: EdgeInsets.symmetric(horizontal: 30),
color: Theme.of(context).primaryColor,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/icon/ppc-icon-white-256.png",
width: 50,
),
SizedBox(height: 60),
Text(
AppLocalizations.instance.translate('setup_pin_title'),
style: TextStyle(color: Colors.white, fontSize: 24),
),
Text(AppLocalizations.instance.translate('setup_pin'),
style: TextStyle(color: Colors.white)),
SizedBox(height: 30),
SwitchListTile(
title: Text(
AppLocalizations.instance
Expand All @@ -49,7 +51,6 @@ class _SetupPinCodeScreenState extends State<SetupPinCodeScreen> {
_biometricsAllowed = newState;
});
}),
SizedBox(height: 30),
ElevatedButton(
onPressed: () async {
await screenLock(
Expand Down
203 changes: 139 additions & 64 deletions lib/screens/setup_save_seed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,92 +15,167 @@ class SetupSaveScreen extends StatefulWidget {
}

class _SetupSaveScreenState extends State<SetupSaveScreen> {
bool sharedYet = false;
String seed = "";
bool _sharedYet = false;
bool _initial = true;
String _seed = "";
double _currentSliderValue = 12;
ActiveWallets _activeWallets;

Future<void> shareSeed(seed) async {
await Share.share(seed);
Timer(
Duration(seconds: 1),
() => setState(() {
sharedYet = true;
_sharedYet = true;
}),
);
}

@override
void didChangeDependencies() async {
var thisSeed = await Provider.of<ActiveWallets>(context).seedPhrase;
if (_initial) {
_activeWallets = Provider.of<ActiveWallets>(context);
_seed = await _activeWallets.seedPhrase;

setState(() {
_initial = false;
});
}

super.didChangeDependencies();
}

void recreatePhrase(double sliderValue) async {
int _entropy = 128;
int _intValue = sliderValue.toInt();

switch (_intValue) {
case 16:
_entropy = 160;
break;
case 20:
_entropy = 192;
break;
case 24:
_entropy = 256;
break;
default:
_entropy = 128;
}

await _activeWallets.createPhrase(null, _entropy);
_seed = await _activeWallets.seedPhrase;

setState(() {
seed = thisSeed;
_sharedYet = false;
});
super.didChangeDependencies();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: SetupProgressIndicator(2),
body: Container(
padding: EdgeInsets.symmetric(horizontal: 30),
color: Theme.of(context).primaryColor,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
"assets/icon/ppc-icon-white-256.png",
width: 50,
),
SizedBox(height: 60),
Container(
alignment: Alignment.center,
width: double.infinity,
child: Text(
AppLocalizations.instance.translate('label_wallet_seed'),
style: TextStyle(color: Colors.white),
),
),
SizedBox(height: 40),
Center(
child: SelectableText(
seed,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
wordSpacing: 10),
),
),
SizedBox(height: 40),
Text(
AppLocalizations.instance.translate('label_keep_seed_safe'),
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
SizedBox(height: 30),
sharedYet
? ElevatedButton(
onPressed: () async {
var prefs = await Provider.of<UnencryptedOptions>(context,
listen: false)
.prefs;
await prefs.setBool("importedSeed", false);
Navigator.popAndPushNamed(context, Routes.SetUpPin);
},
child: Text(
AppLocalizations.instance.translate('continue'),
style: TextStyle(fontSize: 18),
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 30),
height: MediaQuery.of(context).size.height,
color: Theme.of(context).primaryColor,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Image.asset(
"assets/icon/ppc-icon-white-256.png",
width: 50,
),
)
: ElevatedButton(
onPressed: () async => await shareSeed(seed),
child: Text(
AppLocalizations.instance.translate('export_now'),
style: TextStyle(fontSize: 18),
Container(
alignment: Alignment.center,
width: double.infinity,
child: Text(
AppLocalizations.instance
.translate('label_wallet_seed'),
style: TextStyle(color: Colors.white, fontSize: 24),
),
),
)
],
),
SelectableText(
_seed,
minLines: 4,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
wordSpacing: 10),
),
Column(
children: [
Slider(
activeColor: Colors.white,
inactiveColor: Theme.of(context).accentColor,
value: _currentSliderValue,
min: 12,
max: 24,
divisions: 3,
label: _currentSliderValue.round().toString(),
onChanged: (value) {
setState(() {
_currentSliderValue = value;
});
if (value % 4 == 0) {
recreatePhrase(value);
}
},
),
Text(
AppLocalizations.instance
.translate("setup_seed_slider_label"),
style: TextStyle(color: Colors.white, fontSize: 12),
),
],
),
Text(
AppLocalizations.instance.translate(
'label_keep_seed_safe', {
"numberOfWords": _currentSliderValue.round().toString()
}),
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
Container(
padding: EdgeInsets.all(10),
child: _sharedYet
? ElevatedButton(
onPressed: () async {
var prefs =
await Provider.of<UnencryptedOptions>(
context,
listen: false)
.prefs;
await prefs.setBool("importedSeed", false);
Navigator.popAndPushNamed(
context, Routes.SetUpPin);
},
child: Text(
AppLocalizations.instance.translate('continue'),
style: TextStyle(fontSize: 18),
),
)
: ElevatedButton(
onPressed: () async => await shareSeed(_seed),
child: Text(
AppLocalizations.instance
.translate('export_now'),
style: TextStyle(fontSize: 18),
),
),
)
],
),
),
),
),
],
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.1.9+1
version: 0.2.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down

0 comments on commit 6e4b71e

Please sign in to comment.