2022-02-18 00:20:21 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gecko/globals.dart';
|
2022-02-18 02:19:08 +01:00
|
|
|
import 'package:gecko/models/stateful_wrapper.dart';
|
2022-02-18 00:20:21 +01:00
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class SubstrateSandBox extends StatelessWidget {
|
|
|
|
const SubstrateSandBox({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-02-18 18:57:03 +01:00
|
|
|
// SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
2022-02-18 00:20:21 +01:00
|
|
|
|
|
|
|
return StatefulWrapper(
|
|
|
|
onInit: () async {
|
2022-02-18 18:57:03 +01:00
|
|
|
// if (!_sub.sdkReady && !_sub.sdkLoading) await _sub.initApi();
|
|
|
|
// if (_sub.sdkReady && !_sub.nodeConnected) await _sub.connectNode();
|
2022-02-18 00:20:21 +01:00
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
toolbarHeight: 60 * ratio,
|
|
|
|
title: const SizedBox(
|
|
|
|
height: 22,
|
|
|
|
child: Text('Substrate Sandbox'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: SafeArea(
|
|
|
|
child: Consumer<SubstrateSdk>(builder: (context, _sub, _) {
|
2022-02-18 18:57:03 +01:00
|
|
|
return SingleChildScrollView(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text('js-api chargé ?: ${_sub.sdkReady}'),
|
|
|
|
InkWell(
|
|
|
|
onTap: !_sub.nodeConnected
|
|
|
|
? () async {
|
|
|
|
await _sub.connectNode();
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: Text(
|
|
|
|
'Noeud connecté ?: ${_sub.nodeConnected} (${_sub.subNode})')),
|
|
|
|
if (_sub.nodeConnected)
|
|
|
|
Text(
|
|
|
|
'Noeud "${_sub.sdk.api.connectedNode!.name}", bloc N°${_sub.blocNumber}'),
|
|
|
|
const SizedBox(height: 20),
|
2022-02-18 19:49:37 +01:00
|
|
|
Row(children: [
|
|
|
|
const Text('Liste des trousseaux:'),
|
|
|
|
const Spacer(),
|
|
|
|
InkWell(
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/walletOptions/trash.png',
|
|
|
|
height: 35,
|
|
|
|
),
|
|
|
|
onTap: () async {
|
2022-02-19 23:51:12 +01:00
|
|
|
await _sub.deleteAllAccounts();
|
2022-02-18 19:49:37 +01:00
|
|
|
_sub.reload();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
]),
|
2022-02-19 23:51:12 +01:00
|
|
|
FutureBuilder(
|
|
|
|
future: _sub.getKeyStoreAddress(),
|
|
|
|
builder: (BuildContext context,
|
|
|
|
AsyncSnapshot<List<AddressInfo>> _data) {
|
|
|
|
return Column(children: [
|
|
|
|
for (final AddressInfo e in _data.data!)
|
|
|
|
Row(children: [
|
|
|
|
InkWell(
|
|
|
|
onTap: () => _sub.keyring.setCurrent(_sub
|
|
|
|
.keyring.keyPairs
|
|
|
|
.firstWhere((element) =>
|
|
|
|
element.address == e.address!)),
|
|
|
|
child: Text(
|
|
|
|
getShortPubkey(e.address!),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontFamily: 'Monospace'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
InkWell(
|
|
|
|
onTap: () async => await _sub.pay(
|
|
|
|
context,
|
|
|
|
e.address!,
|
|
|
|
10,
|
|
|
|
_sub.keystorePassword.text),
|
|
|
|
child: Text("${e.balance.toString()} ğdev"),
|
|
|
|
)
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
}),
|
2022-02-18 18:57:03 +01:00
|
|
|
const SizedBox(height: 20),
|
2022-02-18 19:49:37 +01:00
|
|
|
const Text('Mot de passe du trousseau:'),
|
2022-02-18 18:57:03 +01:00
|
|
|
TextField(
|
|
|
|
controller: _sub.keystorePassword,
|
|
|
|
obscureText: true,
|
|
|
|
obscuringCharacter: '•',
|
2022-02-19 23:51:12 +01:00
|
|
|
enableSuggestions: false,
|
|
|
|
autocorrect: false,
|
2022-02-18 18:57:03 +01:00
|
|
|
onChanged: (_) => _sub.reload(),
|
|
|
|
),
|
2022-02-18 19:49:37 +01:00
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 20, width: double.infinity),
|
|
|
|
ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: yellowC, // background
|
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
),
|
|
|
|
onPressed: _sub.keystorePassword.text.isNotEmpty
|
|
|
|
? () async {
|
2022-02-19 23:51:12 +01:00
|
|
|
final res = await _sub.importAccount();
|
2022-02-18 19:49:37 +01:00
|
|
|
_sub.importIsLoading = false;
|
|
|
|
_sub.reload();
|
2022-02-19 23:51:12 +01:00
|
|
|
snack(
|
|
|
|
context,
|
|
|
|
res
|
|
|
|
? 'Portefeuille importé'
|
|
|
|
: 'Le format de trousseau est invalide');
|
2022-02-18 19:49:37 +01:00
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: const Text(
|
|
|
|
'Importer le trousseau depuis le presse-papier',
|
|
|
|
style: TextStyle(fontSize: 20),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (_sub.importIsLoading)
|
|
|
|
const CircularProgressIndicator(),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: yellowC, // background
|
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
2022-02-19 23:51:12 +01:00
|
|
|
final res = await _sub.generateMnemonic();
|
|
|
|
_sub.importIsLoading = false;
|
|
|
|
_sub.reload();
|
|
|
|
snack(
|
|
|
|
context,
|
|
|
|
res
|
|
|
|
? 'Portefeuille importé'
|
|
|
|
: 'Le format de trousseau est invalide');
|
2022-02-18 19:49:37 +01:00
|
|
|
},
|
|
|
|
child: const Text(
|
2022-02-19 23:51:12 +01:00
|
|
|
"Générer un mnemonic et l'importer",
|
2022-02-18 19:49:37 +01:00
|
|
|
style: TextStyle(fontSize: 20),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
SizedBox(
|
|
|
|
width: 400,
|
|
|
|
child: Text(
|
|
|
|
_sub.generatedMnemonic,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
])
|
2022-02-18 02:19:08 +01:00
|
|
|
]),
|
2022-02-18 18:57:03 +01:00
|
|
|
);
|
2022-02-18 00:20:21 +01:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|