Milestone 3: RPC server, ZIP-320 #104
2 changed files with 73 additions and 12 deletions
|
@ -102,6 +102,7 @@ import Zenith.Types
|
||||||
, PrivacyPolicy(..)
|
, PrivacyPolicy(..)
|
||||||
, UnifiedAddressDB(..)
|
, UnifiedAddressDB(..)
|
||||||
, ZcashNetDB(..)
|
, ZcashNetDB(..)
|
||||||
|
, ShieldDeshieldOp(..)
|
||||||
)
|
)
|
||||||
import Zenith.Utils
|
import Zenith.Utils
|
||||||
( displayTaz
|
( displayTaz
|
||||||
|
@ -132,6 +133,8 @@ data Name
|
||||||
| PrivacyLowField
|
| PrivacyLowField
|
||||||
| PrivacyMediumField
|
| PrivacyMediumField
|
||||||
| PrivacyFullField
|
| PrivacyFullField
|
||||||
|
| ShieldField
|
||||||
|
| DeshieldField
|
||||||
deriving (Eq, Show, Ord)
|
deriving (Eq, Show, Ord)
|
||||||
|
|
||||||
data DialogInput = DialogInput
|
data DialogInput = DialogInput
|
||||||
|
@ -156,6 +159,13 @@ data AdrBookEntry = AdrBookEntry
|
||||||
|
|
||||||
makeLenses ''AdrBookEntry
|
makeLenses ''AdrBookEntry
|
||||||
|
|
||||||
|
data ShDshEntry = ShDshEntry
|
||||||
|
{ _shieldOp :: !ShieldDeshieldOp
|
||||||
|
, _shAmt :: !Float
|
||||||
|
} deriving (Show)
|
||||||
|
|
||||||
|
makeLenses ''ShDshEntry
|
||||||
|
|
||||||
data DialogType
|
data DialogType
|
||||||
= WName
|
= WName
|
||||||
| AName
|
| AName
|
||||||
|
@ -168,6 +178,7 @@ data DialogType
|
||||||
| AdrBookForm
|
| AdrBookForm
|
||||||
| AdrBookUpdForm
|
| AdrBookUpdForm
|
||||||
| AdrBookDelForm
|
| AdrBookDelForm
|
||||||
|
| ShieldDeshieldForm
|
||||||
|
|
||||||
data DisplayType
|
data DisplayType
|
||||||
= AddrDisplay
|
= AddrDisplay
|
||||||
|
@ -216,6 +227,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
makeLenses ''State
|
makeLenses ''State
|
||||||
|
@ -263,17 +275,24 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
|
||||||
(C.hCenter
|
(C.hCenter
|
||||||
(str ("Last block seen: " ++ show (st ^. syncBlock) ++ "\n")) <=>
|
(str ("Last block seen: " ++ show (st ^. syncBlock) ++ "\n")) <=>
|
||||||
listTxBox " Transactions " (st ^. network) (st ^. transactions))) <=>
|
listTxBox " Transactions " (st ^. network) (st ^. transactions))) <=>
|
||||||
C.hCenter
|
(vBox
|
||||||
(hBox
|
[C.hCenter
|
||||||
[ capCommand "W" "allets"
|
(hBox
|
||||||
, capCommand "A" "ccounts"
|
[ capCommand "W" "allets"
|
||||||
, capCommand "V" "iew address"
|
, capCommand "A" "ccounts"
|
||||||
, capCommand "S" "end Tx"
|
, capCommand "V" "iew address"
|
||||||
, capCommand2 "Address " "B" "ook"
|
, capCommand3 "" "S" "end Tx"
|
||||||
, capCommand "Q" "uit"
|
])
|
||||||
, capCommand "?" " Help"
|
,C.hCenter
|
||||||
, str $ show (st ^. timer)
|
(hBox
|
||||||
])
|
[ capCommand2 "Address " "B" "ook"
|
||||||
|
, capCommand2 "Shield/" "D" "eshield"
|
||||||
|
, capCommand "Q" "uit"
|
||||||
|
, capCommand "?" " Help"
|
||||||
|
, str $ show (st ^. timer)
|
||||||
|
])
|
||||||
|
]
|
||||||
|
)
|
||||||
listBox :: Show e => String -> L.List Name e -> Widget Name
|
listBox :: Show e => String -> L.List Name e -> Widget Name
|
||||||
listBox titleLabel l =
|
listBox titleLabel l =
|
||||||
C.vCenter $
|
C.vCenter $
|
||||||
|
@ -339,7 +358,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
|
||||||
else emptyWidget
|
else emptyWidget
|
||||||
where
|
where
|
||||||
keyList =
|
keyList =
|
||||||
map (C.hCenter . str) ["?", "Esc", "w", "a", "v", "s", "b", "q"]
|
map (C.hCenter . str) ["?", "Esc", "w", "a", "v", "s", "b", "d", "q"]
|
||||||
actionList =
|
actionList =
|
||||||
map
|
map
|
||||||
(hLimit 40 . str)
|
(hLimit 40 . str)
|
||||||
|
@ -350,6 +369,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
|
||||||
, "View address"
|
, "View address"
|
||||||
, "Send Tx"
|
, "Send Tx"
|
||||||
, "Address Book"
|
, "Address Book"
|
||||||
|
, "Shield/De-Shield"
|
||||||
, "Quit"
|
, "Quit"
|
||||||
]
|
]
|
||||||
inputDialog :: State -> Widget Name
|
inputDialog :: State -> Widget Name
|
||||||
|
@ -396,6 +416,12 @@ 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 ->
|
||||||
|
D.renderDialog
|
||||||
|
(D.dialog (Just (str " Shield / De-Shield ")) Nothing 50)
|
||||||
|
(renderForm (st ^. shdshForm) <=>
|
||||||
|
C.hCenter
|
||||||
|
(hBox [capCommand "P" "roceed", capCommand "<esc> " "Cancel"]))
|
||||||
Blank -> emptyWidget
|
Blank -> emptyWidget
|
||||||
-- Address Book List
|
-- Address Book List
|
||||||
AdrBook ->
|
AdrBook ->
|
||||||
|
@ -639,6 +665,24 @@ 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
|
||||||
|
mkshieldDeshieldForm bal =
|
||||||
|
newForm
|
||||||
|
[ label "Select :" @@=
|
||||||
|
radioField
|
||||||
|
shieldOp
|
||||||
|
[ (Shield, ShieldField, "Shield")
|
||||||
|
, (Deshield, DeshieldField, "De-Shield")
|
||||||
|
]
|
||||||
|
, label "Amount: " @@=
|
||||||
|
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
|
||||||
|
@ -887,6 +931,7 @@ appEvent (BT.AppEvent t) = do
|
||||||
AdrBookForm -> return ()
|
AdrBookForm -> return ()
|
||||||
AdrBookUpdForm -> return ()
|
AdrBookUpdForm -> return ()
|
||||||
AdrBookDelForm -> return ()
|
AdrBookDelForm -> return ()
|
||||||
|
ShieldDeshieldForm -> return ()
|
||||||
Blank -> do
|
Blank -> do
|
||||||
if s ^. timer == 90
|
if s ^. timer == 90
|
||||||
then do
|
then do
|
||||||
|
@ -1135,6 +1180,14 @@ appEvent (BT.VtyEvent e) = do
|
||||||
setFieldValid
|
setFieldValid
|
||||||
(isRecipientValidGUI (fs ^. policyField) (fs ^. sendTo))
|
(isRecipientValidGUI (fs ^. policyField) (fs ^. sendTo))
|
||||||
RecField
|
RecField
|
||||||
|
ShieldDeshieldForm -> do
|
||||||
|
case e of
|
||||||
|
V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank
|
||||||
|
ev ->
|
||||||
|
BT.zoom shdshForm $ do
|
||||||
|
handleFormEvent (BT.VtyEvent ev)
|
||||||
|
-- fs <- BT.gets formState
|
||||||
|
-- ev -> BT.zoom shdshForm $ L.handleListEvent ev
|
||||||
AdrBook -> do
|
AdrBook -> do
|
||||||
case e of
|
case e of
|
||||||
V.EvKey (V.KChar 'x') [] ->
|
V.EvKey (V.KChar 'x') [] ->
|
||||||
|
@ -1344,6 +1397,8 @@ appEvent (BT.VtyEvent e) = do
|
||||||
BT.modify $ set dialogBox SendTx
|
BT.modify $ set dialogBox SendTx
|
||||||
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') [] ->
|
||||||
|
BT.modify $ set dialogBox ShieldDeshieldForm
|
||||||
ev ->
|
ev ->
|
||||||
case r of
|
case r of
|
||||||
Just AList ->
|
Just AList ->
|
||||||
|
@ -1482,6 +1537,7 @@ runZenithTUI config = do
|
||||||
""
|
""
|
||||||
Nothing
|
Nothing
|
||||||
uBal
|
uBal
|
||||||
|
(mkshieldDeshieldForm 0 (ShDshEntry Shield 0.0 ))
|
||||||
Left _e -> do
|
Left _e -> do
|
||||||
print $
|
print $
|
||||||
"No Zebra node available on port " <>
|
"No Zebra node available on port " <>
|
||||||
|
|
|
@ -207,6 +207,11 @@ data PrivacyPolicy
|
||||||
|
|
||||||
$(deriveJSON defaultOptions ''PrivacyPolicy)
|
$(deriveJSON defaultOptions ''PrivacyPolicy)
|
||||||
|
|
||||||
|
data ShieldDeshieldOp
|
||||||
|
= Shield
|
||||||
|
| Deshield
|
||||||
|
deriving (Eq, Show, Read, Ord)
|
||||||
|
|
||||||
-- ** `zebrad`
|
-- ** `zebrad`
|
||||||
-- | Type for modeling the tree state response
|
-- | Type for modeling the tree state response
|
||||||
data ZebraTreeInfo = ZebraTreeInfo
|
data ZebraTreeInfo = ZebraTreeInfo
|
||||||
|
|
Loading…
Reference in a new issue