diff --git a/lib/ui/src/Cardano/Wallet/UI/Deposit/Handlers/Payments/Transaction.hs b/lib/ui/src/Cardano/Wallet/UI/Deposit/Handlers/Payments/Transaction.hs index 871f889e5f2..0440f8af900 100644 --- a/lib/ui/src/Cardano/Wallet/UI/Deposit/Handlers/Payments/Transaction.hs +++ b/lib/ui/src/Cardano/Wallet/UI/Deposit/Handlers/Payments/Transaction.hs @@ -11,7 +11,8 @@ import Cardano.Read.Ledger.Tx.CBOR , serializeTx ) import Cardano.Wallet.Deposit.Pure - ( CurrentEraResolvedTx + ( CanSign + , CurrentEraResolvedTx , ErrCreatePayment , InspectTx (..) ) @@ -22,6 +23,7 @@ import Cardano.Wallet.Deposit.REST ( WalletResource , WalletResourceM , availableBalance + , canSign , createPayment , inspectTx , resolveCurrentEraTx @@ -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) @@ -116,6 +118,7 @@ respondCreatePayment render' r = do Left e -> pure $ render' $ ResponseExceptionPayments e Right tx -> do + signing <- canSign itx <- inspectTx tx let mt = @@ -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 diff --git a/lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Payments/Page.hs b/lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Payments/Page.hs index 91d4e9326ab..4632016dc31 100644 --- a/lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Payments/Page.hs +++ b/lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Payments/Page.hs @@ -16,7 +16,8 @@ where import Prelude import Cardano.Wallet.Deposit.Pure - ( InspectTx (..) + ( CanSign (..) + , InspectTx (..) ) import Cardano.Wallet.Deposit.Pure.State.Payment.Inspect ( transactionBalance @@ -300,23 +301,55 @@ 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 @@ -324,7 +357,7 @@ updateReceiversH rs balance transaction = do div_ [id_ "available-balance", hxSwapOob_ "innerHTML"] $ availableBalanceElementH balance $ case transaction of - ResponseSuccess _ inspect -> + ResponseSuccess _ inspect _ -> Just $ fromIntegral $ transactionBalance inspect @@ -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")