From edb74229512809fb4b3c9ba7aae5494b924b0357 Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Sat, 1 Jun 2024 20:04:18 -0400 Subject: [PATCH] rvv001 - AddressBook completed - ready for tests --- CHANGELOG.md | 5 +++++ src/Zenith/CLI.hs | 17 ++++++++++++----- src/Zenith/DB.hs | 7 ++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a865617..e57dddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.5.2.0-beta] +### Added + +- Address Book functionality. Allows users to store frequently used zcash addresses and + generate transactions using them. + ### Changed - Update to `zcash-haskell-0.6.2.0` to increase performance of transaction creation diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index db001aa..c57cd10 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -414,7 +414,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] (D.dialog (Just $ str " Delete Address Book Entry ") Nothing 50) (renderForm (st ^. abForm) <=> C.hCenter - (hBox [capCommand "↲" " Delete", capCommand3 "" "" " Cancel"])) + (hBox [capCommand "C" "onfirm delete", capCommand3 "" "" " Cancel"])) -- splashDialog :: State -> Widget Name @@ -1177,10 +1177,17 @@ appEvent (BT.VtyEvent e) = do AddressField -- Process delete AddresBook entry AdrBookDelForm -> do - case e of - V.EvKey V.KEsc [] -> BT.modify $ set dialogBox AdrBook - V.EvKey V.KEnter [] -> BT.modify $ set dialogBox AdrBook - ev -> BT.modify $ set dialogBox AdrBookDelForm + case e of + V.EvKey V.KEsc [] -> BT.modify $ set dialogBox AdrBook + V.EvKey (V.KChar 'c') [] -> do + pool <- liftIO $ runNoLoggingT $ initPool $ s ^. dbPath + fs <- BT.zoom abForm $ BT.gets formState + res <- liftIO $ deleteAdrsFromAB pool (fs ^.address) + s' <- liftIO $ refreshAddressBook s + BT.put s' + BT.modify $ set dialogBox AdrBook + ev -> BT.modify $ set dialogBox AdrBookDelForm + -- Process any other event Blank -> do case e of V.EvKey (V.KChar '\t') [] -> focusRing %= F.focusNext diff --git a/src/Zenith/DB.hs b/src/Zenith/DB.hs index fe643e9..d95a285 100644 --- a/src/Zenith/DB.hs +++ b/src/Zenith/DB.hs @@ -1504,6 +1504,7 @@ updateAdrsInAdrBook pool d a ia = do set ab [AddressBookDescrip =. val d, AddressBookAddress =. val a] where_ $ ab ^. AddressBookAddress ==. val ia +-- | Get one AddrssBook record using the Address as a key getABookRec :: ConnectionPool -> T.Text -> IO [Entity AddressBook] getABookRec pool a = do runNoLoggingT $ @@ -1515,14 +1516,14 @@ getABookRec pool a = do return adrbook -- | delete an existing address from AddressBook -deleteAdrsFromAB :: ConnectionPool -> AddressBookId -> IO () -deleteAdrsFromAB pool i = do +deleteAdrsFromAB :: ConnectionPool -> T.Text -> IO () +deleteAdrsFromAB pool ia = do runNoLoggingT $ PS.retryOnBusy $ flip PS.runSqlPool pool $ do delete $ do ab <- from $ table @AddressBook - where_ (ab ^. AddressBookId ==. val i) + where_ (ab ^. AddressBookAddress ==. val ia) rmdups :: Ord a => [a] -> [a] rmdups = map head . group . sort