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