Skip to content

Commit

Permalink
Add signing controls to deposit payments UI page
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Nov 15, 2024
1 parent 25e1fa5 commit 3333cf6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Cardano.Read.Ledger.Tx.CBOR
, serializeTx
)
import Cardano.Wallet.Deposit.Pure
( CurrentEraResolvedTx
( CanSign
, CurrentEraResolvedTx
, ErrCreatePayment
, InspectTx (..)
)
Expand All @@ -22,6 +23,7 @@ import Cardano.Wallet.Deposit.REST
( WalletResource
, WalletResourceM
, availableBalance
, canSign
, createPayment
, inspectTx
, resolveCurrentEraTx
Expand Down Expand Up @@ -64,7 +66,7 @@ import qualified Data.ByteString.Lazy.Char8 as BL8
import qualified Data.Text.Encoding as T

data PaymentHandlerResponse
= ResponseSuccess TransactionExport InspectTx
= ResponseSuccess TransactionExport InspectTx CanSign
| ResponseExceptionPayments ErrCreatePayment
| ResponseNoReceivers
deriving (Eq, Show)
Expand Down Expand Up @@ -116,6 +118,7 @@ respondCreatePayment render' r = do
Left e ->
pure $ render' $ ResponseExceptionPayments e
Right tx -> do
signing <- canSign
itx <- inspectTx tx
let
mt =
Expand All @@ -125,7 +128,7 @@ respondCreatePayment render' r = do
$ BL.toStrict
$ serializeTx
$ resolvedTx tx
pure $ render' $ ResponseSuccess mt itx
pure $ render' $ ResponseSuccess mt itx signing

data AddressValidationResponse
= ValidAddress Address Bool
Expand Down
51 changes: 43 additions & 8 deletions lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Payments/Page.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ where
import Prelude

import Cardano.Wallet.Deposit.Pure
( InspectTx (..)
( CanSign (..)
, InspectTx (..)
)
import Cardano.Wallet.Deposit.Pure.State.Payment.Inspect
( transactionBalance
Expand Down Expand Up @@ -300,31 +301,63 @@ transactionCBORH cbor =
$ toHtml
$ Aeson.encode cbor

signatureH :: CanSign -> Html ()
signatureH = \case
CanSign -> do
div_ [class_ "input-group"] $ do
input_
[ id_ "signature-password"
, class_ "form-control"
, type_ "password"
, name_ "passphrase"
, placeholder_ "passphrase"
]
button_
[ class_ "btn"
-- , hxPost_ $ linkText paymentsLink
-- , hxTarget_ "#receivers"
, hxInclude_ "#signature-password"
]
$ i_ [class_ "bi bi-check2-all"] mempty
CannotSign -> do
div_ [class_ "input-group"] $ do
input_
[ class_ "form-control"
, type_ "text"
, name_ "signed-tx"
, placeholder_ "signed tx"
]
button_
[ class_ "btn primary"
]
$ i_ [class_ "bi bi-check2-all"] mempty

updateReceiversH
:: [Receiver] -> Coin -> PaymentHandlerResponse -> Html ()
updateReceiversH rs balance transaction = do
receiversH rs
case transaction of
ResponseNoReceivers ->
ResponseNoReceivers -> do
div_ [id_ "unsigned-transaction-error", hxSwapOob_ "innerHTML"]
$ alertH ("No transaction defined" :: Text)
ResponseExceptionPayments e ->
div_ [id_ "signature", hxSwapOob_ "innerHTML"] mempty
ResponseExceptionPayments e -> do
div_ [id_ "unsigned-transaction-error", hxSwapOob_ "innerHTML"]
$ alertH
$ toText e
ResponseSuccess m tx -> do
div_ [id_ "signature", hxSwapOob_ "innerHTML"] mempty
ResponseSuccess m tx canSign -> do
div_ [id_ "unsigned-transaction-inspection", hxSwapOob_ "innerHTML"]
$ unsignedTransactionH
m
tx
$ unsignedTransactionH m tx
div_ [id_ "signature", hxSwapOob_ "innerHTML"] $ signatureH canSign
div_
[id_ "unsigned-transaction-error", hxSwapOob_ "innerHTML"]
mempty

div_ [id_ "available-balance", hxSwapOob_ "innerHTML"]
$ availableBalanceElementH balance
$ case transaction of
ResponseSuccess _ inspect ->
ResponseSuccess _ inspect _ ->
Just
$ fromIntegral
$ transactionBalance inspect
Expand Down Expand Up @@ -401,6 +434,8 @@ paymentsElementH =
div_ [class_ "", id_ "receivers"]
$ receiversH []
div_ [id_ "unsigned-transaction-error"] mempty
box "Signature" mempty
$ div_ [id_ "signature"] mempty
box
"Inspection"
(collapseBtn "unsigned-transaction-inspection")
Expand Down

0 comments on commit 3333cf6

Please sign in to comment.