Fix a few bugs

This commit is contained in:
poka 2021-12-01 08:14:07 +01:00
parent 8f0018e326
commit 46bfb61391
13 changed files with 839 additions and 717 deletions

View File

@ -65,6 +65,8 @@ Future<void> main() async {
configBox = await Hive.openBox("configBox"); configBox = await Hive.openBox("configBox");
g1WalletsBox = await Hive.openBox<G1WalletsList>("g1WalletsBox"); g1WalletsBox = await Hive.openBox<G1WalletsList>("g1WalletsBox");
g1WalletsBox.clear();
// final HiveStore _store = // final HiveStore _store =
// await HiveStore.open(path: '${appPath.path}/gqlCache'); // await HiveStore.open(path: '${appPath.path}/gqlCache');

View File

@ -61,6 +61,10 @@ class CesiumPlusProvider with ChangeNotifier {
Future<String> getName(String _pubkey) async { Future<String> getName(String _pubkey) async {
String _name; String _name;
if (g1WalletsBox.get(_pubkey).csName != null) {
return g1WalletsBox.get(_pubkey).csName;
}
List queryOptions = await _buildQuery(_pubkey); List queryOptions = await _buildQuery(_pubkey);
final response = await http.post((Uri.parse(queryOptions[0])), final response = await http.post((Uri.parse(queryOptions[0])),
body: queryOptions[1], headers: queryOptions[2]); body: queryOptions[1], headers: queryOptions[2]);
@ -75,6 +79,8 @@ class CesiumPlusProvider with ChangeNotifier {
} }
_name = responseJson['hits']['hits'][0]['_source']['title']; _name = responseJson['hits']['hits'][0]['_source']['title'];
g1WalletsBox.get(_pubkey).csName = _name;
return _name; return _name;
} }
@ -83,6 +89,8 @@ class CesiumPlusProvider with ChangeNotifier {
return g1WalletsBox.get(_pubkey).avatar; return g1WalletsBox.get(_pubkey).avatar;
} }
log.d(_pubkey);
List queryOptions = await _buildQuery(_pubkey); List queryOptions = await _buildQuery(_pubkey);
http.Response response; http.Response response;
@ -106,10 +114,14 @@ class CesiumPlusProvider with ChangeNotifier {
File('${(await getTemporaryDirectory()).path}/avatar_$_pubkey.png'); File('${(await getTemporaryDirectory()).path}/avatar_$_pubkey.png');
await avatarFile.writeAsBytes(base64.decode(_avatar)); await avatarFile.writeAsBytes(base64.decode(_avatar));
return Image.file( final finalAvatar = Image.file(
avatarFile, avatarFile,
height: size, height: size,
fit: BoxFit.fitWidth, fit: BoxFit.fitWidth,
); );
g1WalletsBox.get(_pubkey).avatar = finalAvatar;
return finalAvatar;
} }
} }

View File

@ -17,7 +17,24 @@ class G1WalletsList {
@HiveField(4) @HiveField(4)
Image avatar; Image avatar;
G1WalletsList({this.pubkey, this.balance, this.id, this.avatar}); @HiveField(5)
String username;
@HiveField(6)
String csName;
@HiveField(7)
bool isMembre;
G1WalletsList({
this.pubkey,
this.balance,
this.id,
this.avatar,
this.username,
this.csName,
this.isMembre,
});
G1WalletsList.fromJson(Map<String, dynamic> json) { G1WalletsList.fromJson(Map<String, dynamic> json) {
pubkey = json['pubkey']; pubkey = json['pubkey'];

View File

@ -23,13 +23,16 @@ class G1WalletsListAdapter extends TypeAdapter<G1WalletsList> {
balance: fields[1] as double, balance: fields[1] as double,
id: fields[3] as Id, id: fields[3] as Id,
avatar: fields[4] as Image, avatar: fields[4] as Image,
username: fields[5] as String,
csName: fields[6] as String,
isMembre: fields[7] as bool,
); );
} }
@override @override
void write(BinaryWriter writer, G1WalletsList obj) { void write(BinaryWriter writer, G1WalletsList obj) {
writer writer
..writeByte(4) ..writeByte(7)
..writeByte(0) ..writeByte(0)
..write(obj.pubkey) ..write(obj.pubkey)
..writeByte(1) ..writeByte(1)
@ -37,7 +40,13 @@ class G1WalletsListAdapter extends TypeAdapter<G1WalletsList> {
..writeByte(3) ..writeByte(3)
..write(obj.id) ..write(obj.id)
..writeByte(4) ..writeByte(4)
..write(obj.avatar); ..write(obj.avatar)
..writeByte(5)
..write(obj.username)
..writeByte(6)
..write(obj.csName)
..writeByte(7)
..write(obj.isMembre);
} }
@override @override

View File

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:dubp/dubp.dart'; import 'package:dubp/dubp.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -16,7 +14,6 @@ import 'package:intl/intl.dart';
import 'package:truncate/truncate.dart'; import 'package:truncate/truncate.dart';
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:fast_base58/fast_base58.dart'; import 'package:fast_base58/fast_base58.dart';
import 'package:http/http.dart' as http;
class WalletsProfilesProvider with ChangeNotifier { class WalletsProfilesProvider with ChangeNotifier {
WalletsProfilesProvider(this.pubkey); WalletsProfilesProvider(this.pubkey);
@ -32,6 +29,7 @@ class WalletsProfilesProvider with ChangeNotifier {
String rawSvg; String rawSvg;
TextEditingController payAmount = TextEditingController(); TextEditingController payAmount = TextEditingController();
TextEditingController payComment = TextEditingController(); TextEditingController payComment = TextEditingController();
num balance;
Future scan(context) async { Future scan(context) async {
await Permission.camera.request(); await Permission.camera.request();
@ -47,7 +45,7 @@ class WalletsProfilesProvider with ChangeNotifier {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return const WalletViewScreen(); return WalletViewScreen(pubkey: pubkey);
}), }),
); );
} else { } else {
@ -258,17 +256,24 @@ class WalletsProfilesProvider with ChangeNotifier {
return Jdenticon.toSvg(_pubkey); return Jdenticon.toSvg(_pubkey);
} }
Future<num> getBalance(String _pubkey) async { // Future<num> getBalance(String _pubkey) async {
num balance; // final url = Uri.parse(
final url = Uri.parse( // '$endPointGVA?query={%20balance(script:%20%22$_pubkey%22)%20{%20amount%20base%20}%20}');
'$endPointGVA?query={%20balance(script:%20%22$_pubkey%22)%20{%20amount%20base%20}%20}'); // final response = await http.get(url);
final response = await http.get(url); // final result = json.decode(response.body);
final result = json.decode(response.body);
if (result['data']['balance'] == null) { // if (result['data']['balance'] == null) {
balance = 0.0; // balance = 0.0;
} else { // } else {
balance = removeDecimalZero(result['data']['balance']['amount'] / 100); // balance = removeDecimalZero(result['data']['balance']['amount'] / 100);
// }
// return balance;
// }
Future<num> getBalance(String _pubkey) async {
while (balance == null) {
await Future.delayed(const Duration(milliseconds: 50));
} }
return balance; return balance;

View File

@ -42,7 +42,10 @@ class AvatarFullscreen extends StatelessWidget {
// alignment: Alignment.center, // alignment: Alignment.center,
// height: MediaQuery.of(context).size.height, // height: MediaQuery.of(context).size.height,
// width: MediaQuery.of(context).size.width, // width: MediaQuery.of(context).size.width,
child: avatar, child: Image(
image: avatar.image,
height: avatar.height,
fit: BoxFit.fitWidth),
), ),
), ),
), ),

