Milestone 2: Graphic User Interface #93

Merged
pitmutt merged 38 commits from milestone2 into master 2024-07-17 14:28:52 +00:00
3 changed files with 67 additions and 11 deletions
Showing only changes of commit f332d9b177 - Show all commits

View file

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dialog to display transaction details and copy TX ID
- Dialog to send a new transaction
- Dialog to display Tx ID after successful broadcast
- Unconfirmed balance display on TUI and GUI
### Fixed

View file

@ -180,6 +180,7 @@ data State = State
, _timer :: !Int
, _txForm :: !(Form SendInput () Name)
, _sentTx :: !(Maybe HexString)
, _unconfBalance :: !Integer
}
makeLenses ''State
@ -215,6 +216,12 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
if st ^. network == MainNet
then displayZec (st ^. balance)
else displayTaz (st ^. balance))) <=>
C.hCenter
(str
("Unconf: " ++
if st ^. network == MainNet
then displayZec (st ^. unconfBalance)
else displayTaz (st ^. unconfBalance))) <=>
listAddressBox "Addresses" (st ^. addresses) <+>
B.vBorder <+>
(C.hCenter (str ("Last block seen: " ++ show (st ^. syncBlock))) <=>
@ -1046,6 +1053,10 @@ runZenithCLI config = do
if not (null accList)
then getBalance pool $ entityKey $ head accList
else return 0
uBal <-
if not (null accList)
then getUnconfirmedBalance pool $ entityKey $ head accList
else return 0
eventChan <- BC.newBChan 10
_ <-
forkIO $
@ -1083,6 +1094,7 @@ runZenithCLI config = do
0
(mkSendForm 0 $ SendInput "" 0.0 "")
Nothing
uBal
Left e -> do
print $
"No Zebra node available on port " <>
@ -1111,6 +1123,10 @@ refreshWallet s = do
if not (null aL)
then getBalance pool $ entityKey $ head aL
else return 0
uBal <-
if not (null aL)
then getUnconfirmedBalance pool $ entityKey $ head aL
else return 0
txL <-
if not (null addrL)
then getUserTx pool $ entityKey $ head addrL
@ -1121,6 +1137,8 @@ refreshWallet s = do
let txL' = L.listReplace (Vec.fromList txL) (Just 0) (s ^. transactions)
return $
s & wallets .~ wL & accounts .~ aL' & syncBlock .~ bl & balance .~ bal &
unconfBalance .~
uBal &
addresses .~
addrL' &
transactions .~
@ -1191,6 +1209,7 @@ refreshAccount s = do
Just (_k, w) -> return w
aL <- runNoLoggingT $ getAddresses pool $ entityKey selAccount
bal <- getBalance pool $ entityKey selAccount
uBal <- getUnconfirmedBalance pool $ entityKey selAccount
let aL' = L.listReplace (Vec.fromList aL) (Just 0) (s ^. addresses)
selAddress <-
do case L.listSelectedElement aL' of
@ -1201,13 +1220,17 @@ refreshAccount s = do
case selAddress of
Nothing ->
return $
s & balance .~ bal & addresses .~ aL' & msg .~ "Switched to account: " ++
s & balance .~ bal & unconfBalance .~ uBal & addresses .~ aL' & msg .~
"Switched to account: " ++
T.unpack (zcashAccountName $ entityVal selAccount)
Just (_i, a) -> do
tList <- getUserTx pool $ entityKey a
let tL' = L.listReplace (Vec.fromList tList) (Just 0) (s ^. transactions)
return $
s & balance .~ bal & addresses .~ aL' & transactions .~ tL' & msg .~
s & balance .~ bal & unconfBalance .~ uBal & addresses .~ aL' &
transactions .~
tL' &
msg .~
"Switched to account: " ++
T.unpack (zcashAccountName $ entityVal selAccount)

View file

@ -75,6 +75,7 @@ data AppEvent
| SwitchAddr !Int
| SwitchAcc !Int
| SwitchWal !Int
| UpdateBalance !(Integer, Integer)
| CopyAddr !(Maybe (Entity WalletAddress))
| LoadTxs ![Entity UserTx]
| LoadAddrs ![Entity WalletAddress]
@ -311,7 +312,7 @@ buildUI wenv model = widgetTree
hstack
[ addressBox
, vstack
[ mainButton "Send" ShowSend
[ mainButton "Send" ShowSend `styleBasic` [textFont "Bold"]
, txBox `nodeVisible` not (null $ model ^. transactions)
]
]
@ -322,19 +323,24 @@ buildUI wenv model = widgetTree
box_
[alignMiddle]
(vstack
[ animFadeIn
(label (displayAmount (model ^. network) $ model ^. balance) `styleBasic`
[textSize 20])
[ hstack
[ filler
, animFadeIn
(label
(displayAmount (model ^. network) $ model ^. balance) `styleBasic`
[textSize 20])
, filler
]
, hstack
[ filler
, remixIcon remixHourglassFill `styleBasic` [textSize 8]
, label
(maybe "0" (displayAmount (model ^. network)) $
model ^. unconfBalance) `styleBasic`
[textSize 8] `nodeVisible`
isJust (model ^. unconfBalance)
[textSize 8]
, filler
]
] `nodeVisible`
isJust (model ^. unconfBalance)
]) `styleBasic`
[bgColor white, radius 5, border 1 btnColor]
, filler
@ -923,6 +929,15 @@ handleEvent wenv node model evt =
case selectAccount i of
Nothing -> return []
Just acc -> runNoLoggingT $ getAddresses dbPool $ entityKey acc
, Task $
UpdateBalance <$> do
dbPool <- runNoLoggingT $ initPool $ c_dbPath $ model ^. configuration
case selectAccount i of
Nothing -> return (0, 0)
Just acc -> do
b <- getBalance dbPool $ entityKey acc
u <- getUnconfirmedBalance dbPool $ entityKey acc
return (b, u)
, Event $ SetPool Orchard
]
SwitchWal i ->
@ -934,6 +949,13 @@ handleEvent wenv node model evt =
Nothing -> return []
Just wal -> runNoLoggingT $ getAccounts dbPool $ entityKey wal
]
UpdateBalance (b, u) ->
[ Model $
model & balance .~ b & unconfBalance .~
(if u == 0
then Nothing
else Just u)
]
CopyAddr a ->
[ setClipboardData ClipboardEmpty
, setClipboardData $
@ -1246,6 +1268,14 @@ runZenithGUI config = do
if not (null addrList)
then getQrCode pool Orchard $ entityKey $ head addrList
else return Nothing
bal <-
if not (null accList)
then getBalance pool $ entityKey $ head accList
else return 0
unconfBal <-
if not (null accList)
then getUnconfirmedBalance pool $ entityKey $ head accList
else return 0
let model =
AppModel
config
@ -1260,8 +1290,10 @@ runZenithGUI config = do
0
Nothing
True
314259000
(Just 300000)
bal
(if unconfBal == 0
then Nothing
else Just unconfBal)
Orchard
qr
False