Compare commits

...

4 commits

Author SHA1 Message Date
772025e317 rvv041 - Code Optimizations
getABookRec function commented out from DB.hs
	 abaddresses state renamed to abAddresses
2024-06-03 14:48:01 -04:00
d57ac5db14 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
2024-06-03 14:28:39 -04:00
51116e8083 rvv041 - Code optimizations
ABList removed from focusRing
	 address_book's column address renamed to abaddress
2024-06-03 14:04:16 -04:00
1c88ea5f08 rvv041 - {-# LANGUAGE BlockArguments #-} removed 2024-06-03 12:53:24 -04:00
2 changed files with 39 additions and 40 deletions

View file

@ -2,7 +2,7 @@
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BlockArguments #-}
module Zenith.CLI where module Zenith.CLI where
@ -192,10 +192,10 @@ data State = State
, _eventDispatch :: !(BC.BChan Tick) , _eventDispatch :: !(BC.BChan Tick)
, _timer :: !Int , _timer :: !Int
, _txForm :: !(Form SendInput () Name) , _txForm :: !(Form SendInput () Name)
, _abaddresses :: !(L.List Name (Entity AddressBook)) , _abAddresses :: !(L.List Name (Entity AddressBook))
, _abForm :: !(Form AdrBookEntry () Name) , _abForm :: !(Form AdrBookEntry () Name)
, _abCurAdrs :: !T.Text , _abCurAdrs :: !T.Text -- used for address book CRUD operations
, _abTxt :: !T.Text , _abTxt :: !T.Text -- Holds the Address Book entry data to show
} }
makeLenses ''State makeLenses ''State
@ -379,7 +379,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
hLimit 50 $ hLimit 50 $
vBox [vLimit 16 $ vBox [vLimit 16 $
hLimit 50 $ hLimit 50 $
vBox $ [ L.renderList listDrawAB True (s ^. abaddresses) ], vBox $ [ L.renderList listDrawAB True (s ^. abAddresses) ],
padTop Max $ padTop Max $
vLimit 4 $ vLimit 4 $
hLimit 50 $ hLimit 50 $
@ -1046,50 +1046,50 @@ appEvent (BT.VtyEvent e) = do
BT.modify $ set dialogBox Blank BT.modify $ set dialogBox Blank
V.EvKey (V.KChar 'c') [] -> do V.EvKey (V.KChar 'c') [] -> do
-- Copy Address to Clipboard -- Copy Address to Clipboard
case L.listSelectedElement $ s ^. abaddresses of case L.listSelectedElement $ s ^. abAddresses of
Just (_, a) -> do Just (_, a) -> do
liftIO $ liftIO $
setClipboard $ setClipboard $
T.unpack $ addressBookAddress (entityVal a) T.unpack $ addressBookAbaddress (entityVal a)
BT.modify $ BT.modify $
set msg $ set msg $
"Address copied to Clipboard from >>\n" ++ "Address copied to Clipboard from >>\n" ++
T.unpack (addressBookDescrip (entityVal a)) ++ "->\n" ++ T.unpack (addressBookDescrip (entityVal a)) ++ "->\n" ++
T.unpack (addressBookAddress (entityVal a)) ++ "!" T.unpack (addressBookAbaddress (entityVal a)) ++ "!"
BT.modify $ set displayBox MsgDisplay BT.modify $ set displayBox MsgDisplay
_ -> do _ -> do
BT.modify $ set msg "Error while copying the address!!" BT.modify $ set msg "Error while copying the address!!"
BT.modify $ set displayBox MsgDisplay BT.modify $ set displayBox MsgDisplay
-- Send Zcash transaction -- Send Zcash transaction
V.EvKey (V.KChar 's') [] -> do V.EvKey (V.KChar 's') [] -> do
case L.listSelectedElement $ s ^. abaddresses of case L.listSelectedElement $ s ^. abAddresses of
Just (_, a) -> do Just (_, a) -> do
BT.modify $ BT.modify $
set txForm $ set txForm $
mkSendForm (s ^. balance) (SendInput (addressBookAddress (entityVal a)) 0.0 "") mkSendForm (s ^. balance) (SendInput (addressBookAbaddress (entityVal a)) 0.0 "")
BT.modify $ set dialogBox SendTx BT.modify $ set dialogBox SendTx
_ -> do _ -> do
BT.modify $ set msg "No receiver address available!!" BT.modify $ set msg "No receiver address available!!"
BT.modify $ set displayBox MsgDisplay BT.modify $ set displayBox MsgDisplay
-- Edit an entry in Address Book -- Edit an entry in Address Book
V.EvKey (V.KChar 'e') [] -> do V.EvKey (V.KChar 'e') [] -> do
case L.listSelectedElement $ s ^. abaddresses of case L.listSelectedElement $ s ^. abAddresses of
Just (_, a) -> do Just (_, a) -> do
BT.modify $ set abCurAdrs (addressBookAddress (entityVal a)) BT.modify $ set abCurAdrs (addressBookAbaddress (entityVal a))
BT.modify $ BT.modify $
set abForm $ set abForm $
mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAddress (entityVal a))) mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAbaddress (entityVal a)))
BT.modify $ set dialogBox AdrBookUpdForm BT.modify $ set dialogBox AdrBookUpdForm
_ -> do _ -> do
BT.modify $ set dialogBox Blank BT.modify $ set dialogBox Blank
-- Delete an entry from Address Book -- Delete an entry from Address Book
V.EvKey (V.KChar 'd') [] -> do V.EvKey (V.KChar 'd') [] -> do
case L.listSelectedElement $ s ^. abaddresses of case L.listSelectedElement $ s ^. abAddresses of
Just (_, a) -> do Just (_, a) -> do
BT.modify $ set abCurAdrs (addressBookAddress (entityVal a)) BT.modify $ set abCurAdrs (addressBookAbaddress (entityVal a))
BT.modify $ BT.modify $
set abForm $ set abForm $
mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAddress (entityVal a))) mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAbaddress (entityVal a)))
BT.modify $ set dialogBox AdrBookDelForm BT.modify $ set dialogBox AdrBookDelForm
_ -> do _ -> do
BT.modify $ set dialogBox Blank BT.modify $ set dialogBox Blank
@ -1099,18 +1099,18 @@ appEvent (BT.VtyEvent e) = do
BT.modify $ set dialogBox AdrBookForm BT.modify $ set dialogBox AdrBookForm
-- Show AddressBook entry data -- Show AddressBook entry data
V.EvKey V.KEnter [] -> do V.EvKey V.KEnter [] -> do
case L.listSelectedElement $ s ^. abaddresses of case L.listSelectedElement $ s ^. abAddresses of
Just (_, a) -> do Just (_, a) -> do
BT.modify $ set abTxt $ T.pack $ BT.modify $ set abTxt $ T.pack $
" Descr: " ++ " Descr: " ++
T.unpack (addressBookDescrip (entityVal a)) ++ T.unpack (addressBookDescrip (entityVal a)) ++
"\n Address: " ++ "\n Address: " ++
T.unpack (addressBookAddress (entityVal a)) T.unpack (addressBookAbaddress (entityVal a))
BT.modify $ set displayBox AdrBookEntryDisplay BT.modify $ set displayBox AdrBookEntryDisplay
_ -> do _ -> do
BT.modify $ set dialogBox Blank BT.modify $ set dialogBox Blank
-- Process any other event -- Process any other event
ev -> BT.zoom abaddresses $ L.handleListEvent ev ev -> BT.zoom abAddresses $ L.handleListEvent ev
-- Process new address book entry -- Process new address book entry
AdrBookForm -> do AdrBookForm -> do
case e of case e of
@ -1218,7 +1218,7 @@ appEvent (BT.VtyEvent e) = do
Just TList -> Just TList ->
BT.zoom transactions $ L.handleListEvent ev BT.zoom transactions $ L.handleListEvent ev
Just ABList -> Just ABList ->
BT.zoom abaddresses $ L.handleListEvent ev BT.zoom abAddresses $ L.handleListEvent ev
_anyName -> return () _anyName -> return ()
where where
printMsg :: String -> BT.EventM Name State () printMsg :: String -> BT.EventM Name State ()
@ -1322,7 +1322,7 @@ runZenithCLI config = do
else Blank) else Blank)
True True
(mkInputForm $ DialogInput "Main") (mkInputForm $ DialogInput "Main")
(F.focusRing [AList, TList,ABList]) (F.focusRing [AList, TList])
(zgb_blocks chainInfo) (zgb_blocks chainInfo)
dbFilePath dbFilePath
host host
@ -1485,18 +1485,18 @@ refreshAddressBook :: State -> IO State
refreshAddressBook s = do refreshAddressBook s = do
pool <- runNoLoggingT $ initPool $ s ^. dbPath pool <- runNoLoggingT $ initPool $ s ^. dbPath
selAddress <- selAddress <-
do case L.listSelectedElement $ s ^. abaddresses of do case L.listSelectedElement $ s ^. abAddresses of
Nothing -> do Nothing -> do
let fAdd = let fAdd =
L.listSelectedElement $ L.listMoveToBeginning $ s ^. abaddresses L.listSelectedElement $ L.listMoveToBeginning $ s ^. abAddresses
return fAdd return fAdd
Just a2 -> return $ Just a2 Just a2 -> return $ Just a2
case selAddress of case selAddress of
Nothing -> return s Nothing -> return s
Just (_i, a) -> do Just (_i, a) -> do
abookList <- getAdrBook pool (s ^. network) abookList <- getAdrBook pool (s ^. network)
let tL' = L.listReplace (Vec.fromList abookList) (Just 0) (s ^. abaddresses) let tL' = L.listReplace (Vec.fromList abookList) (Just 0) (s ^. abAddresses)
return $ s & abaddresses .~ tL' return $ s & abAddresses .~ tL'
addNewAddress :: T.Text -> Scope -> State -> IO State addNewAddress :: T.Text -> Scope -> State -> IO State
addNewAddress n scope s = do addNewAddress n scope s = do

