Milestone 3: RPC server, ZIP-320 #104
2 changed files with 83 additions and 5 deletions
|
@ -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
|
||||
, 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
|
||||
""
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue