Add base addressbook to GUI #102

Merged
pitmutt merged 21 commits from rvv041 into milestone3 2024-09-13 11:39:59 +00:00
2 changed files with 57 additions and 35 deletions
Showing only changes of commit 1931098ee9 - Show all commits

View file

@ -51,10 +51,10 @@ import Zenith.DB
import Zenith.GUI.Theme
import Zenith.Scanner (processTx, updateConfs)
import Zenith.Types
( ZcashNetDB
( ZcashNetDB
)
import Zenith.Types
hiding
hiding
( ZcashAddress(..)
)
import Zenith.Utils
@ -68,6 +68,7 @@ import Zenith.Utils
, isValidString
, padWithZero
, getZenithPath
, isEmpty
)
data AppEvent
@ -122,7 +123,9 @@ data AppEvent
| CloseMsgAB
| CheckValidAddress !T.Text
| CheckValidDescrip !T.Text
| ShowMessage !T.Text
| SaveNewABEntry
| ShowMessage !T.Text
deriving (Eq, Show)
data AppModel = AppModel
@ -815,7 +818,7 @@ buildUI wenv model = widgetTree
(hstack
[
label
(T.pack $
(T.pack $
padWithZero 3 $
show (fromSqlKey (entityKey ab))) `styleBasic` [textFont "Bold"]
, spacer
@ -855,12 +858,11 @@ buildUI wenv model = widgetTree
]
]
, spacer
, hstack [
button "Save" (saveAddrBook
(ZcashNetDB (model ^. network))
(model ^. abdescrip)
(model ^. abaddress)) `nodeEnabled`
, hstack
[ button "Save" SaveNewABEntry `nodeEnabled`
((model ^. abAddressValid) && (model ^. abDescripValid))
, spacer
, button "Cancel" CloseNewAdrBook `nodeEnabled` True
]
]
msgAdrBookOverlay=
@ -945,21 +947,6 @@ 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
@ -1201,12 +1188,19 @@ handleEvent wenv node model evt =
(i < (fromIntegral (model ^. balance) / 100000000.0))
]
ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing]
-- |
-- | Address Book Events
-- |
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]
CloseNewAdrBook -> [Model $ model & newAdrBkEntry .~ False]
CloseNewAdrBook -> do
[Model $ model & newAdrBkEntry .~ False]
SaveNewABEntry ->
[ Task $ saveAddrBook (model ^. configuration) (ZcashNetDB (model ^. network)) (model ^. abdescrip) (model ^. abaddress)
]
NotImplemented -> [Model $ model & msgAB ?~ "Function not implemented..." & menuPopup .~ False]
CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False]
ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False]
@ -1297,6 +1291,36 @@ handleEvent wenv node model evt =
Just _ -> do
wL <- getWallets pool (model ^. network)
return $ LoadWallets wL
-- |
-- | Address Book -> save new entry into database
-- |
saveAddrBook :: Config -> ZcashNetDB -> T.Text -> T.Text -> IO AppEvent
saveAddrBook config n d a = do
let dbPath = c_dbPath config
pool <- runNoLoggingT $ initPool dbPath
res <-
liftIO $
saveAdrsInAdrBook pool $
AddressBook
n
d
a
case res of
Nothing -> return $ ShowMessage "Error saving the AddressBook entry..."
Just _ -> loadABList config (model ^. network)
-- |
-- |
-- |
loadABList :: Config -> ZcashNet -> IO AppEvent
loadABList config n = do
let dbPath = c_dbPath config
pool <- runNoLoggingT $ initPool dbPath
abList <- getAdrBook pool n
if isEmpty abList
then return $ ShowMessage "Error loading the AddressBook list..."
else do
model & abaddressList ?~ abList
return $ ShowMessage "AddressBook loaded successfully!!!"
scanZebra :: T.Text -> T.Text -> Int -> (AppEvent -> IO ()) -> IO ()
scanZebra dbPath zHost zPort sendMsg = do
@ -1463,9 +1487,7 @@ 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
@ -1476,9 +1498,7 @@ 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
@ -1492,7 +1512,7 @@ runZenithGUI config = do
False
False
Nothing
""
hD
False
False
""
@ -1501,7 +1521,6 @@ runZenithGUI config = do
False
abList
Nothing
-- hD
startApp model handleEvent buildUI (params hD)
Left e -> do
initDb dbFilePath
@ -1547,7 +1566,7 @@ runZenithGUI config = do
False
False
Nothing
""
hD
False
False
""
@ -1556,7 +1575,6 @@ runZenithGUI config = do
False
[]
Nothing
-- hD
startApp model handleEvent buildUI (params hD)
where
params hd =

View file

@ -157,4 +157,8 @@ padWithZero :: Int -> String -> String
padWithZero n s
| (length s) >= n = s
| otherwise = padWithZero n ("0" ++ s)
isEmpty :: [a] -> Bool
isEmpty [] = True
isEmpty _ = False