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

Contact c+ and wot merge. getProfile with full resize. Disable polkadart for web (temporally)

parent ef40173e
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ Future<Response> searchCPlusUser(String initialSearchTerm) async { ...@@ -77,7 +77,7 @@ Future<Response> searchCPlusUser(String initialSearchTerm) async {
} }
Future<Contact> getProfile(String pubKeyRaw, Future<Contact> getProfile(String pubKeyRaw,
[bool onlyCPlusProfile = false]) async { {bool onlyCPlusProfile = false, bool resize = true}) async {
final String pubKey = extractPublicKey(pubKeyRaw); final String pubKey = extractPublicKey(pubKeyRaw);
try { try {
final Response cPlusResponse = (await requestCPlusWithRetry( final Response cPlusResponse = (await requestCPlusWithRetry(
...@@ -86,19 +86,22 @@ Future<Contact> getProfile(String pubKeyRaw, ...@@ -86,19 +86,22 @@ Future<Contact> getProfile(String pubKeyRaw,
.item2; .item2;
final Map<String, dynamic> result = final Map<String, dynamic> result =
const JsonDecoder().convert(cPlusResponse.body) as Map<String, dynamic>; const JsonDecoder().convert(cPlusResponse.body) as Map<String, dynamic>;
Contact c;
if (result['found'] == false) { if (result['found'] == false) {
return Contact(pubKey: pubKey); c = Contact(pubKey: pubKey);
} else {
final Map<String, dynamic> profile = const JsonDecoder()
.convert(cPlusResponse.body) as Map<String, dynamic>;
c = await contactFromResultSearch(profile, resize: resize);
} }
final Map<String, dynamic> profile =
const JsonDecoder().convert(cPlusResponse.body) as Map<String, dynamic>;
final Contact c = await contactFromResultSearch(profile);
if (!onlyCPlusProfile) { if (!onlyCPlusProfile) {
// This penalize the gva rate limit // This penalize the gva rate limit
// final String? nick = await gvaNick(pubKey); // final String? nick = await gvaNick(pubKey);
final List<Contact> wotList = await searchWotV2(pubKey); final List<Contact> wotList = await searchWotV1(pubKey);
if (wotList.isNotEmpty) { if (wotList.isNotEmpty) {
final Contact c = wotList[0]; final Contact cWot = wotList[0];
c.copyWith(nick: c.nick); c = c.merge(cWot);
// c.copyWith(nick: c.nick);
} }
} }
logger('Contact retrieved in getProfile $c (c+ only $onlyCPlusProfile)'); logger('Contact retrieved in getProfile $c (c+ only $onlyCPlusProfile)');
...@@ -513,21 +516,27 @@ Future<NodeCheck> _pingNode(String node, NodeType type) async { ...@@ -513,21 +516,27 @@ Future<NodeCheck> _pingNode(String node, NodeType type) async {
stopwatch.stop(); stopwatch.stop();
latency = stopwatch.elapsed; latency = stopwatch.elapsed;
} else if (type == NodeType.endpoint) { } else if (type == NodeType.endpoint) {
try { if (!kIsWeb) {
final Provider polkadot = Provider(Uri.parse(node)); try {
// From: final Provider polkadot = Provider(Uri.parse(node));
// https://github.com/leonardocustodio/polkadart/blob/main/examples/bin/extrinsic_demo.dart // From:
final RpcResponse<dynamic> block = // https://github.com/leonardocustodio/polkadart/blob/main/examples/bin/extrinsic_demo.dart
await polkadot.send('chain_getBlock', <dynamic>[]); final RpcResponse<dynamic> block =
currentBlock = int.parse( await polkadot.send('chain_getBlock', <dynamic>[]);
(((block.result as Map<String, dynamic>)['block'] currentBlock = int.parse(
as Map<String, dynamic>)['header'] (((block.result as Map<String, dynamic>)['block']
as Map<String, dynamic>)['number'] as String); as Map<String, dynamic>)['header']
stopwatch.stop(); as Map<String, dynamic>)['number'] as String);
latency = stopwatch.elapsed; stopwatch.stop();
await polkadot.disconnect(); latency = stopwatch.elapsed;
} catch (e) { await polkadot.disconnect();
loggerDev('Cannot parse node/stats $e'); } catch (e) {
loggerDev('Cannot parse node/stats $e');
latency = wrongNodeDuration;
}
} else {
// Waiting for web support in polkadart:
// https://github.com/leonardocustodio/polkadart/issues/297
latency = wrongNodeDuration; latency = wrongNodeDuration;
} }
} else if (type == NodeType.duniterIndexer) { } else if (type == NodeType.duniterIndexer) {
...@@ -939,7 +948,7 @@ void hashAndSign(Map<String, dynamic> data, CesiumWallet wallet) { ...@@ -939,7 +948,7 @@ void hashAndSign(Map<String, dynamic> data, CesiumWallet wallet) {
} }
Future<String?> getCesiumPlusUser(String pubKey) async { Future<String?> getCesiumPlusUser(String pubKey) async {
final Contact c = await getProfile(pubKey, true); final Contact c = await getProfile(pubKey, onlyCPlusProfile: true);
return c.name; return c.name;
} }
......
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