Fix pubkey derivations and few things

This commit is contained in:
poka 2021-12-24 15:27:38 +01:00
parent 7bdd564a91
commit cd71b0eb3d
18 changed files with 109 additions and 90 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View File

@ -14,6 +14,7 @@ late String appVersion;
late SharedPreferences prefs;
late String endPointGVA;
const int pinLength = 5;
const String appLang = 'french';
late Box<WalletData> walletBox;
late Box<ChestData> chestBox;

View File

@ -60,11 +60,11 @@ class CesiumPlusProvider with ChangeNotifier {
return [podRequest, queryGetAvatar, headers];
}
Future<String?> getName(String? _pubkey) async {
Future<String> getName(String? _pubkey) async {
String? _name;
if (g1WalletsBox.get(_pubkey)!.csName != null) {
return g1WalletsBox.get(_pubkey)!.csName;
return g1WalletsBox.get(_pubkey)!.csName!;
}
List queryOptions = await _buildQuery(_pubkey);
@ -97,6 +97,7 @@ class CesiumPlusProvider with ChangeNotifier {
}
_name = response.data['hits']['hits'][0]['_source']['title'];
_name ??= '';
g1WalletsBox.get(_pubkey)!.csName = _name;
return _name;

View File

@ -157,7 +157,7 @@ class GenerateWalletsProvider with ChangeNotifier {
try {
actualWallet = await Dewif().generateDewif(
generatedMnemonic, randomSecretCode(pinLength),
lang: 'french');
lang: appLang);
} catch (e) {
log.e(e);
}
@ -294,7 +294,7 @@ class GenerateWalletsProvider with ChangeNotifier {
}
List<String> generateWordList() {
generatedMnemonic = generateMnemonic(lang: 'french');
generatedMnemonic = generateMnemonic(lang: appLang);
List<String> _wordsList = [];
String word;
int _nbr = 1;
@ -333,8 +333,8 @@ class GenerateWalletsProvider with ChangeNotifier {
cellController0.text = cellController1.text = cellController2.text =
cellController3.text = cellController4.text = cellController5.text =
cellController6.text = cellController7.text = cellController8.text =
cellController9.text =
cellController10.text = cellController11.text = '';
cellController9.text = cellController10.text =
cellController11.text = '';
isFirstTimeSentenceComplete = true;
notifyListeners();
}

View File

@ -39,7 +39,7 @@ class WalletOptionsProvider with ChangeNotifier {
}
if (derivation != -1) {
try {
final _wallet = HdWallet.fromDewif(_dewif!, _pin);
final _wallet = HdWallet.fromDewif(_dewif!, _pin, lang: appLang);
pubkey.text = _wallet.getPubkey(derivation!);
log.d(pubkey.text);
notifyListeners();
@ -66,15 +66,23 @@ class WalletOptionsProvider with ChangeNotifier {
}
String? readLocalWallet(
context, WalletData _wallet, String _pin, int _pinLenght) {
context, WalletData _wallet, String _pin, int _pinLenght,
{String? mnemonic}) {
isWalletUnlock = false;
final String _localPubkey;
try {
String? _localDewif = chestBox.get(_wallet.chest)!.dewif;
String _localPubkey;
if ((_localPubkey = _getPubkeyFromDewif(
_localDewif, _pin, _pinLenght, _wallet.derivation)) !=
'false') {
if (mnemonic == null) {
_localPubkey = _getPubkeyFromDewif(
_localDewif, _pin.toUpperCase(), _pinLenght, _wallet.derivation);
} else {
final _hdwallet = HdWallet.fromMnemonic(mnemonic);
_localPubkey = _hdwallet.getPubkey(_wallet.derivation!);
}
if (_localPubkey != 'false') {
pubkey.text = _localPubkey;
isWalletUnlock = true;
log.d(pubkey.text);

View File

@ -295,11 +295,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
]);
}
if (_avatar.hasData) {
g1WalletsBox.get(repository[2])!.avatar =
g1WalletsBox.get(repository[2])?.avatar =
_avatar.data;
return ClipOval(child: _avatar.data);
} else {
g1WalletsBox.get(repository[2])!.avatar =
g1WalletsBox.get(repository[2])?.avatar =
_cesiumPlusProvider
.defaultAvatar(repository[2]);
return _cesiumPlusProvider
@ -308,7 +308,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
})
: ClipOval(
child: Image(
image: g1WalletsBox.get(repository[2])!.avatar!.image,
image:
g1WalletsBox.get(repository[2])!.avatar!.image,
height: _avatarSize,
),
),

View File

@ -411,19 +411,21 @@ Widget welcomeHome(context) {
]),
),
Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.9),
],
),
flex: 1,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.9),
],
),
child: Center(
),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 480),
child: Column(children: <Widget>[
const Spacer(),
Row(children: <Widget>[
@ -505,7 +507,9 @@ Widget welcomeHome(context) {
SizedBox(height: isTall ? 100 : 50)
]),
),
))
),
),
)
]),
);
}

