Compare commits

..

2 commits

Author SHA1 Message Date
16b5acabf2 rvv041 - Address Book updated
- Functionality to copy receiver address to Clipboard  added
	- Functionality to Send Zcash to selected AddresBook entry added
2024-05-24 21:23:06 -04:00
e946df43f8 rvv041 - Addresss Book Window working with static data
new attributes created for the box
	 At this stage, the Evenhandler is processing the exit command only
         to close the window and return to the main window.
2024-05-24 12:20:49 -04:00
2 changed files with 101 additions and 4 deletions

4
.gitignore vendored
View file

@ -2,4 +2,6 @@
*~ *~
dist-newstyle/ dist-newstyle/
zenith.db zenith.db
zenith.log zenith.log
zenith.db-shm
zenith.db-wal

View file

@ -40,6 +40,8 @@ import Brick.Widgets.Core
, joinBorders , joinBorders
, padAll , padAll
, padBottom , padBottom
, padTop
, setAvailableSize
, str , str
, strWrap , strWrap
, strWrapWith , strWrapWith
@ -48,6 +50,7 @@ import Brick.Widgets.Core
, txtWrapWith , txtWrapWith
, updateAttrMap , updateAttrMap
, vBox , vBox
, viewport
, vLimit , vLimit
, withAttr , withAttr
, withBorderStyle , withBorderStyle
@ -108,6 +111,8 @@ data Name
| RecField | RecField
| AmtField | AmtField
| MemoField | MemoField
| ABViewport
| ABList
deriving (Eq, Show, Ord) deriving (Eq, Show, Ord)
data DialogInput = DialogInput data DialogInput = DialogInput
@ -132,6 +137,7 @@ data DialogType
| ASelect | ASelect
| SendTx | SendTx
| Blank | Blank
| AdrBook
data DisplayType data DisplayType
= AddrDisplay = AddrDisplay
@ -169,6 +175,7 @@ data State = State
, _eventDispatch :: !(BC.BChan Tick) , _eventDispatch :: !(BC.BChan Tick)
, _timer :: !Int , _timer :: !Int
, _txForm :: !(Form SendInput () Name) , _txForm :: !(Form SendInput () Name)
, _abaddresses :: !(L.List Name (Entity AddressBook))
} }
makeLenses ''State makeLenses ''State
@ -341,6 +348,34 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
C.hCenter C.hCenter
(hBox [capCommand "" "Send", capCommand "<esc> " "Cancel"])) (hBox [capCommand "" "Send", capCommand "<esc> " "Cancel"]))
Blank -> emptyWidget Blank -> emptyWidget
AdrBook ->
D.renderDialog
(D.dialog (Just $ str " Address Book ") Nothing 60)
(withAttr abDefAttr $
setAvailableSize (50,20) $
viewport ABViewport BT.Vertical $
vLimit 20 $
hLimit 50 $
vBox $ [vLimit 16 $
hLimit 50 $
vBox $ [ L.renderList listDrawAB True (s ^. abaddresses) ],
-- [str "Addresses 1.................",
-- str "Addresses 2.....",
-- str "Addresses 3",
-- str "Addresses 4"],
padTop Max $
vLimit 4 $
hLimit 50 $
withAttr abMBarAttr $
vBox $ [C.hCenter $
(capCommand "N" "ew Address" <+>
capCommand "E" "dit Address" <+>
capCommand3 "" "C" "opy Address"),
C.hCenter $
(capCommand "D" "elete Address" <+>
capCommand "S" "end Zcash" <+>
capCommand3 "E" "x" "it")]])
splashDialog :: State -> Widget Name splashDialog :: State -> Widget Name
splashDialog st = splashDialog st =
if st ^. splashBox if st ^. splashBox
@ -568,6 +603,14 @@ listDrawTx znet sel tx =
then withAttr customAttr (txt $ "> " <> s) then withAttr customAttr (txt $ "> " <> s)
else txt $ " " <> s else txt $ " " <> s
listDrawAB :: Bool -> Entity AddressBook -> Widget Name
listDrawAB sel ab =
let selStr s =
if sel
then withAttr abSelAttr (txt $ "" <> s <> ">")
else txt s
in selStr $ addressBookDescrip (entityVal ab)
customAttr :: A.AttrName customAttr :: A.AttrName
customAttr = L.listSelectedAttr <> A.attrName "custom" customAttr = L.listSelectedAttr <> A.attrName "custom"
@ -586,6 +629,15 @@ barDoneAttr = A.attrName "done"
barToDoAttr :: A.AttrName barToDoAttr :: A.AttrName
barToDoAttr = A.attrName "remaining" barToDoAttr = A.attrName "remaining"
abDefAttr :: A.AttrName
abDefAttr = A.attrName "abdefault"
abSelAttr :: A.AttrName
abSelAttr = A.attrName "abselected"
abMBarAttr :: A.AttrName
abMBarAttr = A.attrName "menubar"
validBarValue :: Float -> Float validBarValue :: Float -> Float
validBarValue = clamp 0 1 validBarValue = clamp 0 1
@ -694,6 +746,7 @@ appEvent (BT.AppEvent t) = do
WSelect -> return () WSelect -> return ()
ASelect -> return () ASelect -> return ()
SendTx -> return () SendTx -> return ()
AdrBook -> return ()
Blank -> do Blank -> do
if s ^. timer == 90 if s ^. timer == 90
then do then do
@ -931,6 +984,39 @@ appEvent (BT.VtyEvent e) = do
setFieldValid setFieldValid
(isRecipientValid (fs ^. sendTo)) (isRecipientValid (fs ^. sendTo))
RecField RecField
AdrBook -> do
case e of
V.EvKey (V.KChar 'x') [] ->
BT.modify $ set dialogBox Blank
V.EvKey (V.KChar 'c') [] -> do
-- Copy Address to Clipboard
case L.listSelectedElement $ s ^. abaddresses of
Just (_, a) -> do
liftIO $
setClipboard $
T.unpack $ addressBookAddress (entityVal a)
BT.modify $
set msg $
"Address copied to Clipboard from >>\n" ++
T.unpack (addressBookDescrip (entityVal a)) ++ "->\n" ++
T.unpack (addressBookAddress (entityVal a)) ++ "!"
BT.modify $ set displayBox MsgDisplay
_ -> do
BT.modify $ set msg $ "Error while copying the address!!"
BT.modify $ set displayBox MsgDisplay
-- Send Zcash transaction
V.EvKey (V.KChar 's') [] -> do
case L.listSelectedElement $ s ^. abaddresses of
Just (_, a) -> do
BT.modify $
set txForm $
mkSendForm (s ^. balance) (SendInput (addressBookAddress (entityVal a)) 0.0 "")
BT.modify $ set dialogBox SendTx
_ -> do
BT.modify $ set msg $ "No receiver address available!!"
BT.modify $ set displayBox MsgDisplay
-- Process any other event
ev -> BT.zoom abaddresses $ L.handleListEvent ev
Blank -> do Blank -> do
case e of case e of
V.EvKey (V.KChar '\t') [] -> focusRing %= F.focusNext V.EvKey (V.KChar '\t') [] -> focusRing %= F.focusNext
@ -954,14 +1040,16 @@ appEvent (BT.VtyEvent e) = do
set txForm $ set txForm $
mkSendForm (s ^. balance) (SendInput "" 0.0 "") mkSendForm (s ^. balance) (SendInput "" 0.0 "")
BT.modify $ set dialogBox SendTx BT.modify $ set dialogBox SendTx
V.EvKey (V.KChar 'b') [] -> V.EvKey (V.KChar 'b') [] ->
BT.modify $ set dialogBox ASelect BT.modify $ set dialogBox AdrBook
ev -> ev ->
case r of case r of
Just AList -> Just AList ->
BT.zoom addresses $ L.handleListEvent ev BT.zoom addresses $ L.handleListEvent ev
Just TList -> Just TList ->
BT.zoom transactions $ L.handleListEvent ev BT.zoom transactions $ L.handleListEvent ev
Just ABList ->
BT.zoom transactions $ L.handleListEvent ev
_anyName -> return () _anyName -> return ()
where where
printMsg :: String -> BT.EventM Name State () printMsg :: String -> BT.EventM Name State ()
@ -986,6 +1074,9 @@ theMap =
, (baseAttr, bg V.brightBlack) , (baseAttr, bg V.brightBlack)
, (barDoneAttr, V.white `on` V.blue) , (barDoneAttr, V.white `on` V.blue)
, (barToDoAttr, V.white `on` V.black) , (barToDoAttr, V.white `on` V.black)
, (abDefAttr, V.white `on` V.blue)
, (abSelAttr, V.black `on` V.white)
, (abMBarAttr, V.white `on` V.black)
] ]
theApp :: M.App State Tick Name theApp :: M.App State Tick Name
@ -1031,6 +1122,9 @@ runZenithCLI config = do
if not (null walList) if not (null walList)
then zcashWalletLastSync $ entityVal $ head walList then zcashWalletLastSync $ entityVal $ head walList
else 0 else 0
abookList <- getAdrBook pool $ zgb_net chainInfo
bal <- bal <-
if not (null accList) if not (null accList)
then getBalance pool $ entityKey $ head accList then getBalance pool $ entityKey $ head accList
@ -1059,7 +1153,7 @@ runZenithCLI config = do
else Blank) else Blank)
True True
(mkInputForm $ DialogInput "Main") (mkInputForm $ DialogInput "Main")
(F.focusRing [AList, TList]) (F.focusRing [AList, TList,ABList])
(zgb_blocks chainInfo) (zgb_blocks chainInfo)
dbFilePath dbFilePath
host host
@ -1071,6 +1165,7 @@ runZenithCLI config = do
eventChan eventChan
0 0
(mkSendForm 0 $ SendInput "" 0.0 "") (mkSendForm 0 $ SendInput "" 0.0 "")
(L.list ABList (Vec.fromList abookList) 1)
Left e -> do Left e -> do
print $ print $
"No Zebra node available on port " <> "No Zebra node available on port " <>