From 91568080bfe0e19ef997515fb3eb2b93f1cb640e Mon Sep 17 00:00:00 2001 From: Cryptosaka <79313706+Cryptosaka@users.noreply.github.com> Date: Wed, 11 Sep 2024 23:22:56 +0200 Subject: [PATCH 1/3] Added Address book modal to settings --- .../src/components/UI/modals/AddressBook.tsx | 104 ++++++++++++++++++ .../components/UI/sidebar/NetworkSettings.tsx | 20 ++++ packages/renderer/src/tools/utils.ts | 54 +++++++++ 3 files changed, 178 insertions(+) create mode 100644 packages/renderer/src/components/UI/modals/AddressBook.tsx diff --git a/packages/renderer/src/components/UI/modals/AddressBook.tsx b/packages/renderer/src/components/UI/modals/AddressBook.tsx new file mode 100644 index 00000000..a940c989 --- /dev/null +++ b/packages/renderer/src/components/UI/modals/AddressBook.tsx @@ -0,0 +1,104 @@ +import {useEffect, useState} from 'react'; +import Button from '../Button'; +import {getAddresses, removeAddress, saveNewAddress, trimMiddle} from '/@/tools'; +import {toast} from 'react-toastify'; +import Input from '../input/Input'; + +export default function AddressBook() { + const [showAdd, setShowAdd] = useState(false); + const [address, setAddress] = useState(''); + const [alias, setAlias] = useState(''); + const [addressBook, setAddressBook] = useState([]); + + useEffect(() => { + readFromStorage(); + }, []); + + const readFromStorage = () => { + const addresses = getAddresses(); + setAddressBook(addresses); + }; + + const saveAddress = () => { + if (!address) { + return toast.error('Please enter address and alias'); + } + saveNewAddress(address, alias); + setShowAdd(false); + readFromStorage(); + }; + + const deleteAddress = (address: string) => { + removeAddress(address); + readFromStorage(); + }; + + return ( +
{alias}
+{trimMiddle(address, 30)}
+Address
+ { + setAddress(e.target.value); + }} + /> +Alias
+ { + setAlias(e.target.value); + }} + /> + +{alias}
{trimMiddle(address, 30)}
Address
- { - setAddress(e.target.value); - }} - /> -Alias
- { - setAlias(e.target.value); - }} - /> + {editable ? ( + showAdd ? ( +Address
+ { + setAddress(e.target.value); + }} + /> +Alias
+ { + setAlias(e.target.value); + }} + /> + +