Big improve on Wallets Tiles; Review of wallets index format

This commit is contained in:
poka 2021-03-11 07:08:45 +01:00
parent d0e1bbbab6
commit f39cafd309
11 changed files with 122 additions and 76 deletions

9
assets/chopp-gecko.svg Executable file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 14 KiB

BIN
assets/chopp-gecko2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -3,6 +3,8 @@ import 'package:shared_preferences/shared_preferences.dart';
Directory appPath; Directory appPath;
Directory walletsDirectory; Directory walletsDirectory;
File defaultWalletFile;
String defaultWallet;
String appVersion; String appVersion;
SharedPreferences prefs; SharedPreferences prefs;
String endPointGVA; String endPointGVA;

View File

@ -25,8 +25,10 @@ Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
HomeProvider _homeProvider = HomeProvider(); HomeProvider _homeProvider = HomeProvider();
MyWalletsProvider _walletsProvider = MyWalletsProvider();
await _homeProvider.getAppPath(); await _homeProvider.getAppPath();
await _homeProvider.createDefaultAvatar(); await _homeProvider.createDefaultAvatar();
await _walletsProvider.getDefaultWallet();
appVersion = await _homeProvider.getAppVersion(); appVersion = await _homeProvider.getAppVersion();
prefs = await SharedPreferences.getInstance(); prefs = await SharedPreferences.getInstance();
final HiveStore _store = final HiveStore _store =

View File

@ -39,50 +39,30 @@ class GenerateWalletsProvider with ChangeNotifier {
bool canImport = false; bool canImport = false;
bool isPinChanged = false; bool isPinChanged = false;
Future storeWallet(NewWallet wallet, String _name, BuildContext context, Future storeHDWallet(
{bool isHD = false}) async { NewWallet _wallet, String _name, BuildContext context) async {
int nbrWallet; // Directory walletDirectory;
if (isHD) {
nbrWallet = 0;
} else {
nbrWallet = 1;
}
Directory walletNbrDirectory; final Directory hdDirectory = Directory('${walletsDirectory.path}/0');
do { await hdDirectory.create();
nbrWallet++;
walletNbrDirectory = Directory('${walletsDirectory.path}/$nbrWallet');
} while (await walletNbrDirectory.exists());
final walletFile = File('${walletNbrDirectory.path}/wallet.dewif'); final configFile = File('${hdDirectory.path}/config.txt');
final dewifFile = File('${hdDirectory.path}/wallet.dewif');
await walletNbrDirectory.create(); // List<String> _lastConfig = [];
await walletFile.writeAsString(wallet.dewif); // _lastConfig = await masterConfigFile.readAsLines();
// final int _lastDerivation = int.parse(_lastConfig.last.split(':')[2]);
// final int _derivationNbr = _lastDerivation + 3;
final configFile = File('${walletNbrDirectory.path}/config.txt'); final int _derivationNbr = 3;
List _pubkeysTmp = await DubpRust.getBip32DewifAccountsPublicKeys(
dewif: _wallet.dewif,
secretCode: _wallet.pin,
accountsIndex: [_derivationNbr]);
String _pubkey = _pubkeysTmp[0];
if (isHD) { await configFile.writeAsString('0:$_name:$_derivationNbr:$_pubkey');
final int _derivationNbr = 3; await dewifFile.writeAsString(_wallet.dewif);
List _pubkeysTmp = await DubpRust.getBip32DewifAccountsPublicKeys(
dewif: wallet.dewif,
secretCode: wallet.pin,
accountsIndex: [_derivationNbr]);
String _pubkey = _pubkeysTmp[0];
await configFile
.writeAsString('$nbrWallet:$_name:$_derivationNbr:$_pubkey');
// Navigator.pop(context, true);
} else {
final int _derivationNbr = -1;
String _pubkey = await DubpRust.getDewifPublicKey(
dewif: wallet.dewif,
pin: wallet.pin,
);
await configFile
.writeAsString('$nbrWallet:$_name:$_derivationNbr:$_pubkey');
}
// Navigator.pop(context, true);
return _name; return _name;
} }
@ -263,8 +243,8 @@ class GenerateWalletsProvider with ChangeNotifier {
salt: _cesiumID, password: _cesiumPWD); salt: _cesiumID, password: _cesiumPWD);
String shortPubkey = truncate(_walletPubkey, 9, String shortPubkey = truncate(_walletPubkey, 9,
omission: "...", position: TruncatePosition.end); omission: "...", position: TruncatePosition.end);
await storeWallet( // await storeWallet(
actualWallet, 'Portefeuille Cesium - $shortPubkey', context); // actualWallet, 'Portefeuille Cesium - $shortPubkey', context);
cesiumID.text = ''; cesiumID.text = '';
cesiumPWD.text = ''; cesiumPWD.text = '';
cesiumPubkey.text = ''; cesiumPubkey.text = '';

