From d57ac5db140683fb56c348e0aedfc543a5d3e68d Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Mon, 3 Jun 2024 14:28:39 -0400 Subject: [PATCH] rvv041 - Code Optimizations addressbook's column descrip renamed to abdescrip _abText - variable used to hold AddressBook entry data for display _abCurAdrs - variable used to hold unique key in CRUD operations --- src/Zenith/CLI.hs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index 9a874af..73c397e 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -192,10 +192,10 @@ data State = State , _eventDispatch :: !(BC.BChan Tick) , _timer :: !Int , _txForm :: !(Form SendInput () Name) - , _abaddresses :: !(L.List Name (Entity AddressBook)) + , _abAddresses :: !(L.List Name (Entity AddressBook)) , _abForm :: !(Form AdrBookEntry () Name) - , _abCurAdrs :: !T.Text - , _abTxt :: !T.Text + , _abCurAdrs :: !T.Text -- used for address book CRUD operations + , _abTxt :: !T.Text -- Holds the Address Book entry data to show } makeLenses ''State @@ -379,7 +379,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] hLimit 50 $ vBox [vLimit 16 $ hLimit 50 $ - vBox $ [ L.renderList listDrawAB True (s ^. abaddresses) ], + vBox $ [ L.renderList listDrawAB True (s ^. abAddresses) ], padTop Max $ vLimit 4 $ hLimit 50 $ @@ -1046,7 +1046,7 @@ appEvent (BT.VtyEvent e) = do BT.modify $ set dialogBox Blank V.EvKey (V.KChar 'c') [] -> do -- Copy Address to Clipboard - case L.listSelectedElement $ s ^. abaddresses of + case L.listSelectedElement $ s ^. abAddresses of Just (_, a) -> do liftIO $ setClipboard $ @@ -1062,7 +1062,7 @@ appEvent (BT.VtyEvent e) = do BT.modify $ set displayBox MsgDisplay -- Send Zcash transaction V.EvKey (V.KChar 's') [] -> do - case L.listSelectedElement $ s ^. abaddresses of + case L.listSelectedElement $ s ^. abAddresses of Just (_, a) -> do BT.modify $ set txForm $ @@ -1073,7 +1073,7 @@ appEvent (BT.VtyEvent e) = do BT.modify $ set displayBox MsgDisplay -- Edit an entry in Address Book V.EvKey (V.KChar 'e') [] -> do - case L.listSelectedElement $ s ^. abaddresses of + case L.listSelectedElement $ s ^. abAddresses of Just (_, a) -> do BT.modify $ set abCurAdrs (addressBookAbaddress (entityVal a)) BT.modify $ @@ -1084,7 +1084,7 @@ appEvent (BT.VtyEvent e) = do BT.modify $ set dialogBox Blank -- Delete an entry from Address Book V.EvKey (V.KChar 'd') [] -> do - case L.listSelectedElement $ s ^. abaddresses of + case L.listSelectedElement $ s ^. abAddresses of Just (_, a) -> do BT.modify $ set abCurAdrs (addressBookAbaddress (entityVal a)) BT.modify $ @@ -1099,7 +1099,7 @@ appEvent (BT.VtyEvent e) = do BT.modify $ set dialogBox AdrBookForm -- Show AddressBook entry data V.EvKey V.KEnter [] -> do - case L.listSelectedElement $ s ^. abaddresses of + case L.listSelectedElement $ s ^. abAddresses of Just (_, a) -> do BT.modify $ set abTxt $ T.pack $ " Descr: " ++ @@ -1110,7 +1110,7 @@ appEvent (BT.VtyEvent e) = do _ -> do BT.modify $ set dialogBox Blank -- Process any other event - ev -> BT.zoom abaddresses $ L.handleListEvent ev + ev -> BT.zoom abAddresses $ L.handleListEvent ev -- Process new address book entry AdrBookForm -> do case e of @@ -1218,7 +1218,7 @@ appEvent (BT.VtyEvent e) = do Just TList -> BT.zoom transactions $ L.handleListEvent ev Just ABList -> - BT.zoom abaddresses $ L.handleListEvent ev + BT.zoom abAddresses $ L.handleListEvent ev _anyName -> return () where printMsg :: String -> BT.EventM Name State () @@ -1485,18 +1485,18 @@ refreshAddressBook :: State -> IO State refreshAddressBook s = do pool <- runNoLoggingT $ initPool $ s ^. dbPath selAddress <- - do case L.listSelectedElement $ s ^. abaddresses of + do case L.listSelectedElement $ s ^. abAddresses of Nothing -> do let fAdd = - L.listSelectedElement $ L.listMoveToBeginning $ s ^. abaddresses + L.listSelectedElement $ L.listMoveToBeginning $ s ^. abAddresses return fAdd Just a2 -> return $ Just a2 case selAddress of Nothing -> return s Just (_i, a) -> do abookList <- getAdrBook pool (s ^. network) - let tL' = L.listReplace (Vec.fromList abookList) (Just 0) (s ^. abaddresses) - return $ s & abaddresses .~ tL' + let tL' = L.listReplace (Vec.fromList abookList) (Just 0) (s ^. abAddresses) + return $ s & abAddresses .~ tL' addNewAddress :: T.Text -> Scope -> State -> IO State addNewAddress n scope s = do