Big improve on Wallets Tiles; Review of wallets index format
This commit is contained in:
parent
d0e1bbbab6
commit
f39cafd309
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
|
@ -3,6 +3,8 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||
|
||||
Directory appPath;
|
||||
Directory walletsDirectory;
|
||||
File defaultWalletFile;
|
||||
String defaultWallet;
|
||||
String appVersion;
|
||||
SharedPreferences prefs;
|
||||
String endPointGVA;
|
||||
|
|
|
@ -25,8 +25,10 @@ Future<void> main() async {
|
|||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
HomeProvider _homeProvider = HomeProvider();
|
||||
MyWalletsProvider _walletsProvider = MyWalletsProvider();
|
||||
await _homeProvider.getAppPath();
|
||||
await _homeProvider.createDefaultAvatar();
|
||||
await _walletsProvider.getDefaultWallet();
|
||||
appVersion = await _homeProvider.getAppVersion();
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
final HiveStore _store =
|
||||
|
|
|
@ -39,50 +39,30 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
bool canImport = false;
|
||||
bool isPinChanged = false;
|
||||
|
||||
Future storeWallet(NewWallet wallet, String _name, BuildContext context,
|
||||
{bool isHD = false}) async {
|
||||
int nbrWallet;
|
||||
if (isHD) {
|
||||
nbrWallet = 0;
|
||||
} else {
|
||||
nbrWallet = 1;
|
||||
}
|
||||
Future storeHDWallet(
|
||||
NewWallet _wallet, String _name, BuildContext context) async {
|
||||
// Directory walletDirectory;
|
||||
|
||||
Directory walletNbrDirectory;
|
||||
do {
|
||||
nbrWallet++;
|
||||
walletNbrDirectory = Directory('${walletsDirectory.path}/$nbrWallet');
|
||||
} while (await walletNbrDirectory.exists());
|
||||
final Directory hdDirectory = Directory('${walletsDirectory.path}/0');
|
||||
await hdDirectory.create();
|
||||
|
||||
final walletFile = File('${walletNbrDirectory.path}/wallet.dewif');
|
||||
final configFile = File('${hdDirectory.path}/config.txt');
|
||||
final dewifFile = File('${hdDirectory.path}/wallet.dewif');
|
||||
|
||||
await walletNbrDirectory.create();
|
||||
await walletFile.writeAsString(wallet.dewif);
|
||||
// List<String> _lastConfig = [];
|
||||
// _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');
|
||||
|
||||
if (isHD) {
|
||||
final int _derivationNbr = 3;
|
||||
List _pubkeysTmp = await DubpRust.getBip32DewifAccountsPublicKeys(
|
||||
dewif: wallet.dewif,
|
||||
secretCode: wallet.pin,
|
||||
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);
|
||||
await configFile.writeAsString('0:$_name:$_derivationNbr:$_pubkey');
|
||||
await dewifFile.writeAsString(_wallet.dewif);
|
||||
|
||||
return _name;
|
||||
}
|
||||
|
@ -263,8 +243,8 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
salt: _cesiumID, password: _cesiumPWD);
|
||||
String shortPubkey = truncate(_walletPubkey, 9,
|
||||
omission: "...", position: TruncatePosition.end);
|
||||
await storeWallet(
|
||||
actualWallet, 'Portefeuille Cesium - $shortPubkey', context);
|
||||
// await storeWallet(
|
||||
// actualWallet, 'Portefeuille Cesium - $shortPubkey', context);
|
||||
cesiumID.text = '';
|
||||
cesiumPWD.text = '';
|
||||
cesiumPubkey.text = '';
|
||||
|
|
|
@ -13,6 +13,8 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
return false;
|
||||
}
|
||||
|
||||
print(walletsDirectory.listSync());
|
||||
|
||||
List contents = walletsDirectory.listSync();
|
||||
if (contents.length == 0) {
|
||||
print('No wallets detected');
|
||||
|
@ -54,6 +56,23 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
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 {
|
||||
try {
|
||||
print('DELETE THAT ?: $walletsDirectory');
|
||||
|
@ -107,11 +126,9 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> generateNewDerivation(
|
||||
context, String _name, int _walletNbr) async {
|
||||
Future<void> generateNewDerivation(context, String _name) async {
|
||||
int _newDerivationNbr;
|
||||
final _walletConfig =
|
||||
File('${walletsDirectory.path}/$_walletNbr/config.txt');
|
||||
final _walletConfig = File('${walletsDirectory.path}/0/config.txt');
|
||||
|
||||
if (await _walletConfig.readAsString() == '') {
|
||||
_newDerivationNbr = 3;
|
||||
|
@ -122,7 +139,7 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
_newDerivationNbr = _lastDerivation + 3;
|
||||
}
|
||||
|
||||
await _walletConfig.writeAsString('\n$_walletNbr:$_name:$_newDerivationNbr',
|
||||
await _walletConfig.writeAsString('\n0:$_name:$_newDerivationNbr',
|
||||
mode: FileMode.append);
|
||||
|
||||
print(await _walletConfig.readAsString());
|
||||
|
|
|
@ -126,11 +126,10 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
|
|||
.isAskedWordValid &&
|
||||
this.walletName.text != '')
|
||||
? () async {
|
||||
await _generateWalletProvider.storeWallet(
|
||||
await _generateWalletProvider.storeHDWallet(
|
||||
generatedWallet,
|
||||
walletName.text,
|
||||
context,
|
||||
isHD: true);
|
||||
context);
|
||||
_generateWalletProvider.isAskedWordValid =
|
||||
false;
|
||||
_generateWalletProvider.askedWordColor =
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/myWallets.dart';
|
||||
import 'package:gecko/models/walletOptions.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -81,7 +82,9 @@ class WalletsHome extends StatelessWidget {
|
|||
|
||||
List _listWallets = _myWalletProvider.listWallets.split('\n');
|
||||
// final int nbrOfWallets = _listWallets.length;
|
||||
print(_listWallets);
|
||||
// print(_listWallets);
|
||||
// print("${_listWallets[0].split(':')[0]}:${_listWallets[0].split(':')[2]}");
|
||||
// print(defaultWallet);
|
||||
|
||||
return GridView.count(
|
||||
crossAxisCount: 2,
|
||||
|
@ -94,16 +97,49 @@ class WalletsHome extends StatelessWidget {
|
|||
padding: EdgeInsets.all(16),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
child: ListTile(
|
||||
child: Column(children: <Widget>[
|
||||
Expanded(
|
||||
child: Container(
|
||||
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: Colors.green[100],
|
||||
tileColor:
|
||||
"${_repository.split(':')[0]}:${_repository.split(':')[2]}" ==
|
||||
defaultWallet
|
||||
? Color(0xffD28928)
|
||||
: Color(0xffFFD58D),
|
||||
// leading: Text('IMAGE'),
|
||||
|
||||
// subtitle: Text(_repository.split(':')[3],
|
||||
// style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')),
|
||||
title: Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 5),
|
||||
child: Text(_repository.split(':')[1],
|
||||
style: TextStyle(fontSize: 16.0))),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color:
|
||||
"${_repository.split(':')[0]}:${_repository.split(':')[2]}" ==
|
||||
defaultWallet
|
||||
? Color(0xffF9F9F1)
|
||||
: Colors.black)))),
|
||||
// dense: true,
|
||||
onTap: () {
|
||||
Navigator.push(context,
|
||||
|
@ -111,10 +147,12 @@ class WalletsHome extends StatelessWidget {
|
|||
return UnlockingWallet(
|
||||
walletNbr: int.parse(_repository.split(':')[0]),
|
||||
walletName: _repository.split(':')[1],
|
||||
derivation: int.parse(_repository.split(':')[2]));
|
||||
derivation:
|
||||
int.parse(_repository.split(':')[2]));
|
||||
}));
|
||||
},
|
||||
)))
|
||||
)
|
||||
])))
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -200,7 +238,7 @@ class WalletsHome extends StatelessWidget {
|
|||
onPressed: () async {
|
||||
await _myWalletProvider
|
||||
.generateNewDerivation(
|
||||
context, _newDerivationName.text, _walletNbr)
|
||||
context, _newDerivationName.text)
|
||||
.then((_) => _newDerivationName.text == '');
|
||||
},
|
||||
child: Text("Créer")),
|
||||
|
|
|
@ -142,7 +142,7 @@ class WalletsHome extends StatelessWidget {
|
|||
onPressed: () async {
|
||||
await _myWalletProvider
|
||||
.generateNewDerivation(
|
||||
context, _newDerivationName.text, _walletNbr)
|
||||
context, _newDerivationName.text)
|
||||
.then((_) => _newDerivationName.text == '');
|
||||
},
|
||||
child: Text("Créer")),
|
||||
|
|
|
@ -116,9 +116,8 @@ class OnboardingStepFourteen extends StatelessWidget {
|
|||
if (resultWallet) {
|
||||
pinColor = Colors.green[500];
|
||||
print(generatedWallet.pin);
|
||||
await _generateWalletProvider.storeWallet(
|
||||
generatedWallet, 'Mon portefeuille courant', context,
|
||||
isHD: true);
|
||||
await _generateWalletProvider.storeHDWallet(
|
||||
generatedWallet, 'Mon portefeuille courant', context);
|
||||
_myWalletProvider.getAllWalletsNames();
|
||||
_walletOptions.reloadBuild();
|
||||
_myWalletProvider.rebuildWidget();
|
||||
|
|
|
@ -5,7 +5,7 @@ description: Pay with G1.
|
|||
# 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
|
||||
|
||||
version: 0.0.1+20
|
||||
version: 0.0.1+21
|
||||
|
||||
environment:
|
||||
sdk: ">=2.7.0 <3.0.0"
|
||||
|
|
Loading…
Reference in New Issue