Improve wallet generation; Add menu to change endpoint;

This commit is contained in:
poka 2022-05-20 15:15:29 +02:00
parent 345a600599
commit c5317f984d
21 changed files with 330 additions and 264 deletions

View File

@ -41,3 +41,7 @@ Color backgroundColor = const Color(0xFFF5F5F5);
// Substrate settings
const int ss58 = 42;
String currencyName = 'Ğdev';
// Debug
const debugPin = true;

View File

@ -86,7 +86,7 @@ class GenerateWalletsProvider with ChangeNotifier {
address: address,
number: 0,
name: _name,
derivation: 3,
derivation: 2,
imageName: '0.png');
await walletBox.add(myWallet);
@ -297,9 +297,9 @@ class GenerateWalletsProvider with ChangeNotifier {
}
Future<List<String>> generateWordList(BuildContext context) async {
SubstrateSdk _sdk = Provider.of<SubstrateSdk>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
generatedMnemonic = await _sdk.generateMnemonic(lang: appLang);
generatedMnemonic = await _sub.generateMnemonic(lang: appLang);
List<String> _wordsList = [];
String word;
int _nbr = 1;

View File

@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'package:gecko/globals.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:path_provider/path_provider.dart' as pp;
@ -140,22 +139,6 @@ class HomeProvider with ChangeNotifier {
notifyListeners();
}
void snackNode(context) {
if (isFirstBuild) {
String _message;
if (endPointGVA == 'HS') {
_message =
"Aucun noeud Duniter disponible, veuillez réessayer ultérieurement";
} else {
_message = "Vous êtes connecté au noeud\n${SubstrateSdk().subNode}";
}
final snackBar = SnackBar(
content: Text(_message), duration: const Duration(seconds: 2));
isFirstBuild = false;
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
void rebuildWidget() {
notifyListeners();
}

View File

@ -23,6 +23,12 @@ class MyWalletsProvider with ChangeNotifier {
}
bool checkIfWalletExist() {
// configBox.delete('endpoint');
if (!configBox.containsKey('endpoint') || configBox.get('endpoint') == '') {
log.d('No endpoint, configure...');
configBox.put('endpoint', 'ws://192.168.1.72:9944');
}
if (chestBox.isEmpty) {
log.i('No wallets detected');
return false;
@ -68,6 +74,7 @@ class MyWalletsProvider with ChangeNotifier {
}
Future<int> deleteAllWallet(context) async {
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
try {
log.w('DELETE ALL WALLETS ?');
@ -76,9 +83,7 @@ class MyWalletsProvider with ChangeNotifier {
await walletBox.clear();
await chestBox.clear();
await configBox.delete('defaultWallet');
// await Future.delayed(const Duration(milliseconds: 50));
// notifyListeners();
await _sub.deleteAllAccounts();
await Navigator.of(context).pushNamedAndRemoveUntil(
'/',
ModalRoute.withName('/'),
@ -96,23 +101,42 @@ class MyWalletsProvider with ChangeNotifier {
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text(
'Êtes-vous sûr de vouloir supprimer tous vos trousseaux ?'),
content: const SingleChildScrollView(child: Text('')),
backgroundColor: backgroundColor,
content: const Text(
'Êtes-vous sûr de vouloir oublier tous vos coffres ?',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
),
actions: <Widget>[
TextButton(
child: const Text("Non"),
onPressed: () {
Navigator.pop(context, false);
},
),
TextButton(
key: const Key('confirmDeletingAllWallets'),
child: const Text("Oui"),
onPressed: () {
Navigator.pop(context, true);
},
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
key: const Key('confirmDeletingAllWallets'),
child: const Text(
"Oui",
style: TextStyle(
fontSize: 20,
color: Color(0xffD80000),
),
),
onPressed: () {
Navigator.pop(context, true);
},
),
const SizedBox(width: 20),
TextButton(
child: const Text(
"Non",
style: TextStyle(fontSize: 20),
),
onPressed: () {
Navigator.pop(context, false);
},
),
const SizedBox(height: 120)
],
)
],
);
},
@ -136,12 +160,12 @@ class MyWalletsProvider with ChangeNotifier {
MyWalletsProvider myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
SubstrateSdk _sdk = Provider.of<SubstrateSdk>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
final int? _currentChestNumber = myWalletProvider.getCurrentChest();
final ChestData _currentChest = chestBox.get(_currentChestNumber)!;
final address = await _sdk.derive(
final address = await _sub.derive(
context, _currentChest.address!, _newDerivationNbr, pinCode);
WalletData newWallet = WalletData(

View File

@ -14,8 +14,6 @@ import 'package:polkawallet_sdk/storage/types/keyPairData.dart';
import 'package:truncate/truncate.dart';
class SubstrateSdk with ChangeNotifier {
final List subNode = ['192.168.1.72:9944'];
final bool isSsl = false;
final int ss58 = 42;
final WalletSDK sdk = WalletSDK();
@ -26,6 +24,7 @@ class SubstrateSdk with ChangeNotifier {
bool nodeConnected = false;
bool importIsLoading = false;
int blocNumber = 0;
bool isLoadingEndpoint = false;
TextEditingController jsonKeystore = TextEditingController();
TextEditingController keystorePassword = TextEditingController();
@ -41,30 +40,45 @@ class SubstrateSdk with ChangeNotifier {
notifyListeners();
}
Future<void> connectNode() async {
final String socketKind = isSsl ? 'wss' : 'ws';
Future<void> connectNode(BuildContext ctx) async {
List<NetworkParams> node = [];
for (final sn in subNode) {
final n = NetworkParams();
n.name = 'duniter';
n.endpoint = '$socketKind://$sn';
n.ss58 = ss58;
node.add(n);
final n = NetworkParams();
n.name = currencyName;
n.endpoint = configBox.get('endpoint');
n.ss58 = ss58;
node.add(n);
if (sdk.api.connectedNode?.endpoint != null) {
await sdk.api.setting.unsubscribeBestNumber();
}
isLoadingEndpoint = true;
notifyListeners();
final res = await sdk.api.connectNode(keyring, node).timeout(
const Duration(seconds: 10),
const Duration(seconds: 7),
onTimeout: () => null,
);
isLoadingEndpoint = false;
notifyListeners();
if (res != null) {
nodeConnected = true;
notifyListeners();
snackNode(ctx, true);
} else {
nodeConnected = false;
notifyListeners();
snackNode(ctx, false);
}
// Subscribe bloc number
sdk.api.setting.subscribeBestNumber((res) {
blocNumber = int.parse(res.toString());
notifyListeners();
});
if (nodeConnected) {
sdk.api.setting.subscribeBestNumber((res) {
blocNumber = int.parse(res.toString());
notifyListeners();
});
}
log.d(sdk.api.connectedNode?.endpoint);
}
Future<String> importAccount(
@ -177,7 +191,7 @@ class SubstrateSdk with ChangeNotifier {
int getDerivationNumber(String address) {
final account = getKeypair(address);
final deriveNbr = account.name!.split('/')[1];
final deriveNbr = account.name!.split('//')[1];
return int.parse(deriveNbr);
}
@ -290,11 +304,11 @@ class SubstrateSdk with ChangeNotifier {
print(seedMap);
if (seedMap?['type'] != 'mnemonic') return '';
final List seedList = seedMap!['seed'].split('/');
final List seedList = seedMap!['seed'].split('//');
generatedMnemonic = seedList[0];
int sourceDerivation = -1; // To get derivation number of this account
if (seedList.length > 1) {
sourceDerivation = int.parse(seedMap['seed'].split('/')[1]);
sourceDerivation = int.parse(seedList[1]);
}
print(generatedMnemonic);
print(sourceDerivation);
@ -316,6 +330,20 @@ class AddressInfo {
AddressInfo({@required this.address, this.balance = 0});
}
void snackNode(BuildContext context, bool isConnected) {
String _message;
if (!isConnected) {
_message =
"Aucun noeud Duniter disponible, veuillez réessayer ultérieurement";
} else {
_message =
"Vous êtes connecté au noeud\n${configBox.get('endpoint').split('//')[1]}";
}
final snackBar =
SnackBar(content: Text(_message), duration: const Duration(seconds: 2));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
String getShortPubkey(String pubkey) {
List<int> pubkeyByte = Base58Decode(pubkey);
Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes);

View File

@ -79,12 +79,13 @@ class WalletOptionsProvider with ChangeNotifier {
final bool? _answer = await (_confirmDeletingWallet(context, wallet.name));
if (_answer!) {
walletBox.delete(wallet.key);
await walletBox.delete(wallet.key);
Navigator.popUntil(
context,
ModalRoute.withName('/mywallets'),
);
// Navigator.popUntil(
// context,
// ModalRoute.withName('/mywallets'),
// );
Navigator.pop(context);
}
return 0;
}

View File

@ -346,7 +346,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
],
),
),
trailing: Text("${repository[4]} Ğ1",
trailing: Text("${repository[4]} $currencyName",
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
textAlign: TextAlign.justify),
@ -466,7 +466,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
return const Text('...');
}
return Text(
"${_balance.data.toString()} Ğ1",
"${_balance.data.toString()} $currencyName",
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 22, fontWeight: FontWeight.w500),

View File

@ -5,7 +5,6 @@ import 'package:gecko/providers/chest_provider.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:flutter/material.dart';
import 'package:gecko/providers/home.dart';
import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/screens/myWallets/restore_chest.dart';
@ -27,11 +26,12 @@ class HomeScreen extends StatelessWidget {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
Provider.of<ChestProvider>(context);
HomeProvider homeClass = HomeProvider();
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
isTall = false;
ratio = 1;
if (MediaQuery.of(context).size.height >= 930) {
@ -103,9 +103,8 @@ class HomeScreen extends StatelessWidget {
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (!_sub.sdkReady && !_sub.sdkLoading) await _sub.initApi();
if (_sub.sdkReady && !_sub.nodeConnected) {
await _sub.connectNode(); //kopa
await _sub.connectNode(ctx); //kopa
}
if (isWalletsExists) homeClass.snackNode(ctx);
});
},
child: isWalletsExists ? geckHome(context) : welcomeHome(context)
@ -405,31 +404,30 @@ Widget welcomeHome(context) {
]),
Padding(
padding: EdgeInsets.only(top: 1 * ratio),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
Text(
"Lapplication de paiement Ğ1\nplus rapide quun reptile du Vietnam",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.w700,
shadows: <Shadow>[
Shadow(
offset: Offset(0, 0),
blurRadius: 20,
color: Colors.black,
),
Shadow(
offset: Offset(0, 0),
blurRadius: 20,
color: Colors.black,
),
],
child:
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
Text(
"Lapplication de paiement $currencyName\nplus rapide quun reptile du Vietnam",
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.w700,
shadows: <Shadow>[
Shadow(
offset: Offset(0, 0),
blurRadius: 20,
color: Colors.black,
),
)
]),
Shadow(
offset: Offset(0, 0),
blurRadius: 20,
color: Colors.black,
),
],
),
)
]),
),
Expanded(
flex: 1,

View File

@ -25,7 +25,7 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SubstrateSdk _sdk = Provider.of<SubstrateSdk>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
return WillPopScope(
onWillPop: () {
@ -100,7 +100,8 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
),
onPressed: () async {
final _chest = chestBox.get(configBox.get('currentChest'));
_sdk.changePassword(_chest!.address!, walletProvider.pinCode, newPin.text);
_sub.changePassword(
_chest!.address!, walletProvider.pinCode, newPin.text);
newPin.text = '';
walletProvider.pinCode = newPin.text;
},

View File

@ -22,7 +22,7 @@ class ChooseWalletScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SubstrateSdk _sdk = Provider.of<SubstrateSdk>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
WalletsProfilesProvider _walletViewProvider =
Provider.of<WalletsProfilesProvider>(context, listen: false);
// HomeProvider _homeProvider = Provider.of<HomeProvider>(context);
@ -50,10 +50,10 @@ class ChooseWalletScreen extends StatelessWidget {
onPrimary: Colors.white, // foreground
),
onPressed: () async {
final acc = _sdk.getCurrentWallet();
final acc = _sub.getCurrentWallet();
log.d(
"fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.outputPubkey.text}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $pin");
final resultPay = await _sdk.pay(context,
final resultPay = await _sub.pay(context,
fromAddress: acc.address!,
destAddress: _walletViewProvider.outputPubkey.text,
amount:
@ -79,13 +79,14 @@ class ChooseWalletScreen extends StatelessWidget {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
SubstrateSdk _sdk = Provider.of<SubstrateSdk>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
WalletData? defaultWallet =
_myWalletProvider.getDefaultWallet(currentChest);
_selectedId ??= defaultWallet!.id();
_derivation ??= defaultWallet!.derivation!;
_sub.setCurrentWallet(defaultWallet!.address!);
_myWalletProvider.readAllWallets(currentChest);
if (!isWalletsExists) {
@ -128,7 +129,7 @@ class ChooseWalletScreen extends StatelessWidget {
onTap: () {
_derivation = _repository.derivation!;
_selectedId = _repository.id();
_sdk.setCurrentWallet(_repository.address!);
_sub.setCurrentWallet(_repository.address!);
_myWalletProvider.rebuildWidget();
},
child: ClipOvalShadow(
@ -195,7 +196,7 @@ class ChooseWalletScreen extends StatelessWidget {
onTap: () {
_derivation = _repository.derivation!;
_selectedId = _repository.id();
_sdk.setCurrentWallet(_repository.address!);
_sub.setCurrentWallet(_repository.address!);
_myWalletProvider.rebuildWidget();
},
)
@ -209,13 +210,15 @@ class ChooseWalletScreen extends StatelessWidget {
}
Future<bool?> paymentsResult(context, String resultPay) {
if (resultPay != "success") log.e(resultPay);
final bool isValid = resultPay == "confirmed";
if (!isValid) log.e(resultPay);
return showDialog<bool>(
context: context,
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text(resultPay == "confirmed"
title: Text(isValid
? 'Paiement effecuté avec succès !'
: "Une erreur s'est produite lors du paiement:\n$resultPay"),
content: const SingleChildScrollView(child: Text('')),
@ -223,7 +226,7 @@ Future<bool?> paymentsResult(context, String resultPay) {
TextButton(
child: const Text("OK"),
onPressed: () async {
resultPay == "confirmed"
isValid
? await Navigator.of(context).pushNamedAndRemoveUntil(
'/',
ModalRoute.withName('/'),

View File

@ -33,7 +33,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
final int? _currentChest = _myWalletProvider.getCurrentChest();
SubstrateSdk _sdk = Provider.of<SubstrateSdk>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
_mnemonicController.text = generatedMnemonic!;
return WillPopScope(
@ -136,13 +136,13 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
.isAskedWordValid &&
walletName.text != '')
? () async {
final address = await _sdk.importAccount(
final address = await _sub.importAccount(
fromMnemonic: true,
mnemonic: _generateWalletProvider
.generatedMnemonic!,
password:
_generateWalletProvider.pin.text,
derivePath: '/3');
derivePath: '//2');
await _generateWalletProvider.storeHDWChest(
address,
'Mon portefeuille courant',

View File

@ -1,4 +1,5 @@
import 'package:durt/durt.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/providers/generate_wallets.dart';
@ -25,7 +26,9 @@ class GenerateFastChestScreen extends StatelessWidget {
GenerateWalletsProvider _generateWalletProvider =
Provider.of<GenerateWalletsProvider>(context, listen: false);
_generateWalletProvider.changePinCode(reload: false);
_generateWalletProvider.pin.text = kDebugMode && debugPin
? 'AAAAA'
: _generateWalletProvider.changePinCode(reload: false);
return WillPopScope(
onWillPop: () {

View File

@ -145,7 +145,7 @@ class UnlockingWallet extends StatelessWidget {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
SubstrateSdk _sdk = Provider.of<SubstrateSdk>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
FocusNode pinFocus = FocusNode();
@ -200,7 +200,7 @@ class UnlockingWallet extends StatelessWidget {
log.d("Completed");
_myWalletProvider.pinCode = _pin.toUpperCase();
final isValid = await _sdk.checkPassword(
final isValid = await _sub.checkPassword(
currentChest.address!, _pin.toUpperCase());
if (!isValid) {
@ -227,7 +227,7 @@ class UnlockingWallet extends StatelessWidget {
MaterialPageRoute(builder: (context) {
return const WalletsHome();
}),
).then((value) => _myWalletProvider.cesiumSeed.clear());
);
} else if (action == "pay") {
Navigator.push(
context,

View File

@ -32,11 +32,9 @@ class WalletOptions extends StatelessWidget {
final int _currentChest = _myWalletProvider.getCurrentChest()!;
//TODO: Debug multichest
// final currentWallet = _myWalletProvider.getDefaultWallet(_currentChest);
// log.d(_walletOptions.getAddress(_currentChest, 3));
// log.d("Wallet options: $_currentChest:${wallet.number}");
log.d("Wallet options: $_currentChest:${wallet.derivation}");
return WillPopScope(
onWillPop: () {
@ -240,13 +238,13 @@ class WalletOptions extends StatelessWidget {
fontSize: isTall ? 20 : 18,
));
}
balanceCache = "${_balance.data.toString()} Ğ1";
balanceCache = "${_balance.data.toString()} $currencyName";
return ImageFiltered(
imageFilter: ImageFilter.blur(
sigmaX: walletProvider.isBalanceBlur ? 6 : 0,
sigmaY: walletProvider.isBalanceBlur ? 5 : 0),
child: Text(
_balance.data.toString() + ' Ğ1',
balanceCache,
style: TextStyle(
fontSize: isTall ? 20 : 18,
),

View File

@ -1,4 +1,5 @@
// ignore_for_file: file_names
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:gecko/globals.dart';
@ -21,8 +22,10 @@ class OnboardingStepThirteen extends StatelessWidget {
// MyWalletsProvider myWalletProvider =
// Provider.of<MyWalletsProvider>(context);
CommonElements common = CommonElements();
_generateWalletProvider.pin.text =
_generateWalletProvider.changePinCode(reload: false);
_generateWalletProvider.pin.text = kDebugMode && debugPin
? 'AAAAA'
: _generateWalletProvider.changePinCode(reload: false);
return Scaffold(
extendBodyBehindAppBar: true,

View File

@ -45,7 +45,7 @@ class OnboardingStepFourteen extends StatelessWidget {
textKey: const Key('step12'),
),
SizedBox(height: isTall ? 80 : 10),
pinForm(context, _walletOptions, _pinLenght, 1, 3)
pinForm(context, _walletOptions, _pinLenght, 1, 2)
]),
));
}
@ -61,7 +61,7 @@ class OnboardingStepFourteen extends StatelessWidget {
Provider.of<MyWalletsProvider>(context);
GenerateWalletsProvider _generateWalletProvider =
Provider.of<GenerateWalletsProvider>(context);
SubstrateSdk _sdk = Provider.of<SubstrateSdk>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
final int? _currentChest = _myWalletProvider.getCurrentChest();
@ -118,10 +118,10 @@ class OnboardingStepFourteen extends StatelessWidget {
log.d(_pin + ' || ' + _generateWalletProvider.pin.text);
if (_pin.toUpperCase() == _generateWalletProvider.pin.text) {
pinColor = Colors.green[500];
final address = await _sdk.importAccount(
final address = await _sub.importAccount(
fromMnemonic: true,
mnemonic: _generateWalletProvider.generatedMnemonic!,
derivePath: '/3',
derivePath: '//2',
password: _generateWalletProvider.pin.text);
await _generateWalletProvider.storeHDWChest(
address, 'Mon portefeuille courant', context);

View File

@ -57,9 +57,9 @@ class SearchResultScreen extends StatelessWidget {
),
),
const SizedBox(height: 40),
const Text(
'Dans la blockchain Ğ1',
style: TextStyle(fontSize: 20),
Text(
'Dans la blockchain $currencyName',
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: 20),
FutureBuilder(

View File

@ -2,11 +2,13 @@ import 'package:flutter/material.dart';
import 'package:durt/durt.dart';
import 'package:flutter/services.dart';
import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/screens/myWallets/generate_wallets.dart';
import 'dart:io';
// import 'package:gecko/screens/myWallets/import_cesium_wallet.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/screens/myWallets/restore_chest.dart';
import 'package:provider/provider.dart';
// ignore: must_be_immutable
class SettingsScreen extends StatelessWidget {
@ -28,108 +30,123 @@ class SettingsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
const double buttonHigh = 50;
const double buttonWidth = 240;
const double fontSize = 16;
TextEditingController _endpointController =
TextEditingController(text: configBox.get('endpoint'));
// getAppDirectory();
return Scaffold(
appBar: AppBar(
toolbarHeight: 60 * ratio,
title: const SizedBox(
height: 22,
child: Text('Paramètres'),
)),
body: Column(children: <Widget>[
const SizedBox(height: 40),
SizedBox(
height: 70,
width: 500,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 5,
primary: yellowC, // background
onPrimary: Colors.black, // foreground
appBar: AppBar(
toolbarHeight: 60 * ratio,
title: const SizedBox(
height: 22,
child: Text('Paramètres'),
)),
body: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 60),
Row(children: [
Text(' Noeud $currencyName :'),
const SizedBox(width: 20),
SizedBox(
width: 200,
height: 50,
child: TextField(
controller: _endpointController,
autocorrect: false,
),
),
onPressed: null,
// () => Navigator.push(
// context,
// MaterialPageRoute(builder: (context) {
// return const ImportWalletScreen();
// }),
// ).then((value) => {
// if (value == true) {Navigator.pop(context)}
// }),
child: const Text(
"Importer un portefeuille Cesium",
style: TextStyle(fontSize: 16),
const Spacer(),
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
return _sub.isLoadingEndpoint
? CircularProgressIndicator(color: orangeC)
: IconButton(
icon: Icon(
Icons.send,
color: orangeC,
size: 40,
),
onPressed: () async {
configBox.put('endpoint', _endpointController.text);
await _sub.connectNode(context);
});
}),
const Spacer(),
]),
SizedBox(height: isTall ? 50 : 20),
SizedBox(
height: buttonHigh,
width: buttonWidth,
child: ElevatedButton(
key: const Key('generateKeychain'),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: yellowC, // background
onPrimary: Colors.black, // foreground
),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return GenerateFastChestScreen();
}),
),
child: const Text(
"Générer un trousseau",
style: TextStyle(fontSize: fontSize),
),
),
),
),
const SizedBox(height: 30),
SizedBox(
height: 70,
width: 500,
child: ElevatedButton(
key: const Key('generateKeychain'),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: yellowC, // background
onPrimary: Colors.black, // foreground
),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return GenerateFastChestScreen();
}),
),
child: const Text(
"Générer un nouveau trousseau",
style: TextStyle(fontSize: 16),
const SizedBox(height: 20),
SizedBox(
height: buttonHigh,
width: buttonWidth,
child: ElevatedButton(
key: const Key('generateKeychain'),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: yellowC, // background
onPrimary: Colors.black, // foreground
),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return const RestoreChest();
}),
),
child: const Text(
"Restaurer un coffre",
style: TextStyle(fontSize: fontSize),
),
),
),
),
const SizedBox(height: 30),
SizedBox(
height: 70,
width: 500,
child: ElevatedButton(
key: const Key('generateKeychain'),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: yellowC, // background
onPrimary: Colors.black, // foreground
),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return const RestoreChest();
}),
),
child: const Text(
"Restaurer un coffre",
style: TextStyle(fontSize: 16),
const SizedBox(height: 25),
SizedBox(
height: buttonHigh,
width: buttonWidth,
child: Center(
child: InkWell(
key: const Key('deleteChest'),
onTap: () async {
log.i('Oublier tous mes coffres');
await _myWallets.deleteAllWallet(context);
},
child: const Text(
'Oublier tous mes coffres',
style: TextStyle(
fontSize: fontSize + 3,
color: Color(0xffD80000),
fontWeight: FontWeight.w500,
),
),
),
),
),
),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
height: 100,
width: 500,
child: ElevatedButton(
key: const Key('deleteAllWallets'),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: Colors.redAccent, // background
onPrimary: Colors.black, // foreground
),
onPressed: () async => {
log.i('Suppression de tous les wallets'),
await _myWallets.deleteAllWallet(context),
await _sub.deleteAllAccounts()
},
child: const Text("EFFACER TOUS MES PORTEFEUILLES",
style: TextStyle(fontSize: 20)))))),
const SizedBox(height: 50),
]));
]),
);
}
}

View File

@ -33,10 +33,10 @@ class SubstrateSandBox extends StatelessWidget {
Text('js-api chargé ?: ${_sub.sdkReady}'),
InkWell(
onTap: () async {
await _sub.connectNode();
await _sub.connectNode(context);
},
child: Text(
'Noeud connecté ?: ${_sub.nodeConnected} (${_sub.subNode})')),
'Noeud connecté ?: ${_sub.nodeConnected} (${configBox.get('endpoint')})')),
if (_sub.nodeConnected)
Text(
'Noeud "${_sub.sdk.api.connectedNode!.name}", bloc N°${_sub.blocNumber}'),
@ -56,46 +56,49 @@ class SubstrateSandBox extends StatelessWidget {
),
const SizedBox(width: 10),
]),
// FutureBuilder(
// future: _sub.getKeyStoreAddress(),
// builder: (BuildContext context,
// AsyncSnapshot<List<AddressInfo>> _data) {
// return Column(children: [
// if (_data.data != null)
// for (final AddressInfo addressInfo in _data.data!)
// Row(children: [
// InkWell(
// onTap: () => _sub.keyring.setCurrent(_sub
// .keyring.keyPairs
// .firstWhere((element) =>
// element.address == addressInfo.address!)),
// child: Text(
// getShortPubkey(addressInfo.address!),
// style: const TextStyle(
// fontFamily: 'Monospace'),
// ),
// ),
// const SizedBox(width: 20),
// InkWell(
// onTap: () async => await _sub.pay(
// context,
// addressInfo.address!,
// 10,
// _sub.keystorePassword.text),
// child: Text("${addressInfo.balance.toString()} ğdev"),
// ),
// const SizedBox(width: 20),
// InkWell(
// onTap: () async => await _sub.derive(
// context,
// addressInfo.address!,
// 3,
// _sub.keystorePassword.text),
// child: const Text("Dériver"),
// )
// ])
// ]);
// }),
FutureBuilder(
future: _sub.getKeyStoreAddress(),
builder: (BuildContext context,
AsyncSnapshot<List<AddressInfo>> _data) {
return Column(children: [
if (_data.data != null)
for (final AddressInfo addressInfo in _data.data!)
Row(children: [
InkWell(
onTap: () => _sub.keyring.setCurrent(_sub
.keyring.keyPairs
.firstWhere((element) =>
element.address ==
addressInfo.address!)),
child: Text(
getShortPubkey(addressInfo.address!),
style: const TextStyle(
fontFamily: 'Monospace'),
),
),
const SizedBox(width: 20),
// InkWell(
// onTap: () async => await _sub.pay(
// context,
// addressInfo.address!,
// 10,
// _sub.keystorePassword.text),
// child:
Text(
"${addressInfo.balance.toString()} $currencyName"),
// ),
const SizedBox(width: 20),
InkWell(
onTap: () async => await _sub.derive(
context,
addressInfo.address!,
2,
_sub.keystorePassword.text),
child: const Text("Dériver"),
)
])
]);
}),
const SizedBox(height: 20),
const Text('Mot de passe du trousseau:'),
TextField(

View File

@ -255,7 +255,7 @@ class WalletViewScreen extends StatelessWidget {
// onChanged: (v) => _searchProvider.rebuildWidget(),
decoration: InputDecoration(
hintText: '0.00',
suffix: const Text('Ğ1'),
suffix: Text(currencyName),
filled: true,
fillColor: Colors.transparent,
// border: OutlineInputBorder(

View File

@ -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.5+1
version: 0.0.5+2
environment:
sdk: '>=2.12.0 <3.0.0'