From 23737ce4d0bfd5652f17fa917e5b5ea001f8df49 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 13 Oct 2021 15:34:30 -0300 Subject: [PATCH] Support trial and error of multiple event signatures --- src/transaction/LogEntry.tsx | 22 ++++++++++++---------- src/useTopic0.ts | 5 +++-- topic0 | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/transaction/LogEntry.tsx b/src/transaction/LogEntry.tsx index 60b1f39..f404ad3 100644 --- a/src/transaction/LogEntry.tsx +++ b/src/transaction/LogEntry.tsx @@ -22,19 +22,21 @@ const LogEntry: React.FC = ({ txData, log, logDesc }) => { const topic0 = useTopic0(rawTopic0); const topic0LogDesc = useMemo(() => { - if (!topic0?.signature) { + if (!topic0?.signatures) { return undefined; } - const sig = topic0.signature; - const logFragment = Fragment.fromString(`event ${sig}`); - const intf = new Interface([logFragment]); - try { - return intf.parseLog(log); - } catch (err) { - // TODO: try other indexed/non-indexed combinations? - console.error(err); - return undefined; + + const sigs = topic0.signatures; + for (const sig of sigs) { + const logFragment = Fragment.fromString(`event ${sig}`); + const intf = new Interface([logFragment]); + try { + return intf.parseLog(log); + } catch (err) { + // Ignore on purpose; try to match other sigs + } } + return undefined; }, [topic0, log]); const resolvedLogDesc = logDesc ?? topic0LogDesc; diff --git a/src/useTopic0.ts b/src/useTopic0.ts index 314a39e..adcef1e 100644 --- a/src/useTopic0.ts +++ b/src/useTopic0.ts @@ -3,7 +3,7 @@ import { RuntimeContext } from "./useRuntime"; import { topic0URL } from "./url"; export type Topic0Entry = { - signature: string | undefined; + signatures: string[] | undefined; }; const fullCache = new Map(); @@ -46,8 +46,9 @@ export const useTopic0 = ( // Get only the first occurrence, for now ignore alternative param names const sig = await res.text(); + const sigs = sig.split(";"); const entry: Topic0Entry = { - signature: sig, + signatures: sigs, }; setEntry(entry); fullCache.set(topic0, entry); diff --git a/topic0 b/topic0 index 052043e..b30f9d4 160000 --- a/topic0 +++ b/topic0 @@ -1 +1 @@ -Subproject commit 052043e6d51dd18cffb1a5a450262f47e5638684 +Subproject commit b30f9d442081a231641c5cef196be79650306e55