rvv041 - AddressBook - Save new address book entry problem

This commit is contained in:
Rene V. Vergara A. 2024-09-02 09:40:57 -04:00
parent 73ad2f0eb3
commit f8fa5a005a

View file

@ -50,7 +50,13 @@ import Zenith.Core
import Zenith.DB import Zenith.DB
import Zenith.GUI.Theme import Zenith.GUI.Theme
import Zenith.Scanner (processTx, updateConfs) import Zenith.Scanner (processTx, updateConfs)
import Zenith.Types hiding (ZcashAddress(..)) import Zenith.Types
( ZcashNetDB
)
import Zenith.Types
hiding
( ZcashAddress(..)
)
import Zenith.Utils import Zenith.Utils
( displayAmount ( displayAmount
, isRecipientValid , isRecipientValid
@ -61,6 +67,7 @@ import Zenith.Utils
, validateAddressBool , validateAddressBool
, isValidString , isValidString
, padWithZero , padWithZero
, getZenithPath
) )
data AppEvent data AppEvent
@ -115,6 +122,7 @@ data AppEvent
| CloseMsgAB | CloseMsgAB
| CheckValidAddress !T.Text | CheckValidAddress !T.Text
| CheckValidDescrip !T.Text | CheckValidDescrip !T.Text
| ShowMessage !T.Text
deriving (Eq, Show) deriving (Eq, Show)
data AppModel = AppModel data AppModel = AppModel
@ -848,7 +856,10 @@ buildUI wenv model = widgetTree
] ]
, spacer , spacer
, hstack [ , hstack [
button "Save" NotImplemented `nodeEnabled` button "Save" (saveAddrBook
(ZcashNetDB (model ^. network))
(model ^. abdescrip)
(model ^. abaddress)) `nodeEnabled`
((model ^. abAddressValid) && (model ^. abDescripValid)) ((model ^. abAddressValid) && (model ^. abDescripValid))
] ]
] ]
@ -934,6 +945,21 @@ generateQRCodes config = do
Orchard -> Just $ (T.append "zcash:" . getUA . walletAddressUAddress) w Orchard -> Just $ (T.append "zcash:" . getUA . walletAddressUAddress) w
Sprout -> Nothing 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 :: handleEvent ::
WidgetEnv AppModel AppEvent WidgetEnv AppModel AppEvent
-> WidgetNode AppModel AppEvent -> WidgetNode AppModel AppEvent
@ -1183,6 +1209,7 @@ handleEvent wenv node model evt =
CloseNewAdrBook -> [Model $ model & newAdrBkEntry .~ False] CloseNewAdrBook -> [Model $ model & newAdrBkEntry .~ False]
NotImplemented -> [Model $ model & msgAB ?~ "Function not implemented..." & menuPopup .~ False] NotImplemented -> [Model $ model & msgAB ?~ "Function not implemented..." & menuPopup .~ False]
CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False] CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False]
ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False]
where where
currentWallet = currentWallet =
if null (model ^. wallets) if null (model ^. wallets)