From ebf7420615c8e85349e59cde5687fd6c295314d2 Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 7 Jan 2024 21:14:52 +0100 Subject: [PATCH] fix: show received certifications when asked, and keep only latests --- lib/models/queries_indexer.dart | 4 ++-- lib/screens/certifications.dart | 2 +- lib/widgets/certs_list.dart | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/models/queries_indexer.dart b/lib/models/queries_indexer.dart index 9e8b802..9d76b12 100644 --- a/lib/models/queries_indexer.dart +++ b/lib/models/queries_indexer.dart @@ -85,7 +85,7 @@ query ($address: String!, $number: Int!, $offset: Int!) { const String getCertsReceived = r''' query ($address: String!) { - certification(where: {receiver: {pubkey: {_eq: $address}}}) { + certification(where: {receiver: {pubkey: {_eq: $address}}}, order_by: {created_at: desc}) { issuer { pubkey name @@ -97,7 +97,7 @@ query ($address: String!) { const String getCertsSent = r''' query ($address: String!) { - certification(where: {issuer: {pubkey: {_eq: $address}}}) { + certification(where: {issuer: {pubkey: {_eq: $address}}}, order_by: {created_at: desc}) { receiver { pubkey name diff --git a/lib/screens/certifications.dart b/lib/screens/certifications.dart index 278d61d..ff05daa 100644 --- a/lib/screens/certifications.dart +++ b/lib/screens/certifications.dart @@ -51,7 +51,7 @@ class CertificationsScreen extends StatelessWidget { CertsCounter(address: address) ]), content: CertsList( - address: address, direction: CertDirection.sent), + address: address, direction: CertDirection.received), contentHorizontalPadding: 0, contentBorderWidth: 1, ), diff --git a/lib/widgets/certs_list.dart b/lib/widgets/certs_list.dart index a9eb820..12f1fe4 100644 --- a/lib/widgets/certs_list.dart +++ b/lib/widgets/certs_list.dart @@ -87,11 +87,15 @@ class CertsList extends StatelessWidget { final date = DateTime.parse(cert['created_at']); final dp = DateTime(date.year, date.month, date.day); final dateForm = '${dp.day}-${dp.month}-${dp.year}'; - listCerts.add({ - 'address': issuerAddress, - 'name': issuerName, - 'date': dateForm - }); + + // Check if we have a more recent certification, we skip + if (!listCerts.any((cert) => cert['address'] == issuerAddress)) { + listCerts.add({ + 'address': issuerAddress, + 'name': issuerName, + 'date': dateForm + }); + } } // Build history list