diff --git a/src/api/address-resolver/CustomLabelResolver.ts b/src/api/address-resolver/CustomLabelResolver.ts index 64fd9e942..e9de85e7c 100644 --- a/src/api/address-resolver/CustomLabelResolver.ts +++ b/src/api/address-resolver/CustomLabelResolver.ts @@ -98,6 +98,15 @@ export class CustomLabelFetcher { return undefined; } } + + public getAllAddresses(): string[] { + return Array.from(this.localStorageLabels.keys()); + } + + public clearAll() { + this.localStorageLabels.clear(); + this.localStorageLabels.clear(); + } } export class CustomLabelResolver extends BasicAddressResolver { diff --git a/src/execution/address/AddressSubtitle.tsx b/src/execution/address/AddressSubtitle.tsx index 91c6e6269..493ad2b55 100644 --- a/src/execution/address/AddressSubtitle.tsx +++ b/src/execution/address/AddressSubtitle.tsx @@ -1,4 +1,9 @@ -import { faPencil, faTag, faTimes } from "@fortawesome/free-solid-svg-icons"; +import { + faPencil, + faTag, + faTimes, + faTrash, +} from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FC, useContext, useState } from "react"; import Blockies from "react-blockies"; @@ -10,7 +15,7 @@ import { useResolvedAddress } from "../../useResolvedAddresses"; import { RuntimeContext } from "../../useRuntime"; import { AddressAwareComponentProps } from "../types"; import AddressAttributes from "./AddressAttributes"; -import EditableAddressTag from "./EditableAddressTag"; +import EditableAddressTag, { clearAllLabels } from "./EditableAddressTag"; type AddressSubtitleProps = AddressAwareComponentProps & { isENS: boolean | undefined; @@ -64,25 +69,39 @@ const AddressSubtitle: FC = ({ {resolvedName} )} -
- {editingAddressTag && ( - setEditingAddressTag(false)} - /> - )} - -
+ {config?.WIP_customAddressLabels && ( +
+ {editingAddressTag && ( + + setEditingAddressTag(false) + } + /> + )} + + {/* For debugging only; we'll want to create an address label management page. */} + +
+ )} ); diff --git a/src/execution/address/EditableAddressTag.tsx b/src/execution/address/EditableAddressTag.tsx index 919af571d..46af0ae5b 100644 --- a/src/execution/address/EditableAddressTag.tsx +++ b/src/execution/address/EditableAddressTag.tsx @@ -23,6 +23,18 @@ async function setAddressLabel(address: string, label: string | null) { mutate(address, [customLabelResolver, trimmedLabel]); } +export async function clearAllLabels() { + const customLabelFetcher = CustomLabelFetcher.getInstance(); + const addresses: string[] = customLabelFetcher.getAllAddresses(); + await customLabelFetcher.updateLabels( + addresses.reduce( + (obj: Record, key: string) => ({ ...obj, [key]: "" }), + {}, + ), + ); + addresses.forEach((address) => mutate(address)); +} + const EditableAddressTag: FC = ({ address, defaultTag, diff --git a/src/useConfig.ts b/src/useConfig.ts index 4c94f1034..227299632 100644 --- a/src/useConfig.ts +++ b/src/useConfig.ts @@ -185,6 +185,12 @@ export type OtterscanConfig = { */ l1ExplorerURL?: string; }; + + /** + * Temporary config option, until address labels are complete: Enables setting + * address labels which are kept in local storage. + */ + WIP_customAddressLabels?: boolean; }; /**