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

Compress URI for exporting to Marlowe Runner #48

Merged
merged 1 commit into from
Oct 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions marlowe-playground-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions marlowe-playground-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"bootstrap": "^4.3.1",
"decimal.js": "^10.0.0",
"json-bigint": "^1.0.0",
"lz-string": "^1.5.0",
"monaco-editor": "^0.22.3",
"monaco-emacs": "^0.2.2",
"monaco-vim": "^0.1.7",
Expand Down
18 changes: 7 additions & 11 deletions marlowe-playground-client/src/MainFrame/State.purs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Data.RawJson (RawJson(..))
import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (class MonadEffect)
import Effect.Class.Console (log)
import Effect.Console as Console
import Gist (Gist, gistDescription, gistId)
import Gists.Extra (_GistId)
import Gists.Types (GistAction(..))
Expand All @@ -44,7 +43,6 @@ import Halogen.Monaco (KeyBindings(DefaultBindings))
import Halogen.Monaco as Monaco
import Halogen.Query (HalogenM)
import Halogen.Query.Event (eventListener)
import JSURI (encodeURIComponent)
import Language.Marlowe.Core.V1.Semantics.Types (Contract)
import Language.Marlowe.Extended.V1.Metadata
( emptyContractMetadata
Expand Down Expand Up @@ -127,6 +125,7 @@ import Simple.JSON (unsafeStringify)
import StaticData (gistIdLocalStorageKey)
import StaticData as StaticData
import Types (WebpackBuildMode(..))
import Web.Blob.CompressString (compressToURI)
import Web.HTML (window)
import Web.HTML (window) as Web
import Web.HTML.HTMLDocument (toEventTarget)
Expand Down Expand Up @@ -643,15 +642,12 @@ handleAction (OpenModal modalView) = assign _showModal $ Just modalView
handleAction CloseModal = assign _showModal Nothing

handleAction (SendToRunner url contractString) = do
case encodeURIComponent contractString of
Just encodedContract -> do
let fullUrl = url <> "?contract=" <> encodedContract
liftEffect $ do
win <- window
void $ open fullUrl "_blank" "" win
handleAction CloseModal
Nothing -> do
liftEffect $ Console.error "Failed to encode contract string for URL."
let encodedContract = compressToURI contractString
let fullUrl = url <> "?contract=" <> encodedContract
liftEffect $ do
win <- window
void $ open fullUrl "_blank" "" win
handleAction CloseModal

handleAction (OpenLoginPopup intendedAction) = do
authRole <- liftAff openLoginPopup
Expand Down
5 changes: 5 additions & 0 deletions marlowe-playground-client/src/Web/Blob/CompressString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import LZString from 'lz-string';

export function compressToURI(originalString) {
return LZString.compressToEncodedURIComponent(originalString);
}
3 changes: 3 additions & 0 deletions marlowe-playground-client/src/Web/Blob/CompressString.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Web.Blob.CompressString (compressToURI) where

foreign import compressToURI :: String -> String