rvv041 - AddressBook main window - address description list ready

New Address Entry form - Description and Address fields ready
This commit is contained in:
Rene V. Vergara A. 2024-08-28 21:21:05 -04:00
parent 6875917ec7
commit 67d334a60b
2 changed files with 68 additions and 19 deletions

View file

@ -59,6 +59,7 @@ import Zenith.Utils
, showAddress , showAddress
, validBarValue , validBarValue
, validateAddressBool , validateAddressBool
, isValidString
) )
data AppEvent data AppEvent
@ -104,13 +105,15 @@ data AppEvent
| CheckRecipient !T.Text | CheckRecipient !T.Text
| CheckAmount !Float | CheckAmount !Float
| ShowTxId !T.Text | ShowTxId !T.Text
| LoadAbList ![Entity AddressBook]
| ShowAdrBook | ShowAdrBook
| CloseAdrBook | CloseAdrBook
| NewAdrBkEntry | NewAdrBkEntry
| CloseNewAdrBook | CloseNewAdrBook
| NotImplemented | NotImplemented
| CloseMsgAB | CloseMsgAB
| CheckValidAddress !T.Text | CheckValidAddress !T.Text
| CheckValidDescrip !T.Text
deriving (Eq, Show) deriving (Eq, Show)
data AppModel = AppModel data AppModel = AppModel
@ -155,9 +158,11 @@ data AppModel = AppModel
, _home :: !FilePath , _home :: !FilePath
, _showAdrBook :: !Bool , _showAdrBook :: !Bool
, _newAdrBkEntry :: !Bool , _newAdrBkEntry :: !Bool
, _abdescrip :: !(Maybe T.Text) , _abdescrip :: !T.Text
, _abaddress :: !T.Text , _abaddress :: !T.Text
, _abAddressValid :: !Bool , _abAddressValid :: !Bool
, _abDescripValid :: !Bool
, _abaddressList :: ![Entity AddressBook]
, _msgAB :: !(Maybe T.Text) , _msgAB :: !(Maybe T.Text)
} deriving (Eq, Show) } deriving (Eq, Show)
@ -778,16 +783,35 @@ buildUI wenv model = widgetTree
(label "Address Book" `styleBasic` (label "Address Book" `styleBasic`
[textFont "Bold", textSize 12, textColor white]) `styleBasic` [textFont "Bold", textSize 12, textColor white]) `styleBasic`
[bgColor btnColor, radius 2, padding 3] [bgColor btnColor, radius 2, padding 3]
, boxShadow $
box_
[alignMiddle]
(vstack
[ vscroll (vstack (zipWith abookRow [0 ..] (model ^. abaddressList))) `nodeKey` "txScroll"
]) `styleBasic`
[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
, button "Copy" notImplemented , button "Copy" notImplemented
]
]
] ]
abookRow :: Int -> Entity AddressBook -> WidgetNode AppModel AppEvent
abookRow idx ab =
box_
[onClick $ ShowTx idx, alignLeft]
(hstack
[
(label "Descr: ") `styleBasic` [textFont "Bold"]
, spacer
, label
(T.pack $
show (addressBookAbdescrip $ entityVal ab))
]) `styleBasic`
[padding 2, borderB 1 gray]
newAdrBkOverlay = newAdrBkOverlay =
alert CloseNewAdrBook $ alert CloseNewAdrBook $
vstack vstack
@ -800,11 +824,11 @@ buildUI wenv model = widgetTree
, hstack , hstack
[ label "Description: " `styleBasic` [width 80] [ label "Description: " `styleBasic` [width 80]
, spacer , spacer
, textField_ sendRecipient [onChange CheckRecipient] `styleBasic` , textField_ abdescrip [onChange CheckValidDescrip] `styleBasic`
[ width 320 [ width 320
-- , styleIf , styleIf
-- (not $ model ^. recipientValid) (not $ model ^. abDescripValid)
-- (textColor red) (textColor red)
] ]
] ]
, spacer , spacer
@ -818,11 +842,11 @@ buildUI wenv model = widgetTree
(textColor red) (textColor red)
] ]
] ]
, spacer , spacer
, hstack [ , hstack [
button "Save" NotImplemented `nodeEnabled` button "Save" NotImplemented `nodeEnabled`
(model ^. abAddressValid) ((model ^. abAddressValid) && (model ^. abDescripValid))
] ]
] ]
msgAdrBookOverlay= msgAdrBookOverlay=
alert CloseMsgAB $ alert CloseMsgAB $
@ -1148,6 +1172,7 @@ handleEvent wenv node model evt =
] ]
ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing] ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing]
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] 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]
@ -1391,6 +1416,7 @@ runZenithGUI config = do
if not (null accList) if not (null accList)
then getUnconfirmedBalance pool $ entityKey $ head accList then getUnconfirmedBalance pool $ entityKey $ head accList
else return 0 else return 0
abList <- getAdrBook pool (zgb_net chainInfo)
let model = let model =
AppModel AppModel
config config
@ -1421,7 +1447,7 @@ runZenithGUI config = do
"" ""
(SaveAddress (if not (null accList) (SaveAddress (if not (null accList)
then Just (head accList) then Just (head accList)
else Nothing ) ) else Nothing ) )
False False
False False
Nothing Nothing
@ -1438,9 +1464,11 @@ runZenithGUI config = do
"" ""
False False
False False
Nothing ""
"" ""
False False
False
abList
Nothing Nothing
-- hD -- hD
startApp model handleEvent buildUI (params hD) startApp model handleEvent buildUI (params hD)
@ -1491,10 +1519,12 @@ runZenithGUI config = do
"" ""
False False
False False
Nothing ""
"" ""
False False
Nothing False
[]
Nothing
-- hD -- hD
startApp model handleEvent buildUI (params hD) startApp model handleEvent buildUI (params hD)
where where

View file

@ -9,6 +9,7 @@ import Data.Ord (clamp)
import Data.Scientific (Scientific(..), scientific) import Data.Scientific (Scientific(..), scientific)
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Encoding as E import qualified Data.Text.Encoding as E
import Data.Char (isAlphaNum, isSpace)
import System.Directory import System.Directory
import System.Process (createProcess_, shell) import System.Process (createProcess_, shell)
import Text.Regex.Posix import Text.Regex.Posix
@ -134,3 +135,21 @@ parseAddress a znet =
Just a3 -> Just a3 ->
Just $ UnifiedAddress znet Nothing Nothing (Just $ ta_receiver a3) Just $ UnifiedAddress znet Nothing Nothing (Just $ ta_receiver a3)
Nothing -> Nothing Nothing -> Nothing
isValidContent :: String -> Bool
isValidContent [] = False -- an empty string is invalid
isValidContent (x:xs)
| not (isAlphaNum x ) = False -- string must start with an alphanumeric character
| otherwise = allValidChars xs -- process the rest of the string
where
allValidChars :: String -> Bool
allValidChars [] = True -- if we got here, string is valid
allValidChars (y:ys)
| isAlphaNum y || isSpace y = allValidChars ys -- char is valid, continue
| otherwise = False -- found an invalid character, return false
isValidString :: T.Text -> Bool
isValidString c = do
let a = T.unpack c
isValidContent a