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
, validBarValue
, validateAddressBool
, isValidString
)
data AppEvent
@ -104,6 +105,7 @@ data AppEvent
| CheckRecipient !T.Text
| CheckAmount !Float
| ShowTxId !T.Text
| LoadAbList ![Entity AddressBook]
| ShowAdrBook
| CloseAdrBook
| NewAdrBkEntry
@ -111,6 +113,7 @@ data AppEvent
| NotImplemented
| CloseMsgAB
| CheckValidAddress !T.Text
| CheckValidDescrip !T.Text
deriving (Eq, Show)
data AppModel = AppModel
@ -155,9 +158,11 @@ data AppModel = AppModel
, _home :: !FilePath
, _showAdrBook :: !Bool
, _newAdrBkEntry :: !Bool
, _abdescrip :: !(Maybe T.Text)
, _abdescrip :: !T.Text
, _abaddress :: !T.Text
, _abAddressValid :: !Bool
, _abDescripValid :: !Bool
, _abaddressList :: ![Entity AddressBook]
, _msgAB :: !(Maybe T.Text)
} deriving (Eq, Show)
@ -778,6 +783,13 @@ buildUI wenv model = widgetTree
(label "Address Book" `styleBasic`
[textFont "Bold", textSize 12, textColor white]) `styleBasic`
[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
, hstack [
button "New" NewAdrBkEntry
@ -785,9 +797,21 @@ buildUI wenv model = widgetTree
, button "Edit" notImplemented
, spacer
, 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 =
alert CloseNewAdrBook $
vstack
@ -800,11 +824,11 @@ buildUI wenv model = widgetTree
, hstack
[ label "Description: " `styleBasic` [width 80]
, spacer
, textField_ sendRecipient [onChange CheckRecipient] `styleBasic`
, textField_ abdescrip [onChange CheckValidDescrip] `styleBasic`
[ width 320
-- , styleIf
-- (not $ model ^. recipientValid)
-- (textColor red)
, styleIf
(not $ model ^. abDescripValid)
(textColor red)
]
]
, spacer
@ -821,7 +845,7 @@ buildUI wenv model = widgetTree
, spacer
, hstack [
button "Save" NotImplemented `nodeEnabled`
(model ^. abAddressValid)
((model ^. abAddressValid) && (model ^. abDescripValid))
]
]
msgAdrBookOverlay=
@ -1148,6 +1172,7 @@ handleEvent wenv node model evt =
]
ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing]
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]
@ -1391,6 +1416,7 @@ runZenithGUI config = do
if not (null accList)
then getUnconfirmedBalance pool $ entityKey $ head accList
else return 0
abList <- getAdrBook pool (zgb_net chainInfo)
let model =
AppModel
config
@ -1438,9 +1464,11 @@ runZenithGUI config = do
""
False
False
Nothing
""
""
False
False
abList
Nothing
-- hD
startApp model handleEvent buildUI (params hD)
@ -1491,9 +1519,11 @@ runZenithGUI config = do
""
False
False
Nothing
""
""
False
False
[]
Nothing
-- hD
startApp model handleEvent buildUI (params hD)

View file

@ -9,6 +9,7 @@ import Data.Ord (clamp)
import Data.Scientific (Scientific(..), scientific)
import qualified Data.Text as T
import qualified Data.Text.Encoding as E
import Data.Char (isAlphaNum, isSpace)
import System.Directory
import System.Process (createProcess_, shell)
import Text.Regex.Posix
@ -134,3 +135,21 @@ parseAddress a znet =
Just a3 ->
Just $ UnifiedAddress znet Nothing Nothing (Just $ ta_receiver a3)
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