rvv001 - temporary commit

This commit is contained in:
Rene V. Vergara A. 2024-09-29 18:18:46 -04:00
parent abe30db2fe
commit 01cdf9eb14
2 changed files with 104 additions and 39 deletions

View file

@ -54,6 +54,8 @@ import Zenith.Utils
, getZenithPath
, isEmpty
, isRecipientValid
, isRecipientValidGUI
, isZecAddressValid
, isValidString
, jsonNumber
, padWithZero
@ -125,6 +127,7 @@ data AppEvent
| CopyABAdress !T.Text
| DeleteABEntry !T.Text
| UpdateABDescrip !T.Text !T.Text
| ResetRecipientValid
deriving (Eq, Show)
data AppModel = AppModel
@ -606,7 +609,28 @@ buildUI wenv model = widgetTree
, separatorLine `styleBasic` [fgColor btnColor]
, spacer
, hstack
[ label "To:" `styleBasic` [width 50]
[
label "Privacy Level:" `styleBasic` [width 70, textFont "Bold"]
, spacer
, label "Full " `styleBasic` [width 40]
, radio Full privacyChoice
, spacer
, label "Medium " `styleBasic` [width 40]
, radio Medium privacyChoice
]
, hstack
[
label " " `styleBasic` [width 70, textFont "Bold"]
, spacer
, label "Low " `styleBasic` [width 40]
, radio Low privacyChoice
, spacer
, label "None " `styleBasic` [width 40]
, radio None privacyChoice
]
, spacer
, hstack
[ label "To:" `styleBasic` [width 50, textFont "Bold"]
, spacer
, textField_ sendRecipient [onChange CheckRecipient] `styleBasic`
[ width 150
@ -616,7 +640,7 @@ buildUI wenv model = widgetTree
]
]
, hstack
[ label "Amount:" `styleBasic` [width 50]
[ label "Amount:" `styleBasic` [width 50, textFont "Bold"]
, spacer
, numericField_
sendAmount
@ -634,35 +658,13 @@ buildUI wenv model = widgetTree
]
]
, hstack
[ label "Memo:" `styleBasic` [width 50]
[ label "Memo:" `styleBasic` [width 50, textFont "Bold"]
, spacer
, textArea sendMemo `styleBasic`
[width 150, height 40]
]
, spacer
-- Radio button group for privacy level
, hstack
[
label "Privacy Level:" `styleBasic` [width 70]
, spacer
, label "None " `styleBasic` [width 40]
, radio None privacyChoice
, spacer
, label "Low " `styleBasic` [width 40]
, radio Low privacyChoice
]
, hstack
[
label " " `styleBasic` [width 70]
, spacer
, label "Medium " `styleBasic` [width 40]
, radio Medium privacyChoice
, spacer
, label "Full " `styleBasic` [width 40]
, radio Full privacyChoice
]
, spacer
, box_
[alignMiddle]
(hstack
@ -1080,7 +1082,7 @@ handleEvent wenv node model evt =
]
ConfirmCancel -> [Model $ model & confirmTitle .~ Nothing & mainInput .~ ""]
ShowSeed -> [Model $ model & showSeed .~ True & menuPopup .~ False]
ShowSend -> [Model $ model & openSend .~ True]
ShowSend -> [Model $ model & openSend .~ True & privacyChoice .~ Full & recipientValid .~ False]
SendTx ->
case currentAccount of
Nothing -> [Event $ ShowError "No account available", Event CancelSend]
@ -1261,7 +1263,10 @@ handleEvent wenv node model evt =
("Wallet Sync: " <>
T.pack (printf "%.2f%%" (model ^. barValue * 100)))
]
CheckRecipient a -> [Model $ model & recipientValid .~ isRecipientValid a]
ResetRecipientValid -> [Model $ model & recipientValid .~ False]
CheckRecipient a -> [Model $
model & recipientValid .~ isRecipientValidGUI (model ^.privacyChoice) a ]
-- model & recipientValid .~ ((model ^. privacyChoice) == Low) ]
CheckAmount i ->
[ Model $
model & amountValid .~
@ -1272,7 +1277,7 @@ handleEvent wenv node model evt =
-- | Address Book Events
-- |
CheckValidAddress a ->
[Model $ model & abAddressValid .~ isRecipientValid a]
[Model $ model & abAddressValid .~ isZecAddressValid a]
CheckValidDescrip a -> [Model $ model & abDescripValid .~ isValidString a]
ShowAdrBook ->
if null (model ^. abaddressList)
@ -1673,7 +1678,7 @@ runZenithGUI config = do
Nothing
False
False
None
Full
startApp model handleEvent buildUI (params hD)
Left _e -> print "Zebra not available"
where

View file

@ -24,12 +24,15 @@ import ZcashHaskell.Types
, TransparentAddress(..)
, UnifiedAddress(..)
, ZcashNet(..)
, ValidAddress(..)
, ExchangeAddress(..)
)
import Zenith.Types
( AddressGroup(..)
, UnifiedAddressDB(..)
, ZcashAddress(..)
, ZcashPool(..)
, PrivacyPolicy(..)
)
-- | Helper function to convert numbers into JSON
@ -71,8 +74,8 @@ getAddresses ag = agtransparent ag <> agsapling ag <> agunified ag
-- | Helper function to validate potential Zcash addresses
validateAddress :: T.Text -> Maybe ZcashPool
validateAddress txt --(tReg || sReg && isJust chk) || (uReg && isJust chk)
| tReg = Just Transparent
| sReg && chkS = Just Sapling
| tReg = Just Zenith.Types.Transparent
| sReg && chkS = Just Zenith.Types.Sapling
| uReg && chk = Just Orchard
| otherwise = Nothing
where
@ -110,7 +113,64 @@ validBarValue :: Float -> Float
validBarValue = clamp (0, 1)
isRecipientValid :: T.Text -> Bool
isRecipientValid a =
isRecipientValid a = do
case isValidUnifiedAddress (E.encodeUtf8 a) of
Just _a1 -> True
Nothing ->
isValidShieldedAddress (E.encodeUtf8 a) ||
(case decodeTransparentAddress (E.encodeUtf8 a) of
Just _a3 -> True
Nothing ->
case decodeExchangeAddress (E.encodeUtf8 a) of
Just _a4 -> True
Nothing -> False)
isUnifiedAddressValid :: T.Text -> Bool
isUnifiedAddressValid ua =
case isValidUnifiedAddress (E.encodeUtf8 ua) of
Just _a1 -> True
Nothing -> False
isSaplingAddressValid :: T.Text -> Bool
isSaplingAddressValid sa = isValidShieldedAddress (E.encodeUtf8 sa)
isTransparentAddressValid :: T.Text -> Bool
isTransparentAddressValid ta =
case decodeTransparentAddress (E.encodeUtf8 ta) of
Just _a3 -> True
Nothing -> False
isExchangeAddressValid :: T.Text -> Bool
isExchangeAddressValid xa =
case decodeExchangeAddress (E.encodeUtf8 xa) of
Just _a4 -> True
Nothing -> False
isRecipientValidGUI :: PrivacyPolicy -> T.Text -> Bool
isRecipientValidGUI p a = do
case (parseAddress a) of
Just a1 ->
case p of
Full -> case a1 of
Unified ua -> True
ZcashHaskell.Types.Sapling sa -> True
_ -> False
Medium -> case a1 of
Unified ua -> True
ZcashHaskell.Types.Sapling sa -> True
_ -> False
Low -> case a1 of
Unified ua -> True
ZcashHaskell.Types.Sapling sa -> True
ZcashHaskell.Types.Transparent ta -> True
Exchange ea -> True
None -> case a1 of
ZcashHaskell.Types.Transparent ta -> True
Exchange ea -> True
_ -> False
isZecAddressValid :: T.Text -> Bool
isZecAddressValid a = do
case isValidUnifiedAddress (E.encodeUtf8 a) of
Just _a1 -> True
Nothing ->