Add base addressbook to GUI #102

Merged
pitmutt merged 21 commits from rvv041 into milestone3 2024-09-13 11:39:59 +00:00
2 changed files with 83 additions and 5 deletions
Showing only changes of commit cdd28d2184 - Show all commits

View file

@ -58,6 +58,7 @@ import Zenith.Utils
, parseAddress
, showAddress
, validBarValue
, validateAddressBool
)
data AppEvent
@ -105,7 +106,11 @@ data AppEvent
| ShowTxId !T.Text
| ShowAdrBook
| CloseAdrBook
| NewAdrBkEntry
| CloseNewAdrBook
| NotImplemented
| CloseMsgAB
| CheckValidAddress !T.Text
deriving (Eq, Show)
data AppModel = AppModel
@ -149,6 +154,11 @@ data AppModel = AppModel
, _showId :: !(Maybe T.Text)
, _home :: !FilePath
, _showAdrBook :: !Bool
, _newAdrBkEntry :: !Bool
, _abdescrip :: !(Maybe T.Text)
, _abaddress :: !T.Text
, _abAddressValid :: !Bool
, _msgAB :: !(Maybe T.Text)
} deriving (Eq, Show)
makeLenses ''AppModel
@ -191,7 +201,8 @@ buildUI wenv model = widgetTree
, msgOverlay `nodeVisible` isJust (model ^. msg)
, modalOverlay `nodeVisible` isJust (model ^. modalMsg)
, adrbookOverlay `nodeVisible` model ^. showAdrBook
, msgAdrBookOverlay `nodeVisible` model ^. notImplemented
, newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry
, msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB)
]
mainWindow =
vstack
@ -769,7 +780,7 @@ buildUI wenv model = widgetTree
[bgColor btnColor, radius 2, padding 3]
, spacer
pitmutt marked this conversation as resolved Outdated

This is unnecessary, the event can be used directly

This is unnecessary, the event can be used directly
, hstack [
button "New" notImplemented
button "New" NewAdrBkEntry
, spacer
, button "Edit" notImplemented
, spacer
@ -777,6 +788,53 @@ buildUI wenv model = widgetTree
]
]
newAdrBkOverlay =
alert CloseNewAdrBook $
vstack
[ box_
[]
(label "New Address Book Entry" `styleBasic`
[textFont "Bold", textSize 10, textColor white]) `styleBasic`
[bgColor btnColor, radius 2, padding 3]
, spacer
, hstack
[ label "Description: " `styleBasic` [width 80]
, spacer
, textField_ sendRecipient [onChange CheckRecipient] `styleBasic`
[ width 320
-- , styleIf
-- (not $ model ^. recipientValid)
-- (textColor red)
]
]
, spacer
, hstack
[ label "Address:" `styleBasic` [width 50]
, spacer
, textField_ abaddress [onChange CheckValidAddress] `styleBasic`
[ width 350
, styleIf
(not $ model ^. abAddressValid)
(textColor red)
]
]
, spacer
, hstack [
button "Save" NotImplemented `nodeEnabled`
(model ^. abAddressValid)
]
]
msgAdrBookOverlay=
alert CloseMsgAB $
hstack
[ filler
, remixIcon remixErrorWarningFill `styleBasic`
[textSize 32, textColor btnColor] `nodeVisible`
(model ^. inError)
, spacer
, label $ fromMaybe "" (model ^. msgAB)
, filler
]
notImplemented = NotImplemented
@ -1089,9 +1147,13 @@ handleEvent wenv node model evt =
(i < (fromIntegral (model ^. balance) / 100000000.0))
]
ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing]
CheckValidAddress a -> [Model $ model & abAddressValid .~ isRecipientValid a]
ShowAdrBook -> [Model $ model & showAdrBook .~ True & menuPopup .~ False]
CloseAdrBook -> [Model $ model & showAdrBook .~ False]
NotImplemented -> [Model $ model & msg ?~ "Function not implemented..." & menuPopup .~ False & modalMsg .~ Nothing]
NewAdrBkEntry -> [Model $ model & newAdrBkEntry .~ True & menuPopup .~ False]
CloseNewAdrBook -> [Model $ model & newAdrBkEntry .~ False]
NotImplemented -> [Model $ model & msgAB ?~ "Function not implemented..." & menuPopup .~ False]
CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False]
where
currentWallet =
if null (model ^. wallets)
@ -1375,6 +1437,11 @@ runZenithGUI config = do
Nothing
""
pitmutt marked this conversation as resolved Outdated

@reneve Your new fields in the state should be after the hD variable, not before

@reneve Your new fields in the state should be after the `hD` variable, not before
False
False
Nothing
""
False
Nothing
-- hD
startApp model handleEvent buildUI (params hD)
Left e -> do
@ -1423,6 +1490,11 @@ runZenithGUI config = do
Nothing
""
False
False
Nothing
""
False
Nothing
-- hD
startApp model handleEvent buildUI (params hD)
where

View file

@ -84,6 +84,13 @@ validateAddress txt --(tReg || sReg && isJust chk) || (uReg && isJust chk)
chk = isJust $ isValidUnifiedAddress $ E.encodeUtf8 txt
chkS = isValidShieldedAddress $ E.encodeUtf8 txt
-- | Return True if Address is valid
validateAddressBool :: T.Text -> Bool
validateAddressBool a = do
case (validateAddress a) of
Nothing -> False
_ -> True
-- | Copy an address to the clipboard
copyAddress :: ZcashAddress -> IO ()
copyAddress a =
@ -94,8 +101,7 @@ copyAddress a =
-- | Get current user and build zenith path
getZenithPath :: IO String
getZenithPath = do
d <- getHomeDirectory
let homeDirectory = d
homeDirectory <- getHomeDirectory
return (homeDirectory ++ "/Zenith/")
-- | Bound a value to the 0..1 range, used for progress reporting on UIs