Set gdev first bootstrap; Can create idty, can cert;

This commit is contained in:
poka 2022-05-27 08:54:29 +02:00
parent 1227e15fa2
commit 05b425c3d2
9 changed files with 217 additions and 71 deletions

BIN
assets/gecko_certify.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

@ -254,33 +254,6 @@ class SubstrateSdk with ChangeNotifier {
return gen.mnemonic!; return gen.mnemonic!;
} }
// Future<bool> pay(BuildContext context, String address, double amount,
// String password) async {
// final sender = TxSenderData(
// keyring.current.address,
// keyring.current.pubKey,
// );
// final txInfo = TxInfoData('balances', 'transfer', sender);
// try {
// final hash = await sdk.api.tx.signAndSend(
// txInfo,
// [address, amount * 100],
// password,
// onStatusChange: (status) {
// print('status: ' + status);
// if (status == 'Ready') {
// snack(context, 'Transaction terminé');
// }
// },
// );
// print(hash.toString());
// return true;
// } catch (err) {
// print(err.toString());
// return false;
// }
// }
String setCurrentWallet(String address) { String setCurrentWallet(String address) {
try { try {
final acc = getKeypair(address); final acc = getKeypair(address);
@ -300,7 +273,7 @@ class SubstrateSdk with ChangeNotifier {
} }
} }
Future<String> pay(BuildContext context, Future<String> pay(
{required String fromAddress, {required String fromAddress,
required String destAddress, required String destAddress,
required double amount, required double amount,
@ -329,14 +302,89 @@ class SubstrateSdk with ChangeNotifier {
if (status == 'Ready') { if (status == 'Ready') {
transactionStatus = 'sent'; transactionStatus = 'sent';
notifyListeners(); notifyListeners();
// snack(context, 'Transaction terminé');
} }
}, },
).timeout( ).timeout(
const Duration(seconds: 12), const Duration(seconds: 12),
onTimeout: () => {}, onTimeout: () => {},
); );
print(hash.toString()); log.d(hash.toString());
if (hash.isEmpty) {
transactionStatus = 'timeout';
notifyListeners();
return 'timeout';
} else {
transactionStatus = hash.toString();
notifyListeners();
return hash.toString();
}
} catch (e) {
transactionStatus = e.toString();
notifyListeners();
return e.toString();
}
}
Future<String> certify(
String fromAddress, String password, String toAddress) async {
transactionStatus = '';
setCurrentWallet(fromAddress);
log.d('me: ' + fromAddress);
log.d('to: ' + toAddress);
final _myIdtyStatus = await idtyStatus(fromAddress);
final _toIdtyStatus = await idtyStatus(toAddress);
log.d(_myIdtyStatus);
log.d(_toIdtyStatus);
if (_myIdtyStatus != 'Validated') {
transactionStatus = 'notMember';
notifyListeners();
return 'notMember';
}
final sender = TxSenderData(
keyring.current.address,
keyring.current.pubKey,
);
TxInfoData txInfo;
if (_toIdtyStatus == 'noid') {
txInfo = TxInfoData(
'identity',
'createIdentity',
sender,
);
} else if (_toIdtyStatus == 'Validated' ||
_toIdtyStatus == 'ConfirmedByOwner') {
txInfo = TxInfoData(
'cert',
'addCert',
sender,
);
} else {
transactionStatus = 'cantBeCert';
notifyListeners();
return 'cantBeCert';
}
log.d('Cert action: ' + txInfo.call!);
try {
final hash = await sdk.api.tx
.signAndSend(
txInfo,
[toAddress],
password,
)
.timeout(
const Duration(seconds: 12),
onTimeout: () => {},
);
log.d(hash);
if (hash.isEmpty) { if (hash.isEmpty) {
transactionStatus = 'timeout'; transactionStatus = 'timeout';
notifyListeners(); notifyListeners();
@ -378,10 +426,10 @@ class SubstrateSdk with ChangeNotifier {
} }
Future<String> confirmIdentity( Future<String> confirmIdentity(
String address, String name, String password) async { String fromAddress, String name, String password) async {
// Confirm identity // Confirm identity
setCurrentWallet(address); setCurrentWallet(fromAddress);
log.d('idty: ' + keyring.current.address!); log.d('me: ' + keyring.current.address!);
final sender = TxSenderData( final sender = TxSenderData(
keyring.current.address, keyring.current.address,
@ -404,13 +452,14 @@ class SubstrateSdk with ChangeNotifier {
return 'confirmed'; return 'confirmed';
} on Exception catch (e) { } on Exception catch (e) {
log.e(e); log.e(e);
// if (e.toString() == 'Exception: password check failed') {
// throw PasswordException('Bad password');
// }
return e.toString(); return e.toString();
} }
} }
Future<bool> isMember(String address) async {
return await idtyStatus(address) == 'Validated';
}
Future<String> derive( Future<String> derive(
BuildContext context, String address, int number, String password) async { BuildContext context, String address, int number, String password) async {
final keypair = getKeypair(address); final keypair = getKeypair(address);

View File

@ -247,6 +247,7 @@ class WalletOptionsProvider with ChangeNotifier {
child: Column(children: [ child: Column(children: [
const Text('Nom:'), const Text('Nom:'),
TextField( TextField(
autofocus: true,
controller: idtyName, controller: idtyName,
) )
]), ]),

View File

@ -106,6 +106,7 @@ class WalletsProfilesProvider with ChangeNotifier {
} }
String getShortPubkey(String pubkey) { String getShortPubkey(String pubkey) {
// log.d(pubkey);
List<int> pubkeyByte = Base58Decode(pubkey); List<int> pubkeyByte = Base58Decode(pubkey);
Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes); Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes);
String pubkeyCheksum = Base58Encode(pubkeyS256.bytes); String pubkeyCheksum = Base58Encode(pubkeyS256.bytes);

View File

@ -232,29 +232,41 @@ class UnlockingWallet extends StatelessWidget {
); );
break; break;
case "pay": case "pay":
// Navigator.pop(context);
// Navigator.pop(context);
// Payment workflow ! // Payment workflow !
WalletsProfilesProvider _walletViewProvider = WalletsProfilesProvider _walletViewProvider =
Provider.of<WalletsProfilesProvider>(context, Provider.of<WalletsProfilesProvider>(context,
listen: false); listen: false);
final acc = _sub.getCurrentWallet(); final acc = _sub.getCurrentWallet();
log.d( log.d(
"fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.outputPubkey.text}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $_pin"); "fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.pubkey!}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $_pin");
_sub.pay(context, _sub.pay(
fromAddress: acc.address!, fromAddress: acc.address!,
destAddress: _walletViewProvider.outputPubkey.text, destAddress: _walletViewProvider.pubkey!,
amount: amount:
double.parse(_walletViewProvider.payAmount.text), double.parse(_walletViewProvider.payAmount.text),
password: _pin.toUpperCase()); password: _pin.toUpperCase());
// await paymentsResult(context, resultPay);
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return TransactionInProgress( return const TransactionInProgress();
chest: currentChestNumber, pin: _pin.toUpperCase());
}), }),
); );
break;
case "cert":
WalletsProfilesProvider _walletViewProvider =
Provider.of<WalletsProfilesProvider>(context,
listen: false);
final acc = _sub.getCurrentWallet();
_sub.certify(acc.address!, _pin.toUpperCase(),
_walletViewProvider.pubkey!);
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return const TransactionInProgress(transType: 'cert');
}),
);
break; break;
} }
} }