View File

@ -12,7 +12,6 @@ import 'dart:ui';
import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class HistoryScreen extends StatelessWidget with ChangeNotifier { class HistoryScreen extends StatelessWidget with ChangeNotifier {
@ -37,9 +36,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
Provider.of<WalletsProfilesProvider>(context, listen: false); Provider.of<WalletsProfilesProvider>(context, listen: false);
CesiumPlusProvider _cesiumPlusProvider = CesiumPlusProvider _cesiumPlusProvider =
Provider.of<CesiumPlusProvider>(context, listen: false); Provider.of<CesiumPlusProvider>(context, listen: false);
log.i('Build pubkey : ' + _historyProvider.pubkey); log.i('Build pubkey : ' + pubkey);
WidgetsBinding.instance.addPostFrameCallback((_) {}); WidgetsBinding.instance.addPostFrameCallback((_) {});
_historyProvider.balance = _historyProvider.transBC = null;
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
appBar: AppBar( appBar: AppBar(
@ -52,7 +53,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
), ),
body: Column(children: <Widget>[ body: Column(children: <Widget>[
headerProfileView(context, _historyProvider, _cesiumPlusProvider), headerProfileView(context, _historyProvider, _cesiumPlusProvider),
if (_historyProvider.pubkey != '')
historyQuery(context, _historyProvider, _cesiumPlusProvider), historyQuery(context, _historyProvider, _cesiumPlusProvider),
])); ]));
} }
@ -61,8 +61,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
CesiumPlusProvider _cesiumPlusProvider) { CesiumPlusProvider _cesiumPlusProvider) {
WalletsProfilesProvider _historyProvider = WalletsProfilesProvider _historyProvider =
Provider.of<WalletsProfilesProvider>(context, listen: true); Provider.of<WalletsProfilesProvider>(context, listen: true);
RefreshController _refreshController =
RefreshController(initialRefresh: false);
return Expanded( return Expanded(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
@ -72,12 +70,14 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
options: QueryOptions( options: QueryOptions(
document: gql(getHistory), document: gql(getHistory),
variables: <String, dynamic>{ variables: <String, dynamic>{
'pubkey': _historyProvider.pubkey, 'pubkey': pubkey,
'number': nRepositories, 'number': nRepositories,
'cursor': null 'cursor': null
}, },
), ),
builder: (QueryResult result, {fetchMore, refetch}) { builder: (QueryResult result, {fetchMore, refetch}) {
// log.d(result.data);
if (result.isLoading && result.data == null) { if (result.isLoading && result.data == null) {
return const Center( return const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
@ -90,13 +90,24 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
SizedBox(height: 50), SizedBox(height: 50),
Text( Text(
"Aucun noeud GVA valide n'a pu être trouvé.\nVeuillez réessayer ultérieurement.", "Aucun noeud GVA valide n'a pu être trouvé.\nVeuillez réessayer ultérieurement.",
style: TextStyle(fontSize: 17.0), style: TextStyle(fontSize: 18),
)
]);
} else if (result.data == null) {
return Column(children: const <Widget>[
SizedBox(height: 50),
Text(
"Aucune donnée à afficher.",
style: TextStyle(fontSize: 18),
) )
]); ]);
} }
if (result.data == null && result.exception.toString() == null) { if (result.data['balance'] == null) {
return const Text('Aucune donnée à afficher.'); _historyProvider.balance = 0.0;
} else {
_historyProvider.balance = _historyProvider
.removeDecimalZero(result.data['balance']['amount'] / 100);
} }
opts = _historyProvider.checkQueryResult(result, opts, pubkey); opts = _historyProvider.checkQueryResult(result, opts, pubkey);
@ -105,13 +116,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
return NotificationListener( return NotificationListener(
child: Builder( child: Builder(
builder: (context) => Expanded( builder: (context) => Expanded(
child: SmartRefresher(
enablePullUp: false,
controller: _refreshController,
onRefresh: () {
_historyProvider.resetdHistory();
_refreshController.refreshCompleted();
},
child: ListView( child: ListView(
key: const Key('listTransactions'), key: const Key('listTransactions'),
controller: scrollController, controller: scrollController,
@ -119,11 +123,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
), ),
), ),
), ),
),
onNotification: (t) { onNotification: (t) {
if (t is ScrollEndNotification && if (t is ScrollEndNotification &&
scrollController.position.pixels >= scrollController.position.pixels >=
scrollController.position.maxScrollExtent * 0.7) { scrollController.position.maxScrollExtent * 0.7 &&
_historyProvider.pageInfo['hasPreviousPage']) {
fetchMore(opts); fetchMore(opts);
} }
return true; return true;
@ -139,48 +143,15 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
Provider.of<WalletsProfilesProvider>(context, listen: false); Provider.of<WalletsProfilesProvider>(context, listen: false);
return _historyProvider.transBC == null return _historyProvider.transBC == null
? const Text('Aucune transaction à afficher.') ? Column(children: const <Widget>[
SizedBox(height: 50),
Text(
"Aucune transaction à afficher.",
style: TextStyle(fontSize: 18),
)
])
: Column(children: <Widget>[ : Column(children: <Widget>[
getTransactionTile(context, _historyProvider), getTransactionTile(context, _historyProvider),
// for (var repository in _historyProvider.transBC)
// if (repository[1].toString().split(' ')[0] == '22-11-21')
// const Text("Aujourd'hui"),
// Padding(
// padding: const EdgeInsets.symmetric(horizontal: 5.0),
// child: ListTile(
// key: Key('transaction${keyID++}'),
// contentPadding: const EdgeInsets.all(5.0),
// leading: Text(repository[1],
// style: TextStyle(
// fontSize: 12,
// color: Colors.grey[800],
// fontWeight: FontWeight.w700),
// textAlign: TextAlign.center),
// title: Text(repository[3],
// style: const TextStyle(
// fontSize: 15.0, fontFamily: 'Monospace'),
// textAlign: TextAlign.center),
// subtitle: Text(repository[6] != '' ? repository[6] : '-',
// style: const TextStyle(fontSize: 12.0),
// textAlign: TextAlign.center),
// trailing: Text("${repository[4]} Ğ1",
// style: const TextStyle(fontSize: 14.0),
// textAlign: TextAlign.justify),
// dense: true,
// isThreeLine: false,
// onTap: () {
// if (_historyProvider.isPubkey(context, repository[2])) {
// _homeProvider.currentIndex = 0;
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) {
// return const WalletViewScreen();
// }),
// );
// }
// Navigator.pop(context);
// }),
// ),
if (result.isLoading && if (result.isLoading &&
_historyProvider.pageInfo['hasPreviousPage']) _historyProvider.pageInfo['hasPreviousPage'])
Row( Row(
@ -189,7 +160,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
CircularProgressIndicator(), CircularProgressIndicator(),
], ],
), ),
// if (_historyProvider.isTheEnd) // What I did before ...
if (!_historyProvider.pageInfo['hasPreviousPage']) if (!_historyProvider.pageInfo['hasPreviousPage'])
Column( Column(
children: const <Widget>[ children: const <Widget>[
@ -214,6 +184,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
String lastDateDelimiter; String lastDateDelimiter;
const double _avatarSize = 200; const double _avatarSize = 200;
bool isTody = false;
bool isYesterday = false;
bool isThisWeek = false;
const Map<int, String> monthsInYear = { const Map<int, String> monthsInYear = {
1: "Janvier", 1: "Janvier",
2: "Février", 2: "Février",
@ -242,7 +216,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
} else { } else {
dateForm = "${date.day} ${monthsInYear[date.month]}"; dateForm = "${date.day} ${monthsInYear[date.month]}";
} }
log.d(dateForm);
int weekNumber(DateTime date) { int weekNumber(DateTime date) {
int dayOfYear = int.parse(DateFormat("D").format(date)); int dayOfYear = int.parse(DateFormat("D").format(date));
@ -250,17 +223,30 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
} }
if (DateTime(date.year, date.month, date.day) == if (DateTime(date.year, date.month, date.day) ==
DateTime(now.year, now.month, now.day)) { DateTime(now.year, now.month, now.day) &&
!isTody) {
dateDelimiter = lastDateDelimiter = "Aujourd'hui"; dateDelimiter = lastDateDelimiter = "Aujourd'hui";
isTody = true;
} else if (DateTime(date.year, date.month, date.day) == } else if (DateTime(date.year, date.month, date.day) ==
DateTime(now.year, now.month, now.day - 1)) { DateTime(now.year, now.month, now.day - 1) &&
!isYesterday) {
dateDelimiter = lastDateDelimiter = "Hier"; dateDelimiter = lastDateDelimiter = "Hier";
isYesterday = true;
} else if (weekNumber(date) == weekNumber(now) && } else if (weekNumber(date) == weekNumber(now) &&
date.year == now.year && date.year == now.year &&
lastDateDelimiter != "Cette semaine") { lastDateDelimiter != "Cette semaine" &&
DateTime(date.year, date.month, date.day) !=
DateTime(now.year, now.month, now.day - 1) &&
!isThisWeek) {
dateDelimiter = lastDateDelimiter = "Cette semaine"; dateDelimiter = lastDateDelimiter = "Cette semaine";
isThisWeek = true;
} else if (lastDateDelimiter != monthsInYear[date.month] && } else if (lastDateDelimiter != monthsInYear[date.month] &&
lastDateDelimiter != "${monthsInYear[date.month]} ${date.year}") { lastDateDelimiter != "${monthsInYear[date.month]} ${date.year}" &&
DateTime(date.year, date.month, date.day) !=
DateTime(now.year, now.month, now.day) &&
DateTime(date.year, date.month, date.day) !=
DateTime(now.year, now.month, now.day - 1) &&
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
if (date.year == now.year) { if (date.year == now.year) {
dateDelimiter = lastDateDelimiter = monthsInYear[date.month]; dateDelimiter = lastDateDelimiter = monthsInYear[date.month];
} else { } else {
@ -377,11 +363,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return const WalletViewScreen(); return WalletViewScreen(pubkey: repository[2]);
}), }),
); );
} }
Navigator.pop(context); // Navigator.pop(context);
}), }),
), ),
]); ]);
@ -422,13 +408,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
GestureDetector( GestureDetector(
key: const Key('copyPubkey'), key: const Key('copyPubkey'),
onTap: () { onTap: () {
Clipboard.setData(ClipboardData( Clipboard.setData(ClipboardData(text: pubkey));
text: pubkey ?? _historyProvider.pubkey));
_historyProvider.snackCopyKey(context); _historyProvider.snackCopyKey(context);
}, },
child: Text( child: Text(
_historyProvider.getShortPubkey( _historyProvider.getShortPubkey(pubkey),
pubkey ?? _historyProvider.pubkey),
style: const TextStyle( style: const TextStyle(
fontSize: 30, fontSize: 30,
fontWeight: FontWeight.w800, fontWeight: FontWeight.w800,
@ -442,7 +426,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
options: QueryOptions( options: QueryOptions(
document: gql(getId), document: gql(getId),
variables: { variables: {
'pubkey': _historyProvider.pubkey, 'pubkey': pubkey,
}, },
), ),
builder: (QueryResult result, builder: (QueryResult result,
@ -467,13 +451,16 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
}, },
), ),
if (username != null) if (username != null)
Text( SizedBox(
width: 230,
child: Text(
username, username,
style: const TextStyle( style: const TextStyle(
fontSize: 27, fontSize: 27,
color: Color(0xff814C00), color: Color(0xff814C00),
), ),
), ),
),
const SizedBox(height: 25), const SizedBox(height: 25),
]), ]),
FutureBuilder( FutureBuilder(
@ -497,24 +484,22 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
Column(children: <Widget>[ Column(children: <Widget>[
if (avatar == null) if (avatar == null)
FutureBuilder( FutureBuilder(
future: _cesiumPlusProvider.getAvatar( future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize),
_historyProvider.pubkey, _avatarSize),
builder: builder:
(BuildContext context, AsyncSnapshot<Image> _avatar) { (BuildContext context, AsyncSnapshot<Image> _avatar) {
if (_avatar.connectionState != ConnectionState.done || if (_avatar.connectionState != ConnectionState.done) {
_avatar.hasError) {
return Stack(children: [ return Stack(children: [
ClipOval( ClipOval(
child: child:
_cesiumPlusProvider.defaultAvatar(_avatarSize), _cesiumPlusProvider.defaultAvatar(_avatarSize),
), ),
Positioned( Positioned(
top: 16.5, top: 15,
right: 47.5, right: 45,
width: 55, width: 51,
height: 55, height: 51,
child: CircularProgressIndicator( child: CircularProgressIndicator(
strokeWidth: 6, strokeWidth: 5,
color: orangeC, color: orangeC,
), ),
), ),
@ -532,7 +517,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
); );
}, },
child: ClipOval( child: ClipOval(
child: _avatar.data, child: Image(
image: _avatar.data.image,
height: _avatarSize,
fit: BoxFit.cover,
),
), ),
); );
} }

View File

@ -9,8 +9,8 @@ import 'package:gecko/models/wallets_profiles.dart';
import 'package:gecko/models/my_wallets.dart'; import 'package:gecko/models/my_wallets.dart';
import 'package:gecko/models/queries.dart'; import 'package:gecko/models/queries.dart';
import 'package:gecko/models/wallet_options.dart'; import 'package:gecko/models/wallet_options.dart';
import 'package:gecko/screens/history.dart';
import 'package:gecko/screens/myWallets/change_pin.dart'; import 'package:gecko/screens/myWallets/change_pin.dart';
import 'package:gecko/screens/wallet_view.dart';
import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -18,20 +18,30 @@ import 'package:flutter/services.dart';
int _nbrLinesName = 1; int _nbrLinesName = 1;
bool _isNewNameValid = false; bool _isNewNameValid = false;
Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet, class CesiumWalletOptions extends StatelessWidget {
MyWalletsProvider _myWalletProvider) { const CesiumWalletOptions(
{Key key, Key keyMyWallets, @required this.cesiumWallet})
: super(key: key);
final ChestData cesiumWallet;
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
WalletOptionsProvider _walletOptions = WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context); Provider.of<WalletOptionsProvider>(context, listen: false);
ChestProvider _chestProvider = ChestProvider _chestProvider =
Provider.of<ChestProvider>(context, listen: false); Provider.of<ChestProvider>(context, listen: false);
WalletsProfilesProvider _historyProvider = WalletsProfilesProvider _historyProvider =
Provider.of<WalletsProfilesProvider>(context); Provider.of<WalletsProfilesProvider>(context, listen: false);
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
final String shortPubkey = final String shortPubkey =
_walletOptions.getShortPubkey(_walletOptions.pubkey.text); _walletOptions.getShortPubkey(_walletOptions.pubkey.text);
if (_walletOptions.nameController.text == null || _isNewNameValid == false) { if (_walletOptions.nameController.text == null ||
_isNewNameValid == false) {
_walletOptions.nameController.text = cesiumWallet.name; _walletOptions.nameController.text = cesiumWallet.name;
} else { } else {
cesiumWallet.name = _walletOptions.nameController.text; cesiumWallet.name = _walletOptions.nameController.text;
@ -44,16 +54,45 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
_nbrLinesName = 3; _nbrLinesName = 3;
} }
return Scaffold( return WillPopScope(
onWillPop: () {
_walletOptions.isEditing = false;
_walletOptions.isBalanceBlur = true;
Navigator.popUntil(
context,
ModalRoute.withName('/'),
);
return Future<bool>.value(true);
},
child: Scaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
appBar: AppBar(
toolbarHeight: 60 * ratio,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.black),
onPressed: () {
_walletOptions.isEditing = false;
_walletOptions.isBalanceBlur = true;
Navigator.popUntil(
context,
ModalRoute.withName('/'),
);
}),
title: SizedBox(
height: 22,
child: Consumer<WalletOptionsProvider>(
builder: (context, walletProvider, _) {
return Text(_walletOptions.nameController.text);
}),
),
),
body: Builder( body: Builder(
builder: (ctx) => SafeArea( builder: (ctx) => SafeArea(
child: Column(children: <Widget>[ child: Column(children: <Widget>[
Container( Consumer<WalletOptionsProvider>(
height: isTall ? 30 : 15, builder: (context, walletProvider, _) {
color: yellowC, return Container(
),
Container(
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
begin: Alignment.topCenter, begin: Alignment.topCenter,
@ -145,8 +184,10 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
if (result.data['balance'] == null) { if (result.data['balance'] == null) {
wBalanceUD = '0.0'; wBalanceUD = '0.0';
} else { } else {
int wBalanceG1 = result.data['balance']['amount']; int wBalanceG1 =
int currentUD = result.data['currentUd']['amount']; result.data['balance']['amount'];
int currentUD =
result.data['currentUd']['amount'];
double wBalanceUDBrut = double wBalanceUDBrut =
wBalanceG1 / currentUD; // .toString(); wBalanceG1 / currentUD; // .toString();
wBalanceUD = double.parse( wBalanceUD = double.parse(
@ -156,8 +197,10 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
return Row(children: <Widget>[ return Row(children: <Widget>[
ImageFiltered( ImageFiltered(
imageFilter: ImageFilter.blur( imageFilter: ImageFilter.blur(
sigmaX: _walletOptions.isBalanceBlur ? 6 : 0, sigmaX:
sigmaY: _walletOptions.isBalanceBlur ? 5 : 0), _walletOptions.isBalanceBlur ? 6 : 0,
sigmaY:
_walletOptions.isBalanceBlur ? 5 : 0),
child: Text(wBalanceUD, child: Text(wBalanceUD,
style: TextStyle( style: TextStyle(
fontSize: isTall ? 20 : 18, fontSize: isTall ? 20 : 18,
@ -216,13 +259,17 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
]) ])
]), ]),
]), ]),
])), ]),
);
}),
SizedBox(height: 4 * ratio), SizedBox(height: 4 * ratio),
FutureBuilder( FutureBuilder(
future: _walletOptions.generateQRcode(_walletOptions.pubkey.text), future:
_walletOptions.generateQRcode(_walletOptions.pubkey.text),
builder: (context, snapshot) { builder: (context, snapshot) {
return snapshot.data != null return snapshot.data != null
? Image.memory(snapshot.data, height: isTall ? 300 : 270) ? Image.memory(snapshot.data,
height: isTall ? 300 : 270)
: const Text('-', style: TextStyle(fontSize: 20)); : const Text('-', style: TextStyle(fontSize: 20));
}), }),
SizedBox(height: 15 * ratio), SizedBox(height: 15 * ratio),
@ -290,7 +337,8 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return const WalletViewScreen(); return HistoryScreen(
pubkey: _walletOptions.pubkey.text);
}), }),
); );
} }
@ -305,14 +353,15 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
), ),
const SizedBox(width: 22), const SizedBox(width: 22),
const Text('Historique des transactions', const Text('Historique des transactions',
style: TextStyle(fontSize: 20, color: Colors.black)), style:
TextStyle(fontSize: 20, color: Colors.black)),
]))), ]))),
SizedBox(height: 7 * ratio), SizedBox(height: 7 * ratio),
InkWell( InkWell(
key: const Key('changePin'), key: const Key('changePin'),
onTap: () async { onTap: () async {
// await _chestProvider.changePin(context, cesiumWallet); // await _chestProvider.changePin(context, cesiumWallet);
_myWalletProvider.pinCode = await Navigator.push( String newPin = await Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) { builder: (context) {
@ -323,6 +372,8 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
}, },
), ),
); );
if (newPin != null) _myWalletProvider.pinCode = newPin;
}, },
child: SizedBox( child: SizedBox(
height: 50, height: 50,
@ -335,7 +386,8 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
const SizedBox(width: 20), const SizedBox(width: 20),
const Text('Changer mon code secret', const Text('Changer mon code secret',
style: TextStyle(fontSize: 20, color: Colors.black)), style: TextStyle(fontSize: 20, color: Colors.black)),
])), ]),
),
), ),
SizedBox(height: 7 * ratio), SizedBox(height: 7 * ratio),
InkWell( InkWell(
@ -365,5 +417,7 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
]), ]),
), ),
), ),
),
); );
}
} }

