From 42ea3534bf073ef85ab35a1e970b38e096331af5 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Mon, 19 Jul 2021 23:33:19 -0300 Subject: [PATCH] Add highlighting support to transfer values --- src/TokenTransferItem.tsx | 11 ++++++--- src/components/ValueHighlighter.tsx | 38 +++++++++++++++++++++++++++++ src/useSelection.ts | 2 +- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/components/ValueHighlighter.tsx diff --git a/src/TokenTransferItem.tsx b/src/TokenTransferItem.tsx index 83c5e81..92ec6ee 100644 --- a/src/TokenTransferItem.tsx +++ b/src/TokenTransferItem.tsx @@ -2,6 +2,7 @@ import React from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCaretRight } from "@fortawesome/free-solid-svg-icons"; import AddressHighlighter from "./components/AddressHighlighter"; +import ValueHighlighter from "./components/ValueHighlighter"; import DecoratedAddressLink from "./components/DecoratedAddressLink"; import FormattedBalance from "./components/FormattedBalance"; import { @@ -52,10 +53,12 @@ const TokenTransferItem: React.FC = ({
For - + + + ; + +const ValueHighlighter: React.FC = ({ + value, + children, +}) => { + const [selection, setSelection] = useSelectionContext(); + const select = () => { + setSelection({ type: "value", content: value.toString() }); + }; + const deselect = () => { + setSelection(null); + }; + + return ( +
+ {children} +
+ ); +}; + +export default React.memo(ValueHighlighter); diff --git a/src/useSelection.ts b/src/useSelection.ts index a02f1fe..b34dc81 100644 --- a/src/useSelection.ts +++ b/src/useSelection.ts @@ -1,7 +1,7 @@ import React, { useState, useContext } from "react"; export type Selection = { - type: "address"; + type: "address" | "value"; content: string; };