Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numerous small housekeeping tasks on the playground. #410

Merged
merged 7 commits into from Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions plutus-playground/plutus-playground-client/.gitignore
@@ -1,8 +1,6 @@
/bower_components/
/node_modules/
/output/
/generated/
/yarn-error.log
/src/Playground/*
/src/Wallet/*
/src/Ledger/*
/.psci_modules/
3 changes: 2 additions & 1 deletion plutus-playground/plutus-playground-client/default.nix
Expand Up @@ -49,7 +49,8 @@ in {

${patchShebangs "node_modules/.bin/"}

cp -R ${psSrc}/* ./src/
mkdir generated
cp -R ${psSrc}/* generated/
cp --reflink=auto --no-preserve=mode -R $bowerComponents/bower_components .
'';

Expand Down
2 changes: 1 addition & 1 deletion plutus-playground/plutus-playground-client/package.json
Expand Up @@ -7,7 +7,7 @@
"purs:compile": "purs compile 'bower_components/purescript-*/src/**/*.purs' 'src/**/*.purs'",
"purs:bundle": "purs bundle output/**/*.js",
"start": "node bundle.js",
"test": "pulp test"
"test": "pulp test -I generated"
},
"dependencies": {
"ace-builds": "^1.4.1",
Expand Down
15 changes: 7 additions & 8 deletions plutus-playground/plutus-playground-client/src/Action.purs
Expand Up @@ -7,9 +7,8 @@ import Control.Monad.Aff.Class (class MonadAff)
import Data.Array (mapWithIndex)
import Data.Array as Array
import Data.Int as Int
import Data.Lens (view)
import Data.Lens (to, view)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Newtype (unwrap)
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Halogen (HTML)
Expand All @@ -22,11 +21,11 @@ import Halogen.HTML.Events as HE
import Halogen.HTML.Properties (InputType(InputText, InputNumber), class_, classes, disabled, for, placeholder, required, type_, value)
import Halogen.Query as HQ
import Icons (Icon(..), icon)
import Network.RemoteData (RemoteData(..))
import Playground.API (EvaluationResult, FunctionSchema, SimpleArgumentSchema)
import Network.RemoteData (RemoteData(Loading, NotAsked, Failure, Success))
import Playground.API (EvaluationResult, FunctionSchema, SimpleArgumentSchema, _EvaluationResult, _Fn, _FunctionSchema)
import Prelude (map, show, unit, ($), (+), (/=), (<$>), (<<<), (<>))
import Servant.PureScript.Affjax (AjaxError)
import Types (Action(Wait, Action), Blockchain, ChildQuery, ChildSlot, FormEvent(SetSubField, SetStringField, SetIntField), MockWallet, Query(EvaluateActions, AddWaitAction, PopulateAction, SetWaitTime, RemoveAction), SimpleArgument(Unknowable, SimpleObject, SimpleString, SimpleInt), ValidationError, _MockWallet, _wallet, validate)
import Types (Action(Wait, Action), Blockchain, ChildQuery, ChildSlot, FormEvent(SetSubField, SetStringField, SetIntField), MockWallet, Query(EvaluateActions, AddWaitAction, PopulateAction, SetWaitTime, RemoveAction), SimpleArgument(Unknowable, SimpleObject, SimpleString, SimpleInt), ValidationError, _MockWallet, _argumentSchema, _functionName, _wallet, validate)
import Wallet (walletIdPane, walletsPane)

simulationPane ::
Expand All @@ -41,7 +40,7 @@ simulationPane schemas wallets actions evaluationResult =
div_
[ walletsPane schemas wallets
, br_
, actionsPane actions ((_.resultBlockchain <<< unwrap) <$> evaluationResult)
, actionsPane actions (view (_EvaluationResult <<< to _.resultBlockchain) <$> evaluationResult)
]

actionsPane :: forall p. Array Action -> RemoteData AjaxError Blockchain -> HTML p Query
Expand Down Expand Up @@ -79,9 +78,9 @@ actionPane index action =
[ h3_
[ walletIdPane (view (_MockWallet <<< _wallet) mockWallet)
, text ": "
, text $ unwrap $ _.functionName $ unwrap functionSchema
, text $ view (_FunctionSchema <<< _functionName <<< _Fn) functionSchema
]
, actionArgumentForm index $ _.argumentSchema $ unwrap functionSchema
, actionArgumentForm index $ view (_FunctionSchema <<< _argumentSchema) functionSchema
]
(Wait {blocks}) ->
div_
Expand Down
113 changes: 0 additions & 113 deletions plutus-playground/plutus-playground-client/src/Data/JsonSchema.purs

This file was deleted.

@@ -1,12 +1,10 @@
module Data.RawJson where

import Data.Generic (class Generic)
import Data.Lens (Iso')
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Newtype (class Newtype)

import Prelude
import Data.Generic (class Generic)

newtype RawJson = RawJson String

derive instance genericRawJson :: Generic RawJson
Expand Down
16 changes: 9 additions & 7 deletions plutus-playground/plutus-playground-client/src/MainFrame.purs
Expand Up @@ -28,7 +28,6 @@ import Data.Generic (gEq)
import Data.Int as Int
import Data.Lens (_2, assign, maximumOf, modifying, over, set, to, traversed, use, view)
import Data.Lens.Index (ix)
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Map as Map
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Newtype (unwrap)
Expand All @@ -49,7 +48,7 @@ import Halogen.HTML.Properties (class_, classes, href)
import Halogen.Query (HalogenM)
import Network.HTTP.Affjax (AJAX)
import Network.RemoteData (RemoteData(Success, Failure, Loading, NotAsked))
import Playground.API (CompilationError(CompilationError, RawError), Evaluation(Evaluation), EvaluationResult(EvaluationResult), SourceCode(SourceCode))
import Playground.API (CompilationError(CompilationError, RawError), Evaluation(Evaluation), EvaluationResult(EvaluationResult), SourceCode(SourceCode), _FunctionSchema)
import Playground.API as API
import Playground.Server (SPParams_, postContract, postEvaluate)
import Prelude (type (~>), Unit, Void, bind, const, discard, flip, map, pure, unit, void, ($), (+), (<$>), (<*>), (<<<), (>>=))
Expand Down Expand Up @@ -92,6 +91,8 @@ evalWithAnalyticsTracking query = do
Just event -> liftEff $ trackEvent event
eval query

-- | Here we decide which top-level queries to track as GA events, and
-- how to classify them.
toEvent :: forall a. Query a -> Maybe Event
toEvent (HandleEditorMessage _ _) = Nothing
toEvent (HandleMockchainChartMessage _ _) = Nothing
Expand Down Expand Up @@ -217,7 +218,7 @@ eval (PopulateAction n l event) = do
<<< ix n
<<< _Action
<<< _functionSchema
<<< _Newtype
<<< _FunctionSchema
<<< _argumentSchema
<<< ix l)
(evalForm event)
Expand Down Expand Up @@ -355,15 +356,16 @@ mainHeader :: forall p i. HTML p i
mainHeader =
div_
[ div [ classes [ btnGroup, pullRight ] ]
(makeLink <$> [ Tuple "Getting Started" "https://webdevf.iohk.io/plutus/get-started/writing-contracts-in-plutus/"
, Tuple "Tutorial" "https://github.com/input-output-hk/plutus/blob/master/wallet-api/tutorial/Tutorial.md"
, Tuple "API" "https://input-output-hk.github.io/plutus/"
])
(makeLink <$> links)
, h1
[ class_ $ ClassName "main-title" ]
[ text "Plutus Playground" ]
]
where
links = [ Tuple "Getting Started" "https://webdevf.iohk.io/plutus/get-started/writing-contracts-in-plutus/"
, Tuple "Tutorial" "https://github.com/input-output-hk/plutus/blob/master/wallet-api/tutorial/Tutorial.md"
, Tuple "API" "https://input-output-hk.github.io/plutus/"
]
makeLink (Tuple name link) =
a [ classes [ btn, btnSmall ]
, href link
Expand Down
14 changes: 8 additions & 6 deletions plutus-playground/plutus-playground-client/src/Types.purs
Expand Up @@ -8,7 +8,7 @@ import Data.Either (Either)
import Data.Either.Nested (Either3)
import Data.Functor.Coproduct.Nested (Coproduct3)
import Data.Generic (class Generic, gShow)
import Data.Lens (Lens', Prism', _2, over, prism', traversed, view)
import Data.Lens (Lens', Prism', Lens, _2, over, prism', traversed, view)
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Record (prop)
import Data.Maybe (Maybe(..))
Expand Down Expand Up @@ -77,13 +77,16 @@ _Wait = prism' Wait f
f (Wait r) = Just r
f _ = Nothing

_functionSchema :: forall a r. Lens'{ functionSchema :: a | r} a
_functionSchema :: forall a b r. Lens { functionSchema :: a | r} { functionSchema :: b | r} a b
_functionSchema = prop (SProxy :: SProxy "functionSchema")

_argumentSchema :: forall a r. Lens'{ argumentSchema :: a | r} a
_argumentSchema :: forall a b r. Lens {argumentSchema :: a | r} {argumentSchema :: b | r} a b
_argumentSchema = prop (SProxy :: SProxy "argumentSchema")

_blocks :: forall a r. Lens'{ blocks :: a | r} a
_functionName :: forall a b r. Lens {functionName :: a | r} {functionName :: b | r} a b
_functionName = prop (SProxy :: SProxy "functionName")

_blocks :: forall a b r. Lens { blocks :: a | r} { blocks :: b | r} a b
_blocks = prop (SProxy :: SProxy "blocks")

------------------------------------------------------------
Expand Down Expand Up @@ -156,7 +159,6 @@ instance extendFormEvent :: Extend FormEvent where
extend f event@(SetStringField s _) = SetStringField s $ f event
extend f event@(SetSubField n _) = SetSubField n $ extend f event


instance comonadFormEvent :: Comonad FormEvent where
extract (SetIntField _ a) = a
extract (SetStringField _ a) = a
Expand Down Expand Up @@ -239,4 +241,4 @@ toValue (UnknownArgument _) = Unknowable

-- | This should just be `map` but we can't put an orphan instance on FunctionSchema. :-(
toValueLevel :: FunctionSchema SimpleArgumentSchema -> FunctionSchema SimpleArgument
toValueLevel = over (_Newtype <<< prop (SProxy :: SProxy "argumentSchema") <<< traversed) toValue
toValueLevel = over (_Newtype <<< _argumentSchema <<< traversed) toValue
3 changes: 2 additions & 1 deletion plutus-playground/plutus-playground-client/webpack.config.js
Expand Up @@ -53,7 +53,8 @@ module.exports = {
options: {
src: [
'bower_components/purescript-*/src/**/*.purs',
'src/**/*.purs'
'src/**/*.purs',
'generated/**/*.purs'
],
bundle: false,
psc: 'psa',
Expand Down