View File

@ -13,6 +13,8 @@ class MyWalletsProvider with ChangeNotifier {
return false; return false;
} }
print(walletsDirectory.listSync());
List contents = walletsDirectory.listSync(); List contents = walletsDirectory.listSync();
if (contents.length == 0) { if (contents.length == 0) {
print('No wallets detected'); print('No wallets detected');
@ -54,6 +56,23 @@ class MyWalletsProvider with ChangeNotifier {
return listWallets; return listWallets;
} }
Future getDefaultWallet() async {
defaultWalletFile = File('${appPath.path}/defaultWallet');
bool isdefaultWalletFile = await defaultWalletFile.exists();
if (!isdefaultWalletFile) {
await File(defaultWalletFile.path).create();
}
try {
defaultWallet = await defaultWalletFile.readAsString();
} catch (e) {
defaultWallet = '0:3';
}
if (defaultWallet == '') defaultWallet = '0:3';
}
Future<int> deleteAllWallet(context) async { Future<int> deleteAllWallet(context) async {
try { try {
print('DELETE THAT ?: $walletsDirectory'); print('DELETE THAT ?: $walletsDirectory');
@ -107,11 +126,9 @@ class MyWalletsProvider with ChangeNotifier {
); );
} }
Future<void> generateNewDerivation( Future<void> generateNewDerivation(context, String _name) async {
context, String _name, int _walletNbr) async {
int _newDerivationNbr; int _newDerivationNbr;
final _walletConfig = final _walletConfig = File('${walletsDirectory.path}/0/config.txt');
File('${walletsDirectory.path}/$_walletNbr/config.txt');
if (await _walletConfig.readAsString() == '') { if (await _walletConfig.readAsString() == '') {
_newDerivationNbr = 3; _newDerivationNbr = 3;
@ -122,7 +139,7 @@ class MyWalletsProvider with ChangeNotifier {
_newDerivationNbr = _lastDerivation + 3; _newDerivationNbr = _lastDerivation + 3;
} }
await _walletConfig.writeAsString('\n$_walletNbr:$_name:$_newDerivationNbr', await _walletConfig.writeAsString('\n0:$_name:$_newDerivationNbr',
mode: FileMode.append); mode: FileMode.append);
print(await _walletConfig.readAsString()); print(await _walletConfig.readAsString());

View File

@ -126,11 +126,10 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
.isAskedWordValid && .isAskedWordValid &&
this.walletName.text != '') this.walletName.text != '')
? () async { ? () async {
await _generateWalletProvider.storeWallet( await _generateWalletProvider.storeHDWallet(
generatedWallet, generatedWallet,
walletName.text, walletName.text,
context, context);
isHD: true);
_generateWalletProvider.isAskedWordValid = _generateWalletProvider.isAskedWordValid =
false; false;
_generateWalletProvider.askedWordColor = _generateWalletProvider.askedWordColor =

View File

@ -1,4 +1,5 @@
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/myWallets.dart'; import 'package:gecko/models/myWallets.dart';
import 'package:gecko/models/walletOptions.dart'; import 'package:gecko/models/walletOptions.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -81,7 +82,9 @@ class WalletsHome extends StatelessWidget {
List _listWallets = _myWalletProvider.listWallets.split('\n'); List _listWallets = _myWalletProvider.listWallets.split('\n');
// final int nbrOfWallets = _listWallets.length; // final int nbrOfWallets = _listWallets.length;
print(_listWallets); // print(_listWallets);
// print("${_listWallets[0].split(':')[0]}:${_listWallets[0].split(':')[2]}");
// print(defaultWallet);
return GridView.count( return GridView.count(
crossAxisCount: 2, crossAxisCount: 2,
@ -94,27 +97,62 @@ class WalletsHome extends StatelessWidget {
padding: EdgeInsets.all(16), padding: EdgeInsets.all(16),
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(12)), borderRadius: BorderRadius.all(Radius.circular(12)),
child: ListTile( child: Column(children: <Widget>[
// contentPadding: const EdgeInsets.only(left: 7.0), Expanded(
tileColor: Colors.green[100], child: Container(
// leading: Text('IMAGE'), width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
gradient: RadialGradient(
radius: 1,
colors: [
Colors.green[100],
Colors.green[500],
],
)),
child:
// SvgPicture.asset('assets/chopp-gecko2.png',
// semanticsLabel: 'Gecko', height: 48),
Image.asset(
'assets/chopp-gecko2.png',
),
)),
ListTile(
// contentPadding: const EdgeInsets.only(left: 7.0),
tileColor:
"${_repository.split(':')[0]}:${_repository.split(':')[2]}" ==
defaultWallet
? Color(0xffD28928)
: Color(0xffFFD58D),
// leading: Text('IMAGE'),
// subtitle: Text(_repository.split(':')[3], // subtitle: Text(_repository.split(':')[3],
// style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')),
title: Center( title: Center(
child: Text(_repository.split(':')[1], child: Padding(
style: TextStyle(fontSize: 16.0))), padding: EdgeInsets.symmetric(horizontal: 5),
// dense: true, child: Text(_repository.split(':')[1],
onTap: () { textAlign: TextAlign.center,
Navigator.push(context, style: TextStyle(
MaterialPageRoute(builder: (context) { fontSize: 16.0,
return UnlockingWallet( color:
walletNbr: int.parse(_repository.split(':')[0]), "${_repository.split(':')[0]}:${_repository.split(':')[2]}" ==
walletName: _repository.split(':')[1], defaultWallet
derivation: int.parse(_repository.split(':')[2])); ? Color(0xffF9F9F1)
})); : Colors.black)))),
}, // dense: true,
))) onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) {
return UnlockingWallet(
walletNbr: int.parse(_repository.split(':')[0]),
walletName: _repository.split(':')[1],
derivation:
int.parse(_repository.split(':')[2]));
}));
},
)
])))
]); ]);
} }
@ -200,7 +238,7 @@ class WalletsHome extends StatelessWidget {
onPressed: () async { onPressed: () async {
await _myWalletProvider await _myWalletProvider
.generateNewDerivation( .generateNewDerivation(
context, _newDerivationName.text, _walletNbr) context, _newDerivationName.text)
.then((_) => _newDerivationName.text == ''); .then((_) => _newDerivationName.text == '');
}, },
child: Text("Créer")), child: Text("Créer")),

