Compare commits
4 commits
0b70bbb8de
...
772025e317
Author | SHA1 | Date | |
---|---|---|---|
772025e317 | |||
d57ac5db14 | |||
51116e8083 | |||
1c88ea5f08 |
2 changed files with 39 additions and 40 deletions
|
@ -2,7 +2,7 @@
|
|||
{-# LANGUAGE TypeApplications #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE BlockArguments #-}
|
||||
|
||||
|
||||
module Zenith.CLI where
|
||||
|
||||
|
@ -192,10 +192,10 @@ data State = State
|
|||
, _eventDispatch :: !(BC.BChan Tick)
|
||||
, _timer :: !Int
|
||||
, _txForm :: !(Form SendInput () Name)
|
||||
, _abaddresses :: !(L.List Name (Entity AddressBook))
|
||||
, _abAddresses :: !(L.List Name (Entity AddressBook))
|
||||
, _abForm :: !(Form AdrBookEntry () Name)
|
||||
, _abCurAdrs :: !T.Text
|
||||
, _abTxt :: !T.Text
|
||||
, _abCurAdrs :: !T.Text -- used for address book CRUD operations
|
||||
, _abTxt :: !T.Text -- Holds the Address Book entry data to show
|
||||
}
|
||||
|
||||
makeLenses ''State
|
||||
|
@ -379,7 +379,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
|
|||
hLimit 50 $
|
||||
vBox [vLimit 16 $
|
||||
hLimit 50 $
|
||||
vBox $ [ L.renderList listDrawAB True (s ^. abaddresses) ],
|
||||
vBox $ [ L.renderList listDrawAB True (s ^. abAddresses) ],
|
||||
padTop Max $
|
||||
vLimit 4 $
|
||||
hLimit 50 $
|
||||
|
@ -1046,50 +1046,50 @@ appEvent (BT.VtyEvent e) = do
|
|||
BT.modify $ set dialogBox Blank
|
||||
V.EvKey (V.KChar 'c') [] -> do
|
||||
-- Copy Address to Clipboard
|
||||
case L.listSelectedElement $ s ^. abaddresses of
|
||||
case L.listSelectedElement $ s ^. abAddresses of
|
||||
Just (_, a) -> do
|
||||
liftIO $
|
||||
setClipboard $
|
||||
T.unpack $ addressBookAddress (entityVal a)
|
||||
T.unpack $ addressBookAbaddress (entityVal a)
|
||||
BT.modify $
|
||||
set msg $
|
||||
"Address copied to Clipboard from >>\n" ++
|
||||
T.unpack (addressBookDescrip (entityVal a)) ++ "->\n" ++
|
||||
T.unpack (addressBookAddress (entityVal a)) ++ "!"
|
||||
T.unpack (addressBookAbaddress (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
|
||||
case L.listSelectedElement $ s ^. abAddresses of
|
||||
Just (_, a) -> do
|
||||
BT.modify $
|
||||
set txForm $
|
||||
mkSendForm (s ^. balance) (SendInput (addressBookAddress (entityVal a)) 0.0 "")
|
||||
mkSendForm (s ^. balance) (SendInput (addressBookAbaddress (entityVal a)) 0.0 "")
|
||||
BT.modify $ set dialogBox SendTx
|
||||
_ -> do
|
||||
BT.modify $ set msg "No receiver address available!!"
|
||||
BT.modify $ set displayBox MsgDisplay
|
||||
-- Edit an entry in Address Book
|
||||
V.EvKey (V.KChar 'e') [] -> do
|
||||
case L.listSelectedElement $ s ^. abaddresses of
|
||||
case L.listSelectedElement $ s ^. abAddresses of
|
||||
Just (_, a) -> do
|
||||
BT.modify $ set abCurAdrs (addressBookAddress (entityVal a))
|
||||
BT.modify $ set abCurAdrs (addressBookAbaddress (entityVal a))
|
||||
BT.modify $
|
||||
set abForm $
|
||||
mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAddress (entityVal a)))
|
||||
mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAbaddress (entityVal a)))
|
||||
BT.modify $ set dialogBox AdrBookUpdForm
|
||||
_ -> do
|
||||
BT.modify $ set dialogBox Blank
|
||||
-- Delete an entry from Address Book
|
||||
V.EvKey (V.KChar 'd') [] -> do
|
||||
case L.listSelectedElement $ s ^. abaddresses of
|
||||
case L.listSelectedElement $ s ^. abAddresses of
|
||||
Just (_, a) -> do
|
||||
BT.modify $ set abCurAdrs (addressBookAddress (entityVal a))
|
||||
BT.modify $ set abCurAdrs (addressBookAbaddress (entityVal a))
|
||||
BT.modify $
|
||||
set abForm $
|
||||
mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAddress (entityVal a)))
|
||||
mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAbaddress (entityVal a)))
|
||||
BT.modify $ set dialogBox AdrBookDelForm
|
||||
_ -> do
|
||||
BT.modify $ set dialogBox Blank
|
||||
|
@ -1099,18 +1099,18 @@ appEvent (BT.VtyEvent e) = do
|
|||
BT.modify $ set dialogBox AdrBookForm
|
||||
-- Show AddressBook entry data
|
||||
V.EvKey V.KEnter [] -> do
|
||||
case L.listSelectedElement $ s ^. abaddresses of
|
||||
case L.listSelectedElement $ s ^. abAddresses of
|
||||
Just (_, a) -> do
|
||||
BT.modify $ set abTxt $ T.pack $
|
||||
" Descr: " ++
|
||||
T.unpack (addressBookDescrip (entityVal a)) ++
|
||||
"\n Address: " ++
|
||||
T.unpack (addressBookAddress (entityVal a))
|
||||
T.unpack (addressBookAbaddress (entityVal a))
|
||||
BT.modify $ set displayBox AdrBookEntryDisplay
|
||||
_ -> do
|
||||
BT.modify $ set dialogBox Blank
|
||||
-- Process any other event
|
||||
ev -> BT.zoom abaddresses $ L.handleListEvent ev
|
||||
ev -> BT.zoom abAddresses $ L.handleListEvent ev
|
||||
-- Process new address book entry
|
||||
AdrBookForm -> do
|
||||
case e of
|
||||
|
@ -1218,7 +1218,7 @@ appEvent (BT.VtyEvent e) = do
|
|||
Just TList ->
|
||||
BT.zoom transactions $ L.handleListEvent ev
|
||||
Just ABList ->
|
||||
BT.zoom abaddresses $ L.handleListEvent ev
|
||||
BT.zoom abAddresses $ L.handleListEvent ev
|
||||
_anyName -> return ()
|
||||
where
|
||||
printMsg :: String -> BT.EventM Name State ()
|
||||
|
@ -1322,7 +1322,7 @@ runZenithCLI config = do
|
|||
else Blank)
|
||||
True
|
||||
(mkInputForm $ DialogInput "Main")
|
||||
(F.focusRing [AList, TList,ABList])
|
||||
(F.focusRing [AList, TList])
|
||||
(zgb_blocks chainInfo)
|
||||
dbFilePath
|
||||
host
|
||||
|
@ -1485,18 +1485,18 @@ refreshAddressBook :: State -> IO State
|
|||
refreshAddressBook s = do
|
||||
pool <- runNoLoggingT $ initPool $ s ^. dbPath
|
||||
selAddress <-
|
||||
do case L.listSelectedElement $ s ^. abaddresses of
|
||||
do case L.listSelectedElement $ s ^. abAddresses of
|
||||
Nothing -> do
|
||||
let fAdd =
|
||||
L.listSelectedElement $ L.listMoveToBeginning $ s ^. abaddresses
|
||||
L.listSelectedElement $ L.listMoveToBeginning $ s ^. abAddresses
|
||||
return fAdd
|
||||
Just a2 -> return $ Just a2
|
||||
case selAddress of
|
||||
Nothing -> return s
|
||||
Just (_i, a) -> do
|
||||
abookList <- getAdrBook pool (s ^. network)
|
||||
let tL' = L.listReplace (Vec.fromList abookList) (Just 0) (s ^. abaddresses)
|
||||
return $ s & abaddresses .~ tL'
|
||||
let tL' = L.listReplace (Vec.fromList abookList) (Just 0) (s ^. abAddresses)
|
||||
return $ s & abAddresses .~ tL'
|
||||
|
||||
addNewAddress :: T.Text -> Scope -> State -> IO State
|
||||
addNewAddress n scope s = do
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
{-# LANGUAGE BlockArguments #-}
|
||||
|
||||
module Zenith.DB where
|
||||
|
||||
|
@ -250,8 +249,8 @@ share
|
|||
AddressBook
|
||||
network ZcashNetDB
|
||||
descrip T.Text
|
||||
address T.Text
|
||||
UniqueABA address
|
||||
abaddress T.Text
|
||||
UniqueABA abaddress
|
||||
deriving Show Eq
|
||||
|]
|
||||
|
||||
|
@ -1501,19 +1500,19 @@ updateAdrsInAdrBook pool d a ia = do
|
|||
PS.retryOnBusy $
|
||||
flip PS.runSqlPool pool $ do
|
||||
update $ \ab -> do
|
||||
set ab [AddressBookDescrip =. val d, AddressBookAddress =. val a]
|
||||
where_ $ ab ^. AddressBookAddress ==. val ia
|
||||
set ab [AddressBookDescrip =. val d, AddressBookAbaddress =. val a]
|
||||
where_ $ ab ^. AddressBookAbaddress ==. val ia
|
||||
|
||||
-- | Get one AddrssBook record using the Address as a key
|
||||
getABookRec :: ConnectionPool -> T.Text -> IO [Entity AddressBook]
|
||||
getABookRec pool a = do
|
||||
runNoLoggingT $
|
||||
PS.retryOnBusy $
|
||||
flip PS.runSqlPool pool $
|
||||
select $ do
|
||||
adrbook <- from $ table @AddressBook
|
||||
where_ ((adrbook ^. AddressBookAddress) ==. val a)
|
||||
return adrbook
|
||||
-- getABookRec :: ConnectionPool -> T.Tex t -> IO (Maybe (Entity AddressBook))
|
||||
-- getABookRec pool a = do
|
||||
-- runNoLoggingT $
|
||||
-- PS.retryOnBusy $
|
||||
-- flip PS.runSqlPool pool $
|
||||
-- select $ do
|
||||
-- adrbook <- from $ table @AddressBook
|
||||
-- where_ ((adrbook ^. AddressBookAbaddress) ==. val a)
|
||||
-- return adrbook
|
||||
|
||||
-- | delete an existing address from AddressBook
|
||||
deleteAdrsFromAB :: ConnectionPool -> T.Text -> IO ()
|
||||
|
@ -1523,7 +1522,7 @@ deleteAdrsFromAB pool ia = do
|
|||
flip PS.runSqlPool pool $ do
|
||||
delete $ do
|
||||
ab <- from $ table @AddressBook
|
||||
where_ (ab ^. AddressBookAddress ==. val ia)
|
||||
where_ (ab ^. AddressBookAbaddress ==. val ia)
|
||||
|
||||
rmdups :: Ord a => [a] -> [a]
|
||||
rmdups = map head . group . sort
|
||||
|
|
Loading…
Reference in a new issue