2022-09-05 04:15:27 +02:00
|
|
|
// ignore_for_file: must_be_immutable
|
|
|
|
|
2022-06-18 01:50:06 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
|
2021-11-30 10:28:13 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2022-06-16 02:43:30 +02:00
|
|
|
import 'package:gecko/models/queries_indexer.dart';
|
2022-08-23 00:25:16 +02:00
|
|
|
import 'package:gecko/models/widgets_keys.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/cesium_plus.dart';
|
2022-06-16 02:43:30 +02:00
|
|
|
import 'package:gecko/providers/duniter_indexer.dart';
|
2022-06-16 20:09:35 +02:00
|
|
|
import 'package:gecko/providers/home.dart';
|
2022-05-28 00:17:50 +02:00
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/wallets_profiles.dart';
|
2021-11-30 10:28:13 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gecko/screens/wallet_view.dart';
|
|
|
|
import 'package:graphql_flutter/graphql_flutter.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2022-06-16 02:43:30 +02:00
|
|
|
class ActivityScreen extends StatelessWidget with ChangeNotifier {
|
2022-09-12 11:22:26 +02:00
|
|
|
ActivityScreen({required this.address, required this.avatar, this.username})
|
|
|
|
: super(key: keyActivityScreen);
|
2021-11-30 10:28:13 +01:00
|
|
|
final ScrollController scrollController = ScrollController();
|
|
|
|
final double avatarsSize = 80;
|
2022-09-12 11:22:26 +02:00
|
|
|
final String address;
|
2021-12-23 12:36:09 +01:00
|
|
|
final String? username;
|
2022-09-12 11:22:26 +02:00
|
|
|
final Image avatar;
|
2021-11-30 10:28:13 +01:00
|
|
|
|
2021-12-23 12:36:09 +01:00
|
|
|
FetchMore? fetchMore;
|
|
|
|
FetchMoreOptions? opts;
|
2021-11-30 10:28:13 +01:00
|
|
|
|
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-06 02:22:41 +02:00
|
|
|
WalletsProfilesProvider walletProfile =
|
2022-06-16 20:09:35 +02:00
|
|
|
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
2022-08-06 02:22:41 +02:00
|
|
|
HomeProvider homeProvider =
|
2022-06-16 20:09:35 +02:00
|
|
|
Provider.of<HomeProvider>(context, listen: false);
|
2021-12-01 08:14:07 +01:00
|
|
|
|
2021-11-30 10:28:13 +01:00
|
|
|
return Scaffold(
|
|
|
|
key: _scaffoldKey,
|
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
toolbarHeight: 60 * ratio,
|
2022-06-18 01:50:06 +02:00
|
|
|
title: SizedBox(
|
2021-11-30 10:28:13 +01:00
|
|
|
height: 22,
|
2022-06-18 01:50:06 +02:00
|
|
|
child: Text('accountActivity'.tr()),
|
2021-11-30 10:28:13 +01:00
|
|
|
),
|
|
|
|
),
|
2022-08-06 02:22:41 +02:00
|
|
|
bottomNavigationBar: homeProvider.bottomAppBar(context),
|
2021-11-30 10:28:13 +01:00
|
|
|
body: Column(children: <Widget>[
|
2022-09-12 11:22:26 +02:00
|
|
|
walletProfile.headerProfileView(context, address, username),
|
2022-06-16 02:43:30 +02:00
|
|
|
historyQuery(context),
|
2021-11-30 10:28:13 +01:00
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
2022-06-16 02:43:30 +02:00
|
|
|
Widget historyQuery(context) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
2021-12-02 07:23:12 +01:00
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
if (indexerEndpoint == '') {
|
2022-06-18 01:50:06 +02:00
|
|
|
Column(children: <Widget>[
|
|
|
|
const SizedBox(height: 50),
|
2022-06-16 19:45:34 +02:00
|
|
|
Text(
|
2022-06-18 01:50:06 +02:00
|
|
|
"noNetworkNoHistory".tr(),
|
2022-06-16 19:45:34 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-06-18 01:50:06 +02:00
|
|
|
style: const TextStyle(fontSize: 18),
|
2022-06-16 19:45:34 +02:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final httpLink = HttpLink(
|
2022-06-16 19:45:34 +02:00
|
|
|
'$indexerEndpoint/v1beta1/relay',
|
|
|
|
);
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final client = ValueNotifier(
|
2022-06-16 19:45:34 +02:00
|
|
|
GraphQLClient(
|
|
|
|
cache: GraphQLCache(),
|
2022-08-06 02:22:41 +02:00
|
|
|
link: httpLink,
|
2022-06-16 19:45:34 +02:00
|
|
|
),
|
|
|
|
);
|
2021-11-30 10:28:13 +01:00
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
return GraphQLProvider(
|
2022-08-06 02:22:41 +02:00
|
|
|
client: client,
|
2022-06-16 19:45:34 +02:00
|
|
|
child: Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: <Widget>[
|
|
|
|
Query(
|
|
|
|
options: QueryOptions(
|
2022-09-12 11:32:41 +02:00
|
|
|
document: gql(getHistoryByAddressQ),
|
2022-06-16 19:45:34 +02:00
|
|
|
variables: <String, dynamic>{
|
|
|
|
'address': address,
|
|
|
|
'number': 20,
|
|
|
|
'cursor': null
|
|
|
|
},
|
|
|
|
),
|
|
|
|
builder: (QueryResult result, {fetchMore, refetch}) {
|
|
|
|
if (result.isLoading && result.data == null) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.hasException) {
|
2022-08-06 02:22:41 +02:00
|
|
|
log.e('Error Indexer: ${result.exception}');
|
2022-06-18 01:50:06 +02:00
|
|
|
return Column(children: <Widget>[
|
|
|
|
const SizedBox(height: 50),
|
2022-06-16 19:45:34 +02:00
|
|
|
Text(
|
2022-06-18 01:50:06 +02:00
|
|
|
"noNetworkNoHistory".tr(),
|
2022-06-16 19:45:34 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-06-18 01:50:06 +02:00
|
|
|
style: const TextStyle(fontSize: 18),
|
2022-06-16 19:45:34 +02:00
|
|
|
)
|
|
|
|
]);
|
2022-07-08 23:23:05 +02:00
|
|
|
} else if (result
|
|
|
|
.data?['transaction_connection']?['edges'].isEmpty) {
|
2022-06-18 01:50:06 +02:00
|
|
|
return Column(children: <Widget>[
|
|
|
|
const SizedBox(height: 50),
|
2022-06-16 19:45:34 +02:00
|
|
|
Text(
|
2022-06-18 01:50:06 +02:00
|
|
|
"noDataToDisplay".tr(),
|
|
|
|
style: const TextStyle(fontSize: 18),
|
2022-06-16 19:45:34 +02:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
2021-11-30 10:28:13 +01:00
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
if (result.isNotLoading) {
|
|
|
|
// log.d(result.data);
|
2022-09-12 11:22:26 +02:00
|
|
|
opts = duniterIndexer.checkQueryResult(result, opts, address);
|
2022-06-16 19:45:34 +02:00
|
|
|
}
|
2021-11-30 10:28:13 +01:00
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
// Build history list
|
|
|
|
return NotificationListener(
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) => Expanded(
|
|
|
|
child: ListView(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyListTransactions,
|
2022-06-16 19:45:34 +02:00
|
|
|
controller: scrollController,
|
|
|
|
children: <Widget>[historyView(context, result)],
|
|
|
|
),
|
2021-11-30 10:28:13 +01:00
|
|
|
),
|
|
|
|
),
|
2022-06-16 19:45:34 +02:00
|
|
|
onNotification: (dynamic t) {
|
|
|
|
if (t is ScrollEndNotification &&
|
|
|
|
scrollController.position.pixels >=
|
|
|
|
scrollController.position.maxScrollExtent * 0.7 &&
|
2022-08-06 02:22:41 +02:00
|
|
|
duniterIndexer.pageInfo!['hasNextPage'] &&
|
2022-06-16 19:45:34 +02:00
|
|
|
result.isNotLoading) {
|
|
|
|
fetchMore!(opts!);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
);
|
2021-11-30 10:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget historyView(context, result) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
2021-11-30 10:28:13 +01:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
return duniterIndexer.transBC == null
|
2022-06-18 01:50:06 +02:00
|
|
|
? Column(children: <Widget>[
|
|
|
|
const SizedBox(height: 50),
|
2021-12-01 08:14:07 +01:00
|
|
|
Text(
|
2022-06-18 01:50:06 +02:00
|
|
|
"noTransactionToDisplay".tr(),
|
|
|
|
style: const TextStyle(fontSize: 18),
|
2021-12-01 08:14:07 +01:00
|
|
|
)
|
|
|
|
])
|
2021-11-30 10:28:13 +01:00
|
|
|
: Column(children: <Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
getTransactionTile(context, duniterIndexer),
|
|
|
|
if (result.isLoading && duniterIndexer.pageInfo!['hasPreviousPage'])
|
2021-11-30 10:28:13 +01:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: const <Widget>[
|
|
|
|
CircularProgressIndicator(),
|
|
|
|
],
|
|
|
|
),
|
2022-08-06 02:22:41 +02:00
|
|
|
if (!duniterIndexer.pageInfo!['hasNextPage'])
|
2021-11-30 10:28:13 +01:00
|
|
|
Column(
|
|
|
|
children: const <Widget>[
|
|
|
|
SizedBox(height: 15),
|
|
|
|
Text("Début de l'historique.",
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(fontSize: 20)),
|
|
|
|
SizedBox(height: 15)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-11-30 05:42:08 +01:00
|
|
|
Widget getTransactionTile(BuildContext context, final duniterIndexer) {
|
|
|
|
final cesiumPlusProvider =
|
2021-11-30 10:28:13 +01:00
|
|
|
Provider.of<CesiumPlusProvider>(context, listen: false);
|
2022-09-11 13:14:52 +02:00
|
|
|
|
2021-11-30 10:28:13 +01:00
|
|
|
int keyID = 0;
|
2021-12-23 12:36:09 +01:00
|
|
|
String? dateDelimiter;
|
|
|
|
String? lastDateDelimiter;
|
2022-08-06 02:22:41 +02:00
|
|
|
const double avatarSize = 200;
|
2021-11-30 10:28:13 +01:00
|
|
|
|
2021-12-01 08:14:07 +01:00
|
|
|
bool isTody = false;
|
|
|
|
bool isYesterday = false;
|
|
|
|
bool isThisWeek = false;
|
|
|
|
|
2022-06-18 01:50:06 +02:00
|
|
|
final Map<int, String> monthsInYear = {
|
|
|
|
1: "month1".tr(),
|
|
|
|
2: "month2".tr(),
|
|
|
|
3: "month3".tr(),
|
|
|
|
4: "month4".tr(),
|
|
|
|
5: "month5".tr(),
|
|
|
|
6: "month6".tr(),
|
|
|
|
7: "month7".tr(),
|
|
|
|
8: "month8".tr(),
|
|
|
|
9: "month9".tr(),
|
|
|
|
10: "month10".tr(),
|
|
|
|
11: "month11".tr(),
|
|
|
|
12: "month12".tr()
|
2021-11-30 10:28:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return Column(
|
2022-08-06 02:22:41 +02:00
|
|
|
children: duniterIndexer.transBC!.map((repository) {
|
2022-06-16 19:45:34 +02:00
|
|
|
// log.d('bbbbbbbbbbbbbbbbbbbbbb: ' + repository.toString());
|
|
|
|
|
2021-11-30 10:28:13 +01:00
|
|
|
DateTime now = DateTime.now();
|
2022-06-16 19:45:34 +02:00
|
|
|
DateTime date = repository[0];
|
2021-11-30 10:28:13 +01:00
|
|
|
|
|
|
|
String dateForm;
|
|
|
|
if ({4, 10, 11, 12}.contains(date.month)) {
|
2021-12-23 12:36:09 +01:00
|
|
|
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 3)}.";
|
2021-11-30 10:28:13 +01:00
|
|
|
} else if ({1, 2, 7, 9}.contains(date.month)) {
|
2021-12-23 12:36:09 +01:00
|
|
|
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 4)}.";
|
2021-11-30 10:28:13 +01:00
|
|
|
} else {
|
|
|
|
dateForm = "${date.day} ${monthsInYear[date.month]}";
|
|
|
|
}
|
|
|
|
|
|
|
|
int weekNumber(DateTime date) {
|
|
|
|
int dayOfYear = int.parse(DateFormat("D").format(date));
|
|
|
|
return ((dayOfYear - date.weekday + 10) / 7).floor();
|
|
|
|
}
|
|
|
|
|
2021-12-30 00:51:04 +01:00
|
|
|
final transactionDate = DateTime(date.year, date.month, date.day);
|
|
|
|
final todayDate = DateTime(now.year, now.month, now.day);
|
|
|
|
final yesterdayDate = DateTime(now.year, now.month, now.day - 1);
|
|
|
|
|
|
|
|
if (transactionDate == todayDate && !isTody) {
|
2022-06-18 01:50:06 +02:00
|
|
|
dateDelimiter = lastDateDelimiter = "today".tr();
|
2021-12-01 08:14:07 +01:00
|
|
|
isTody = true;
|
2021-12-30 00:51:04 +01:00
|
|
|
} else if (transactionDate == yesterdayDate && !isYesterday) {
|
2022-06-18 01:50:06 +02:00
|
|
|
dateDelimiter = lastDateDelimiter = "yesterday".tr();
|
2021-12-01 08:14:07 +01:00
|
|
|
isYesterday = true;
|
2021-11-30 10:28:13 +01:00
|
|
|
} else if (weekNumber(date) == weekNumber(now) &&
|
|
|
|
date.year == now.year &&
|
2022-06-18 01:50:06 +02:00
|
|
|
lastDateDelimiter != "thisWeek".tr() &&
|
2021-12-30 00:51:04 +01:00
|
|
|
transactionDate != yesterdayDate &&
|
|
|
|
transactionDate != todayDate &&
|
2021-12-01 08:14:07 +01:00
|
|
|
!isThisWeek) {
|
2022-06-18 01:50:06 +02:00
|
|
|
dateDelimiter = lastDateDelimiter = "thisWeek".tr();
|
2021-12-01 08:14:07 +01:00
|
|
|
isThisWeek = true;
|
2021-11-30 10:28:13 +01:00
|
|
|
} else if (lastDateDelimiter != monthsInYear[date.month] &&
|
2021-12-01 08:14:07 +01:00
|
|
|
lastDateDelimiter != "${monthsInYear[date.month]} ${date.year}" &&
|
2021-12-30 00:51:04 +01:00
|
|
|
transactionDate != todayDate &&
|
|
|
|
transactionDate != yesterdayDate &&
|
2021-12-01 08:14:07 +01:00
|
|
|
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
|
2021-11-30 10:28:13 +01:00
|
|
|
if (date.year == now.year) {
|
|
|
|
dateDelimiter = lastDateDelimiter = monthsInYear[date.month];
|
|
|
|
} else {
|
|
|
|
dateDelimiter =
|
|
|
|
lastDateDelimiter = "${monthsInYear[date.month]} ${date.year}";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dateDelimiter = null;
|
|
|
|
}
|
|
|
|
|
2022-09-11 13:14:52 +02:00
|
|
|
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
|
|
|
late double amount;
|
|
|
|
late String finalAmount;
|
|
|
|
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
|
|
|
|
|
|
|
if (isUdUnit) {
|
2022-09-12 12:04:08 +02:00
|
|
|
amount = round(amount / balanceRatio);
|
2022-09-11 14:04:52 +02:00
|
|
|
finalAmount = 'ud'.tr(args: ['$amount ']);
|
2022-09-11 13:14:52 +02:00
|
|
|
} else {
|
|
|
|
finalAmount = '$amount $currencyName';
|
|
|
|
}
|
|
|
|
|
2021-11-30 10:28:13 +01:00
|
|
|
return Column(children: <Widget>[
|
|
|
|
if (dateDelimiter != null)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 30),
|
|
|
|
child: Text(
|
2021-12-23 12:36:09 +01:00
|
|
|
dateDelimiter!,
|
2022-09-12 12:38:32 +02:00
|
|
|
style: const TextStyle(
|
2021-11-30 10:28:13 +01:00
|
|
|
fontSize: 23, color: orangeC, fontWeight: FontWeight.w300),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 0),
|
|
|
|
child:
|
|
|
|
// Row(children: [Column(children: [],)],)
|
|
|
|
ListTile(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyTransaction(keyID++),
|
2021-11-30 10:28:13 +01:00
|
|
|
contentPadding: const EdgeInsets.only(
|
|
|
|
left: 20, right: 30, top: 15, bottom: 15),
|
2022-06-16 19:45:34 +02:00
|
|
|
leading: ClipOval(
|
2022-08-06 02:22:41 +02:00
|
|
|
child: cesiumPlusProvider.defaultAvatar(avatarSize),
|
2022-06-16 19:45:34 +02:00
|
|
|
),
|
2021-11-30 10:28:13 +01:00
|
|
|
title: Padding(
|
2022-06-16 19:45:34 +02:00
|
|
|
padding: const EdgeInsets.only(bottom: 5),
|
|
|
|
child: Text(getShortPubkey(repository[1]),
|
2021-11-30 10:28:13 +01:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18, fontFamily: 'Monospace')),
|
|
|
|
),
|
|
|
|
subtitle: RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
color: Colors.grey[700],
|
|
|
|
),
|
|
|
|
children: <TextSpan>[
|
|
|
|
TextSpan(
|
|
|
|
text: dateForm,
|
|
|
|
),
|
2022-06-16 19:45:34 +02:00
|
|
|
if (repository[2] != '')
|
2021-11-30 10:28:13 +01:00
|
|
|
TextSpan(
|
|
|
|
text: ' · ',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
color: Colors.grey[550],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TextSpan(
|
2022-06-16 19:45:34 +02:00
|
|
|
text: repository[2],
|
2021-11-30 10:28:13 +01:00
|
|
|
style: TextStyle(
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-09-11 13:14:52 +02:00
|
|
|
trailing: Text(finalAmount,
|
2021-11-30 10:28:13 +01:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18, fontWeight: FontWeight.w500),
|
|
|
|
textAlign: TextAlign.justify),
|
|
|
|
dense: false,
|
|
|
|
isThreeLine: false,
|
|
|
|
onTap: () {
|
2022-08-06 02:22:41 +02:00
|
|
|
duniterIndexer.nPage = 1;
|
2021-12-02 07:23:12 +01:00
|
|
|
// _cesiumPlusProvider.avatarCancelToken.cancel('cancelled');
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
2022-09-12 04:52:34 +02:00
|
|
|
return WalletViewScreen(address: repository[1]);
|
2021-12-02 07:23:12 +01:00
|
|
|
}),
|
|
|
|
);
|
2021-12-01 08:14:07 +01:00
|
|
|
// Navigator.pop(context);
|
2021-11-30 10:28:13 +01:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
}).toList());
|
|
|
|
}
|
|
|
|
}
|