From 66d6ccae10bbdc031904126052e3fd503dc9db4e Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 24 Aug 2022 04:38:15 -0300 Subject: [PATCH] Simplify syntax --- src/useErigonHooks.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 3fee30e..7de952a 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -255,22 +255,14 @@ export const useTokenTransfers = ( return undefined; } - const _transfers: TokenTransfer[] = []; - for (const l of txData.confirmedData.logs) { - if (l.topics.length !== 3) { - continue; - } - if (l.topics[0] !== TRANSFER_TOPIC) { - continue; - } - _transfers.push({ + return txData.confirmedData.logs + .filter((l) => l.topics.length === 3 && l.topics[0] === TRANSFER_TOPIC) + .map((l) => ({ token: l.address, from: getAddress(hexDataSlice(arrayify(l.topics[1]), 12)), to: getAddress(hexDataSlice(arrayify(l.topics[2]), 12)), value: BigNumber.from(l.data), - }); - } - return _transfers; + })); }, [txData]); return transfers;