View file

@ -15,7 +15,6 @@
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
{-# LANGUAGE BlockArguments #-}
module Zenith.DB where module Zenith.DB where
@ -250,8 +249,8 @@ share
AddressBook AddressBook
network ZcashNetDB network ZcashNetDB
descrip T.Text descrip T.Text
address T.Text abaddress T.Text
UniqueABA address UniqueABA abaddress
deriving Show Eq deriving Show Eq
|] |]
@ -1501,19 +1500,19 @@ updateAdrsInAdrBook pool d a ia = do
PS.retryOnBusy $ PS.retryOnBusy $
flip PS.runSqlPool pool $ do flip PS.runSqlPool pool $ do
update $ \ab -> do update $ \ab -> do
set ab [AddressBookDescrip =. val d, AddressBookAddress =. val a] set ab [AddressBookDescrip =. val d, AddressBookAbaddress =. val a]
where_ $ ab ^. AddressBookAddress ==. val ia where_ $ ab ^. AddressBookAbaddress ==. val ia
-- | Get one AddrssBook record using the Address as a key -- | Get one AddrssBook record using the Address as a key
getABookRec :: ConnectionPool -> T.Text -> IO [Entity AddressBook] -- getABookRec :: ConnectionPool -> T.Tex t -> IO (Maybe (Entity AddressBook))
getABookRec pool a = do -- getABookRec pool a = do
runNoLoggingT $ -- runNoLoggingT $
PS.retryOnBusy $ -- PS.retryOnBusy $
flip PS.runSqlPool pool $ -- flip PS.runSqlPool pool $
select $ do -- select $ do
adrbook <- from $ table @AddressBook -- adrbook <- from $ table @AddressBook
where_ ((adrbook ^. AddressBookAddress) ==. val a) -- where_ ((adrbook ^. AddressBookAbaddress) ==. val a)
return adrbook -- return adrbook
-- | delete an existing address from AddressBook -- | delete an existing address from AddressBook
deleteAdrsFromAB :: ConnectionPool -> T.Text -> IO () deleteAdrsFromAB :: ConnectionPool -> T.Text -> IO ()
@ -1523,7 +1522,7 @@ deleteAdrsFromAB pool ia = do
flip PS.runSqlPool pool $ do flip PS.runSqlPool pool $ do
delete $ do delete $ do
ab <- from $ table @AddressBook ab <- from $ table @AddressBook
where_ (ab ^. AddressBookAddress ==. val ia) where_ (ab ^. AddressBookAbaddress ==. val ia)
rmdups :: Ord a => [a] -> [a] rmdups :: Ord a => [a] -> [a]
rmdups = map head . group . sort rmdups = map head . group . sort