-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
357 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module Cardano.Wallet.UI.Deposit.API.Payments | ||
( NewPaymentParams (..) | ||
) | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.UI.Deposit.Types.Payments | ||
( Receiver (..) | ||
) | ||
import Web.FormUrlEncoded | ||
( FromForm (..) | ||
, parseAll | ||
, parseUnique | ||
) | ||
|
||
data NewPaymentParams = NewPaymentParams | ||
{ receivers :: [Receiver] | ||
, newReceiver :: Receiver | ||
} | ||
deriving (Eq, Show) | ||
|
||
instance FromForm NewPaymentParams where | ||
fromForm form = do | ||
receivers <- parseAll "receiver-defined" form | ||
address <- parseUnique "new-receiver-address" form | ||
amount <- parseUnique "new-receiver-amount" form | ||
let newReceiver = Receiver{address = address, amount = amount} | ||
pure $ NewPaymentParams{receivers, newReceiver} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Payments/Page.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
module Cardano.Wallet.UI.Deposit.Html.Pages.Payments.Page | ||
( paymentsH | ||
, paymentsElementH | ||
, receiversH | ||
) | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Deposit.IO | ||
( WalletPublicIdentity (..) | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Htmx | ||
( hxInclude_ | ||
, hxPost_ | ||
, hxTarget_ | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Lib | ||
( AlertH | ||
, WithCopy (..) | ||
, linkText | ||
, tdEnd | ||
, thEnd | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Pages.Lib | ||
( addressH | ||
, box | ||
, showAdaOfLoveLace | ||
, sseH | ||
) | ||
import Cardano.Wallet.UI.Deposit.API | ||
( paymentsNewReceiverLink | ||
) | ||
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet | ||
( WalletPresent (..) | ||
, onWalletPresentH | ||
) | ||
import Cardano.Wallet.UI.Deposit.Types.Payments | ||
( Receiver (..) | ||
) | ||
import Cardano.Wallet.UI.Type | ||
( WHtml | ||
) | ||
import Control.Monad | ||
( forM_ | ||
) | ||
import Lucid | ||
( Html | ||
, ToHtml (toHtml) | ||
, button_ | ||
, class_ | ||
, div_ | ||
, hidden_ | ||
, id_ | ||
, input_ | ||
, name_ | ||
, placeholder_ | ||
, table_ | ||
, tbody_ | ||
, thead_ | ||
, tr_ | ||
, type_ | ||
, value_ | ||
) | ||
import Servant | ||
( Link | ||
, ToHttpApiData (toUrlPiece) | ||
) | ||
|
||
paymentsH :: Link -> WHtml () | ||
paymentsH paymentsLink = do | ||
sseH paymentsLink "payments-page" ["wallet"] | ||
|
||
newReceiverH :: Html () | ||
newReceiverH = do | ||
div_ | ||
[id_ "new-receiver-form"] | ||
$ do | ||
input_ | ||
[ class_ "form-control" | ||
, type_ "text" | ||
, name_ "new-receiver-address" | ||
, placeholder_ "Address" | ||
] | ||
input_ | ||
[ class_ "form-control" | ||
, type_ "text" | ||
, name_ "new-receiver-amount" | ||
, placeholder_ "Amount" | ||
] | ||
button_ | ||
[ class_ "btn btn-primary" | ||
, type_ "submit" | ||
, hxPost_ $ linkText paymentsNewReceiverLink | ||
, hxTarget_ "#receivers" | ||
, hxInclude_ "#receivers-state , #new-receiver-form" | ||
] | ||
"Add" | ||
|
||
settledReceiversH :: [Receiver] -> Html () | ||
settledReceiversH rs = do | ||
table_ [class_ "table table-striped"] $ do | ||
thead_ $ do | ||
tr_ $ do | ||
thEnd Nothing "Address" | ||
thEnd (Just 7) "Amount" | ||
tbody_ [id_ "receivers-state"] | ||
$ forM_ rs | ||
$ \r@Receiver{address, amount} -> do | ||
tr_ $ do | ||
tdEnd $ do | ||
addressH WithCopy address | ||
input_ | ||
[ hidden_ "" | ||
, value_ $ toUrlPiece r | ||
, name_ "receiver-defined" | ||
] | ||
|
||
tdEnd $ toHtml $ showAdaOfLoveLace amount | ||
|
||
receiversH | ||
:: [Receiver] -> Html () | ||
receiversH rs = do | ||
settledReceiversH rs | ||
newReceiverH | ||
|
||
paymentsElementH | ||
:: AlertH | ||
-> WalletPresent | ||
-> Html () | ||
paymentsElementH = onWalletPresentH $ \case | ||
WalletPublicIdentity _xpub _customers -> | ||
div_ | ||
[ class_ "row mt-3 gx-0" | ||
] | ||
$ do | ||
box "New Payment" mempty | ||
$ div_ [class_ "ms-3"] | ||
$ do | ||
box "Receivers" mempty | ||
$ div_ [class_ "ms-3", id_ "receivers"] | ||
$ receiversH [] | ||
box "Transaction" mempty mempty | ||
box "Payments History" mempty "To be done" |
Oops, something went wrong.