rvv001 - URI string generation in progress
This commit is contained in:
parent
9ab31a6d9b
commit
de3bc48c38
4 changed files with 172 additions and 14 deletions
|
@ -166,8 +166,12 @@ data AppEvent
|
||||||
| ShowViewingKey !VkTypeDef !T.Text
|
| ShowViewingKey !VkTypeDef !T.Text
|
||||||
| CopyViewingKey !T.Text !T.Text
|
| CopyViewingKey !T.Text !T.Text
|
||||||
| CloseShowVK
|
| CloseShowVK
|
||||||
| DisplayPaymentURI
|
| DisplayPaymentURIForm
|
||||||
| ClosePaymentURI
|
| ClosePaymentURIForm
|
||||||
|
| GenURIString
|
||||||
|
| CheckAmountURI !Float
|
||||||
|
| CloseShowURIOverlay
|
||||||
|
| CopyURIString !T.Text
|
||||||
| DisplayPayUsingURI
|
| DisplayPayUsingURI
|
||||||
| ClosePayUsingURI
|
| ClosePayUsingURI
|
||||||
| ProcIfValidURI
|
| ProcIfValidURI
|
||||||
|
@ -238,6 +242,7 @@ data AppModel = AppModel
|
||||||
, _vkTypeName :: !T.Text
|
, _vkTypeName :: !T.Text
|
||||||
, _vkData :: !T.Text
|
, _vkData :: !T.Text
|
||||||
, _paymentURIDisplay :: !Bool
|
, _paymentURIDisplay :: !Bool
|
||||||
|
, _showURIDisplay :: !Bool
|
||||||
, _usepmtURIOverlay :: !Bool
|
, _usepmtURIOverlay :: !Bool
|
||||||
, _uriString :: !T.Text
|
, _uriString :: !T.Text
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
@ -292,6 +297,7 @@ buildUI wenv model = widgetTree
|
||||||
updateABAddress
|
updateABAddress
|
||||||
, showVKOverlay `nodeVisible` model ^. viewingKeyDisplay
|
, showVKOverlay `nodeVisible` model ^. viewingKeyDisplay
|
||||||
, paymentURIOverlay `nodeVisible` model ^. paymentURIDisplay
|
, paymentURIOverlay `nodeVisible` model ^. paymentURIDisplay
|
||||||
|
, showURIOverlay `nodeVisible` model ^. showURIDisplay
|
||||||
, pmtUsingURIOverlay `nodeVisible` model ^. usepmtURIOverlay
|
, pmtUsingURIOverlay `nodeVisible` model ^. usepmtURIOverlay
|
||||||
, shieldOverlay `nodeVisible` model ^. shieldZec
|
, shieldOverlay `nodeVisible` model ^. shieldZec
|
||||||
, deShieldOverlay `nodeVisible` model ^. deShieldZec
|
, deShieldOverlay `nodeVisible` model ^. deShieldZec
|
||||||
|
@ -387,7 +393,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 DisplayPaymentURI] (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]
|
||||||
|
@ -1253,10 +1259,40 @@ buildUI wenv model = widgetTree
|
||||||
[ box_
|
[ box_
|
||||||
[alignMiddle]
|
[alignMiddle]
|
||||||
(label "Create URI" `styleBasic`
|
(label "Create URI" `styleBasic`
|
||||||
[textColor white, textFont "Bold", textSize 12]) `styleBasic`
|
[textFont "Bold", textSize 12])
|
||||||
[bgColor btnColor]
|
|
||||||
, separatorLine `styleBasic` [fgColor btnColor]
|
, separatorLine `styleBasic` [fgColor btnColor]
|
||||||
, spacer
|
, spacer
|
||||||
|
, hstack
|
||||||
|
[ 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
|
||||||
|
, styleIf
|
||||||
|
(not $ model ^. recipientValid)
|
||||||
|
(textColor red)
|
||||||
|
]
|
||||||
|
]
|
||||||
, hstack
|
, hstack
|
||||||
[ label "Amount:" `styleBasic`
|
[ label "Amount:" `styleBasic`
|
||||||
[width 50, textFont "Bold"]
|
[width 50, textFont "Bold"]
|
||||||
|
@ -1284,14 +1320,14 @@ buildUI wenv model = widgetTree
|
||||||
[width 150, height 40]
|
[width 150, height 40]
|
||||||
]
|
]
|
||||||
, spacer
|
, spacer
|
||||||
|
-- Radio button group for privacy level
|
||||||
, box_
|
, box_
|
||||||
[alignMiddle]
|
[alignMiddle]
|
||||||
(hstack
|
(hstack
|
||||||
[ spacer
|
[ spacer
|
||||||
, mainButton "Create URI" NotImplemented `nodeEnabled`
|
, button "Cancel" ClosePaymentURIForm
|
||||||
True
|
|
||||||
, spacer
|
, spacer
|
||||||
, button "Cancel" ClosePaymentURI
|
, mainButton "Send" SendTx `nodeEnabled` False
|
||||||
, spacer
|
, spacer
|
||||||
])
|
])
|
||||||
]) `styleBasic`
|
]) `styleBasic`
|
||||||
|
@ -1301,6 +1337,82 @@ buildUI wenv model = widgetTree
|
||||||
, filler
|
, filler
|
||||||
]) `styleBasic`
|
]) `styleBasic`
|
||||||
[bgColor (white & L.a .~ 0.5)]
|
[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 =
|
||||||
|
alert CloseShowURIOverlay $
|
||||||
|
vstack
|
||||||
|
[ box_
|
||||||
|
[]
|
||||||
|
(label "Payment URI" `styleBasic`
|
||||||
|
[textFont "Bold", textColor white, textSize 12, padding 3]) `styleBasic`
|
||||||
|
[bgColor btnColor, radius 2, padding 3]
|
||||||
|
, spacer
|
||||||
|
, hstack
|
||||||
|
[filler, label_ (txtWrapN (model ^. uriString ) 64) [multiline], filler]
|
||||||
|
, spacer
|
||||||
|
, hstack
|
||||||
|
[ filler
|
||||||
|
, button "Copy to Clipboard" $
|
||||||
|
CopyURIString (model ^. uriString)
|
||||||
|
, filler
|
||||||
|
]
|
||||||
|
]
|
||||||
pmtUsingURIOverlay =
|
pmtUsingURIOverlay =
|
||||||
box
|
box
|
||||||
(vstack
|
(vstack
|
||||||
|
@ -1694,6 +1806,10 @@ handleEvent wenv node model evt =
|
||||||
model & amountValid .~
|
model & amountValid .~
|
||||||
(i < (fromIntegral (model ^. balance) / 100000000.0))
|
(i < (fromIntegral (model ^. balance) / 100000000.0))
|
||||||
]
|
]
|
||||||
|
CheckAmountURI i ->
|
||||||
|
[ Model $
|
||||||
|
model & amountValid .~ (i < (fromIntegral (model ^. balance) / 100000000.0))
|
||||||
|
]
|
||||||
ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing]
|
ShowTxId tx -> [Model $ model & showId ?~ tx & modalMsg .~ Nothing]
|
||||||
-- |
|
-- |
|
||||||
-- | Address Book Events
|
-- | Address Book Events
|
||||||
|
@ -1752,6 +1868,11 @@ handleEvent wenv node model evt =
|
||||||
, setClipboardData $ ClipboardText v
|
, setClipboardData $ ClipboardText v
|
||||||
, Event $ ShowMessage (t <> " viewing key copied!!")
|
, Event $ ShowMessage (t <> " viewing key copied!!")
|
||||||
]
|
]
|
||||||
|
CopyURIString u ->
|
||||||
|
[ setClipboardData ClipboardEmpty
|
||||||
|
, setClipboardData $ ClipboardText u
|
||||||
|
, Event $ ShowMessage "URI string copied to clipboard!!"
|
||||||
|
]
|
||||||
DeleteABEntry a ->
|
DeleteABEntry a ->
|
||||||
[ Task $ deleteAdrBook (model ^. configuration) a
|
[ Task $ deleteAdrBook (model ^. configuration) a
|
||||||
, Model $
|
, Model $
|
||||||
|
@ -1814,11 +1935,21 @@ handleEvent wenv node model evt =
|
||||||
--
|
--
|
||||||
-- Display PaymentURI Form
|
-- Display PaymentURI Form
|
||||||
--
|
--
|
||||||
DisplayPaymentURI ->
|
DisplayPaymentURIForm ->
|
||||||
[ Model $
|
[ Model $
|
||||||
model & paymentURIDisplay .~ True & uriString .~ "" & menuPopup .~ False
|
model & paymentURIDisplay .~ True
|
||||||
|
& uriString .~ ""
|
||||||
|
& amountValid .~ False
|
||||||
|
& sendAmount .~ 0.0
|
||||||
|
& sendMemo .~ ""
|
||||||
|
& menuPopup .~ False
|
||||||
]
|
]
|
||||||
ClosePaymentURI -> [Model $ model & paymentURIDisplay .~ False]
|
ClosePaymentURIForm -> [Model $ model & paymentURIDisplay .~ False]
|
||||||
|
--
|
||||||
|
-- Generate URI
|
||||||
|
--
|
||||||
|
GenURIString -> [ Task $ genURIString (model ^. sendAmount) (model ^. sendMemo) ]
|
||||||
|
CloseShowURIOverlay -> [ Model $ model & showURIDisplay .~ False & uriString .~ "" ]
|
||||||
--
|
--
|
||||||
-- Display Pay using URI Form
|
-- Display Pay using URI Form
|
||||||
--
|
--
|
||||||
|
@ -1841,9 +1972,8 @@ handleEvent wenv node model evt =
|
||||||
T.pack (uriAddress p) &
|
T.pack (uriAddress p) &
|
||||||
sendAmount .~
|
sendAmount .~
|
||||||
realToFrac a &
|
realToFrac a &
|
||||||
sendMemo .~
|
sendMemo .~ (uriMemo p)
|
||||||
(uriMemo p)
|
, Event $ ClosePaymentURIForm
|
||||||
, Event $ ClosePaymentURI
|
|
||||||
]
|
]
|
||||||
Nothing ->
|
Nothing ->
|
||||||
[ Model $
|
[ Model $
|
||||||
|
@ -2062,6 +2192,12 @@ handleEvent wenv node model evt =
|
||||||
let tsk = getTranSK $ zcashAccountTPrivateKey $ entityVal acc
|
let tsk = getTranSK $ zcashAccountTPrivateKey $ entityVal acc
|
||||||
ivk <- deriveUivk n osk ssk tsk
|
ivk <- deriveUivk n osk ssk tsk
|
||||||
return $ ShowViewingKey VkIncoming ivk
|
return $ ShowViewingKey VkIncoming ivk
|
||||||
|
--
|
||||||
|
-- Gen URI String
|
||||||
|
--
|
||||||
|
genURIString :: Float -> T.Text -> IO AppEvent
|
||||||
|
genURIString mAmt mMemo = do
|
||||||
|
return $ ShowMessage "Prueba de URI"
|
||||||
|
|
||||||
scanZebra ::
|
scanZebra ::
|
||||||
T.Text
|
T.Text
|
||||||
|
@ -2415,6 +2551,7 @@ runZenithGUI config = do
|
||||||
""
|
""
|
||||||
False
|
False
|
||||||
False
|
False
|
||||||
|
False
|
||||||
""
|
""
|
||||||
startApp model handleEvent buildUI (params hD)
|
startApp model handleEvent buildUI (params hD)
|
||||||
Left _e -> print "Zebra not available"
|
Left _e -> print "Zebra not available"
|
||||||
|
|
|
@ -22,6 +22,7 @@ import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
import qualified Data.Text.Encoding as TE
|
import qualified Data.Text.Encoding as TE
|
||||||
import Network.HTTP.Simple
|
import Network.HTTP.Simple
|
||||||
|
import Network.URI (escapeURIString, isUnreserved)
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.Process (createProcess_, shell)
|
import System.Process (createProcess_, shell)
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
|
@ -334,3 +335,14 @@ padBase64 bs = bs <> BC.replicate paddingLength '='
|
||||||
-- Function to decode a base64 un-padded string
|
-- Function to decode a base64 un-padded string
|
||||||
decodeBase64Unpadded :: BC.ByteString -> Either String BC.ByteString
|
decodeBase64Unpadded :: BC.ByteString -> Either String BC.ByteString
|
||||||
decodeBase64Unpadded = B64.decode . padBase64
|
decodeBase64Unpadded = B64.decode . padBase64
|
||||||
|
|
||||||
|
-- Function to encode memo as un-padded Base64
|
||||||
|
encodeMemo :: String -> String
|
||||||
|
encodeMemo = BC.unpack . BC.takeWhile (/= '=') . B64.encode . BC.pack
|
||||||
|
|
||||||
|
-- Function to create a ZIP-321 URI
|
||||||
|
createZip321 :: String -> Maybe Double -> Maybe String -> String
|
||||||
|
createZip321 address mAmount mMemo =
|
||||||
|
"zcash:" ++ address
|
||||||
|
++ maybe "" (\amount -> "?amount=" ++ show amount) mAmount
|
||||||
|
++ maybe "" (\memo -> "&memo=" ++ escapeURIString isUnreserved (encodeMemo memo)) mMemo
|
||||||
|
|
|
@ -1138,3 +1138,11 @@ main = do
|
||||||
print p
|
print p
|
||||||
(uriAmount p) `shouldBe` Just 100.0
|
(uriAmount p) `shouldBe` Just 100.0
|
||||||
Left e -> assertFailure $ "Error: " ++ e
|
Left e -> assertFailure $ "Error: " ++ e
|
||||||
|
describe "Create a ZIP-321 URI payment string " $ do
|
||||||
|
it "Creating an URI using a valid Zcash address, an amount, and a memo " $ do
|
||||||
|
let address = "ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez"
|
||||||
|
let amount = Just 1.2345
|
||||||
|
let memo = Just "This is a simple memo."
|
||||||
|
let uriString = createZip321 address amount memo
|
||||||
|
print uriString
|
||||||
|
uriString `shouldBe` "zcash:ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez?amount=1.2345&memo=VGhpcyBpcyBhIHNpbXBsZSBtZW1vLg"
|
||||||
|
|
|
@ -97,6 +97,7 @@ library
|
||||||
, word-wrap
|
, word-wrap
|
||||||
, zcash-haskell
|
, zcash-haskell
|
||||||
, unordered-containers
|
, unordered-containers
|
||||||
|
, network-uri
|
||||||
--pkgconfig-depends: rustzcash_wrapper
|
--pkgconfig-depends: rustzcash_wrapper
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue