/
View.purs
179 lines (170 loc) · 6.37 KB
/
View.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
module View (render) where
import Types
import AjaxUtils (ajaxErrorPane)
import Bootstrap (btn, btnGroup, btnInfo, btnSmall, colLg5, colLg7, colMd4, colMd8, colSm5, colSm6, colXs12, container_, empty, justifyContentBetween, noGutters, row, row_)
import Chain (evaluationPane)
import Control.Monad.State (evalState)
import Data.Either (Either(..))
import Data.Lens (_Right, view)
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
import Data.Semiring (zero)
import Data.Tuple (Tuple(Tuple))
import Editor.View (compileButton, editorFeedback, editorView)
import Effect.Aff.Class (class MonadAff)
import Gists.View (gistControls)
import Halogen.HTML (ClassName(ClassName), ComponentHTML, HTML, a, button, div, div_, h1, span, strong_, text)
import Halogen.HTML.Events (onClick)
import Halogen.HTML.Extra (mapComponent)
import Halogen.HTML.Properties (class_, classes, href, id_, target)
import Icons (Icon(..), icon)
import Language.Haskell.Interpreter (_SourceCode)
import NavTabs (mainTabBar, viewContainer)
import Network.RemoteData (RemoteData(..), _Success)
import Playground.Types (ContractDemo(..))
import Prelude (const, ($), (<$>), (<<<))
import Schema.Types (mkInitialValue)
import Simulation (actionsErrorPane, simulationPane)
import StaticData (_contractDemoEditorContents)
import StaticData as StaticData
render ::
forall m.
MonadAff m =>
State -> ComponentHTML HAction ChildSlots m
render state@(State { currentView, blockchainVisualisationState, contractDemos, editorState }) =
div
[ class_ $ ClassName "main-frame" ]
[ container_
[ mainHeader
, div [ classes [ row, noGutters, justifyContentBetween ] ]
[ div [ classes [ colXs12, colSm6 ] ] [ mainTabBar ChangeView tabs currentView ]
, div
[ classes [ colXs12, colSm5 ] ]
[ GistAction <$> gistControls (unwrap state) ]
]
]
, viewContainer currentView Editor
let
compilationResult = view _compilationResult state
in
[ row_
[ div
[ classes [ colXs12, colMd4, colLg7 ] ]
[ compileButton CompileProgram compilationResult ]
, div
[ classes [ colXs12, colMd8, colLg5 ] ]
[ documentationLinksPane
, contractDemosPane contractDemos
]
]
, mapComponent EditorAction $ editorView defaultContents StaticData.bufferLocalStorageKey editorState
, compileButton CompileProgram compilationResult
, mapComponent EditorAction $ editorFeedback compilationResult
, case compilationResult of
Failure error -> ajaxErrorPane error
_ -> empty
]
, viewContainer currentView Simulations
$ let
knownCurrencies = evalState getKnownCurrencies state
initialValue = mkInitialValue knownCurrencies zero
in
[ simulationPane
initialValue
(view _actionDrag state)
( view
( _compilationResult
<<< _Success
<<< _Right
<<< _Newtype
<<< _result
<<< _functionSchema
)
state
)
(view _simulations state)
(view _evaluationResult state)
, case (view _evaluationResult state) of
Failure error -> ajaxErrorPane error
Success (Left error) -> actionsErrorPane error
_ -> empty
]
, viewContainer currentView Transactions
$ case view _evaluationResult state of
Success (Right evaluation) -> [ evaluationPane blockchainVisualisationState evaluation ]
Success (Left error) ->
[ text "Your simulation has errors. Click the "
, strong_ [ text "Simulation" ]
, text " tab above to fix them and recompile."
]
Failure error ->
[ text "Your simulation has errors. Click the "
, strong_ [ text "Simulation" ]
, text " tab above to fix them and recompile."
]
Loading -> [ icon Spinner ]
NotAsked ->
[ text "Click the "
, strong_ [ text "Simulation" ]
, text " tab above and evaluate a simulation to see some results."
]
]
where
defaultContents :: Maybe String
defaultContents = view (_contractDemoEditorContents <<< _SourceCode) <$> StaticData.lookup "Vesting" contractDemos
contractDemosPane :: forall p. Array ContractDemo -> HTML p HAction
contractDemosPane contractDemos =
div [ id_ "demos" ]
[ strong_ [ text "Demos: " ]
, span [ classes [ btnGroup ] ] (demoScriptButton <$> contractDemos)
]
demoScriptButton :: forall p. ContractDemo -> HTML p HAction
demoScriptButton (ContractDemo { contractDemoName }) =
button
[ classes [ btn, btnInfo, btnSmall ]
, onClick $ const $ Just $ LoadScript contractDemoName
]
[ text contractDemoName ]
mainHeader :: forall p. HTML p HAction
mainHeader =
div_
[ h1
[ class_ $ ClassName "main-title" ]
[ text "Plutus Playground" ]
]
documentationLinksPane :: forall p i. HTML p i
documentationLinksPane =
div [ id_ "docs" ]
[ strong_ [ text "Documentation: " ]
, span [ classes [ btnGroup ] ] (makeLink <$> links)
]
where
links =
[ Tuple "Getting Started" "https://testnet.iohkdev.io/plutus/get-started/writing-contracts-in-plutus/"
, Tuple "Tutorial" "./tutorial/index.html"
, Tuple "API" "./tutorial/haddock/index.html"
, Tuple "Privacy" "https://static.iohk.io/docs/data-protection/iohk-data-protection-gdpr-policy.pdf"
]
makeLink (Tuple name link) =
a
[ classes [ btn, btnInfo, btnSmall ]
, href link
, target "_blank"
]
[ text name ]
tabs :: Array { help :: String, link :: View, title :: String }
tabs =
[ { link: Editor
, title: "Editor"
, help: "Edit and compile your contract."
}
, { link: Simulations
, title: "Simulation"
, help: "Set up simulations to test your contract's behavior."
}
, { link: Transactions
, title: "Transactions"
, help: "See how your contract behaves on a simulated blockchain."
}
]