WIP: Refactore history screen to new activity screen
This commit is contained in:
parent
4e9e2d40d1
commit
1c4da17db9
|
@ -17,6 +17,7 @@ import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class DuniterIndexer with ChangeNotifier {
|
class DuniterIndexer with ChangeNotifier {
|
||||||
Map<String, String?> walletNameIndexer = {};
|
Map<String, String?> walletNameIndexer = {};
|
||||||
|
Map? pageInfo;
|
||||||
|
|
||||||
void reload() {
|
void reload() {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -257,4 +258,10 @@ class DuniterIndexer with ChangeNotifier {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
checkHistoryResult(QueryResult<Object?> result, FetchMoreOptions options, String address) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:gecko/globals.dart';
|
import 'package:gecko/globals.dart';
|
||||||
|
import 'package:gecko/models/queries_indexer.dart';
|
||||||
import 'package:gecko/providers/cesium_plus.dart';
|
import 'package:gecko/providers/cesium_plus.dart';
|
||||||
|
import 'package:gecko/providers/duniter_indexer.dart';
|
||||||
import 'package:gecko/providers/substrate_sdk.dart';
|
import 'package:gecko/providers/substrate_sdk.dart';
|
||||||
|
import 'package:gecko/providers/wallet_options.dart';
|
||||||
import 'package:gecko/providers/wallets_profiles.dart';
|
import 'package:gecko/providers/wallets_profiles.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:gecko/screens/avatar_fullscreen.dart';
|
|
||||||
import 'package:gecko/screens/wallet_view.dart';
|
import 'package:gecko/screens/wallet_view.dart';
|
||||||
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';
|
||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
class ActivityScreen extends StatelessWidget with ChangeNotifier {
|
||||||
HistoryScreen({required this.pubkey, this.avatar, this.username, Key? key})
|
ActivityScreen({required this.address, this.avatar, this.username, Key? key})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
final ScrollController scrollController = ScrollController();
|
final ScrollController scrollController = ScrollController();
|
||||||
final double avatarsSize = 80;
|
final double avatarsSize = 80;
|
||||||
final String? pubkey;
|
final String? address;
|
||||||
final String? username;
|
final String? username;
|
||||||
final Image? avatar;
|
final Image? avatar;
|
||||||
|
|
||||||
|
@ -28,14 +30,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
WalletsProfilesProvider _historyProvider =
|
|
||||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
|
||||||
CesiumPlusProvider _cesiumPlusProvider =
|
|
||||||
Provider.of<CesiumPlusProvider>(context, listen: false);
|
|
||||||
log.i('Build pubkey : ' + pubkey!);
|
|
||||||
// WidgetsBinding.instance.addPostFrameCallback((_) {});
|
|
||||||
|
|
||||||
_historyProvider.balance = _historyProvider.transBC = null;
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
|
@ -44,18 +38,18 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
toolbarHeight: 60 * ratio,
|
toolbarHeight: 60 * ratio,
|
||||||
title: const SizedBox(
|
title: const SizedBox(
|
||||||
height: 22,
|
height: 22,
|
||||||
child: Text('Historique des transactions'),
|
child: Text('Activité du compte'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: Column(children: <Widget>[
|
body: Column(children: <Widget>[
|
||||||
headerProfileView(context, _historyProvider, _cesiumPlusProvider),
|
headerProfileView(context),
|
||||||
historyQuery(context, _cesiumPlusProvider),
|
historyQuery(context),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget historyQuery(context, CesiumPlusProvider _cesiumPlusProvider) {
|
Widget historyQuery(context) {
|
||||||
WalletsProfilesProvider _historyProvider =
|
DuniterIndexer _duniterIndexer =
|
||||||
Provider.of<WalletsProfilesProvider>(context, listen: true);
|
Provider.of<DuniterIndexer>(context, listen: false);
|
||||||
|
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -64,14 +58,13 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Query(
|
Query(
|
||||||
options: QueryOptions(
|
options: QueryOptions(
|
||||||
document: gql('getHistory'),
|
document: gql(getHistoryByAddressQ3),
|
||||||
variables: <String, dynamic>{
|
variables: <String, dynamic>{
|
||||||
'pubkey': pubkey,
|
'address': address,
|
||||||
'number': 10,
|
|
||||||
'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(),
|
||||||
|
@ -79,11 +72,12 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.hasException) {
|
if (result.hasException) {
|
||||||
log.e('Error GVA: ' + result.exception.toString());
|
log.e('Error Indexer: ' + result.exception.toString());
|
||||||
return Column(children: const <Widget>[
|
return Column(children: const <Widget>[
|
||||||
SizedBox(height: 50),
|
SizedBox(height: 50),
|
||||||
Text(
|
Text(
|
||||||
"Aucun noeud GVA valide n'a pu être trouvé.\nVeuillez réessayer ultérieurement.",
|
"L'état du réseau ne permet pas\nd'afficher l'historique du compte",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(fontSize: 18),
|
style: TextStyle(fontSize: 18),
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
|
@ -97,16 +91,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.data!['balance'] == null) {
|
|
||||||
_historyProvider.balance = 0.0;
|
|
||||||
} else {
|
|
||||||
_historyProvider.balance = _historyProvider
|
|
||||||
.removeDecimalZero(result.data!['balance']['amount'] / 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.isNotLoading) {
|
if (result.isNotLoading) {
|
||||||
// log.d(result.data);
|
// log.d(result.data);
|
||||||
opts = _historyProvider.checkQueryResult(result, opts, pubkey);
|
opts =
|
||||||
|
_duniterIndexer.checkHistoryResult(result, opts!, address!);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build history list
|
// Build history list
|
||||||
|
@ -124,7 +112,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
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'] &&
|
_duniterIndexer.pageInfo!['hasPreviousPage'] &&
|
||||||
result.isNotLoading) {
|
result.isNotLoading) {
|
||||||
fetchMore!(opts!);
|
fetchMore!(opts!);
|
||||||
}
|
}
|
||||||
|
@ -368,11 +356,9 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
}).toList());
|
}).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget headerProfileView(
|
Widget headerProfileView(BuildContext context) {
|
||||||
BuildContext context,
|
DuniterIndexer _duniterIndexer =
|
||||||
WalletsProfilesProvider _historyProvider,
|
Provider.of<DuniterIndexer>(context, listen: false);
|
||||||
CesiumPlusProvider _cesiumPlusProvider) {
|
|
||||||
const double _avatarSize = 140;
|
|
||||||
|
|
||||||
return Column(children: <Widget>[
|
return Column(children: <Widget>[
|
||||||
Container(
|
Container(
|
||||||
|
@ -402,11 +388,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
key: const Key('copyPubkey'),
|
key: const Key('copyPubkey'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Clipboard.setData(ClipboardData(text: pubkey));
|
Clipboard.setData(ClipboardData(text: address));
|
||||||
snackCopyKey(context);
|
snackCopyKey(context);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
getShortPubkey(pubkey!),
|
getShortPubkey(address!),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 30,
|
fontSize: 30,
|
||||||
fontWeight: FontWeight.w800,
|
fontWeight: FontWeight.w800,
|
||||||
|
@ -416,34 +402,15 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
]),
|
]),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
if (username == null)
|
if (username == null)
|
||||||
Query(
|
_duniterIndexer.getNameByAddress(
|
||||||
options: QueryOptions(
|
context,
|
||||||
document: gql('getId'),
|
address!,
|
||||||
variables: {
|
null,
|
||||||
'pubkey': pubkey,
|
27,
|
||||||
},
|
false,
|
||||||
),
|
Colors.black,
|
||||||
builder: (QueryResult result,
|
FontWeight.w400,
|
||||||
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
FontStyle.normal),
|
||||||
if (result.isLoading || result.hasException) {
|
|
||||||
return const Text('...');
|
|
||||||
} else if (result.data!['idty'] == null ||
|
|
||||||
result.data!['idty']['username'] == null) {
|
|
||||||
return const Text('');
|
|
||||||
} else {
|
|
||||||
return SizedBox(
|
|
||||||
width: 230,
|
|
||||||
child: Text(
|
|
||||||
result.data!['idty']['username'] ?? '',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 27,
|
|
||||||
color: Color(0xff814C00),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (username != null)
|
if (username != null)
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 230,
|
width: 230,
|
||||||
|
@ -457,91 +424,12 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 25),
|
const SizedBox(height: 25),
|
||||||
]),
|
]),
|
||||||
FutureBuilder(
|
balance(context, address!, 21),
|
||||||
future: _historyProvider.getBalance(pubkey),
|
|
||||||
builder:
|
|
||||||
(BuildContext context, AsyncSnapshot<num?> _balance) {
|
|
||||||
if (_balance.connectionState != ConnectionState.done ||
|
|
||||||
_balance.hasError) {
|
|
||||||
return const Text('...');
|
|
||||||
}
|
|
||||||
return Text(
|
|
||||||
"${_balance.data.toString()} $currencyName",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 22, fontWeight: FontWeight.w500),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
const SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
]),
|
]),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
Column(children: <Widget>[
|
Column(children: <Widget>[
|
||||||
if (avatar == null)
|
Image.asset(('assets/icon_user.png'), height: 50),
|
||||||
FutureBuilder(
|
|
||||||
future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize),
|
|
||||||
builder:
|
|
||||||
(BuildContext context, AsyncSnapshot<Image?> _avatar) {
|
|
||||||
if (_avatar.connectionState != ConnectionState.done) {
|
|
||||||
return Stack(children: [
|
|
||||||
ClipOval(
|
|
||||||
child:
|
|
||||||
_cesiumPlusProvider.defaultAvatar(_avatarSize),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
top: 15,
|
|
||||||
right: 45,
|
|
||||||
width: 51,
|
|
||||||
height: 51,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 5,
|
|
||||||
color: orangeC,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if (_avatar.hasData) {
|
|
||||||
return GestureDetector(
|
|
||||||
key: const Key('openAvatar'),
|
|
||||||
onTap: () {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) {
|
|
||||||
return AvatarFullscreen(_avatar.data);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: ClipOval(
|
|
||||||
child: Image(
|
|
||||||
image: _avatar.data!.image,
|
|
||||||
height: _avatarSize,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return ClipOval(
|
|
||||||
child: _cesiumPlusProvider.defaultAvatar(_avatarSize),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
if (avatar != null)
|
|
||||||
GestureDetector(
|
|
||||||
key: const Key('openAvatar'),
|
|
||||||
onTap: () {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) {
|
|
||||||
return AvatarFullscreen(avatar);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: ClipOval(
|
|
||||||
child: Image(
|
|
||||||
image: avatar!.image,
|
|
||||||
height: _avatarSize,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 25),
|
const SizedBox(height: 25),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
|
@ -10,6 +10,7 @@ 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/common_elements.dart';
|
import 'package:gecko/screens/common_elements.dart';
|
||||||
|
import 'package:gecko/screens/activity.dart';
|
||||||
import 'package:gecko/screens/myWallets/manage_membership.dart';
|
import 'package:gecko/screens/myWallets/manage_membership.dart';
|
||||||
import 'package:gecko/screens/qrcode_fullscreen.dart';
|
import 'package:gecko/screens/qrcode_fullscreen.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
@ -162,7 +163,7 @@ class WalletOptions extends StatelessWidget {
|
||||||
return Column(children: [
|
return Column(children: [
|
||||||
pubkeyWidget(walletProvider, ctx),
|
pubkeyWidget(walletProvider, ctx),
|
||||||
SizedBox(height: 10 * ratio),
|
SizedBox(height: 10 * ratio),
|
||||||
historyWidget(
|
activityWidget(
|
||||||
context, _historyProvider, walletProvider),
|
context, _historyProvider, walletProvider),
|
||||||
SizedBox(height: 12 * ratio),
|
SizedBox(height: 12 * ratio),
|
||||||
setDefaultWalletWidget(
|
setDefaultWalletWidget(
|
||||||
|
@ -316,30 +317,30 @@ class WalletOptions extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget historyWidget(
|
Widget activityWidget(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
WalletsProfilesProvider _historyProvider,
|
WalletsProfilesProvider _historyProvider,
|
||||||
WalletOptionsProvider walletProvider) {
|
WalletOptionsProvider walletProvider) {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
key: const Key('displayHistory'),
|
key: const Key('displayActivity'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_historyProvider.nPage = 1;
|
// _historyProvider.nPage = 1;
|
||||||
// Navigator.push(
|
Navigator.push(
|
||||||
// context,
|
context,
|
||||||
// MaterialPageRoute(builder: (context) {
|
MaterialPageRoute(builder: (context) {
|
||||||
// return HistoryScreen(
|
return ActivityScreen(
|
||||||
// pubkey: walletProvider.address.text,
|
address: walletProvider.address.text,
|
||||||
// avatar: wallet.imageCustomPath == null
|
avatar: wallet.imageCustomPath == null
|
||||||
// ? Image.asset(
|
? Image.asset(
|
||||||
// 'assets/avatars/${wallet.imageDefaultPath}',
|
'assets/avatars/${wallet.imageDefaultPath}',
|
||||||
// width: 110,
|
width: 110,
|
||||||
// )
|
)
|
||||||
// : Image.asset(
|
: Image.asset(
|
||||||
// wallet.imageCustomPath!,
|
wallet.imageCustomPath!,
|
||||||
// width: 110,
|
width: 110,
|
||||||
// ));
|
));
|
||||||
// }),
|
}),
|
||||||
// );
|
);
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 50,
|
height: 50,
|
||||||
|
@ -350,8 +351,8 @@ class WalletOptions extends StatelessWidget {
|
||||||
height: 45,
|
height: 45,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 22),
|
const SizedBox(width: 22),
|
||||||
Text('Historique des transactions',
|
const Text('Activité',
|
||||||
style: TextStyle(fontSize: 20, color: Colors.grey[500])),
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500)),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -97,7 +97,6 @@ flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
assets:
|
assets:
|
||||||
- images/
|
|
||||||
- config/
|
- config/
|
||||||
- assets/
|
- assets/
|
||||||
- assets/home/
|
- assets/home/
|
||||||
|
|
Loading…
Reference in New Issue