View File

@ -7,6 +7,7 @@ import 'package:gecko/models/my_wallets.dart';
import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/models/wallet_options.dart'; import 'package:gecko/models/wallet_options.dart';
import 'package:flutter/material.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/choose_chest.dart';
import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:pin_code_fields/pin_code_fields.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -86,7 +87,7 @@ class UnlockingWallet extends StatelessWidget {
fontWeight: FontWeight.w400), fontWeight: FontWeight.w400),
)), )),
SizedBox(height: 40 * ratio), SizedBox(height: 40 * ratio),
pinForm(context, _pinLenght), pinForm(context, _pinLenght, currentChest),
SizedBox(height: 3 * ratio), SizedBox(height: 3 * ratio),
InkWell( InkWell(
key: const Key('chooseChest'), key: const Key('chooseChest'),
@ -114,7 +115,7 @@ class UnlockingWallet extends StatelessWidget {
)); ));
} }
Widget pinForm(context, _pinLenght) { Widget pinForm(context, _pinLenght, ChestData currentChest) {
// var _walletPin = ''; // var _walletPin = '';
// ignore: close_sinks // ignore: close_sinks
StreamController<ErrorAnimationType> errorController = StreamController<ErrorAnimationType> errorController =
@ -194,7 +195,16 @@ class UnlockingWallet extends StatelessWidget {
pinColor = Colors.green[400]; pinColor = Colors.green[400];
// await Future.delayed(Duration(milliseconds: 50)); // await Future.delayed(Duration(milliseconds: 50));
if (action == "mywallets") { if (action == "mywallets") {
Navigator.pushNamed(formKey.currentContext, '/mywallets'); currentChest.isCesium
? Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return CesiumWalletOptions(
cesiumWallet: currentChest);
}),
)
: Navigator.pushNamed(
formKey.currentContext, '/mywallets');
} else if (action == "pay") { } else if (action == "pay") {
resultPay = resultPay =
await _historyProvider.pay(context, _pin.toUpperCase()); await _historyProvider.pay(context, _pin.toUpperCase());

View File

@ -3,12 +3,11 @@ import 'dart:ui';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gecko/globals.dart'; import 'package:gecko/globals.dart';
import 'package:gecko/models/wallets_profiles.dart';
import 'package:gecko/models/my_wallets.dart'; import 'package:gecko/models/my_wallets.dart';
import 'package:gecko/models/queries.dart'; import 'package:gecko/models/queries.dart';
import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/models/wallet_options.dart'; import 'package:gecko/models/wallet_options.dart';
import 'package:gecko/screens/wallet_view.dart'; import 'package:gecko/screens/history.dart';
import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -25,11 +24,10 @@ class WalletOptions extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
WalletOptionsProvider _walletOptions = WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context); Provider.of<WalletOptionsProvider>(context, listen: false);
MyWalletsProvider _myWalletProvider = MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context); Provider.of<MyWalletsProvider>(context);
WalletsProfilesProvider _historyProvider =
Provider.of<WalletsProfilesProvider>(context);
final int _currentChest = _myWalletProvider.getCurrentChest(); final int _currentChest = _myWalletProvider.getCurrentChest();
final String shortPubkey = final String shortPubkey =
@ -72,6 +70,7 @@ class WalletOptions extends StatelessWidget {
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
appBar: AppBar( appBar: AppBar(
toolbarHeight: 60 * ratio, toolbarHeight: 60 * ratio,
elevation: 0,
leading: IconButton( leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.black), icon: const Icon(Icons.arrow_back, color: Colors.black),
onPressed: () { onPressed: () {
@ -84,16 +83,22 @@ class WalletOptions extends StatelessWidget {
}), }),
title: SizedBox( title: SizedBox(
height: 22, height: 22,
child: Text(_walletOptions.nameController.text), child: Consumer<WalletOptionsProvider>(
)), builder: (context, walletProvider, _) {
return Text(_walletOptions.nameController.text);
}),
),
),
body: Builder( body: Builder(
builder: (ctx) => SafeArea( builder: (ctx) => SafeArea(
child: Column(children: <Widget>[ child: Column(children: <Widget>[
Container( Container(
height: isTall ? 15 : 0, height: isTall ? 5 : 0,
color: yellowC, color: yellowC,
), ),
Container( Consumer<WalletOptionsProvider>(
builder: (context, walletProvider, _) {
return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
begin: Alignment.topCenter, begin: Alignment.topCenter,
@ -107,11 +112,11 @@ class WalletOptions extends StatelessWidget {
const SizedBox(width: 25), const SizedBox(width: 25),
InkWell( InkWell(
onTap: () async { onTap: () async {
File newAvatar = await _walletOptions.changeAvatar(); File newAvatar = await walletProvider.changeAvatar();
if (newAvatar != null) { if (newAvatar != null) {
wallet.imageFile = newAvatar; wallet.imageFile = newAvatar;
} }
_walletOptions.reloadBuild(); walletProvider.reloadBuild();
}, },
child: wallet.imageFile == null child: wallet.imageFile == null
? Image.asset( ? Image.asset(
@ -121,14 +126,15 @@ class WalletOptions extends StatelessWidget {
: Image.file( : Image.file(
wallet.imageFile, wallet.imageFile,
width: 110, width: 110,
)), ),
),
InkWell( InkWell(
onTap: () async { onTap: () async {
File newAvatar = await _walletOptions.changeAvatar(); File newAvatar = await walletProvider.changeAvatar();
if (newAvatar != null) { if (newAvatar != null) {
wallet.imageFile = newAvatar; wallet.imageFile = newAvatar;
} }
_walletOptions.reloadBuild(); walletProvider.reloadBuild();
}, },
child: Column(children: <Widget>[ child: Column(children: <Widget>[
Image.asset( Image.asset(
@ -145,9 +151,9 @@ class WalletOptions extends StatelessWidget {
child: TextField( child: TextField(
key: const Key('walletName'), key: const Key('walletName'),
autofocus: false, autofocus: false,
focusNode: _walletOptions.walletNameFocus, focusNode: walletProvider.walletNameFocus,
enabled: _walletOptions.isEditing, enabled: walletProvider.isEditing,
controller: _walletOptions.nameController, controller: walletProvider.nameController,
maxLines: _nbrLinesName, maxLines: _nbrLinesName,
textAlign: TextAlign.center, textAlign: TextAlign.center,
decoration: const InputDecoration( decoration: const InputDecoration(
@ -168,7 +174,7 @@ class WalletOptions extends StatelessWidget {
options: QueryOptions( options: QueryOptions(
document: gql(getBalance), document: gql(getBalance),
variables: { variables: {
'pubkey': _walletOptions.pubkey.text, 'pubkey': walletProvider.pubkey.text,
}, },
// pollInterval: Duration(seconds: 1), // pollInterval: Duration(seconds: 1),
), ),
@ -186,6 +192,8 @@ class WalletOptions extends StatelessWidget {
String wBalanceUD; String wBalanceUD;
if (result.data['balance'] == null) { if (result.data['balance'] == null) {
wBalanceUD = '0.0'; wBalanceUD = '0.0';
} else if (result.hasException) {
wBalanceUD = '?';
} else { } else {
int wBalanceG1 = int wBalanceG1 =
result.data['balance']['amount']; result.data['balance']['amount'];
@ -201,13 +209,15 @@ class WalletOptions extends StatelessWidget {
ImageFiltered( ImageFiltered(
imageFilter: ImageFilter.blur( imageFilter: ImageFilter.blur(
sigmaX: sigmaX:
_walletOptions.isBalanceBlur ? 6 : 0, walletProvider.isBalanceBlur ? 6 : 0,
sigmaY: sigmaY:
_walletOptions.isBalanceBlur ? 5 : 0), walletProvider.isBalanceBlur ? 5 : 0),
child: Text(wBalanceUD, child: Text(
wBalanceUD,
style: TextStyle( style: TextStyle(
fontSize: isTall ? 20 : 18, fontSize: isTall ? 20 : 18,
color: Colors.black)), color: Colors.black),
),
), ),
Text(' DU', Text(' DU',
style: TextStyle( style: TextStyle(
@ -226,10 +236,10 @@ class WalletOptions extends StatelessWidget {
InkWell( InkWell(
key: const Key('displayBalance'), key: const Key('displayBalance'),
onTap: () { onTap: () {
_walletOptions.bluringBalance(); walletProvider.bluringBalance();
}, },
child: Image.asset( child: Image.asset(
_walletOptions.isBalanceBlur walletProvider.isBalanceBlur
? 'assets/walletOptions/icon_oeuil.png' ? 'assets/walletOptions/icon_oeuil.png'
: 'assets/walletOptions/icon_oeuil_close.png', : 'assets/walletOptions/icon_oeuil_close.png',
height: 35, height: 35,
@ -241,16 +251,16 @@ class WalletOptions extends StatelessWidget {
InkWell( InkWell(
key: const Key('renameWallet'), key: const Key('renameWallet'),
onTap: () async { onTap: () async {
_isNewNameValid = _walletOptions.editWalletName( _isNewNameValid = walletProvider.editWalletName(
wallet.id(), wallet.id(),
isCesium: false); isCesium: false);
await Future.delayed( await Future.delayed(
const Duration(milliseconds: 30)); const Duration(milliseconds: 30));
_walletOptions.walletNameFocus.requestFocus(); walletProvider.walletNameFocus.requestFocus();
}, },
child: ClipRRect( child: ClipRRect(
child: Image.asset( child: Image.asset(
_walletOptions.isEditing walletProvider.isEditing
? 'assets/walletOptions/android-checkmark.png' ? 'assets/walletOptions/android-checkmark.png'
: 'assets/walletOptions/edit.png', : 'assets/walletOptions/edit.png',
width: 20, width: 20,
@ -262,7 +272,9 @@ class WalletOptions extends StatelessWidget {
]) ])
]), ]),
]), ]),
])), ]),
);
}),
SizedBox(height: 4 * ratio), SizedBox(height: 4 * ratio),
FutureBuilder( FutureBuilder(
future: future:
@ -274,12 +286,15 @@ class WalletOptions extends StatelessWidget {
}, },
), ),
SizedBox(height: 15 * ratio), SizedBox(height: 15 * ratio),
Consumer<WalletOptionsProvider>(
builder: (context, walletProvider, _) {
return Column(children: [
GestureDetector( GestureDetector(
key: const Key('copyPubkey'), key: const Key('copyPubkey'),
onTap: () { onTap: () {
Clipboard.setData( Clipboard.setData(
ClipboardData(text: _walletOptions.pubkey.text)); ClipboardData(text: walletProvider.pubkey.text));
_walletOptions.snackCopyKey(ctx); walletProvider.snackCopyKey(ctx);
}, },
child: SizedBox( child: SizedBox(
height: 50, height: 50,
@ -314,9 +329,9 @@ class WalletOptions extends StatelessWidget {
onPrimary: Colors.black, // foreground onPrimary: Colors.black, // foreground
), ),
onPressed: () { onPressed: () {
Clipboard.setData( Clipboard.setData(ClipboardData(
ClipboardData(text: _walletOptions.pubkey.text)); text: walletProvider.pubkey.text));
_walletOptions.snackCopyKey(ctx); walletProvider.snackCopyKey(ctx);
}, },
child: Row(children: <Widget>[ child: Row(children: <Widget>[
Image.asset( Image.asset(
@ -326,8 +341,8 @@ class WalletOptions extends StatelessWidget {
const SizedBox(width: 7), const SizedBox(width: 7),
Text( Text(
'Copier', 'Copier',
style: style: TextStyle(
TextStyle(fontSize: 15, color: Colors.grey[50]), fontSize: 15, color: Colors.grey[50]),
) )
]), ]),
), ),
@ -339,15 +354,22 @@ class WalletOptions extends StatelessWidget {
InkWell( InkWell(
key: const Key('displayHistory'), key: const Key('displayHistory'),
onTap: () { onTap: () {
if (_historyProvider.isPubkey(
context, _walletOptions.pubkey.text)) {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return const WalletViewScreen(); return HistoryScreen(
pubkey: walletProvider.pubkey.text,
avatar: wallet.imageFile == null
? Image.asset(
'assets/avatars/${wallet.imageName}',
width: 110,
)
: Image.file(
wallet.imageFile,
width: 110,
));
}), }),
); );
}
}, },
child: SizedBox( child: SizedBox(
height: 50, height: 50,
@ -359,14 +381,15 @@ class WalletOptions extends StatelessWidget {
), ),
const SizedBox(width: 22), const SizedBox(width: 22),
const Text('Historique des transactions', const Text('Historique des transactions',
style: TextStyle(fontSize: 20, color: Colors.black)), style:
TextStyle(fontSize: 20, color: Colors.black)),
]), ]),
), ),
), ),
SizedBox(height: 12 * ratio), SizedBox(height: 12 * ratio),
InkWell( InkWell(
key: const Key('setDefaultWallet'), key: const Key('setDefaultWallet'),
onTap: !_walletOptions.isDefaultWallet onTap: !walletProvider.isDefaultWallet
? () { ? () {
defaultWallet = wallet; defaultWallet = wallet;
chestBox.get(currentChest).defaultWallet = chestBox.get(currentChest).defaultWallet =
@ -381,7 +404,7 @@ class WalletOptions extends StatelessWidget {
const SizedBox(width: 31), const SizedBox(width: 31),
CircleAvatar( CircleAvatar(
backgroundColor: Colors backgroundColor: Colors
.grey[_walletOptions.isDefaultWallet ? 300 : 500], .grey[walletProvider.isDefaultWallet ? 300 : 500],
child: Image.asset( child: Image.asset(
'assets/walletOptions/android-checkmark.png', 'assets/walletOptions/android-checkmark.png',
height: 25, height: 25,
@ -389,27 +412,29 @@ class WalletOptions extends StatelessWidget {
), ),
const SizedBox(width: 22), const SizedBox(width: 22),
Text( Text(
_walletOptions.isDefaultWallet walletProvider.isDefaultWallet
? 'Ce portefeuille est celui par defaut' ? 'Ce portefeuille est celui par defaut'
: 'Définir comme portefeuille par défaut', : 'Définir comme portefeuille par défaut',
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
color: _walletOptions.isDefaultWallet color: walletProvider.isDefaultWallet
? Colors.grey[500] ? Colors.grey[500]
: Colors.black)), : Colors.black)),
]), ]),
), ),
), ),
SizedBox(height: 17 * ratio), SizedBox(height: 17 * ratio),
if (!_walletOptions.isDefaultWallet) if (!walletProvider.isDefaultWallet)
InkWell( InkWell(
key: const Key('deleteWallet'), key: const Key('deleteWallet'),
onTap: !_walletOptions.isDefaultWallet onTap: !walletProvider.isDefaultWallet
? () async { ? () async {
await _walletOptions.deleteWallet(context, wallet); await walletProvider.deleteWallet(
context, wallet);
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
_myWalletProvider.listWallets = _myWalletProvider.listWallets =
_myWalletProvider.readAllWallets(_currentChest); _myWalletProvider
.readAllWallets(_currentChest);
_myWalletProvider.rebuildWidget(); _myWalletProvider.rebuildWidget();
}); });
} }
@ -422,10 +447,12 @@ class WalletOptions extends StatelessWidget {
), ),
const SizedBox(width: 19), const SizedBox(width: 19),
const Text('Supprimer ce portefeuille', const Text('Supprimer ce portefeuille',
style: style: TextStyle(
TextStyle(fontSize: 20, color: Color(0xffD80000))), fontSize: 20, color: Color(0xffD80000))),
]), ]),
), ),
]);
}),
]), ]),
), ),
), ),

View File

@ -7,7 +7,6 @@ import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/models/wallet_options.dart'; import 'package:gecko/models/wallet_options.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/common_elements.dart';
import 'package:gecko/screens/myWallets/cesium_wallet_options.dart';
import 'package:gecko/screens/myWallets/chest_options.dart'; import 'package:gecko/screens/myWallets/chest_options.dart';
import 'package:gecko/screens/myWallets/choose_chest.dart'; import 'package:gecko/screens/myWallets/choose_chest.dart';
import 'package:gecko/screens/myWallets/wallet_options.dart'; import 'package:gecko/screens/myWallets/wallet_options.dart';
@ -27,10 +26,8 @@ class WalletsHome extends StatelessWidget {
final int _currentChestNumber = myWalletProvider.getCurrentChest(); final int _currentChestNumber = myWalletProvider.getCurrentChest();
final ChestData _currentChest = chestBox.get(_currentChestNumber); final ChestData _currentChest = chestBox.get(_currentChestNumber);
if (!_currentChest.isCesium) {
myWalletProvider.listWallets = myWalletProvider.listWallets =
myWalletProvider.readAllWallets(_currentChestNumber); myWalletProvider.readAllWallets(_currentChestNumber);
}
return WillPopScope( return WillPopScope(
onWillPop: () { onWillPop: () {
@ -57,9 +54,7 @@ class WalletsHome extends StatelessWidget {
backgroundColor: const Color(0xffFFD58D), backgroundColor: const Color(0xffFFD58D),
), ),
body: SafeArea( body: SafeArea(
child: _currentChest.isCesium child: myWalletsTiles(context),
? cesiumWalletOptions(context, _currentChest, myWalletProvider)
: myWalletsTiles(context),
), ),
), ),
); );

View File

@ -68,7 +68,7 @@ class OldHistoryScreen extends StatelessWidget with ChangeNotifier {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return const WalletViewScreen(); return WalletViewScreen(pubkey: text);
}), }),
); );
} }
@ -452,7 +452,7 @@ class OldHistoryScreen extends StatelessWidget with ChangeNotifier {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return const WalletViewScreen(); return WalletViewScreen(pubkey: repository[2]);
}), }),
); );
} }