View File

@ -120,7 +120,7 @@ class GenerateFastChestScreen extends StatelessWidget {
_generateWalletProvider
.generatedMnemonic!,
_generateWalletProvider.pin.text,
lang: 'french');
lang: appLang);
await Navigator.push(
context,
MaterialPageRoute(builder: (context) {

View File

@ -8,6 +8,7 @@ import 'package:gecko/providers/wallet_options.dart';
import 'package:flutter/material.dart';
import 'package:gecko/screens/myWallets/cesium_wallet_options.dart';
import 'package:gecko/screens/myWallets/choose_chest.dart';
import 'package:gecko/screens/myWallets/wallets_home.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
import 'package:provider/provider.dart';
import 'package:gecko/globals.dart';
@ -223,8 +224,12 @@ class UnlockingWallet extends StatelessWidget {
cesiumWallet: currentChest);
}),
)
: Navigator.pushNamed(
formKey.currentContext!, '/mywallets');
: Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return const WalletsHome();
}),
);
} else if (action == "pay") {
resultPay =
await _historyProvider.pay(context, _pin.toUpperCase());

View File

@ -27,8 +27,6 @@ class WalletOptions extends StatelessWidget {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
_walletOptions.pubkey.text =
log.d(_walletOptions.pubkey.text);
final int _currentChest = _myWalletProvider.getCurrentChest()!;
@ -39,10 +37,7 @@ class WalletOptions extends StatelessWidget {
onWillPop: () {
_walletOptions.isEditing = false;
_walletOptions.isBalanceBlur = true;
Navigator.popUntil(
context,
ModalRoute.withName('/mywallets'),
);
Navigator.pop(context);
return Future<bool>.value(true);
},
child: Scaffold(
@ -55,10 +50,7 @@ class WalletOptions extends StatelessWidget {
onPressed: () {
_walletOptions.isEditing = false;
_walletOptions.isBalanceBlur = true;
Navigator.popUntil(
context,
ModalRoute.withName('/mywallets'),
);
Navigator.pop(context);
}),
title: SizedBox(
height: 22,
@ -88,6 +80,7 @@ class WalletOptions extends StatelessWidget {
],
)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
const Spacer(),
@ -138,8 +131,7 @@ class WalletOptions extends StatelessWidget {
children: <Widget>[
InkWell(
onTap: () async {
File newAvatar =
await (walletProvider.changeAvatar());
File newAvatar = await (walletProvider.changeAvatar());
wallet.imageFile = newAvatar;
walletProvider.reloadBuild();
},
@ -155,10 +147,10 @@ class WalletOptions extends StatelessWidget {
),
Positioned(
right: 0,
top: 0,
child: InkWell(
onTap: () async {
File newAvatar =
await (walletProvider.changeAvatar());
File newAvatar = await (walletProvider.changeAvatar());
wallet.imageFile = newAvatar;
walletProvider.reloadBuild();
},
@ -174,13 +166,6 @@ class WalletOptions extends StatelessWidget {
Widget walletName(WalletOptionsProvider walletProvider,
WalletOptionsProvider _walletOptions) {
int _nbrLinesName = 1;
_walletOptions.nameController.text.length >= 15
? _nbrLinesName = 2
: _nbrLinesName = 1;
if (_walletOptions.nameController.text.length >= 26 && isTall) {
_nbrLinesName = 3;
}
bool _isNewNameValid = false;
if (_isNewNameValid == false) {
_walletOptions.nameController.text = wallet.name!;
@ -197,7 +182,8 @@ class WalletOptions extends StatelessWidget {
focusNode: walletProvider.walletNameFocus,
enabled: walletProvider.isEditing,
controller: walletProvider.nameController,
maxLines: _nbrLinesName,
minLines: 1,
maxLines: 3,
textAlign: TextAlign.center,
decoration: const InputDecoration(
border: InputBorder.none,
@ -207,10 +193,10 @@ class WalletOptions extends StatelessWidget {
contentPadding: EdgeInsets.all(15.0),
),
style: TextStyle(
fontSize: isTall ? 27 : 23,
color: Colors.black,
fontWeight: FontWeight.w400,
fontFamily: 'Monospace'),
fontSize: isTall ? 27 : 23,
color: Colors.black,
fontWeight: FontWeight.w400,
),
),
Positioned(
right: 0,
@ -253,7 +239,7 @@ class WalletOptions extends StatelessWidget {
sigmaX: walletProvider.isBalanceBlur ? 6 : 0,
sigmaY: walletProvider.isBalanceBlur ? 5 : 0),
child: Text(
_balance.data.toString() + ' DU',
_balance.data.toString() + ' Ğ1',
style: TextStyle(
fontSize: isTall ? 20 : 18,
),

View File

@ -5,6 +5,7 @@ import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/models/queries.dart';
import 'package:gecko/models/wallet_data.dart';
import 'package:flutter/material.dart';
import 'package:gecko/providers/wallet_options.dart';
import 'package:gecko/screens/common_elements.dart';
import 'package:gecko/screens/myWallets/chest_options.dart';
import 'package:gecko/screens/myWallets/choose_chest.dart';
@ -131,7 +132,8 @@ class WalletsHome extends StatelessWidget {
Widget myWalletsTiles(BuildContext context) {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context, listen: false);
final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
if (!isWalletsExists) {
@ -175,6 +177,8 @@ class WalletsHome extends StatelessWidget {
padding: const EdgeInsets.all(16),
child: GestureDetector(
onTap: () {
_walletOptions.readLocalWallet(context, _repository,
_myWalletProvider.pinCode, pinLength);
Navigator.push(
context,
SmoothTransition(
@ -260,6 +264,11 @@ class WalletsHome extends StatelessWidget {
),
// dense: true,
onTap: () {
_walletOptions.readLocalWallet(
context,
_repository,
_myWalletProvider.pinCode,
pinLength);
Navigator.push(
context,
SmoothTransition(

View File

@ -120,16 +120,15 @@ class OnboardingStepFourteen extends StatelessWidget {
NewWallet generatedWallet = await Dewif().generateDewif(
_generateWalletProvider.generatedMnemonic!,
_generateWalletProvider.pin.text,
lang: 'french');
lang: appLang);
await _generateWalletProvider.storeHDWChest(
generatedWallet, 'Mon portefeuille courant', context);
_myWalletProvider.readAllWallets(_currentChest);
// scheduleMicrotask(() {
_walletOptions.reloadBuild();
// _myWalletProvider.rebuildWidget();
// _walletOptions.reloadBuild();
_myWalletProvider.rebuildWidget();
// });
_generateWalletProvider.generatedMnemonic =
_generateWalletProvider.pin.text = '';
_generateWalletProvider.generatedMnemonic = '';
Navigator.push(
context,
FaderTransition(

View File

@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/screens/common_elements.dart';
import 'package:gecko/screens/myWallets/wallets_home.dart';
// ignore: must_be_immutable
class OnboardingStepFiveteen extends StatelessWidget {
@ -33,28 +34,32 @@ class OnboardingStepFiveteen extends StatelessWidget {
height: isTall ? 400 : 300,
),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: 400,
height: 62,
child: ElevatedButton(
key: const Key('goWalletHome'),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: orangeC,
onPrimary: Colors.white, // foreground
),
onPressed: () {
Navigator.pushNamedAndRemoveUntil(
context,
'/mywallets',
ModalRoute.withName('/'),
);
},
child: const Text("Accéder à mes portefeuilles",
style: TextStyle(fontSize: 20))),
))),
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: 400,
height: 62,
child: ElevatedButton(
key: const Key('goWalletHome'),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: orangeC,
onPrimary: Colors.white, // foreground
),
onPressed: () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) {
return const WalletsHome();
}),
ModalRoute.withName('/'),
);
},
child: const Text("Accéder à mes portefeuilles",
style: TextStyle(fontSize: 20))),
),
),
),
const SizedBox(height: 80),
]),
));

View File

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

View File

@ -301,7 +301,7 @@ packages:
name: durt
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
version: "0.1.5+2"
fake_async:
dependency: transitive
description:

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.4+5
version: 0.0.4+6
environment:
sdk: '>=2.12.0 <3.0.0'
@ -62,7 +62,7 @@ dependencies:
pull_to_refresh: ^2.0.0
dio: ^4.0.4
desktop_window: ^0.4.0
durt: ^0.1.5
durt: ^0.1.5+2
package_info_plus: ^1.3.0
flutter_icons: