diff --git a/lib/ui/cardano-wallet-ui.cabal b/lib/ui/cardano-wallet-ui.cabal index d08ce72f0ee..eb2d7f3c57a 100644 --- a/lib/ui/cardano-wallet-ui.cabal +++ b/lib/ui/cardano-wallet-ui.cabal @@ -121,7 +121,7 @@ library , aeson , aeson-pretty , base - , base58-bytestring + , base16-bytestring , bech32 , bech32-th , bytestring 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 50d1d418ecb..3a9d3186099 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 @@ -46,6 +46,14 @@ import Cardano.Wallet.UI.Deposit.Types.Payments import Control.Monad ( (<=<) ) +import Data.Aeson + ( FromJSON (parseJSON) + , KeyValue ((.=)) + , ToJSON (toJSON) + , object + , withObject + , (.:) + ) import Data.Text ( Text ) @@ -54,12 +62,12 @@ import Servant , Handler ) -import qualified Data.ByteString.Base58 as Base58 +import qualified Data.ByteString.Base16 as B16 import qualified Data.ByteString.Lazy as BL import qualified Data.Text.Encoding as T data PaymentHandlerResponse - = ResponseSuccess Text InspectTx + = ResponseSuccess TransactionExport InspectTx | ResponseExceptionPayments ErrCreatePayment | ResponseNoReceivers deriving (Eq, Show) @@ -88,6 +96,37 @@ createPaymentHandler layer alert render receivers = do Receiver{address, amount} <- receivers pure (address, ValueC (CoinC $ fromIntegral amount) mempty) +data TransactionExport + = TransactionExport + { dataType :: Text + , description :: Text + , cborHex :: Text + } + deriving (Eq, Show) + +instance ToJSON TransactionExport where + toJSON TransactionExport{dataType, description, cborHex} = + object + [ "type" .= dataType + , "description" .= description + , "cborHex" .= cborHex + ] + +instance FromJSON TransactionExport where + parseJSON = withObject "TransactionExport" $ \o -> do + dataType <- o .: "type" + description <- o .: "description" + cborHex <- o .: "cborHex" + pure TransactionExport{dataType, description, cborHex} + +conwayEraTransactionExport :: Text -> TransactionExport +conwayEraTransactionExport cborHex = + TransactionExport + { dataType = "Unwitnessed Tx ConwayEra" + , description = "Ledger Cddl Format" + , cborHex + } + respondCreatePayment :: (PaymentHandlerResponse -> html) -> Either ErrCreatePayment CurrentEraResolvedTx @@ -100,8 +139,9 @@ respondCreatePayment render' r = do itx <- inspectTx tx let mt = - T.decodeUtf8 - $ Base58.encodeBase58 Base58.bitcoinAlphabet + conwayEraTransactionExport + $ T.decodeUtf8 + $ B16.encode $ BL.toStrict $ serializeTx $ resolvedTx tx 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 012bb061c16..4c6aa5eeb90 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 @@ -65,6 +65,7 @@ import Cardano.Wallet.UI.Deposit.Handlers.Payments.Transaction ( AddressValidationResponse (..) , AmountValidationResponse (..) , PaymentHandlerResponse (..) + , TransactionExport ) import Cardano.Wallet.UI.Deposit.Html.Common ( lovelaceH @@ -111,6 +112,8 @@ import Servant , ToHttpApiData (toUrlPiece) ) +import qualified Data.Aeson as Aeson + paymentsH :: Link -> WHtml () paymentsH paymentsLink = do sseH paymentsLink "payments-page" ["payments"] @@ -289,10 +292,10 @@ unsignedTransactionH = \case tdEnd $ addressH WithCopy addr tdEnd $ lovelaceH $ fromIntegral amount -transactionCBORH :: Text -> Html () +transactionCBORH :: TransactionExport -> Html () transactionCBORH cbor = truncatableText WithCopy "unsigned-transaction-copy" - $ toHtml cbor + $ toHtml $ Aeson.encode cbor updateReceiversH :: [Receiver] -> Coin -> PaymentHandlerResponse -> Html ()