View File

@ -12,11 +12,14 @@ import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class WalletViewScreen extends StatelessWidget { class WalletViewScreen extends StatelessWidget {
const WalletViewScreen({this.pubkey, this.username, this.avatar, Key key}) const WalletViewScreen(
{@required this.pubkey, this.username, this.avatar, Key key})
: super(key: key); : super(key: key);
final String pubkey; final String pubkey;
final String username; final String username;
final Image avatar; final Image avatar;
final double buttonSize = 100;
final double buttonFontSize = 18;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -34,42 +37,15 @@ class WalletViewScreen extends StatelessWidget {
height: 22, height: 22,
child: Text('Voir un portefeuille'), child: Text('Voir un portefeuille'),
), ),
// actions: [
// FutureBuilder(
// future: _walletOptions.generateQRcode(_historyProvider.pubkey),
// builder: (context, snapshot) {
// return snapshot.data != null
// ? GestureDetector(
// key: const Key('openAvatar'),
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) {
// return AvatarFullscreen(
// Image.memory(snapshot.data),
// title: 'QrCode du profil',
// );
// }),
// );
// // isAvatarView = !isAvatarView;
// // _historyProvider.resetdHistory();
// },
// child: Image.memory(snapshot.data, height: 40 * ratio),
// )
// : const Text('-', style: TextStyle(fontSize: 20));
// },
// ),
// const SizedBox(width: 75)
// ],
), ),
body: SafeArea( body: SafeArea(
child: Column(children: <Widget>[ child: Column(children: <Widget>[
headerProfileView(context, _historyProvider, _cesiumPlusProvider), headerProfileView(context, _historyProvider, _cesiumPlusProvider),
SizedBox(height: isTall ? 60 : 30), SizedBox(height: isTall ? 120 : 70),
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
Column(children: <Widget>[ Column(children: <Widget>[
SizedBox( SizedBox(
height: 120, height: buttonSize,
child: ClipOval( child: ClipOval(
child: Material( child: Material(
color: const Color(0xffFFD58D), // button color color: const Color(0xffFFD58D), // button color
@ -77,7 +53,7 @@ class WalletViewScreen extends StatelessWidget {
key: const Key('viewHistory'), key: const Key('viewHistory'),
splashColor: orangeC, // inkwell color splashColor: orangeC, // inkwell color
child: const Padding( child: const Padding(
padding: EdgeInsets.all(15), padding: EdgeInsets.all(13),
child: Image( child: Image(
image: AssetImage( image: AssetImage(
'assets/walletOptions/clock.png'), 'assets/walletOptions/clock.png'),
@ -87,9 +63,11 @@ class WalletViewScreen extends StatelessWidget {
context, context,
FaderTransition( FaderTransition(
page: HistoryScreen( page: HistoryScreen(
pubkey: pubkey ?? _historyProvider.pubkey, pubkey: pubkey,
username: username, username: username ??
avatar: avatar, g1WalletsBox.get(pubkey).username,
avatar: avatar ??
g1WalletsBox.get(pubkey).avatar,
), ),
isFast: false), isFast: false),
); );
@ -98,15 +76,16 @@ class WalletViewScreen extends StatelessWidget {
), ),
), ),
const SizedBox(height: 9), const SizedBox(height: 9),
const Text( Text(
"Voir\nl'historique", "Voir\nl'historique",
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500), style: TextStyle(
fontSize: buttonFontSize, fontWeight: FontWeight.w500),
), ),
]), ]),
Column(children: <Widget>[ Column(children: <Widget>[
SizedBox( SizedBox(
height: 120, height: buttonSize,
child: ClipOval( child: ClipOval(
child: Material( child: Material(
color: const Color(0xffFFD58D), // button color color: const Color(0xffFFD58D), // button color
@ -127,10 +106,11 @@ class WalletViewScreen extends StatelessWidget {
), ),
), ),
const SizedBox(height: 9), const SizedBox(height: 9),
const Text( Text(
"Copier\nla clef", "Copier\nla clef",
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500), style: TextStyle(
fontSize: buttonFontSize, fontWeight: FontWeight.w500),
), ),
]), ]),
]), ]),
@ -159,7 +139,7 @@ class WalletViewScreen extends StatelessWidget {
// ), // ),
const Spacer(), const Spacer(),
Container( Container(
height: 120, height: buttonSize,
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color(0xff7c94b6), color: const Color(0xff7c94b6),
borderRadius: const BorderRadius.all(Radius.circular(100)), borderRadius: const BorderRadius.all(Radius.circular(100)),
@ -175,7 +155,7 @@ class WalletViewScreen extends StatelessWidget {
key: const Key('pay'), key: const Key('pay'),
splashColor: yellowC, // inkwell color splashColor: yellowC, // inkwell color
child: const Padding( child: const Padding(
padding: EdgeInsets.all(16), padding: EdgeInsets.all(14),
child: Image( child: Image(
image: AssetImage('assets/vector_white.png'), image: AssetImage('assets/vector_white.png'),
)), )),
@ -186,12 +166,13 @@ class WalletViewScreen extends StatelessWidget {
), ),
), ),
const SizedBox(height: 9), const SizedBox(height: 9),
const Text( Text(
"Faire un\nvirement", "Faire un\nvirement",
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500), style: TextStyle(
fontSize: buttonFontSize, fontWeight: FontWeight.w500),
), ),
SizedBox(height: isTall ? 100 : 50) SizedBox(height: isTall ? 120 : 70)
]), ]),
)); ));
} }
@ -226,13 +207,11 @@ class WalletViewScreen extends StatelessWidget {
GestureDetector( GestureDetector(
key: const Key('copyPubkey'), key: const Key('copyPubkey'),
onTap: () { onTap: () {
Clipboard.setData( Clipboard.setData(ClipboardData(text: pubkey));
ClipboardData(text: pubkey ?? _historyProvider.pubkey));
_historyProvider.snackCopyKey(context); _historyProvider.snackCopyKey(context);
}, },
child: Text( child: Text(
_historyProvider _historyProvider.getShortPubkey(pubkey),
.getShortPubkey(pubkey ?? _historyProvider.pubkey),
style: const TextStyle( style: const TextStyle(
fontSize: 30, fontSize: 30,
fontWeight: FontWeight.w800, fontWeight: FontWeight.w800,
@ -241,7 +220,7 @@ class WalletViewScreen extends StatelessWidget {
), ),
]), ]),
const SizedBox(height: 10), const SizedBox(height: 10),
if (username == null) if (username == null && g1WalletsBox.get(pubkey).username == null)
Query( Query(
options: QueryOptions( options: QueryOptions(
document: gql(getId), document: gql(getId),
@ -255,8 +234,11 @@ class WalletViewScreen extends StatelessWidget {
return const Text('...'); return const Text('...');
} else if (result.data['idty'] == null || } else if (result.data['idty'] == null ||
result.data['idty']['username'] == null) { result.data['idty']['username'] == null) {
g1WalletsBox.get(pubkey).username = '';
return const Text(''); return const Text('');
} else { } else {
g1WalletsBox.get(pubkey).username =
result?.data['idty']['username'] ?? '';
return SizedBox( return SizedBox(
width: 230, width: 230,
child: Text( child: Text(
@ -270,14 +252,28 @@ class WalletViewScreen extends StatelessWidget {
} }
}, },
), ),
if (username == null && g1WalletsBox.get(pubkey).username != null)
SizedBox(
width: 230,
child: Text(
g1WalletsBox.get(pubkey).username,
style: const TextStyle(
fontSize: 27,
color: Color(0xff814C00),
),
),
),
if (username != null) if (username != null)
Text( SizedBox(
width: 230,
child: Text(
username, username,
style: const TextStyle( style: const TextStyle(
fontSize: 27, fontSize: 27,
color: Color(0xff814C00), color: Color(0xff814C00),
), ),
), ),
),
const SizedBox(height: 25), const SizedBox(height: 25),
FutureBuilder( FutureBuilder(
future: _cesiumPlusProvider.getName(_historyProvider.pubkey), future: _cesiumPlusProvider.getName(_historyProvider.pubkey),
@ -302,20 +298,19 @@ class WalletViewScreen extends StatelessWidget {
_historyProvider.pubkey, _avatarSize), _historyProvider.pubkey, _avatarSize),
builder: builder:
(BuildContext context, AsyncSnapshot<Image> _avatar) { (BuildContext context, AsyncSnapshot<Image> _avatar) {
if (_avatar.connectionState != ConnectionState.done || if (_avatar.connectionState != ConnectionState.done) {
_avatar.hasError) {
return Stack(children: [ return Stack(children: [
ClipOval( ClipOval(
child: child:
_cesiumPlusProvider.defaultAvatar(_avatarSize), _cesiumPlusProvider.defaultAvatar(_avatarSize),
), ),
Positioned( Positioned(
top: 16.5, top: 15,
right: 47.5, right: 45,
width: 55, width: 51,
height: 55, height: 51,
child: CircularProgressIndicator( child: CircularProgressIndicator(
strokeWidth: 6, strokeWidth: 5,
color: orangeC, color: orangeC,
), ),
), ),
@ -333,7 +328,11 @@ class WalletViewScreen extends StatelessWidget {
); );
}, },
child: ClipOval( child: ClipOval(
child: _avatar.data, child: Image(
image: _avatar.data.image,
height: _avatarSize,
fit: BoxFit.cover,
),
), ),
); );
} }