rvv001 -> Payment URI generation : Form to capture payment data ready.

This commit is contained in:
Rene V. Vergara 2025-01-11 20:02:29 -05:00
parent de3bc48c38
commit 149d74d4e2

View file

@ -33,7 +33,6 @@ import Database.Persist
import Lens.Micro ((&), (+~), (.~), (?~), (^.), set) import Lens.Micro ((&), (+~), (.~), (?~), (^.), set)
import Lens.Micro.TH import Lens.Micro.TH
import Monomer import Monomer
import qualified Monomer.Lens as L import qualified Monomer.Lens as L
import System.Directory (getHomeDirectory) import System.Directory (getHomeDirectory)
import System.FilePath ((</>)) import System.FilePath ((</>))
@ -69,15 +68,15 @@ import Zenith.Types hiding (ZcashAddress(..))
import Zenith.Utils import Zenith.Utils
( displayAmount ( displayAmount
, getChainTip , getChainTip
, getZcashPrice
, isRecipientValidGUI , isRecipientValidGUI
, isValidString , isValidString
, isZecAddressValid , isZecAddressValid
, jsonNumber , jsonNumber
, padWithZero , padWithZero
, parseZcashPayment
, showAddress , showAddress
, validBarValue , validBarValue
, parseZcashPayment
, getZcashPrice
) )
data VkTypeDef data VkTypeDef
@ -96,7 +95,6 @@ data AppEvent
| AccountClicked | AccountClicked
| MenuClicked | MenuClicked
| NewClicked | NewClicked
| ViewingKeysClicked
| NewAddress !(Maybe (Entity ZcashAccount)) | NewAddress !(Maybe (Entity ZcashAccount))
| NewInternalAddress !(Maybe (Entity ZcashAccount)) | NewInternalAddress !(Maybe (Entity ZcashAccount))
| NewAccount !(Maybe (Entity ZcashWallet)) | NewAccount !(Maybe (Entity ZcashWallet))
@ -162,14 +160,15 @@ data AppEvent
| ShowFIATBalance | ShowFIATBalance
| DisplayFIATBalance Double Double | DisplayFIATBalance Double Double
| CloseFIATBalance | CloseFIATBalance
| ViewingKeysClicked
| PrepareViewingKey !VkTypeDef !(Maybe (Entity ZcashAccount)) | PrepareViewingKey !VkTypeDef !(Maybe (Entity ZcashAccount))
| ShowViewingKey !VkTypeDef !T.Text | ShowViewingKey !VkTypeDef !T.Text
| CopyViewingKey !T.Text !T.Text | CopyViewingKey !T.Text !T.Text
| CloseShowVK | CloseShowVK
| DisplayPaymentURIForm | DisplayPaymentURIForm
| ClosePaymentURIForm | ClosePaymentURIForm
| GenURIString | PrepareURIString
| CheckAmountURI !Float | IsAmountValid !Float
| CloseShowURIOverlay | CloseShowURIOverlay
| CopyURIString !T.Text | CopyURIString !T.Text
| DisplayPayUsingURI | DisplayPayUsingURI
@ -288,19 +287,19 @@ buildUI wenv model = widgetTree
, modalOverlay `nodeVisible` isJust (model ^. modalMsg) , modalOverlay `nodeVisible` isJust (model ^. modalMsg)
, adrbookOverlay `nodeVisible` model ^. showAdrBook , adrbookOverlay `nodeVisible` model ^. showAdrBook
, newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry , newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry
, dfBalOverlay `nodeVisible` model ^. displayFIATBalance
, showABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible` , showABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible`
model ^. model ^.
showABAddress showABAddress
, updateABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible` , updateABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible`
model ^. model ^.
updateABAddress updateABAddress
, shieldOverlay `nodeVisible` model ^. shieldZec
, deShieldOverlay `nodeVisible` model ^. deShieldZec
, dfBalOverlay `nodeVisible` model ^. displayFIATBalance
, showVKOverlay `nodeVisible` model ^. viewingKeyDisplay , showVKOverlay `nodeVisible` model ^. viewingKeyDisplay
, paymentURIOverlay `nodeVisible` model ^. paymentURIDisplay , paymentURIOverlay `nodeVisible` model ^. paymentURIDisplay
, showURIOverlay `nodeVisible` model ^. showURIDisplay , showURIOverlay `nodeVisible` model ^. showURIDisplay
, pmtUsingURIOverlay `nodeVisible` model ^. usepmtURIOverlay , pmtUsingURIOverlay `nodeVisible` model ^. usepmtURIOverlay
, shieldOverlay `nodeVisible` model ^. shieldZec
, deShieldOverlay `nodeVisible` model ^. deShieldZec
, msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB) , msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB)
] ]
mainWindow = mainWindow =
@ -393,7 +392,7 @@ buildUI wenv model = widgetTree
("Balance in " <> ("Balance in " <>
T.toUpper (c_currencyCode (model ^. configuration)))) `styleBasic` T.toUpper (c_currencyCode (model ^. configuration)))) `styleBasic`
[bgColor white, borderB 1 gray, padding 3] [bgColor white, borderB 1 gray, padding 3]
, box_ [alignLeft, onClick DisplayPaymentURIForm] (label "Create URI") `styleBasic` , box_ [alignLeft, onClick DisplayPaymentURIForm ] (label "Create URI") `styleBasic`
[bgColor white, borderB 1 gray, padding 3] [bgColor white, borderB 1 gray, padding 3]
, box_ , box_
[alignLeft, onClick DisplayPayUsingURI] [alignLeft, onClick DisplayPayUsingURI]
@ -1247,153 +1246,41 @@ buildUI wenv model = widgetTree
, filler , filler
]) `styleBasic` ]) `styleBasic`
[bgColor (white & L.a .~ 0.5)] [bgColor (white & L.a .~ 0.5)]
--
paymentURIOverlay = paymentURIOverlay =
box alert ClosePaymentURIForm $
(vstack vstack
[ filler
, hstack
[ filler
, box_
[]
(vstack
[ box_ [ box_
[alignMiddle] []
(label "Create URI" `styleBasic` (label "Create a Payment URI" `styleBasic`
[textFont "Bold", textSize 12]) [textFont "Bold", textColor white, textSize 10, padding 3]) `styleBasic`
, separatorLine `styleBasic` [fgColor btnColor] [bgColor btnColor, radius 2, padding 3]
, spacer , spacer
, hstack , hstack
[ label "Privacy Level:" `styleBasic` [ label "Amount : " `styleBasic` [textFont "Bold"]
[width 70, textFont "Bold"] , numericField_ sendAmount
, spacer [ decimals 8 ]
, label "Full " `styleBasic` [width 40] `nodeKey` "floatInput"
, radio Full privacyChoice `styleBasic`
, 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 [ width 150
, styleIf , styleIf (model ^. sendAmount <= 0.0) (textColor red)
(not $ model ^. recipientValid)
(textColor red)
] ]
] ]
, spacer
, hstack , hstack
[ label "Amount:" `styleBasic` [ label "Memo: " `styleBasic` [textFont "Bold"]
[width 50, textFont "Bold"]
, spacer , spacer
, numericField_ , textField_ sendMemo [] `styleBasic` [width 300]
sendAmount
[ decimals 8
, minValue 0.0
, maxValue
(fromIntegral (model ^. balance) / 100000000.0)
, validInput amountValid
, onChange CheckAmount
] `styleBasic`
[ width 150
, styleIf
(not $ model ^. amountValid)
(textColor red)
]
] ]
, spacer
, hstack , hstack
[ label "Memo:" `styleBasic` [ filler
[width 50, textFont "Bold"] , mainButton "Create URI" PrepareURIString `nodeEnabled`
, spacer (model ^. sendAmount > 0.0)
, textArea sendMemo `styleBasic`
[width 150, height 40]
]
, spacer
-- Radio button group for privacy level
, box_
[alignMiddle]
(hstack
[ spacer
, button "Cancel" ClosePaymentURIForm
, spacer
, mainButton "Send" SendTx `nodeEnabled` False
, spacer
])
]) `styleBasic`
[radius 4, border 2 btnColor, bgColor white, padding 4]
, filler , filler
] ]
, filler ] `styleBasic` [bgColor (white & L.a .~ 0.5)]
]) `styleBasic` --
[bgColor (white & L.a .~ 0.5)]
-- box
-- (vstack
-- [ filler
-- , hstack
-- [ filler
-- , box_
-- []
-- (vstack
-- [ box_
-- [alignMiddle]
-- (label "Create URI" `styleBasic`
-- [textColor white, textFont "Bold", textSize 12]) `styleBasic`
-- [bgColor btnColor]
-- , separatorLine `styleBasic` [fgColor btnColor]
-- , spacer
-- , hstack
-- [ label "Amount:" `styleBasic`
-- [width 50, textFont "Bold"]
-- , spacer
-- , numericField_
-- sendAmount
-- [ decimals 8
-- , minValue 0.0
-- , maxValue (fromIntegral (model ^. balance) / 100000000.0)
-- , validInput amountValid
-- , onChange CheckAmountURI
-- ] `styleBasic`
-- [ width 150
-- , styleIf
-- (not $ model ^. amountValid)
-- (textColor red)
-- ]
-- ]
-- -- , hstack
-- -- [ label "Memo:" `styleBasic`
-- -- [width 50, textFont "Bold"]
-- -- , spacer
-- -- , textArea sendMemo `styleBasic`
-- -- [width 150, height 40]
-- -- ]
-- , spacer
-- , box_
-- [alignMiddle]
-- (hstack
-- [ spacer
-- -- , mainButton "Create URI" NotImplemented `nodeEnabled` True
-- -- , spacer
-- , button "Cancel" ClosePaymentURIForm
-- , spacer
-- ])
-- ]) `styleBasic`
-- [radius 4, border 2 btnColor, bgColor white, padding 4]
-- , filler
-- ]
-- , filler
-- ]) `styleBasic`
-- [bgColor (white & L.a .~ 0.5)]
showURIOverlay = showURIOverlay =
alert CloseShowURIOverlay $ alert CloseShowURIOverlay $
vstack vstack
@ -1806,10 +1693,12 @@ handleEvent wenv node model evt =
model & amountValid .~ model & amountValid .~
(i < (fromIntegral (model ^. balance) / 100000000.0)) (i < (fromIntegral (model ^. balance) / 100000000.0))
] ]
CheckAmountURI i -> --
[ Model $ IsAmountValid k ->
model & amountValid .~ (i < (fromIntegral (model ^. balance) / 100000000.0)) if (k > 0.0) && (k < (fromIntegral (model ^. balance) / 100000000.0))
] then [ Model $ model & amountValid .~ True ]
else [ Model $ model & amountValid .~ False ]
--
ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing] ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing]
-- | -- |
-- | Address Book Events -- | Address Book Events
@ -1937,18 +1826,18 @@ handleEvent wenv node model evt =
-- --
DisplayPaymentURIForm -> DisplayPaymentURIForm ->
[ Model $ [ Model $
model & paymentURIDisplay .~ True model & uriString .~ ""
& uriString .~ ""
& amountValid .~ False & amountValid .~ False
& sendAmount .~ 0.0 & sendAmount .~ 0.0
& sendMemo .~ "" & sendMemo .~ ""
& paymentURIDisplay .~ True
& menuPopup .~ False & menuPopup .~ False
] ]
ClosePaymentURIForm -> [Model $ model & paymentURIDisplay .~ False] ClosePaymentURIForm -> [Model $ model & paymentURIDisplay .~ False]
-- --
-- Generate URI -- Generate URI
-- --
GenURIString -> [ Task $ genURIString (model ^. sendAmount) (model ^. sendMemo) ] PrepareURIString -> [ Task $ genURIString (model ^. sendAmount) (model ^. sendMemo) ]
CloseShowURIOverlay -> [ Model $ model & showURIDisplay .~ False & uriString .~ "" ] CloseShowURIOverlay -> [ Model $ model & showURIDisplay .~ False & uriString .~ "" ]
-- --
-- Display Pay using URI Form -- Display Pay using URI Form