Compare commits

...

2 commits

2 changed files with 64 additions and 15 deletions

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,8 @@ import Zenith.Utils
, validateAddressBool , validateAddressBool
, isValidString , isValidString
, padWithZero , padWithZero
, getZenithPath
, isEmpty
) )
data AppEvent data AppEvent
@ -115,6 +123,9 @@ data AppEvent
| CloseMsgAB | CloseMsgAB
| CheckValidAddress !T.Text | CheckValidAddress !T.Text
| CheckValidDescrip !T.Text | CheckValidDescrip !T.Text
| SaveNewABEntry
| ShowMessage !T.Text
deriving (Eq, Show) deriving (Eq, Show)
data AppModel = AppModel data AppModel = AppModel
@ -847,9 +858,11 @@ buildUI wenv model = widgetTree
] ]
] ]
, spacer , spacer
, hstack [ , hstack
button "Save" NotImplemented `nodeEnabled` [ button "Save" SaveNewABEntry `nodeEnabled`
((model ^. abAddressValid) && (model ^. abDescripValid)) ((model ^. abAddressValid) && (model ^. abDescripValid))
, spacer
, button "Cancel" CloseNewAdrBook `nodeEnabled` True
] ]
] ]
msgAdrBookOverlay= msgAdrBookOverlay=
@ -1175,14 +1188,22 @@ handleEvent wenv node model evt =
(i < (fromIntegral (model ^. balance) / 100000000.0)) (i < (fromIntegral (model ^. balance) / 100000000.0))
] ]
ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing] ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing]
-- |
-- | Address Book Events
-- |
CheckValidAddress a -> [Model $ model & abAddressValid .~ isRecipientValid a] CheckValidAddress a -> [Model $ model & abAddressValid .~ isRecipientValid a]
CheckValidDescrip a -> [Model $ model & abDescripValid .~ isValidString a] CheckValidDescrip a -> [Model $ model & abDescripValid .~ isValidString a]
ShowAdrBook -> [Model $ model & showAdrBook .~ True & menuPopup .~ False] ShowAdrBook -> [Model $ model & showAdrBook .~ True & menuPopup .~ False]
CloseAdrBook -> [Model $ model & showAdrBook .~ False] CloseAdrBook -> [Model $ model & showAdrBook .~ False]
NewAdrBkEntry -> [Model $ model & newAdrBkEntry .~ True & menuPopup .~ 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] 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)
@ -1270,6 +1291,36 @@ handleEvent wenv node model evt =
Just _ -> do Just _ -> do
wL <- getWallets pool (model ^. network) wL <- getWallets pool (model ^. network)
return $ LoadWallets wL 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 :: T.Text -> T.Text -> Int -> (AppEvent -> IO ()) -> IO ()
scanZebra dbPath zHost zPort sendMsg = do scanZebra dbPath zHost zPort sendMsg = do
@ -1436,9 +1487,7 @@ runZenithGUI config = do
Nothing Nothing
True True
bal bal
(if unconfBal == 0 (if unconfBal == 0 then Nothing else Just unconfBal)
then Nothing
else Just unconfBal)
Orchard Orchard
qr qr
False False
@ -1449,9 +1498,7 @@ runZenithGUI config = do
Nothing Nothing
"" ""
"" ""
(SaveAddress (if not (null accList) (SaveAddress (if not (null accList) then Just (head accList) else Nothing ) )
then Just (head accList)
else Nothing ) )
False False
False False
Nothing Nothing
@ -1465,7 +1512,7 @@ runZenithGUI config = do
False False
False False
Nothing Nothing
"" hD
False False
False False
"" ""
@ -1474,7 +1521,6 @@ runZenithGUI config = do
False False
abList abList
Nothing Nothing
-- hD
startApp model handleEvent buildUI (params hD) startApp model handleEvent buildUI (params hD)
Left e -> do Left e -> do
initDb dbFilePath initDb dbFilePath
@ -1520,7 +1566,7 @@ runZenithGUI config = do
False False
False False
Nothing Nothing
"" hD
False False
False False
"" ""
@ -1529,7 +1575,6 @@ runZenithGUI config = do
False False
[] []
Nothing Nothing
-- hD
startApp model handleEvent buildUI (params hD) startApp model handleEvent buildUI (params hD)
where where
params hd = params hd =

View file

@ -158,3 +158,7 @@ padWithZero n s
| (length s) >= n = s | (length s) >= n = s
| otherwise = padWithZero n ("0" ++ s) | otherwise = padWithZero n ("0" ++ s)
isEmpty :: [a] -> Bool
isEmpty [] = True
isEmpty _ = False