From 05719eb4ae2aeb30ad5d643203c4ea5fa611c37d Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 14 Jul 2021 03:52:31 -0300 Subject: [PATCH 1/7] Add selection support for addresses --- src/AddressTransactions.tsx | 7 +++-- src/BlockTransactions.tsx | 7 +++-- src/search/TransactionItem.tsx | 57 +++++++++++++++++++++++++++------- src/useSelection.ts | 23 ++++++++++++++ 4 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 src/useSelection.ts diff --git a/src/AddressTransactions.tsx b/src/AddressTransactions.tsx index e671087..076d9be 100644 --- a/src/AddressTransactions.tsx +++ b/src/AddressTransactions.tsx @@ -15,6 +15,7 @@ import { SearchController } from "./search/search"; import { RuntimeContext } from "./useRuntime"; import { useENSCache } from "./useReverseCache"; import { useFeeToggler } from "./search/useFeeToggler"; +import { SelectionContext, useSelection } from "./useSelection"; type BlockParams = { addressOrName: string; @@ -153,6 +154,8 @@ const AddressTransactions: React.FC = () => { const [feeDisplay, feeDisplayToggler] = useFeeToggler(); + const selection = useSelection(); + return ( {error ? ( @@ -204,7 +207,7 @@ const AddressTransactions: React.FC = () => { feeDisplayToggler={feeDisplayToggler} /> {controller ? ( - <> + {controller.getPage().map((tx) => ( { nextHash={page ? page[page.length - 1].hash : ""} /> - + ) : ( )} diff --git a/src/BlockTransactions.tsx b/src/BlockTransactions.tsx index 8f8f474..e8cbc52 100644 --- a/src/BlockTransactions.tsx +++ b/src/BlockTransactions.tsx @@ -15,6 +15,7 @@ import { PAGE_SIZE } from "./params"; import { useFeeToggler } from "./search/useFeeToggler"; import { RuntimeContext } from "./useRuntime"; import { useENSCache } from "./useReverseCache"; +import { SelectionContext, useSelection } from "./useSelection"; type BlockParams = { blockNumber: string; @@ -116,6 +117,8 @@ const BlockTransactions: React.FC = () => { const [feeDisplay, feeDisplayToggler] = useFeeToggler(); + const selection = useSelection(); + return ( Transactions @@ -142,7 +145,7 @@ const BlockTransactions: React.FC = () => { feeDisplayToggler={feeDisplayToggler} /> {page ? ( - <> + {page.map((tx) => ( { total={total} /> - + ) : ( )} diff --git a/src/search/TransactionItem.tsx b/src/search/TransactionItem.tsx index 7cfaf76..516554f 100644 --- a/src/search/TransactionItem.tsx +++ b/src/search/TransactionItem.tsx @@ -14,6 +14,7 @@ import TransactionValue from "../components/TransactionValue"; import { ENSReverseCache, ProcessedTransaction } from "../types"; import { FeeDisplay } from "./useFeeToggler"; import { formatValue } from "../components/formatter"; +import { useSelectionContext } from "../useSelection"; type TransactionItemProps = { tx: ProcessedTransaction; @@ -45,6 +46,14 @@ const TransactionItem: React.FC = ({ const ensTo = ensCache && tx.to && ensCache[tx.to]; const flash = tx.gasPrice.isZero() && tx.internalMinerInteraction; + const [selection, setSelection] = useSelectionContext(); + const select = (address: string) => { + setSelection({ type: "address", content: address }); + }; + const deselect = () => { + setSelection(null); + }; + return (
= ({ {tx.from && ( - +
select(tx.from!)} + onMouseLeave={deselect} + > + +
)}
@@ -86,12 +107,24 @@ const TransactionItem: React.FC = ({ {tx.to && ( - +
select(tx.to!)} + onMouseLeave={deselect} + > + +
)}
diff --git a/src/useSelection.ts b/src/useSelection.ts new file mode 100644 index 0000000..ed66746 --- /dev/null +++ b/src/useSelection.ts @@ -0,0 +1,23 @@ +import React, { useState, useContext } from "react"; + +export type Selection = { + type: string; + content: string; +}; + +export const useSelection = (): [ + Selection | null, + React.Dispatch> +] => { + const [selection, setSelection] = useState(null); + return [selection, setSelection]; +}; + +export const SelectionContext = React.createContext< + ReturnType +>(null!); + +export const useSelectionContext = () => { + const ctx = useContext(SelectionContext); + return ctx; +}; From 4b3ab2ec8aa342a018e979180e8db0c0306fdb9e Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 14 Jul 2021 04:24:28 -0300 Subject: [PATCH 2/7] Extract highlighter decorator component --- src/AddressTransactions.tsx | 4 +-- src/BlockTransactions.tsx | 4 +-- src/components/AddressHighlighter.tsx | 37 ++++++++++++++++++++++++++ src/search/TransactionItem.tsx | 38 ++++----------------------- 4 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 src/components/AddressHighlighter.tsx diff --git a/src/AddressTransactions.tsx b/src/AddressTransactions.tsx index 076d9be..4727f7c 100644 --- a/src/AddressTransactions.tsx +++ b/src/AddressTransactions.tsx @@ -154,7 +154,7 @@ const AddressTransactions: React.FC = () => { const [feeDisplay, feeDisplayToggler] = useFeeToggler(); - const selection = useSelection(); + const selectionCtx = useSelection(); return ( @@ -207,7 +207,7 @@ const AddressTransactions: React.FC = () => { feeDisplayToggler={feeDisplayToggler} /> {controller ? ( - + {controller.getPage().map((tx) => ( { const [feeDisplay, feeDisplayToggler] = useFeeToggler(); - const selection = useSelection(); + const selectionCtx = useSelection(); return ( @@ -145,7 +145,7 @@ const BlockTransactions: React.FC = () => { feeDisplayToggler={feeDisplayToggler} /> {page ? ( - + {page.map((tx) => ( = ({ + address, + children, +}) => { + const [selection, setSelection] = useSelectionContext(); + const select = () => { + setSelection({ type: "address", content: address }); + }; + const deselect = () => { + setSelection(null); + }; + + return ( +
+ {children} +
+ ); +}; + +export default AddressHighlighter; diff --git a/src/search/TransactionItem.tsx b/src/search/TransactionItem.tsx index 516554f..ca4fbed 100644 --- a/src/search/TransactionItem.tsx +++ b/src/search/TransactionItem.tsx @@ -6,6 +6,7 @@ import BlockLink from "../components/BlockLink"; import TransactionLink from "../components/TransactionLink"; import AddressOrENSName from "../components/AddressOrENSName"; import TimestampAge from "../components/TimestampAge"; +import AddressHighlighter from "../components/AddressHighlighter"; import TransactionDirection, { Direction, Flags, @@ -14,7 +15,6 @@ import TransactionValue from "../components/TransactionValue"; import { ENSReverseCache, ProcessedTransaction } from "../types"; import { FeeDisplay } from "./useFeeToggler"; import { formatValue } from "../components/formatter"; -import { useSelectionContext } from "../useSelection"; type TransactionItemProps = { tx: ProcessedTransaction; @@ -46,14 +46,6 @@ const TransactionItem: React.FC = ({ const ensTo = ensCache && tx.to && ensCache[tx.to]; const flash = tx.gasPrice.isZero() && tx.internalMinerInteraction; - const [selection, setSelection] = useSelectionContext(); - const select = (address: string) => { - setSelection({ type: "address", content: address }); - }; - const deselect = () => { - setSelection(null); - }; - return (
= ({ {tx.from && ( -
select(tx.from!)} - onMouseLeave={deselect} - > + -
+ )}
@@ -107,24 +89,14 @@ const TransactionItem: React.FC = ({ {tx.to && ( -
select(tx.to!)} - onMouseLeave={deselect} - > + -
+ )}
From e2e94a4d30183d33aed00a94e928bdf7d6771223 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 14 Jul 2021 04:43:58 -0300 Subject: [PATCH 3/7] Apply highlighter decorator to transaction details page --- src/TokenTransferItem.tsx | 11 ++++-- src/Transaction.tsx | 28 +++++++++----- src/components/AddressHighlighter.tsx | 2 +- src/components/InternalTransfer.tsx | 53 +++++++++++++++------------ 4 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/TokenTransferItem.tsx b/src/TokenTransferItem.tsx index 64a42f6..b341f0d 100644 --- a/src/TokenTransferItem.tsx +++ b/src/TokenTransferItem.tsx @@ -1,8 +1,9 @@ import React from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCaretRight } from "@fortawesome/free-solid-svg-icons"; -import AddressLink from "./components/AddressLink"; +import AddressHighlighter from "./components/AddressHighlighter"; import AddressOrENSName from "./components/AddressOrENSName"; +import AddressLink from "./components/AddressLink"; import TokenLogo from "./components/TokenLogo"; import FormattedBalance from "./components/FormattedBalance"; import { TokenMetas, TokenTransfer } from "./types"; @@ -23,11 +24,15 @@ const TokenTransferItem: React.FC = ({
From - + + +
To - + + +
For diff --git a/src/Transaction.tsx b/src/Transaction.tsx index e2b6390..4235c3e 100644 --- a/src/Transaction.tsx +++ b/src/Transaction.tsx @@ -17,6 +17,7 @@ import StandardSubtitle from "./StandardSubtitle"; import Tab from "./components/Tab"; import ContentFrame from "./ContentFrame"; import BlockLink from "./components/BlockLink"; +import AddressHighlighter from "./components/AddressHighlighter"; import AddressOrENSName from "./components/AddressOrENSName"; import AddressLink from "./components/AddressLink"; import Copy from "./components/Copy"; @@ -29,6 +30,7 @@ import TokenTransferItem from "./TokenTransferItem"; import erc20 from "./erc20.json"; import { TokenMetas, TokenTransfer, TransactionData, Transfer } from "./types"; import { RuntimeContext } from "./useRuntime"; +import { SelectionContext, useSelection } from "./useSelection"; const TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"; @@ -160,11 +162,13 @@ const Transaction: React.FC = () => { traceTransfersUsingOtsTrace(); }, [traceTransfersUsingOtsTrace]); + const selectionCtx = useSelection(); + return ( Transaction Details {txData && ( - <> +
Overview @@ -206,19 +210,23 @@ const Transaction: React.FC = () => {
- + + +
- + + +
{transfers && ( @@ -350,7 +358,7 @@ const Transaction: React.FC = () => { - + )} ); diff --git a/src/components/AddressHighlighter.tsx b/src/components/AddressHighlighter.tsx index 78524a7..114157c 100644 --- a/src/components/AddressHighlighter.tsx +++ b/src/components/AddressHighlighter.tsx @@ -19,7 +19,7 @@ const AddressHighlighter: React.FC = ({ return (
= ({ {ethers.utils.formatEther(transfer.value)} Ether From -
- {fromMiner && ( - - - - )} - -
+ +
+ {fromMiner && ( + + + + )} + +
+
To -
- {toMiner && ( - - - - )} - -
+ +
+ {toMiner && ( + + + + )} + +
+
); }; From f3213b3c6939eaf66ff5472b29a29e01a6ea5338 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 14 Jul 2021 15:35:53 -0300 Subject: [PATCH 4/7] Fix spacing and alignment due to addresss highlight feature --- src/TokenTransferItem.tsx | 8 ++-- src/Transaction.tsx | 4 +- src/components/InternalTransfer.tsx | 64 +++++++++++++++-------------- src/search/ResultHeader.tsx | 4 +- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/TokenTransferItem.tsx b/src/TokenTransferItem.tsx index b341f0d..4b1fc62 100644 --- a/src/TokenTransferItem.tsx +++ b/src/TokenTransferItem.tsx @@ -21,20 +21,20 @@ const TokenTransferItem: React.FC = ({ -
-
+
+
From
-
+
To
-
+
For { -
+
{
-
+
= ({ TRANSFER {ethers.utils.formatEther(transfer.value)} Ether - From - -
- {fromMiner && ( - - - - )} - -
-
- To - -
- {toMiner && ( - - - - )} - -
-
+
+ From + +
+ {fromMiner && ( + + + + )} + +
+
+
+
+ To + +
+ {toMiner && ( + + + + )} + +
+
+
); }; diff --git a/src/search/ResultHeader.tsx b/src/search/ResultHeader.tsx index 0b63c90..13880bd 100644 --- a/src/search/ResultHeader.tsx +++ b/src/search/ResultHeader.tsx @@ -15,8 +15,8 @@ const ResultHeader: React.FC = ({
Method
Block
Age
-
From
-
To
+
From
+
To
Value
- - -
- {txData.transactionHash} - -
-
- - {txData.status ? ( - - - Success - - ) : ( - - - Fail - - )} - - -
- - - {txData.confirmations} Block Confirmations - -
-
- - - - -
- - - - -
-
- -
- - - - -
- {transfers && ( -
- {transfers.map((t, i) => ( - - ))} -
- )} -
- - - - {txData.tokenTransfers.length > 0 && ( - -
- {txData.tokenTransfers.map((t, i) => ( - - ))} -
-
- )} - - - {ethers.utils.formatEther(txData.value)} Ether - - - - Ether - - -
- - Ether ( - {" "} - Gwei) - - {sendsEthToMiner && ( - - Flashbots - - )} -
-
- N/A - - - - - ( - {(txData.gasUsedPerc * 100).toFixed(2)}%) - - {txData.nonce} - - - {txData.transactionIndex} - - - -