From ff6168b45e4f030993be289088565e92cfca03e5 Mon Sep 17 00:00:00 2001 From: "Rene V. Vergara A." Date: Sat, 4 Jan 2025 13:53:14 -0500 Subject: [PATCH] rvv001 - Synchronize branch with recent changes --- src/Zenith/CLI.hs | 34 ++++++---------------------------- src/Zenith/Utils.hs | 32 +++++++++++++++++++------------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index c48de3c..87807fc 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -512,7 +512,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] ]) <=> renderForm (st ^. deshieldForm) <=> C.hCenter - (hBox [capCommand "P" "roceed", capCommand " " "Cancel"])) + (hBox [capCommand "P" "roceed", capCommand3 "" " " "Cancel"])) ShieldForm -> D.renderDialog (D.dialog (Just (str " Shield ZEC ")) Nothing 50) @@ -523,7 +523,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] then displayZec (st ^. tBalance) else displayTaz (st ^. tBalance) ++ "?") <=> C.hCenter - (hBox [capCommand "P" "roceed", capCommand " " "Cancel"])) + (hBox [capCommand "P" "roceed", capCommand3 "" " " "Cancel"])) ViewingKeyShow -> D.renderDialog (D.dialog @@ -651,7 +651,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] (str " _____ _ _ _ \n|__ /___ _ __ (_) |_| |__\n / // _ \\ '_ \\| | __| '_ \\\n / /| __/ | | | | |_| | | |\n/____\\___|_| |_|_|\\__|_| |_|") <=> C.hCenter - (withAttr titleAttr (str "Zcash Wallet v0.7.0.0-beta")) <=> + (withAttr titleAttr (str "Zcash Wallet v0.7.1.0-beta")) <=> C.hCenter (withAttr blinkAttr $ str "Press any key...")) else emptyWidget capCommand3 :: String -> String -> String -> Widget Name @@ -854,29 +854,7 @@ mkDeshieldForm tbal = isAmountValid b i = fromIntegral b >= (i * scientific 1 8) label s w = padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w - -mkDeshieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name -mkDeshieldForm bal = - newForm - [ label "Total Transp. : " @@= - editShowableFieldWithValidate - totalTransparent - TotalTranspField - (isAmountValid bal) - , label "Total Shielded : " @@= - editShowableFieldWithValidate - totalShielded - TotalShieldedField - (isAmountValid bal) - , label "Amount: " @@= - editShowableFieldWithValidate shAmt AmtField (isAmountValid bal) - ] - where - isAmountValid :: Integer -> Float -> Bool - isAmountValid b i = (fromIntegral b / 100000000.0) >= i - label s w = - padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w - +{-- mkShieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name mkShieldForm bal = newForm @@ -884,11 +862,11 @@ mkShieldForm bal = editShowableFieldWithValidate shAmt AmtField (isAmountValid bal) ] where - isAmountValid :: Integer -> Float -> Bool + isAmountValid :: Integer -> Scientific -> Bool isAmountValid b i = (fromIntegral b / 100000000.0) >= i label s w = padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w - +--} mkNewABForm :: AdrBookEntry -> Form AdrBookEntry e Name mkNewABForm = newForm diff --git a/src/Zenith/Utils.hs b/src/Zenith/Utils.hs index 396e4f6..732ed33 100644 --- a/src/Zenith/Utils.hs +++ b/src/Zenith/Utils.hs @@ -311,20 +311,26 @@ parseQuery query = map (breakOn '=') (splitOn '&' query) -- Parse a ZIP-321 encoded string into a ZcashPayment structure parseZcashPayment :: String -> Either String ZcashPaymentURI parseZcashPayment input - | not (T.isPrefixOf "zcash:" (T.pack input)) = - Left "Invalid scheme: must start with 'zcash:'" + | not (T.isPrefixOf "zcash:" (T.pack input)) = Left "Invalid scheme: must start with 'zcash:'" | otherwise = - let (addrPart, queryPart) = break (== '?') (drop 6 input) - queryParams = parseQuery (drop 1 queryPart) - in Right - ZcashPaymentURI + let (addrPart, queryPart) = break (== '?') (drop 6 input) + queryParams = parseQuery (drop 1 queryPart) + in Right ZcashPaymentURI { uriAddress = addrPart - , uriAmount = lookup "amount" queryParams >>= readMaybe - , uriMemo = - case lookup "memo" queryParams of - Just m -> - T.pack (BC.unpack (processEither $ B64.decode $ BC.pack m)) - _ -> "" - , uriLabel = lookup "label" queryParams + , uriAmount = lookup "amount" queryParams >>= readMaybe + , uriMemo = case lookup "memo" queryParams of + Just m -> T.pack ( BC.unpack (processEither $ decodeBase64Unpadded (BC.pack m) ) ) + _ -> "" + , uriLabel = lookup "label" queryParams , uriMessage = lookup "message" queryParams } + +-- Function to pad a base64 string if it's not a multiple of 4 +padBase64 :: BC.ByteString -> BC.ByteString +padBase64 bs = bs <> BC.replicate paddingLength '=' + where + paddingLength = (4 - BC.length bs `mod` 4) `mod` 4 + +-- Function to decode a base64 un-padded string +decodeBase64Unpadded :: BC.ByteString -> Either String BC.ByteString +decodeBase64Unpadded = B64.decode . padBase64