Skip to content

Commit

Permalink
Implement provisional rendering for transaction composer
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Mar 14, 2019
1 parent 23bae57 commit 65bc427
Showing 1 changed file with 70 additions and 20 deletions.
90 changes: 70 additions & 20 deletions meadow-client/src/Simulation.purs
Expand Up @@ -17,10 +17,11 @@ import Bootstrap
, cardBody_
, card_
, col6
, col_
, row_
, empty
, listGroupItem_
, listGroup_
, row_
)
import Control.Alternative (map, (<|>))
import Control.Monad.Aff.Class (class MonadAff)
Expand All @@ -36,6 +37,7 @@ import Halogen.HTML
( ClassName
( ClassName
)
, b_
, br_
, button
, code_
Expand Down Expand Up @@ -99,6 +101,7 @@ import Types
, MarloweError
( MarloweError
)
, MarloweState
, OracleEntry
, Query
( SetSignature
Expand Down Expand Up @@ -215,7 +218,7 @@ inputComposer :: forall p. InputData -> Array (HTML p Query)
inputComposer { inputs, choiceData, oracleData } =
Array.concat [ Array.concat (Array.fromFoldable (map (\x -> inputComposerPerson x inputs choiceData) people))
, if (Map.isEmpty oracleData)
then []
then []
else [ h3_ [ text ("Oracles") ] ]
, Array.fromFoldable (map inputComposerOracle oracles)
]
Expand All @@ -235,7 +238,7 @@ inputComposerPerson person inputs choices =
, case Map.lookup person inputs of
Nothing -> []
Just x -> Array.fromFoldable
do y <- x
do y <- x
case y of
DWAICommit idAction idCommit val tim ->
pure (inputCommit person idAction idCommit val tim)
Expand Down Expand Up @@ -284,7 +287,7 @@ inputChoice person idChoice val =
-- , onClick <<< input_ <<< UpdatePerson $ promoteAction person idx
] [ text "+"
]
, spanText "Choice "
, spanText "Choice "
, spanText (show idChoice)
, spanText ": Choose value "
, spanText (show val)
Expand Down Expand Up @@ -403,15 +406,18 @@ transactionComposerPane ::
forall p.
FrontendState ->
HTML p Query
transactionComposerPane state = div [ classes [ col6
, ClassName "input-composer"
]
] [ paneHeader "Transaction Composer"
, div [ class_ $ ClassName "wallet"
] [ card_ [ cardBody_ $ (signatures state.marloweState.transaction.signatures) <> transactionButtons
]
]
]
transactionComposerPane state =
div [ classes [ col6
, ClassName "input-composer"
]
] [ paneHeader "Transaction Composer"
, div [ class_ $ ClassName "wallet"
] [ card_ [ cardBody_ $ transactionInputs state.marloweState
<> (signatures state.marloweState.transaction.signatures)
<> transactionButtons
]
]
]

transactionButtons :: forall p. Array (HTML p Query)
transactionButtons = [ div [ classes [ ClassName "d-flex"
Expand Down Expand Up @@ -466,13 +472,57 @@ signature (Tuple person isChecked) = span [ class_ $ ClassName "pr-2"
]
]

--transactionComposerPerson ::
-- forall p.
-- Person ->
-- Array (HTML p Query)
--transactionComposerPerson person = [ h3_ [ text ("Person " <> show person.id)
-- ]
-- ] <> mapWithIndex (actionRow person) person.actions
transactionInputs :: forall p. MarloweState -> Array (HTML p Query)
transactionInputs state = [ h3_ [ text "Action list"
]
] <> map (inputRow) state.transaction.inputs

inputRow :: forall p. AnyInput -> HTML p Query
inputRow (Action idAction) =
row_ [ col_ [ button [ class_ $ ClassName "composer-add-button"
-- , onClick <<< input_ <<< UpdatePerson $ demoteAction person idx
] [ text "-"
]
, text "Action with id "
, b_ [ text (show idAction)
]
]
]

inputRow (Input (IChoice (IdChoice {choice, person}) val)) =
row_ [ col_ [ button [ class_ $ ClassName "composer-add-button"
-- , onClick <<< input_ <<< UpdatePerson $ demoteAction person idx
] [ text "-"
]
, text "Participant "
, b_ [ text (show person)
]
, text " chooses the value "
, b_ [ text (show val)
]
, text " for choice with id "
, b_ [ text (show choice)
]
]
]

inputRow (Input (IOracle idOracle bn val)) =
row_ [ col_ [ button [ class_ $ ClassName "composer-add-button"
-- , onClick <<< input_ <<< UpdatePerson $ demoteAction person idx
] [ text "-"
]
, text "Oracle "
, b_ [ text (show idOracle)
]
, text " had value "
, b_ [ text (show val)
]
, text " at block "
, b_ [ text (show bn)
]
]
]

--actionRow ::
-- forall p.
-- Person ->
Expand Down

0 comments on commit 65bc427

Please sign in to comment.