View File

@ -4,6 +4,7 @@ import 'package:gecko/globals.dart';
import 'package:gecko/models/chest_data.dart'; import 'package:gecko/models/chest_data.dart';
import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallet_options.dart'; import 'package:gecko/providers/wallet_options.dart';
import 'package:gecko/providers/wallets_profiles.dart'; import 'package:gecko/providers/wallets_profiles.dart';
import 'package:gecko/screens/history.dart'; import 'package:gecko/screens/history.dart';
@ -114,7 +115,7 @@ class WalletOptions extends StatelessWidget {
SizedBox(height: 10 * ratio), SizedBox(height: 10 * ratio),
historyWidget(context, _historyProvider, walletProvider), historyWidget(context, _historyProvider, walletProvider),
SizedBox(height: 12 * ratio), SizedBox(height: 12 * ratio),
setDefaultWallet(walletProvider, _myWalletProvider, setDefaultWallet(context, walletProvider, _myWalletProvider,
_walletOptions, _currentChest), _walletOptions, _currentChest),
SizedBox(height: 17 * ratio), SizedBox(height: 17 * ratio),
if (!walletProvider.isDefaultWallet) if (!walletProvider.isDefaultWallet)
@ -332,11 +333,13 @@ class WalletOptions extends StatelessWidget {
} }
Widget setDefaultWallet( Widget setDefaultWallet(
BuildContext context,
WalletOptionsProvider walletProvider, WalletOptionsProvider walletProvider,
MyWalletsProvider _myWalletProvider, MyWalletsProvider _myWalletProvider,
WalletOptionsProvider _walletOptions, WalletOptionsProvider _walletOptions,
int _currentChest) { int _currentChest) {
WalletData defaultWallet = _myWalletProvider.getDefaultWallet()!; WalletData defaultWallet = _myWalletProvider.getDefaultWallet()!;
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
_walletOptions.isDefaultWallet = (defaultWallet.number == wallet.id()[1]); _walletOptions.isDefaultWallet = (defaultWallet.number == wallet.id()[1]);
@ -348,6 +351,7 @@ class WalletOptions extends StatelessWidget {
ChestData _newChestData = chestBox.get(_currentChest)!; ChestData _newChestData = chestBox.get(_currentChest)!;
_newChestData.defaultWallet = wallet.number; _newChestData.defaultWallet = wallet.number;
await chestBox.put(_currentChest, _newChestData); await chestBox.put(_currentChest, _newChestData);
_sub.setCurrentWallet(wallet.address!);
_myWalletProvider.readAllWallets(_currentChest); _myWalletProvider.readAllWallets(_currentChest);
_myWalletProvider.rebuildWidget(); _myWalletProvider.rebuildWidget();
} }

View File

@ -10,11 +10,9 @@ import 'package:provider/provider.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class TransactionInProgress extends StatelessWidget { class TransactionInProgress extends StatelessWidget {
const TransactionInProgress( const TransactionInProgress({Key? key, this.transType = 'pay'})
{Key? key, required this.chest, required this.pin})
: super(key: key); : super(key: key);
final int chest; final String transType;
final String pin;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -30,10 +28,29 @@ class TransactionInProgress extends StatelessWidget {
// Map jsonResult; // Map jsonResult;
final _result = _sub.transactionStatus; final _result = _sub.transactionStatus;
log.d(_walletViewProvider.pubkey!);
final from = _myWalletProvider.getDefaultWallet()!.name!; final from = _myWalletProvider.getDefaultWallet()!.name!;
final to = _walletViewProvider final to = _walletViewProvider.getShortPubkey(_walletViewProvider.pubkey!);
.getShortPubkey(_walletViewProvider.outputPubkey.text);
final amount = _walletViewProvider.payAmount.text; final amount = _walletViewProvider.payAmount.text;
String _actionName = '';
switch (transType) {
case 'pay':
{
_actionName = 'Transaction';
}
break;
case 'cert':
{
_actionName = 'Certification';
}
break;
default:
{
_actionName = 'Transaction étrange';
}
}
switch (_result) { switch (_result) {
case '': case '':
@ -52,7 +69,7 @@ class TransactionInProgress extends StatelessWidget {
// jsonResult = json.decode(_result); // jsonResult = json.decode(_result);
log.d(_result); log.d(_result);
if (_result.contains('blockHash: ')) { if (_result.contains('blockHash: ')) {
_resultText = 'Transcation validé !'; _resultText = '$_actionName validé !';
} else { } else {
_resultText = "Une erreur s'est produite:\n\n$_result"; _resultText = "Une erreur s'est produite:\n\n$_result";
} }
@ -64,7 +81,9 @@ class TransactionInProgress extends StatelessWidget {
_sub.transactionStatus = ''; _sub.transactionStatus = '';
Navigator.pop(context); Navigator.pop(context);
Navigator.pop(context); Navigator.pop(context);
Navigator.pop(context); if (_actionName == 'pay') {
Navigator.pop(context);
}
return Future<bool>.value(true); return Future<bool>.value(true);
}, },
child: Scaffold( child: Scaffold(
@ -76,7 +95,7 @@ class TransactionInProgress extends StatelessWidget {
height: 22, height: 22,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[Text('Transaction en cours')]), children: <Widget>[Text('$_actionName en cours')]),
)), )),
body: SafeArea( body: SafeArea(
child: Align( child: Align(
@ -95,13 +114,14 @@ class TransactionInProgress extends StatelessWidget {
)), )),
child: Column(children: <Widget>[ child: Column(children: <Widget>[
const SizedBox(height: 10), const SizedBox(height: 10),
Text( if (transType == 'pay')
'$amount $currencyName', Text(
textAlign: TextAlign.center, '$amount $currencyName',
style: const TextStyle( textAlign: TextAlign.center,
fontSize: 18, fontWeight: FontWeight.w600), style: const TextStyle(
), fontSize: 18, fontWeight: FontWeight.w600),
const SizedBox(height: 10), ),
if (transType == 'pay') const SizedBox(height: 10),
const Text( const Text(
'de', 'de',
textAlign: TextAlign.center, textAlign: TextAlign.center,
@ -130,23 +150,24 @@ class TransactionInProgress extends StatelessWidget {
), ),
// const SizedBox(height: 20, width: double.infinity), // const SizedBox(height: 20, width: double.infinity),
const Spacer(), const Spacer(),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Column(children: [
Text(
_resultText,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 19 * ratio),
),
Visibility( Visibility(
visible: isLoading, visible: isLoading,
child: SizedBox( child: SizedBox(
height: 15, height: 18,
width: 15, width: 18,
child: CircularProgressIndicator( child: CircularProgressIndicator(
color: orangeC, color: orangeC,
strokeWidth: 2, strokeWidth: 2,
), ),
), ),
), ),
const SizedBox(height: 10),
Text(
_resultText,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 19 * ratio),
),
]), ]),
const Spacer(), const Spacer(),
Expanded( Expanded(
@ -164,7 +185,9 @@ class TransactionInProgress extends StatelessWidget {
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
Navigator.pop(context); Navigator.pop(context);
Navigator.pop(context); if (_actionName == 'pay') {
Navigator.pop(context);
}
}, },
child: Text( child: Text(
'Fermer', 'Fermer',

View File

@ -29,6 +29,12 @@ class WalletViewScreen extends StatelessWidget {
CesiumPlusProvider _cesiumPlusProvider = CesiumPlusProvider _cesiumPlusProvider =
Provider.of<CesiumPlusProvider>(context, listen: false); Provider.of<CesiumPlusProvider>(context, listen: false);
_walletViewProvider.pubkey = pubkey!; _walletViewProvider.pubkey = pubkey!;
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
WalletData? defaultWallet = _myWalletProvider.getDefaultWallet();
_sub.setCurrentWallet(defaultWallet!.address!);
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
@ -89,6 +95,56 @@ class WalletViewScreen extends StatelessWidget {
fontSize: buttonFontSize, fontWeight: FontWeight.w500), fontSize: buttonFontSize, fontWeight: FontWeight.w500),
), ),
]), ]),
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
return FutureBuilder(
future: _sub.isMember(defaultWallet.address!),
builder: (context, AsyncSnapshot<bool?> snapshot) {
return Visibility(
visible: (snapshot.data ?? false),
child: Column(children: <Widget>[
SizedBox(
height: buttonSize,
child: ClipOval(
child: Material(
color: const Color(0xffFFD58D), // button color
child: InkWell(
key: const Key('copyKey'),
splashColor: orangeC, // inkwell color
child: const Padding(
padding: EdgeInsets.only(bottom: 0),
child: Image(
image: AssetImage(
'assets/gecko_certify.png')),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return UnlockingWallet(
wallet: defaultWallet,
action: "cert");
},
),
);
// _sub.certify(fromAddress, password, toAddress);
}),
),
),
),
const SizedBox(height: 9),
Text(
"Certifier",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: buttonFontSize,
fontWeight: FontWeight.w500),
),
]),
);
},
);
}),
Column(children: <Widget>[ Column(children: <Widget>[
SizedBox( SizedBox(
height: buttonSize, height: buttonSize,

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.6+4 version: 0.0.6+5
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'