Skip to content
Snippets Groups Projects
Commit aeb253ff authored by vjrj's avatar vjrj
Browse files

pubkey checksum

parent f446da4d
No related branches found
No related tags found
No related merge requests found
import 'package:flutter/foundation.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import '../../g1/g1_helper.dart';
import '../../ui/ui_helpers.dart';
import 'contact.dart';
import 'contact_state.dart';
......@@ -66,14 +67,17 @@ class ContactsCubit extends HydratedCubit<ContactsState> {
}
void updateContact(Contact contact) {
final String pubKey = extractPublicKey(contact.pubKey);
final List<Contact> contacts = state.contacts.map((Contact c) {
if (c.pubKey == contact.pubKey) {
if (c.pubKey == contact.pubKey ||
c.pubKey == extractPublicKey(contact.pubKey)) {
return contact;
}
return c;
}).toList();
final List<Contact> fcontacts = state.filteredContacts.map((Contact c) {
if (c.pubKey == contact.pubKey) {
if (c.pubKey == contact.pubKey ||
c.pubKey == extractPublicKey(contact.pubKey)) {
return contact;
}
return c;
......@@ -101,6 +105,9 @@ class ContactsCubit extends HydratedCubit<ContactsState> {
if (c.pubKey.contains(query)) {
return true;
}
if (c.pubKey.contains(extractPublicKey(query))) {
return true;
}
if (c.nick != null &&
containsLowerOrUpper(c.nick!, query, queryLower, queryUpper)) {
return true;
......
......@@ -62,8 +62,9 @@ Future<Response> searchCPlusUser(String searchTerm) async {
return response;
}
Future<Contact> getProfile(String pubKey,
Future<Contact> getProfile(String pubKeyRaw,
[bool onlyCPlusProfile = false]) async {
final String pubKey = extractPublicKey(pubKeyRaw);
try {
final Response cPlusResponse = await requestCPlusWithRetry(
'/user/profile/$pubKey',
......@@ -103,7 +104,11 @@ Not found sample:
"found": false
}
*/
Future<List<Contact>> searchWot(String searchTerm) async {
Future<List<Contact>> searchWot(String searchTermRaw) async {
// If pubkey, remove checksum
final String searchTerm = validateKey(searchTermRaw)
? extractPublicKey(searchTermRaw)
: searchTermRaw;
final Response response = await requestDuniterWithRetry(
'/wot/lookup/$searchTerm',
retryWith404: false);
......@@ -554,7 +559,7 @@ Future<PayResult> pay(
'Trying $nodeUrl to send $amount to $to with comment ${comment ?? ''}');
final String response = await gva.pay(
recipient: to,
recipient: extractPublicKey(to),
amount: amount,
comment: comment ?? '',
cesiumSeed: wallet.seed,
......@@ -616,20 +621,24 @@ String proxyfyNode(String nodeUrl) {
return url;
}
Future<Tuple2<Map<String, dynamic>?, Node>> gvaHistoryAndBalance(String pubKey,
[int? pageSize, String? cursor]) async {
Future<Tuple2<Map<String, dynamic>?, Node>> gvaHistoryAndBalance(
String pubKeyRaw,
[int? pageSize,
String? cursor]) async {
logger('Get tx history (page size: $pageSize: cursor $cursor)');
final String pubKey = extractPublicKey(pubKeyRaw);
return gvaFunctionWrapper<Map<String, dynamic>>(
pubKey, (Gva gva) => gva.history(pubKey, pageSize, cursor));
}
Future<Tuple2<double?, Node>> gvaBalance(String pubKey) async {
return gvaFunctionWrapper<double>(pubKey, (Gva gva) => gva.balance(pubKey));
return gvaFunctionWrapper<double>(
extractPublicKey(pubKey), (Gva gva) => gva.balance(pubKey));
}
Future<Tuple2<String?, Node>> gvaNick(String pubKey) async {
return gvaFunctionWrapper<String>(
pubKey, (Gva gva) => gva.getUsername(pubKey));
pubKey, (Gva gva) => gva.getUsername(extractPublicKey(pubKey)));
}
Future<Tuple2<T?, Node>> gvaFunctionWrapper<T>(
......
......@@ -247,3 +247,5 @@ int toCG1(double amount) => (amount.toPrecision(2) * 100).toInt();
extension Ex on double {
double toPrecision(int n) => double.parse(toStringAsFixed(n));
}
String extractPublicKey(String key) => key.split(':')[0];
......@@ -108,7 +108,9 @@ class SharedPreferencesHelper {
// Get the public key from the specified index (default to first wallet)
String getPubKey({int index = 0}) {
final CesiumCard card = cesiumCards[index];
return card.pubKey;
final String pubKey = card.pubKey;
final String checksum = pkChecksum(pubKey);
return '$pubKey:$checksum';
}
List<CesiumCard> get cards => cesiumCards;
......
......@@ -88,10 +88,11 @@ class _TransactionsAndBalanceWidgetState
SnackBar(
content: Text(tr('fetch_tx_error')),
action: SnackBarAction(
label: tr('retry'),
textColor: Theme.of(context).primaryColor,
onPressed: () => _pagingController.retryLastFailedRequest(),
),
label: tr('retry'),
textColor: Theme.of(context).primaryColor,
onPressed: () =>
_refresh() // _pagingController.retryLastFailedRequest(),
),
),
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment