RPC Server #103

Merged
pitmutt merged 129 commits from rav001 into milestone3 2024-11-21 15:30:22 +00:00
Showing only changes of commit 53eac75aa5 - Show all commits

View file

@ -164,7 +164,6 @@ makeLenses ''AdrBookEntry
data ShDshEntry = ShDshEntry data ShDshEntry = ShDshEntry
{ _totalTransparent :: !Float { _totalTransparent :: !Float
, _totalShielded :: !Float , _totalShielded :: !Float
, _shieldOp :: !ShieldDeshieldOp
, _shAmt :: !Float , _shAmt :: !Float
} deriving (Show) } deriving (Show)
@ -182,7 +181,8 @@ data DialogType
| AdrBookForm | AdrBookForm
| AdrBookUpdForm | AdrBookUpdForm
| AdrBookDelForm | AdrBookDelForm
| ShieldDeshieldForm | DeshieldForm
| ShieldForm
data DisplayType data DisplayType
= AddrDisplay = AddrDisplay
@ -231,7 +231,8 @@ data State = State
, _abCurAdrs :: !T.Text -- used for address book CRUD operations , _abCurAdrs :: !T.Text -- used for address book CRUD operations
, _sentTx :: !(Maybe HexString) , _sentTx :: !(Maybe HexString)
, _unconfBalance :: !Integer , _unconfBalance :: !Integer
, _shdshForm :: !(Form ShDshEntry () Name) , _deshieldForm :: !(Form ShDshEntry () Name)
, _shieldForm :: !(Form ShDshEntry () Name)
} }
makeLenses ''State makeLenses ''State
@ -290,7 +291,8 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
,C.hCenter ,C.hCenter
(hBox (hBox
[ capCommand2 "Address " "B" "ook" [ capCommand2 "Address " "B" "ook"
, capCommand2 "Shield/" "D" "eshield" , capCommand2 "s" "H" "ield"
, capCommand "D" "e-shield"
, capCommand "Q" "uit" , capCommand "Q" "uit"
, capCommand "?" " Help" , capCommand "?" " Help"
, str $ show (st ^. timer) , str $ show (st ^. timer)
@ -420,10 +422,16 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
(renderForm (st ^. txForm) <=> (renderForm (st ^. txForm) <=>
C.hCenter C.hCenter
(hBox [capCommand "" "Send", capCommand "<esc> " "Cancel"])) (hBox [capCommand "" "Send", capCommand "<esc> " "Cancel"]))
ShieldDeshieldForm -> DeshieldForm ->
D.renderDialog D.renderDialog
(D.dialog (Just (str " Shield / De-Shield ")) Nothing 50) (D.dialog (Just (str " De-Shield Zec ")) Nothing 50)
(renderForm (st ^. shdshForm) <=> (renderForm (st ^. deshieldForm) <=>
C.hCenter
(hBox [capCommand "P" "roceed", capCommand "<esc> " "Cancel"]))
ShieldForm ->
D.renderDialog
(D.dialog (Just (str " Shield Zec ")) Nothing 50)
(renderForm (st ^. shieldForm) <=>
C.hCenter C.hCenter
(hBox [capCommand "P" "roceed", capCommand "<esc> " "Cancel"])) (hBox [capCommand "P" "roceed", capCommand "<esc> " "Cancel"]))
Blank -> emptyWidget Blank -> emptyWidget
@ -669,8 +677,8 @@ mkSendForm bal =
label s w = label s w =
padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w
mkshieldDeshieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name mkDeshieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name
mkshieldDeshieldForm bal = mkDeshieldForm bal =
newForm newForm
[ label "Total Transp. : " @@= [ label "Total Transp. : " @@=
editShowableFieldWithValidate totalTransparent TotalTranspField (isAmountValid bal) editShowableFieldWithValidate totalTransparent TotalTranspField (isAmountValid bal)
@ -685,6 +693,18 @@ mkshieldDeshieldForm bal =
label s w = label s w =
padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w
mkShieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name
mkShieldForm bal =
newForm
[ label "Amount to Shield: " @@=
editShowableFieldWithValidate shAmt AmtField (isAmountValid bal)
]
where
isAmountValid :: Integer -> Float -> Bool
isAmountValid b i = (fromIntegral b / 100000000.0) >= i
label s w =
padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w
mkNewABForm :: AdrBookEntry -> Form AdrBookEntry e Name mkNewABForm :: AdrBookEntry -> Form AdrBookEntry e Name
mkNewABForm = mkNewABForm =
newForm newForm
@ -933,7 +953,8 @@ appEvent (BT.AppEvent t) = do
AdrBookForm -> return () AdrBookForm -> return ()
AdrBookUpdForm -> return () AdrBookUpdForm -> return ()
AdrBookDelForm -> return () AdrBookDelForm -> return ()
ShieldDeshieldForm -> return () DeshieldForm -> return ()
ShieldForm -> return ()
Blank -> do Blank -> do
if s ^. timer == 90 if s ^. timer == 90
then do then do
@ -1182,14 +1203,14 @@ appEvent (BT.VtyEvent e) = do
setFieldValid setFieldValid
(isRecipientValidGUI (fs ^. policyField) (fs ^. sendTo)) (isRecipientValidGUI (fs ^. policyField) (fs ^. sendTo))
RecField RecField
ShieldDeshieldForm -> do DeshieldForm -> do
case e of case e of
V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank
ev -> ev ->
BT.zoom shdshForm $ do BT.zoom deshieldForm $ do
handleFormEvent (BT.VtyEvent ev) handleFormEvent (BT.VtyEvent ev)
-- fs <- BT.gets formState -- fs <- BT.gets formState
-- ev -> BT.zoom shdshForm $ L.handleListEvent ev -- ev -> BT.zoom deshieldForm $ L.handleListEvent ev
AdrBook -> do AdrBook -> do
case e of case e of
V.EvKey (V.KChar 'x') [] -> V.EvKey (V.KChar 'x') [] ->
@ -1400,7 +1421,9 @@ appEvent (BT.VtyEvent e) = do
V.EvKey (V.KChar 'b') [] -> V.EvKey (V.KChar 'b') [] ->
BT.modify $ set dialogBox AdrBook BT.modify $ set dialogBox AdrBook
V.EvKey (V.KChar 'd') [] -> V.EvKey (V.KChar 'd') [] ->
BT.modify $ set dialogBox ShieldDeshieldForm BT.modify $ set dialogBox DeshieldForm
V.EvKey (V.KChar 'h') [] ->
BT.modify $ set dialogBox ShieldForm
ev -> ev ->
case r of case r of
Just AList -> Just AList ->
@ -1539,7 +1562,8 @@ runZenithTUI config = do
"" ""
Nothing Nothing
uBal uBal
(mkshieldDeshieldForm 0 (ShDshEntry 0 0 Shield 0.0 )) (mkDeshieldForm 0 (ShDshEntry 0 0 0.0 ))
(mkShieldForm 0 (ShDshEntry 0 0 0.0 ))
Left _e -> do Left _e -> do
print $ print $
"No Zebra node available on port " <> "No Zebra node available on port " <>