Add base addressbook to GUI #102

Merged
pitmutt merged 21 commits from rvv041 into milestone3 2024-09-13 11:39:59 +00:00
Showing only changes of commit 538216944d - Show all commits

View file

@ -50,25 +50,19 @@ import Zenith.Core
import Zenith.DB
import Zenith.GUI.Theme
import Zenith.Scanner (processTx, updateConfs)
import Zenith.Types
( ZcashNetDB
)
import Zenith.Types
hiding
( ZcashAddress(..)
)
import Zenith.Types hiding (ZcashAddress(..))
import Zenith.Utils
( displayAmount
, getZenithPath
, isEmpty
, isRecipientValid
, isValidString
, jsonNumber
, padWithZero
, parseAddress
, showAddress
, validBarValue
, validateAddressBool
, isValidString
, padWithZero
, getZenithPath
, isEmpty
)
data AppEvent
@ -125,7 +119,6 @@ data AppEvent
| CheckValidDescrip !T.Text
| SaveNewABEntry
| ShowMessage !T.Text
deriving (Eq, Show)
data AppModel = AppModel
@ -799,12 +792,14 @@ buildUI wenv model = widgetTree
box_
[alignMiddle]
(vstack
[ vscroll (vstack (zipWith abookRow [0 ..] (model ^. abaddressList))) `nodeKey` "txScroll"
[ vscroll
(vstack (zipWith abookRow [0 ..] (model ^. abaddressList))) `nodeKey`
"txScroll"
]) `styleBasic`
[radius 2, padding 3, bgColor white]
, spacer
, hstack [
button "New" NewAdrBkEntry
, hstack
[ button "New" NewAdrBkEntry
, spacer
, button "Edit" notImplemented
, spacer
@ -816,15 +811,10 @@ buildUI wenv model = widgetTree
box_
[onClick $ ShowMessage (addressBookAbaddress $ entityVal ab), alignLeft]
(hstack
[
label
(T.pack $
padWithZero 3 $
show (fromSqlKey (entityKey ab))) `styleBasic` [textFont "Bold"]
[ label (T.pack $ padWithZero 3 $ show (fromSqlKey (entityKey ab))) `styleBasic`
[textFont "Bold"]
, spacer
, label
(T.pack $
show (addressBookAbdescrip $ entityVal ab))
, label (T.pack $ show (addressBookAbdescrip $ entityVal ab))
]) `styleBasic`
[padding 2, borderB 1 gray]
newAdrBkOverlay =
@ -841,9 +831,7 @@ buildUI wenv model = widgetTree
, spacer
, textField_ abdescrip [onChange CheckValidDescrip] `styleBasic`
[ width 320
, styleIf
(not $ model ^. abDescripValid)
(textColor red)
, styleIf (not $ model ^. abDescripValid) (textColor red)
]
]
, spacer
@ -852,9 +840,7 @@ buildUI wenv model = widgetTree
, spacer
, textField_ abaddress [onChange CheckValidAddress] `styleBasic`
[ width 350
, styleIf
(not $ model ^. abAddressValid)
(textColor red)
, styleIf (not $ model ^. abAddressValid) (textColor red)
]
]
, spacer
@ -1191,20 +1177,36 @@ handleEvent wenv node model evt =
-- |
-- | Address Book Events
-- |
CheckValidAddress a -> [Model $ model & abAddressValid .~ isRecipientValid a]
CheckValidAddress a ->
[Model $ model & abAddressValid .~ isRecipientValid a]
CheckValidDescrip a -> [Model $ model & abDescripValid .~ isValidString a]
ShowAdrBook -> [Model $ model & showAdrBook .~ True & menuPopup .~ False]
CloseAdrBook -> [Model $ model & showAdrBook .~ False]
NewAdrBkEntry -> [Model $ model & newAdrBkEntry .~ True & menuPopup .~ False]
NewAdrBkEntry ->
[Model $ model & newAdrBkEntry .~ True & menuPopup .~ False]
CloseNewAdrBook -> do
[Model $ model & newAdrBkEntry .~ False]
SaveNewABEntry ->
[ Task $ saveAddrBook (model ^. configuration) (ZcashNetDB (model ^. network)) (model ^. abdescrip) (model ^. abaddress)
, Model $ model & abdescrip .~ "" & abaddress .~ "" & newAdrBkEntry .~ False
[ Task $
saveAddrBook
(model ^. configuration)
(ZcashNetDB (model ^. network))
(model ^. abdescrip)
(model ^. abaddress)
, Model $
model & abdescrip .~ "" & abaddress .~ "" & newAdrBkEntry .~ False
, Task $ do
dbPool <- runNoLoggingT $ initPool $ c_dbPath $ model ^. configuration
abList <- getAdrBook dbPool $ model ^. network
return $ LoadAbList abList
]
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]
ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False]
LoadAbList a -> [Model $ model & abaddressList .~ a]
where
currentWallet =
if null (model ^. wallets)
@ -1299,23 +1301,17 @@ handleEvent wenv node model evt =
saveAddrBook config n d a = do
let dbPath = c_dbPath config
pool <- runNoLoggingT $ initPool dbPath
res <-
liftIO $
saveAdrsInAdrBook pool $
AddressBook
n
d
a
res <- liftIO $ saveAdrsInAdrBook pool $ AddressBook n d a
case res of
Nothing -> return $ ShowMessage "Error saving the AddressBook entry..."
Just _ -> return $ ShowMessage "New Address Book entry added!!"
-- |
-- |
-- |
-- loadABList :: Config -> ZcashNet -> IO AppEvent
-- loadABList config n = do
-- pool <- runNoLoggingT $ initPool $ c_dbPath config
scanZebra :: T.Text -> T.Text -> Int -> (AppEvent -> IO ()) -> IO ()
scanZebra dbPath zHost zPort sendMsg = do
_ <- liftIO $ initDb dbPath
@ -1484,7 +1480,9 @@ runZenithGUI config = do
Nothing
True
bal
(if unconfBal == 0 then Nothing else Just unconfBal)
(if unconfBal == 0
then Nothing
else Just unconfBal)
Orchard
qr
False
@ -1495,7 +1493,10 @@ runZenithGUI config = do
Nothing
""
""
(SaveAddress (if not (null accList) then Just (head accList) else Nothing ) )
(SaveAddress
(if not (null accList)
then Just (head accList)
else Nothing))
False
False
Nothing
@ -1533,8 +1534,8 @@ runZenithGUI config = do
0
[]
0
(Just (
"Couldn't connect to Zebra on " <>
(Just
("Couldn't connect to Zebra on " <>
host <> ":" <> showt port <> ". Check your configuration."))
False
314259000