From f8fa5a005a832c125ee07a2438120d6835775e1a Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Mon, 2 Sep 2024 09:40:57 -0400 Subject: [PATCH] rvv041 - AddressBook - Save new address book entry problem --- src/Zenith/GUI.hs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Zenith/GUI.hs b/src/Zenith/GUI.hs index 1b430d7..1d537ba 100644 --- a/src/Zenith/GUI.hs +++ b/src/Zenith/GUI.hs @@ -50,7 +50,13 @@ import Zenith.Core import Zenith.DB import Zenith.GUI.Theme import Zenith.Scanner (processTx, updateConfs) -import Zenith.Types hiding (ZcashAddress(..)) +import Zenith.Types + ( ZcashNetDB + ) +import Zenith.Types + hiding + ( ZcashAddress(..) + ) import Zenith.Utils ( displayAmount , isRecipientValid @@ -61,6 +67,7 @@ import Zenith.Utils , validateAddressBool , isValidString , padWithZero + , getZenithPath ) data AppEvent @@ -115,6 +122,7 @@ data AppEvent | CloseMsgAB | CheckValidAddress !T.Text | CheckValidDescrip !T.Text + | ShowMessage !T.Text deriving (Eq, Show) data AppModel = AppModel @@ -848,7 +856,10 @@ buildUI wenv model = widgetTree ] , spacer , hstack [ - button "Save" NotImplemented `nodeEnabled` + button "Save" (saveAddrBook + (ZcashNetDB (model ^. network)) + (model ^. abdescrip) + (model ^. abaddress)) `nodeEnabled` ((model ^. abAddressValid) && (model ^. abDescripValid)) ] ] @@ -934,6 +945,21 @@ generateQRCodes config = do Orchard -> Just $ (T.append "zcash:" . getUA . walletAddressUAddress) w Sprout -> Nothing +saveAddrBook :: ZcashNetDB -> T.Text -> T.Text -> AppEvent +saveAddrBook n d a = do + dPath <- liftIO $ getZenithPath + pool <- runNoLoggingT $ initPool $ (T.pack dPath) + res <- + liftIO $ + saveAdrsInAdrBook pool $ + AddressBook + n + d + a + case res of + Nothing -> return $ ShowMessage "Error while saving address book entry" + Just _ -> return $ ShowMessage "New address book entry saved successfully!!" + handleEvent :: WidgetEnv AppModel AppEvent -> WidgetNode AppModel AppEvent @@ -1183,6 +1209,7 @@ handleEvent wenv node model evt = CloseNewAdrBook -> [Model $ model & newAdrBkEntry .~ False] NotImplemented -> [Model $ model & msgAB ?~ "Function not implemented..." & menuPopup .~ False] CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False] + ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False] where currentWallet = if null (model ^. wallets)