View File

@ -142,7 +142,7 @@ class WalletsHome extends StatelessWidget {
onPressed: () async { onPressed: () async {
await _myWalletProvider await _myWalletProvider
.generateNewDerivation( .generateNewDerivation(
context, _newDerivationName.text, _walletNbr) context, _newDerivationName.text)
.then((_) => _newDerivationName.text == ''); .then((_) => _newDerivationName.text == '');
}, },
child: Text("Créer")), child: Text("Créer")),

View File

@ -116,9 +116,8 @@ class OnboardingStepFourteen extends StatelessWidget {
if (resultWallet) { if (resultWallet) {
pinColor = Colors.green[500]; pinColor = Colors.green[500];
print(generatedWallet.pin); print(generatedWallet.pin);
await _generateWalletProvider.storeWallet( await _generateWalletProvider.storeHDWallet(
generatedWallet, 'Mon portefeuille courant', context, generatedWallet, 'Mon portefeuille courant', context);
isHD: true);
_myWalletProvider.getAllWalletsNames(); _myWalletProvider.getAllWalletsNames();
_walletOptions.reloadBuild(); _walletOptions.reloadBuild();
_myWalletProvider.rebuildWidget(); _myWalletProvider.rebuildWidget();

View File

@ -5,7 +5,7 @@ description: Pay with G1.
# pub.dev using `pub publish`. This is preferred for private packages. # pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.0.1+20 version: 0.0.1+21
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.7.0 <3.0.0"