-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
180 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_10101/settings/seed_words.dart'; | ||
import 'package:get_10101/settings/settings_service.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class SeedScreen extends StatefulWidget { | ||
const SeedScreen({super.key}); | ||
|
||
@override | ||
State<SeedScreen> createState() => _SeedScreenState(); | ||
} | ||
|
||
class _SeedScreenState extends State<SeedScreen> { | ||
bool checked = false; | ||
bool visibility = false; | ||
|
||
List<String>? phrase; | ||
|
||
@override | ||
void initState() { | ||
context.read<SettingsService>().getSeedPhrase().then((value) => setState(() => phrase = value)); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Padding( | ||
padding: const EdgeInsets.only(top: 20, left: 10, right: 10), | ||
child: Column( | ||
children: [ | ||
Container( | ||
margin: const EdgeInsets.all(10), | ||
child: Center( | ||
child: RichText( | ||
text: const TextSpan( | ||
style: TextStyle(color: Colors.black, fontSize: 18), | ||
children: [ | ||
TextSpan( | ||
text: | ||
"The recovery phrase (sometimes called a seed), is a list of 12 English words. It allows you to recover full access to your funds if needed\n\n"), | ||
TextSpan( | ||
text: "Do not share this seed with anyone. ", | ||
style: TextStyle(fontWeight: FontWeight.bold)), | ||
TextSpan( | ||
text: | ||
"Beware of phising. The developers of 10101 will never ask for your seed.\n\n"), | ||
TextSpan( | ||
text: "Do not lose this seed. ", | ||
style: TextStyle(fontWeight: FontWeight.bold)), | ||
TextSpan( | ||
text: | ||
"Save it somewhere safe. If you lose your seed your lose your funds."), | ||
])), | ||
), | ||
), | ||
const SizedBox(height: 25), | ||
Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
buildSeedWordsWidget(phrase!, visibility), | ||
const SizedBox(height: 20), | ||
Center( | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
IconButton( | ||
icon: visibility | ||
? const Icon(Icons.visibility) | ||
: const Icon(Icons.visibility_off), | ||
onPressed: () { | ||
setState(() { | ||
visibility = !visibility; | ||
}); | ||
}, | ||
tooltip: visibility ? 'Hide Seed' : 'Show Seed'), | ||
Text(visibility ? 'Hide Seed' : 'Show Seed') | ||
], | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
Row buildSeedWordsWidget(List<String> phrase, bool visible) { | ||
final firstColumn = phrase | ||
.getRange(0, 6) | ||
.toList() | ||
.asMap() | ||
.entries | ||
.map((entry) => SeedWord(entry.value, entry.key + 1, visible)) | ||
.toList(); | ||
final secondColumn = phrase | ||
.getRange(6, 12) | ||
.toList() | ||
.asMap() | ||
.entries | ||
.map((entry) => SeedWord(entry.value, entry.key + 7, visible)) | ||
.toList(); | ||
|
||
return Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: firstColumn), | ||
const SizedBox(width: 30), | ||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: secondColumn) | ||
], | ||
); | ||
} | ||
|
||
class SeedWord extends StatelessWidget { | ||
final String? word; | ||
final int? index; | ||
final bool visibility; | ||
|
||
const SeedWord(this.word, this.index, this.visibility, {super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
padding: const EdgeInsets.fromLTRB(0, 5, 0, 5), | ||
child: Row( | ||
crossAxisAlignment: visibility ? CrossAxisAlignment.baseline : CrossAxisAlignment.end, | ||
textBaseline: TextBaseline.alphabetic, | ||
children: [ | ||
SizedBox( | ||
width: 25.0, | ||
child: Text( | ||
'#$index', | ||
style: TextStyle(fontSize: 14, color: Colors.grey[600]), | ||
), | ||
), | ||
const SizedBox(width: 5), | ||
visibility | ||
? SizedBox( | ||
width: 100, | ||
child: Text( | ||
word!, | ||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), | ||
), | ||
) | ||
: Container(width: 100, height: 24, color: Colors.grey[300]), | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
import 'package:http/http.dart' as http; | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:get_10101/common/http_client.dart'; | ||
|
||
class SettingsService { | ||
const SettingsService(); | ||
|
||
Future<String> getNodeId() async { | ||
// TODO(holzeis): this should come from the config | ||
const port = "3001"; | ||
const host = "localhost"; | ||
final response = await HttpClientManager.instance.get(Uri(path: '/api/node')); | ||
|
||
if (response.statusCode == 200) { | ||
return response.body; | ||
} else { | ||
throw FlutterError("Failed to fetch node id"); | ||
} | ||
} | ||
|
||
try { | ||
final response = await http.get(Uri.http('$host:$port', '/api/node')); | ||
Future<List<String>> getSeedPhrase() async { | ||
final response = await HttpClientManager.instance.get(Uri(path: '/api/seed')); | ||
|
||
if (response.statusCode == 200) { | ||
return response.body; | ||
} else { | ||
return "unknown"; | ||
} | ||
} catch (e) { | ||
return "unknown"; | ||
if (response.statusCode == 200) { | ||
return jsonDecode(response.body); | ||
} else { | ||
throw FlutterError("Failed to fetch seed phrase"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters