diff --git a/src/features/messages/MessageTable.tsx b/src/features/messages/MessageTable.tsx index 3712471..141202d 100644 --- a/src/features/messages/MessageTable.tsx +++ b/src/features/messages/MessageTable.tsx @@ -91,12 +91,12 @@ export function MessageSummaryRow({ message, mp }: { message: MessageStub; mp: M > {shortenAddress(origin.hash)} - + {getHumanReadableTimeString(origin.timestamp)} {statusIcon && ( - + parseMessageStub(multiProvider, scrapedChains, m)) - .filter((m): m is MessageStub => !!m) - .sort((a, b) => b.origin.timestamp - a.origin.timestamp); + return queryResult(multiProvider, scrapedChains, data, parseMessageStub); } export function parseMessageQueryResult( @@ -39,12 +34,23 @@ export function parseMessageQueryResult( scrapedChains: DomainsEntry[], data: MessagesQueryResult | undefined, ): Message[] { + return queryResult(multiProvider, scrapedChains, data, parseMessage); +} + +function queryResult( + multiProvider: MultiProvider, + scrapedChains: DomainsEntry[], + data: Record | undefined, + parseFn: (multiProvider: MultiProvider, scrapedChains: DomainsEntry[], data: D) => M | null, +) { if (!data || !Object.keys(data).length) return []; - return Object.values(data) - .flat() - .map((m) => parseMessage(multiProvider, scrapedChains, m)) - .filter((m): m is Message => !!m) - .sort((a, b) => b.origin.timestamp - a.origin.timestamp); + return deduplicateMessageList( + Object.values(data) + .flat() + .map((d) => parseFn(multiProvider, scrapedChains, d)) + .filter((m): m is M => !!m) + .sort((a, b) => b.origin.timestamp - a.origin.timestamp), + ); } function parseMessageStub( @@ -171,3 +177,11 @@ function getMessageStatus(m: MessageEntry | MessageStubEntry) { return MessageStatus.Pending; } } + +function deduplicateMessageList(messages: Array): Array { + const map = new Map(); + for (const item of messages) { + map.set(item.id, item); + } + return Array.from(map.values()); +}