Add base addressbook to GUI #102
1 changed files with 45 additions and 12 deletions
|
@ -119,6 +119,8 @@ data AppEvent
|
||||||
| CheckValidDescrip !T.Text
|
| CheckValidDescrip !T.Text
|
||||||
| SaveNewABEntry
|
| SaveNewABEntry
|
||||||
| ShowMessage !T.Text
|
| ShowMessage !T.Text
|
||||||
|
| ShowABAddress !T.Text !T.Text
|
||||||
|
| CloseShowABAddress
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
data AppModel = AppModel
|
data AppModel = AppModel
|
||||||
|
@ -169,6 +171,7 @@ data AppModel = AppModel
|
||||||
, _abDescripValid :: !Bool
|
, _abDescripValid :: !Bool
|
||||||
, _abaddressList :: ![Entity AddressBook]
|
, _abaddressList :: ![Entity AddressBook]
|
||||||
, _msgAB :: !(Maybe T.Text)
|
, _msgAB :: !(Maybe T.Text)
|
||||||
|
, _showABAddress :: !Bool
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
makeLenses ''AppModel
|
makeLenses ''AppModel
|
||||||
|
@ -212,6 +215,9 @@ buildUI wenv model = widgetTree
|
||||||
, modalOverlay `nodeVisible` isJust (model ^. modalMsg)
|
, modalOverlay `nodeVisible` isJust (model ^. modalMsg)
|
||||||
, adrbookOverlay `nodeVisible` model ^. showAdrBook
|
, adrbookOverlay `nodeVisible` model ^. showAdrBook
|
||||||
, newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry
|
, newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry
|
||||||
|
, showABAddressOverlay
|
||||||
|
(model ^. abdescrip)
|
||||||
|
(model ^. abaddress) `nodeVisible` model ^. showABAddress
|
||||||
, msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB)
|
, msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB)
|
||||||
]
|
]
|
||||||
mainWindow =
|
mainWindow =
|
||||||
|
@ -780,6 +786,9 @@ buildUI wenv model = widgetTree
|
||||||
]
|
]
|
||||||
]) `styleBasic`
|
]) `styleBasic`
|
||||||
[padding 2, bgColor white, width 280, borderB 1 gray, borderT 1 gray]
|
[padding 2, bgColor white, width 280, borderB 1 gray, borderT 1 gray]
|
||||||
|
-- |
|
||||||
|
-- | Address Book overlays
|
||||||
|
-- |
|
||||||
adrbookOverlay =
|
adrbookOverlay =
|
||||||
alert CloseAdrBook $
|
alert CloseAdrBook $
|
||||||
vstack
|
vstack
|
||||||
|
@ -809,12 +818,16 @@ buildUI wenv model = widgetTree
|
||||||
abookRow :: Int -> Entity AddressBook -> WidgetNode AppModel AppEvent
|
abookRow :: Int -> Entity AddressBook -> WidgetNode AppModel AppEvent
|
||||||
abookRow idx ab =
|
abookRow idx ab =
|
||||||
box_
|
box_
|
||||||
[onClick $ ShowMessage (addressBookAbaddress $ entityVal ab), alignLeft]
|
[ onClick $ ShowABAddress
|
||||||
|
(addressBookAbdescrip $ entityVal ab)
|
||||||
|
(addressBookAbaddress $ entityVal ab),
|
||||||
|
alignLeft
|
||||||
|
]
|
||||||
(hstack
|
(hstack
|
||||||
[ label (T.pack $ padWithZero 3 $ show (fromSqlKey (entityKey ab))) `styleBasic`
|
[ label (T.pack $ padWithZero 3 $ show (fromSqlKey (entityKey ab))) `styleBasic`
|
||||||
[textFont "Bold"]
|
[textFont "Bold"]
|
||||||
, spacer
|
, spacer
|
||||||
, label (T.pack $ show (addressBookAbdescrip $ entityVal ab))
|
, label (addressBookAbdescrip $ entityVal ab)
|
||||||
]) `styleBasic`
|
]) `styleBasic`
|
||||||
[padding 2, borderB 1 gray]
|
[padding 2, borderB 1 gray]
|
||||||
newAdrBkOverlay =
|
newAdrBkOverlay =
|
||||||
|
@ -851,6 +864,27 @@ buildUI wenv model = widgetTree
|
||||||
, button "Cancel" CloseNewAdrBook `nodeEnabled` True
|
, button "Cancel" CloseNewAdrBook `nodeEnabled` True
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
showABAddressOverlay abd aba =
|
||||||
|
alert CloseShowABAddress $
|
||||||
|
vstack
|
||||||
|
[ box_
|
||||||
|
[]
|
||||||
|
(label "Address Book Entry" `styleBasic`
|
||||||
|
[textFont "Bold", textColor white, textSize 12, padding 3]) `styleBasic`
|
||||||
|
[bgColor btnColor, radius 2, padding 3]
|
||||||
|
, spacer
|
||||||
|
, hstack
|
||||||
|
[ filler
|
||||||
|
, label_ (txtWrapN abd 64) [multiline]
|
||||||
|
, filler
|
||||||
|
]
|
||||||
|
, spacer
|
||||||
|
, hstack
|
||||||
|
[ filler
|
||||||
|
, label_ (txtWrapN aba 64) [multiline]
|
||||||
|
, filler
|
||||||
|
]
|
||||||
|
]
|
||||||
msgAdrBookOverlay =
|
msgAdrBookOverlay =
|
||||||
alert CloseMsgAB $
|
alert CloseMsgAB $
|
||||||
hstack
|
hstack
|
||||||
|
@ -862,7 +896,6 @@ buildUI wenv model = widgetTree
|
||||||
, label_ (txtWrapN (fromMaybe "" (model ^. msgAB)) 64) [multiline]
|
, label_ (txtWrapN (fromMaybe "" (model ^. msgAB)) 64) [multiline]
|
||||||
, filler
|
, filler
|
||||||
]
|
]
|
||||||
|
|
||||||
notImplemented = NotImplemented
|
notImplemented = NotImplemented
|
||||||
|
|
||||||
generateQRCodes :: Config -> IO ()
|
generateQRCodes :: Config -> IO ()
|
||||||
|
@ -1200,12 +1233,16 @@ handleEvent wenv node model evt =
|
||||||
abList <- getAdrBook dbPool $ model ^. network
|
abList <- getAdrBook dbPool $ model ^. network
|
||||||
return $ LoadAbList abList
|
return $ LoadAbList abList
|
||||||
]
|
]
|
||||||
|
ShowABAddress d a ->
|
||||||
|
[ Model $ model & abdescrip .~ d & abaddress .~ a & showABAddress .~ True & menuPopup .~ False ]
|
||||||
|
CloseShowABAddress ->
|
||||||
|
[Model $ model & showABAddress .~ False & inError .~ False]
|
||||||
|
ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False]
|
||||||
NotImplemented ->
|
NotImplemented ->
|
||||||
[ Model $
|
[ Model $
|
||||||
model & msgAB ?~ "Function not implemented..." & menuPopup .~ False
|
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]
|
|
||||||
LoadAbList a -> [Model $ model & abaddressList .~ a]
|
LoadAbList a -> [Model $ model & abaddressList .~ a]
|
||||||
where
|
where
|
||||||
currentWallet =
|
currentWallet =
|
||||||
|
@ -1299,19 +1336,13 @@ handleEvent wenv node model evt =
|
||||||
-- |
|
-- |
|
||||||
saveAddrBook :: Config -> ZcashNetDB -> T.Text -> T.Text -> IO AppEvent
|
saveAddrBook :: Config -> ZcashNetDB -> T.Text -> T.Text -> IO AppEvent
|
||||||
saveAddrBook config n d a = do
|
saveAddrBook config n d a = do
|
||||||
let dbPath = c_dbPath config
|
pool <- runNoLoggingT $ initPool $ 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
|
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 n = do
|
|
||||||
-- 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
|
||||||
|
@ -1519,6 +1550,7 @@ runZenithGUI config = do
|
||||||
False
|
False
|
||||||
abList
|
abList
|
||||||
Nothing
|
Nothing
|
||||||
|
False
|
||||||
startApp model handleEvent buildUI (params hD)
|
startApp model handleEvent buildUI (params hD)
|
||||||
Left e -> do
|
Left e -> do
|
||||||
initDb dbFilePath
|
initDb dbFilePath
|
||||||
|
@ -1573,6 +1605,7 @@ runZenithGUI config = do
|
||||||
False
|
False
|
||||||
[]
|
[]
|
||||||
Nothing
|
Nothing
|
||||||
|
False
|
||||||
startApp model handleEvent buildUI (params hD)
|
startApp model handleEvent buildUI (params hD)
|
||||||
where
|
where
|
||||||
params hd =
|
params hd =
|
||||||
|
|
Loading…
Reference in a new issue