fix: bug on delimiter redondance
This commit is contained in:
parent
f7fe3fa7df
commit
792ac2f715
|
@ -1,4 +1,5 @@
|
|||
import 'dart:io';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/chest_data.dart';
|
||||
import 'package:gecko/models/g1_wallets_list.dart';
|
||||
|
@ -55,3 +56,18 @@ late int udValue;
|
|||
late DateTime startBlockchainTime;
|
||||
|
||||
late int currentUdIndex;
|
||||
|
||||
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()
|
||||
};
|
||||
|
|
|
@ -6,22 +6,13 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/queries_indexer.dart';
|
||||
import 'package:gecko/models/widgets_keys.dart';
|
||||
import 'package:gecko/providers/cesium_plus.dart';
|
||||
import 'package:gecko/providers/search.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/screens/wallet_view.dart';
|
||||
import 'package:gecko/widgets/balance.dart';
|
||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class DuniterIndexer with ChangeNotifier {
|
||||
Map<String, String?> walletNameIndexer = {};
|
||||
String? fetchMoreCursor;
|
||||
Map? pageInfo;
|
||||
int nPage = 1;
|
||||
int nRepositories = 20;
|
||||
List? transBC;
|
||||
List listIndexerEndpoints = [];
|
||||
bool isLoadingIndexer = false;
|
||||
|
@ -92,7 +83,6 @@ class DuniterIndexer with ChangeNotifier {
|
|||
|
||||
if (configBox.containsKey('customIndexer')) {
|
||||
return configBox.get('customIndexer');
|
||||
// listIndexerEndpoints.insert(0, configBox.get('customIndexer'));
|
||||
}
|
||||
|
||||
if (configBox.containsKey('indexerEndpoint')) {
|
||||
|
@ -154,125 +144,6 @@ class DuniterIndexer with ChangeNotifier {
|
|||
return indexerEndpoint;
|
||||
}
|
||||
|
||||
Widget searchIdentity(BuildContext context, String name) {
|
||||
// WalletOptionsProvider _walletOptions =
|
||||
// Provider.of<WalletOptionsProvider>(context, listen: false);
|
||||
WalletsProfilesProvider walletsProfiles =
|
||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
||||
final searchProvider = Provider.of<SearchProvider>(context, listen: false);
|
||||
if (indexerEndpoint == '') {
|
||||
return const Text('Aucun résultat');
|
||||
}
|
||||
|
||||
log.d(indexerEndpoint);
|
||||
final httpLink = HttpLink(
|
||||
'$indexerEndpoint/v1/graphql',
|
||||
);
|
||||
|
||||
final client = ValueNotifier(
|
||||
GraphQLClient(
|
||||
cache: GraphQLCache(
|
||||
store: HiveStore()), // GraphQLCache(store: HiveStore())
|
||||
link: httpLink,
|
||||
),
|
||||
);
|
||||
return GraphQLProvider(
|
||||
client: client,
|
||||
child: Query(
|
||||
options: QueryOptions(
|
||||
document: gql(
|
||||
searchAddressByNameQ), // this is the query string you just created
|
||||
variables: {
|
||||
'name': name,
|
||||
},
|
||||
// pollInterval: const Duration(seconds: 10),
|
||||
),
|
||||
builder: (QueryResult result,
|
||||
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
||||
if (result.hasException) {
|
||||
return Text(result.exception.toString());
|
||||
}
|
||||
|
||||
if (result.isLoading) {
|
||||
return Text('loading'.tr());
|
||||
}
|
||||
|
||||
final List identities = result.data?['search_identity'] ?? [];
|
||||
|
||||
if (identities.isEmpty) {
|
||||
return Text('noResult'.tr());
|
||||
}
|
||||
|
||||
for (Map profile in identities) {
|
||||
duniterIndexer.walletNameIndexer
|
||||
.putIfAbsent(profile['pubkey'], () => profile['name']);
|
||||
}
|
||||
|
||||
searchProvider.resultLenght = identities.length;
|
||||
// TODO: Find a way to reload a provider here, in Widget build...
|
||||
|
||||
double avatarSize = 55;
|
||||
return Expanded(
|
||||
child: ListView(children: <Widget>[
|
||||
for (Map profile in identities)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
child: ListTile(
|
||||
key: keySearchResult(profile['pubkey']),
|
||||
horizontalTitleGap: 40,
|
||||
contentPadding: const EdgeInsets.all(5),
|
||||
leading: defaultAvatar(avatarSize),
|
||||
title: Row(children: <Widget>[
|
||||
Text(getShortPubkey(profile['pubkey']),
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontFamily: 'Monospace',
|
||||
fontWeight: FontWeight.w500),
|
||||
textAlign: TextAlign.center),
|
||||
]),
|
||||
trailing: SizedBox(
|
||||
width: 110,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Balance(
|
||||
address: profile['pubkey'], size: 16),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
subtitle: Row(children: <Widget>[
|
||||
Text(profile['name'] ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.w500),
|
||||
textAlign: TextAlign.center),
|
||||
]),
|
||||
dense: false,
|
||||
isThreeLine: false,
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
walletsProfiles.address = profile['pubkey'];
|
||||
return WalletViewScreen(
|
||||
address: profile['pubkey'],
|
||||
username: name,
|
||||
avatar:
|
||||
g1WalletsBox.get(profile['pubkey'])?.avatar,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
List parseHistory(blockchainTX, pubkey) {
|
||||
List transBC = [];
|
||||
int i = 0;
|
||||
|
@ -296,35 +167,22 @@ class DuniterIndexer with ChangeNotifier {
|
|||
}
|
||||
transBC[i].add(amount);
|
||||
transBC[i].add(direction);
|
||||
// transBC[i].add(''); //transaction comment
|
||||
|
||||
i++;
|
||||
}
|
||||
return transBC;
|
||||
}
|
||||
|
||||
FetchMoreOptions? checkQueryResult(result, opts, pubkey) {
|
||||
FetchMoreOptions? mergeQueryResult(result, opts, pubkey, nRepositories) {
|
||||
final List<dynamic>? blockchainTX =
|
||||
(result.data['transaction_connection']['edges'] as List<dynamic>?);
|
||||
// final List<dynamic> mempoolTX =
|
||||
// (result.data['txsHistoryMp']['receiving'] as List<dynamic>);
|
||||
|
||||
pageInfo = result.data['transaction_connection']['pageInfo'];
|
||||
fetchMoreCursor = pageInfo!['endCursor'];
|
||||
final hasNextPage = pageInfo!['hasNextPage'];
|
||||
final hasPreviousPage = pageInfo!['hasPreviousPage'];
|
||||
if (fetchMoreCursor == null) nPage = 1;
|
||||
|
||||
log.d('endCursor: $fetchMoreCursor $hasNextPage $hasPreviousPage');
|
||||
|
||||
// if (nPage == 1) {
|
||||
// nRepositories = 20;
|
||||
// } else if (nPage == 4) {
|
||||
// nRepositories = 40;
|
||||
// }
|
||||
// // nRepositories = 10;
|
||||
nPage++;
|
||||
|
||||
if (fetchMoreCursor != null) {
|
||||
opts = FetchMoreOptions(
|
||||
variables: {'cursor': fetchMoreCursor, 'number': nRepositories},
|
||||
|
@ -336,18 +194,12 @@ class DuniterIndexer with ChangeNotifier {
|
|||
as List<dynamic>
|
||||
];
|
||||
|
||||
log.d('repos: $previousResultData');
|
||||
log.d('repos: $fetchMoreResultData');
|
||||
log.d('repos: $repos');
|
||||
|
||||
fetchMoreResultData['transaction_connection']['edges'] = repos;
|
||||
return fetchMoreResultData;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
log.d(
|
||||
"###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
|
||||
if (fetchMoreCursor != null) {
|
||||
transBC = parseHistory(blockchainTX, pubkey);
|
||||
} else {
|
||||
|
@ -395,3 +247,86 @@ Future<QueryResult> _execQuery(
|
|||
|
||||
return await client.query(options);
|
||||
}
|
||||
|
||||
Map computeHistoryView(repository, lastDateDelimiter, isDouble) {
|
||||
bool isTody = false;
|
||||
bool isYesterday = false;
|
||||
bool isThisWeek = false;
|
||||
bool isMigrationTime = false;
|
||||
String? dateDelimiter;
|
||||
DateTime now = DateTime.now();
|
||||
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
||||
|
||||
late double amount;
|
||||
late String finalAmount;
|
||||
DateTime date = repository[0];
|
||||
String dateForm;
|
||||
bool isDelimiter = true;
|
||||
|
||||
if ({4, 10, 11, 12}.contains(date.month)) {
|
||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 3)}.";
|
||||
} else if ({1, 2, 7, 9}.contains(date.month)) {
|
||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 4)}.";
|
||||
} else {
|
||||
dateForm = "${date.day} ${monthsInYear[date.month]}";
|
||||
}
|
||||
|
||||
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) {
|
||||
dateDelimiter = lastDateDelimiter = "today".tr();
|
||||
isTody = true;
|
||||
} else if (transactionDate == yesterdayDate && !isYesterday) {
|
||||
dateDelimiter = lastDateDelimiter = "yesterday".tr();
|
||||
isYesterday = true;
|
||||
} else if (weekNumber(date) == weekNumber(now) &&
|
||||
date.year == now.year &&
|
||||
transactionDate != yesterdayDate &&
|
||||
transactionDate != todayDate &&
|
||||
!isThisWeek) {
|
||||
dateDelimiter = lastDateDelimiter = "thisWeek".tr();
|
||||
isThisWeek = true;
|
||||
} else if (lastDateDelimiter != "${monthsInYear[date.month]} ${date.year}" &&
|
||||
transactionDate != todayDate &&
|
||||
transactionDate != yesterdayDate &&
|
||||
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
|
||||
if (date.year == now.year) {
|
||||
dateDelimiter = lastDateDelimiter = monthsInYear[date.month];
|
||||
} else {
|
||||
dateDelimiter =
|
||||
lastDateDelimiter = "${monthsInYear[date.month]} ${date.year}";
|
||||
}
|
||||
} else {
|
||||
isDelimiter = false;
|
||||
}
|
||||
|
||||
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
||||
|
||||
if (isUdUnit) {
|
||||
amount = round(amount / balanceRatio);
|
||||
finalAmount = 'ud'.tr(args: ['$amount ']);
|
||||
} else {
|
||||
finalAmount = '$amount $currencyName';
|
||||
}
|
||||
|
||||
if (date.compareTo(startBlockchainTime) < 0) {
|
||||
isMigrationTime = true;
|
||||
} else {
|
||||
isMigrationTime = false;
|
||||
}
|
||||
|
||||
return {
|
||||
'finalAmount': finalAmount,
|
||||
'isMigrationTime': isMigrationTime,
|
||||
'dateDelimiter': dateDelimiter ?? '',
|
||||
'isDelimiter': isDelimiter,
|
||||
'dateForm': dateForm,
|
||||
};
|
||||
}
|
||||
|
||||
int weekNumber(DateTime date) {
|
||||
int dayOfYear = int.parse(DateFormat("D").format(date));
|
||||
return ((dayOfYear - date.weekday + 10) / 7).floor();
|
||||
}
|
||||
|
|
|
@ -180,8 +180,6 @@ class SubstrateSdk with ChangeNotifier {
|
|||
}
|
||||
|
||||
Future<Map<String, double>> getBalance(String address) async {
|
||||
log.d('BALANCE: $address');
|
||||
|
||||
if (!nodeConnected) {
|
||||
return {
|
||||
'transferableBalance': 0,
|
||||
|
@ -220,6 +218,8 @@ class SubstrateSdk with ChangeNotifier {
|
|||
};
|
||||
|
||||
// log.i(finalBalances);
|
||||
log.d(
|
||||
'${getShortPubkey(address)} --- BALANCE: ${finalBalances['transferableBalance']}');
|
||||
|
||||
return finalBalances;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import 'package:gecko/globals.dart';
|
|||
import 'package:gecko/models/queries_indexer.dart';
|
||||
import 'package:gecko/models/widgets_keys.dart';
|
||||
import 'package:gecko/providers/duniter_indexer.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/widgets/bottom_app_bar.dart';
|
||||
import 'package:gecko/widgets/header_profile.dart';
|
||||
|
@ -26,14 +25,10 @@ class ActivityScreen extends StatefulWidget with ChangeNotifier {
|
|||
}
|
||||
|
||||
class _ActivityScreenState extends State<ActivityScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
final duniterIndexerInit =
|
||||
Provider.of<DuniterIndexer>(context, listen: false);
|
||||
duniterIndexerInit.nPage = 1;
|
||||
|
||||
super.initState();
|
||||
}
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// }
|
||||
|
||||
final ScrollController scrollController = ScrollController();
|
||||
final double avatarsSize = 80;
|
||||
|
@ -62,6 +57,8 @@ class _ActivityScreenState extends State<ActivityScreen> {
|
|||
|
||||
Widget historyQuery(context) {
|
||||
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
||||
int nPage = 1;
|
||||
int nRepositories = 20;
|
||||
|
||||
if (indexerEndpoint == '') {
|
||||
return Column(children: <Widget>[
|
||||
|
@ -132,9 +129,22 @@ class _ActivityScreenState extends State<ActivityScreen> {
|
|||
}
|
||||
|
||||
if (result.isNotLoading) {
|
||||
// log.d(result.data);
|
||||
opts = duniterIndexer.checkQueryResult(
|
||||
result, opts, widget.address);
|
||||
if (duniterIndexer.fetchMoreCursor == null) nPage = 1;
|
||||
|
||||
// log.d('nPage: $nPage');
|
||||
|
||||
if (nPage <= 3) {
|
||||
nRepositories = 20;
|
||||
} else if (nPage <= 6) {
|
||||
nRepositories = 40;
|
||||
} else if (nPage <= 12) {
|
||||
nRepositories = 80;
|
||||
} else {
|
||||
nRepositories = 120;
|
||||
}
|
||||
nPage++;
|
||||
opts = duniterIndexer.mergeQueryResult(
|
||||
result, opts, widget.address, nRepositories);
|
||||
}
|
||||
|
||||
// Build history list
|
||||
|
@ -167,6 +177,11 @@ class _ActivityScreenState extends State<ActivityScreen> {
|
|||
|
||||
Widget historyView(context, result) {
|
||||
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
||||
int keyID = 0;
|
||||
const double avatarSize = 200;
|
||||
String? lastDateDelimiter;
|
||||
bool? isDouble;
|
||||
bool isMigrationPassed = false;
|
||||
|
||||
return duniterIndexer.transBC == null
|
||||
? Column(children: <Widget>[
|
||||
|
@ -177,7 +192,53 @@ class _ActivityScreenState extends State<ActivityScreen> {
|
|||
)
|
||||
])
|
||||
: Column(children: <Widget>[
|
||||
getHistory(context, duniterIndexer),
|
||||
Column(
|
||||
children: duniterIndexer.transBC!.map((repository) {
|
||||
final answer =
|
||||
computeHistoryView(repository, lastDateDelimiter, isDouble);
|
||||
isDouble = lastDateDelimiter == answer['dateDelimiter'] ||
|
||||
answer['dateDelimiter'] == '';
|
||||
lastDateDelimiter = answer['dateDelimiter'];
|
||||
bool isMigrationTime = false;
|
||||
if (answer['isMigrationTime'] && !isMigrationPassed) {
|
||||
isMigrationPassed = true;
|
||||
isMigrationTime = true;
|
||||
}
|
||||
|
||||
return Column(children: <Widget>[
|
||||
if (isMigrationTime)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 30),
|
||||
child: Text(
|
||||
'Début de la ĞDev',
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: Colors.blueAccent,
|
||||
fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
if (!isDouble!)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 30),
|
||||
child: Text(
|
||||
answer['dateDelimiter'],
|
||||
style: const TextStyle(
|
||||
fontSize: 23,
|
||||
color: orangeC,
|
||||
fontWeight: FontWeight.w300),
|
||||
),
|
||||
),
|
||||
TransactionTile(
|
||||
widget: widget,
|
||||
keyID: keyID,
|
||||
avatarSize: avatarSize,
|
||||
repository: repository,
|
||||
dateForm: answer['dateForm'],
|
||||
finalAmount: answer['finalAmount'],
|
||||
duniterIndexer: duniterIndexer,
|
||||
context: context),
|
||||
]);
|
||||
}).toList()),
|
||||
if (result.isLoading && duniterIndexer.pageInfo!['hasPreviousPage'])
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
@ -197,155 +258,4 @@ class _ActivityScreenState extends State<ActivityScreen> {
|
|||
)
|
||||
]);
|
||||
}
|
||||
|
||||
Widget getHistory(BuildContext context, DuniterIndexer duniterIndexer) {
|
||||
int keyID = 0;
|
||||
const double avatarSize = 200;
|
||||
String? lastDateDelimiter;
|
||||
bool? isDouble;
|
||||
|
||||
return Column(
|
||||
children: duniterIndexer.transBC!.map((repository) {
|
||||
final answer =
|
||||
_computeHistoryView(repository, lastDateDelimiter, isDouble);
|
||||
isDouble = lastDateDelimiter == answer['dateDelimiter'];
|
||||
lastDateDelimiter = answer['dateDelimiter'];
|
||||
|
||||
return Column(children: <Widget>[
|
||||
if (answer['isMigrationTime'])
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 30),
|
||||
child: Text(
|
||||
'Début de la ĞDev',
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: Colors.blueAccent,
|
||||
fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
if (!isDouble! && answer['dateDelimiter'] != '')
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 30),
|
||||
child: Text(
|
||||
answer['dateDelimiter'],
|
||||
style: const TextStyle(
|
||||
fontSize: 23, color: orangeC, fontWeight: FontWeight.w300),
|
||||
),
|
||||
),
|
||||
TransactionTile(
|
||||
widget: widget,
|
||||
keyID: keyID,
|
||||
avatarSize: avatarSize,
|
||||
repository: repository,
|
||||
dateForm: answer['dateForm'],
|
||||
finalAmount: answer['finalAmount'],
|
||||
duniterIndexer: duniterIndexer,
|
||||
context: context),
|
||||
]);
|
||||
}).toList());
|
||||
}
|
||||
|
||||
Map _computeHistoryView(repository, lastDateDelimiter, isDouble) {
|
||||
bool isTody = false;
|
||||
bool isYesterday = false;
|
||||
bool isThisWeek = false;
|
||||
bool isMigrationTime = false;
|
||||
bool isMigrationTimePassed = false;
|
||||
String? dateDelimiter;
|
||||
|
||||
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()
|
||||
};
|
||||
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
||||
late double amount;
|
||||
late String finalAmount;
|
||||
DateTime now = DateTime.now();
|
||||
DateTime date = repository[0];
|
||||
String dateForm;
|
||||
bool isDelimiter = true;
|
||||
|
||||
if ({4, 10, 11, 12}.contains(date.month)) {
|
||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 3)}.";
|
||||
} else if ({1, 2, 7, 9}.contains(date.month)) {
|
||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 4)}.";
|
||||
} 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();
|
||||
}
|
||||
|
||||
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) {
|
||||
dateDelimiter = lastDateDelimiter = "today".tr();
|
||||
isTody = true;
|
||||
} else if (transactionDate == yesterdayDate && !isYesterday) {
|
||||
dateDelimiter = lastDateDelimiter = "yesterday".tr();
|
||||
isYesterday = true;
|
||||
} else if (weekNumber(date) == weekNumber(now) &&
|
||||
date.year == now.year &&
|
||||
lastDateDelimiter != "thisWeek".tr() &&
|
||||
transactionDate != yesterdayDate &&
|
||||
transactionDate != todayDate &&
|
||||
!isThisWeek) {
|
||||
dateDelimiter = lastDateDelimiter = "thisWeek".tr();
|
||||
isThisWeek = true;
|
||||
} else if (lastDateDelimiter != monthsInYear[date.month] &&
|
||||
lastDateDelimiter != "${monthsInYear[date.month]} ${date.year}" &&
|
||||
transactionDate != todayDate &&
|
||||
transactionDate != yesterdayDate &&
|
||||
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
|
||||
if (date.year == now.year) {
|
||||
dateDelimiter = lastDateDelimiter = monthsInYear[date.month];
|
||||
} else {
|
||||
dateDelimiter =
|
||||
lastDateDelimiter = "${monthsInYear[date.month]} ${date.year}";
|
||||
}
|
||||
} else {
|
||||
isDelimiter = false;
|
||||
}
|
||||
|
||||
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
||||
|
||||
if (isUdUnit) {
|
||||
amount = round(amount / balanceRatio);
|
||||
finalAmount = 'ud'.tr(args: ['$amount ']);
|
||||
} else {
|
||||
finalAmount = '$amount $currencyName';
|
||||
}
|
||||
|
||||
if (!isMigrationTimePassed && date.compareTo(startBlockchainTime) < 0) {
|
||||
isMigrationTimePassed = true;
|
||||
isMigrationTime = true;
|
||||
} else {
|
||||
isMigrationTime = false;
|
||||
}
|
||||
|
||||
log.d('dateDelimiter: $dateDelimiter');
|
||||
log.d('lastDateDelimiter: $lastDateDelimiter');
|
||||
|
||||
return {
|
||||
'finalAmount': finalAmount,
|
||||
'isMigrationTime': isMigrationTime,
|
||||
'dateDelimiter': dateDelimiter ?? '',
|
||||
'isDelimiter': isDelimiter,
|
||||
'dateForm': dateForm,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,8 +162,8 @@ class WalletViewScreen extends StatelessWidget {
|
|||
builder: (context, AsyncSnapshot<Map<String, int>> snapshot) {
|
||||
if (snapshot.data == null) return const SizedBox();
|
||||
String duration = '';
|
||||
log.d('certDelay ${snapshot.data!['certDelay']}');
|
||||
log.d('certRenewable ${snapshot.data!['certRenewable']}');
|
||||
log.d(
|
||||
'${getShortPubkey(address)} --- certDelay ${snapshot.data!['certDelay']} --- certRenewable ${snapshot.data!['certRenewable']}');
|
||||
|
||||
if (snapshot.data!['certDelay'] != null ||
|
||||
snapshot.data!['certRenewable'] != null) {
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/queries_indexer.dart';
|
||||
import 'package:gecko/models/widgets_keys.dart';
|
||||
import 'package:gecko/providers/cesium_plus.dart';
|
||||
import 'package:gecko/providers/duniter_indexer.dart';
|
||||
import 'package:gecko/providers/search.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/screens/wallet_view.dart';
|
||||
import 'package:gecko/widgets/balance.dart';
|
||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class SearchIdentityQuery extends StatelessWidget {
|
||||
const SearchIdentityQuery({Key? key, required this.name}) : super(key: key);
|
||||
final String name;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
WalletsProfilesProvider walletsProfiles =
|
||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
||||
final searchProvider = Provider.of<SearchProvider>(context, listen: false);
|
||||
if (indexerEndpoint == '') {
|
||||
return const Text('Aucun résultat');
|
||||
}
|
||||
|
||||
log.d(indexerEndpoint);
|
||||
final httpLink = HttpLink(
|
||||
'$indexerEndpoint/v1/graphql',
|
||||
);
|
||||
|
||||
final client = ValueNotifier(
|
||||
GraphQLClient(
|
||||
cache: GraphQLCache(
|
||||
store: HiveStore()), // GraphQLCache(store: HiveStore())
|
||||
link: httpLink,
|
||||
),
|
||||
);
|
||||
return GraphQLProvider(
|
||||
client: client,
|
||||
child: Query(
|
||||
options: QueryOptions(
|
||||
document: gql(
|
||||
searchAddressByNameQ), // this is the query string you just created
|
||||
variables: {
|
||||
'name': name,
|
||||
},
|
||||
// pollInterval: const Duration(seconds: 10),
|
||||
),
|
||||
builder: (QueryResult result,
|
||||
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
||||
if (result.hasException) {
|
||||
return Text(result.exception.toString());
|
||||
}
|
||||
|
||||
if (result.isLoading) {
|
||||
return Text('loading'.tr());
|
||||
}
|
||||
|
||||
final List identities = result.data?['search_identity'] ?? [];
|
||||
|
||||
if (identities.isEmpty) {
|
||||
return Text('noResult'.tr());
|
||||
}
|
||||
|
||||
for (Map profile in identities) {
|
||||
duniterIndexer.walletNameIndexer
|
||||
.putIfAbsent(profile['pubkey'], () => profile['name']);
|
||||
}
|
||||
|
||||
searchProvider.resultLenght = identities.length;
|
||||
// TODO: Find a way to reload a provider here, in Widget build...
|
||||
|
||||
double avatarSize = 55;
|
||||
return Expanded(
|
||||
child: ListView(children: <Widget>[
|
||||
for (Map profile in identities)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
child: ListTile(
|
||||
key: keySearchResult(profile['pubkey']),
|
||||
horizontalTitleGap: 40,
|
||||
contentPadding: const EdgeInsets.all(5),
|
||||
leading: defaultAvatar(avatarSize),
|
||||
title: Row(children: <Widget>[
|
||||
Text(getShortPubkey(profile['pubkey']),
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontFamily: 'Monospace',
|
||||
fontWeight: FontWeight.w500),
|
||||
textAlign: TextAlign.center),
|
||||
]),
|
||||
trailing: SizedBox(
|
||||
width: 110,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Balance(
|
||||
address: profile['pubkey'], size: 16),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
subtitle: Row(children: <Widget>[
|
||||
Text(profile['name'] ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.w500),
|
||||
textAlign: TextAlign.center),
|
||||
]),
|
||||
dense: false,
|
||||
isThreeLine: false,
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
walletsProfiles.address = profile['pubkey'];
|
||||
return WalletViewScreen(
|
||||
address: profile['pubkey'],
|
||||
username: name,
|
||||
avatar:
|
||||
g1WalletsBox.get(profile['pubkey'])?.avatar,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import 'package:gecko/providers/wallets_profiles.dart';
|
|||
import 'package:gecko/screens/wallet_view.dart';
|
||||
import 'package:gecko/widgets/balance.dart';
|
||||
import 'package:gecko/widgets/name_by_address.dart';
|
||||
import 'package:gecko/widgets/search_identity_query.dart';
|
||||
|
||||
class SearchResult extends StatelessWidget {
|
||||
const SearchResult({
|
||||
|
@ -33,8 +34,8 @@ class SearchResult extends StatelessWidget {
|
|||
builder: (context, AsyncSnapshot<List?> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.data?.isEmpty ?? true) {
|
||||
return duniterIndexer.searchIdentity(
|
||||
context, searchProvider.searchController.text);
|
||||
return SearchIdentityQuery(
|
||||
name: searchProvider.searchController.text);
|
||||
// const Text('Aucun résultat');
|
||||
} else {
|
||||
return Expanded(
|
||||
|
|
|
@ -80,8 +80,6 @@ class TransactionTile extends StatelessWidget {
|
|||
dense: false,
|
||||
isThreeLine: false,
|
||||
onTap: () {
|
||||
duniterIndexer.nPage = 1;
|
||||
// _cesiumPlusProvider.avatarCancelToken.cancel('cancelled');
|
||||
Navigator.push(
|
||||
context,
|
||||
PageNoTransit(builder: (context) {
|
||||
|
|
Loading…
Reference in New Issue