mirror of
https://github.com/status-im/pluto.git
synced 2026-08-30 20:11:07 +00:00
301 lines
8.8 KiB
HTML
301 lines
8.8 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codemirror@5.40.2/lib/codemirror.css">
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
|
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
|
|
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.40.2/lib/codemirror.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.40.2/mode/clojure/clojure.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/parinfer@3.12.0/parinfer.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/parinfer-codemirror@1.4.2/parinfer-codemirror.min.js"></script>
|
|
<script src="https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
|
|
const TIMEOUT = 5; // seconds
|
|
const timeout = new Promise((resolve, reject) => {
|
|
return setTimeout(() => reject(new Error('request timeout')), TIMEOUT * 1000);
|
|
});
|
|
|
|
async function cat(hash) {
|
|
try {
|
|
const response = await Promise.race([timeout, fetch("https://ipfs.infura.io:5001/api/v0/cat?arg=" + hash)]);
|
|
if (response.status === 200) {
|
|
return response.text();
|
|
}
|
|
return null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function add(content) {
|
|
const formData = new FormData();
|
|
formData.append("extension.edn", content);
|
|
const response = await fetch("https://ipfs.infura.io:5001/api/v0/add", {
|
|
method: 'post',
|
|
body: formData
|
|
});
|
|
if (response.status === 200) {
|
|
return response.json();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
const defaultHash = "Qmaznq6qZWPTjzh1ZcKJrwSQKt6VF3UL2tUSDkvAUYDRk2";
|
|
|
|
function clearHash() {
|
|
history.replaceState({hash: null}, null, document.location.href.split('?')[0]);
|
|
}
|
|
|
|
async function main () {
|
|
const params = (new URL(document.location)).searchParams;
|
|
const hash = params.get("hash") || defaultHash;
|
|
const content = await cat(hash);
|
|
if (content != null) {
|
|
codeMirror.setValue(content);
|
|
history.replaceState({hash: hash}, null, document.location.href.split('?')[0] + "?hash=" + hash);
|
|
displayQR(hash);
|
|
} else {
|
|
codeMirror.setValue("Failed to load the extension");
|
|
clearHash();
|
|
}
|
|
}
|
|
|
|
function extensionLink(hash) {
|
|
return "https://get.status.im/extension/ipfs@" + hash;
|
|
}
|
|
|
|
async function publish() {
|
|
const content = codeMirror.getValue();
|
|
const bel = document.getElementById("publish");
|
|
bel.disabled = true;
|
|
const object = await add(content);
|
|
if (object !== null) {
|
|
const hash = object.Hash;
|
|
history.pushState({hash: hash}, null, document.location.href.split('?')[0] + "?hash=" + hash);
|
|
displayQR(hash);
|
|
} else {
|
|
const qel = document.getElementById("qr-wrapper");
|
|
qel.innerHTML = "Failed to publish the extension";
|
|
}
|
|
bel.disabled = false;
|
|
}
|
|
|
|
function clearErrors() {
|
|
const elErrors = document.getElementById("errors");
|
|
elErrors.innerHTML = '';
|
|
elErrors.className = "";
|
|
}
|
|
|
|
function displayErrors(errors) {
|
|
const elErrors = document.getElementById("errors");
|
|
if (errors == null) {
|
|
elErrors.innerHTML = '<div>No errors</div>';
|
|
elErrors.classList.add("ok");
|
|
} else {
|
|
elErrors.classList.add("errors");
|
|
|
|
const names = errors.map( (error, i) => {
|
|
return [error.type, error.value]
|
|
})
|
|
var s = '<div>Errors</div><ul>';
|
|
names.forEach(function(element) {
|
|
s = s.concat("<li>" + element[0]);
|
|
if (element[1] != null) {
|
|
s = s.concat(":" + JSON.stringify(element[1]));
|
|
}
|
|
s = s.concat("</li>");
|
|
});
|
|
s = s.concat("</ul>")
|
|
elErrors.innerHTML = s;
|
|
}
|
|
}
|
|
|
|
function clearQR() {
|
|
const qel = document.getElementById("qr-wrapper");
|
|
qel.innerHTML = '';
|
|
}
|
|
|
|
function displayQR(hash) {
|
|
const qel = document.getElementById("qr-wrapper");
|
|
const s = extensionLink(hash);
|
|
qel.innerHTML = '<canvas id="qr"></canvas><a href="' + s + '">Universal link</a><a href="https://ipfs.infura.io/ipfs/' + hash + '/">IPFS link</a>';
|
|
new QRious({
|
|
element: document.getElementById('qr'),
|
|
value: s,
|
|
size: 250
|
|
});
|
|
}
|
|
|
|
main();
|
|
</script>
|
|
<div id="wrapper">
|
|
<main>
|
|
<div id="content"></div>
|
|
<div id="errors"></div>
|
|
</main>
|
|
<aside id="side-column">
|
|
<div id="panel">
|
|
<p>A playground to experiment with extensions and easily publish them on IPFS. Go ahead, modify the default extension on the left side!</p>
|
|
<p>Find more details about building your own extension in this <a href="https://status.im/extensions/">tutorial</a></p>
|
|
<button id="publish" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" onclick="publish()">Publish</button>
|
|
<div id="qr-wrapper"></div>
|
|
</div>
|
|
<div id="docs">
|
|
<h6>Components</h6>
|
|
<ul>
|
|
<li><code>view</code></li>
|
|
<li><code>text</code></li>
|
|
<li>
|
|
<code>touchable-opacity</code>
|
|
<pre class="inline-args">{:on-press Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>image</code>
|
|
<pre class="inline-args">{:uri String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>input</code>
|
|
<pre>{:on-change Event
|
|
:placeholder String}</pre></li>
|
|
<li>
|
|
<code>button</code>
|
|
<pre class="inline-args">{:on-click Event}</pre></li>
|
|
<li>
|
|
<code>link</code>
|
|
<pre class="inline-args">{:uri String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>checkbox</code>
|
|
<pre class="inline-args">{:on-change Event :checked Bool}</pre>
|
|
</li>
|
|
<li>
|
|
<code>list</code>
|
|
<pre class="inline-args">{:data Vector :item-view View :key Keyword}</pre>
|
|
</li>
|
|
<li>
|
|
<code>picker</code>
|
|
<pre class="inline-args">{:on-change Event :selected String :enabled Boolean :data Vector}</pre>
|
|
</li>
|
|
<li>
|
|
<code>activity-indicator</code>
|
|
<pre class="inline-args">{:animating Boolean :color String :size Keyword :hides-when-stopped Boolean}</pre>
|
|
</li>
|
|
<li>
|
|
<code>nft-token-viewer</code>
|
|
<pre class="inline-args">{:token String}</pre>
|
|
</li>
|
|
<li><code>transaction-status</code>
|
|
<pre class="inline-args">{:outgoing String :tx-hash String}</pre></li>
|
|
<li><code>asset-selector</code></li>
|
|
<li><code>token-selector</code></li>
|
|
</ul>
|
|
<h6>Queries</h6>
|
|
<ul>
|
|
<li>
|
|
<code>store/get</code>
|
|
<pre class="inline-args">{:key String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>wallet/collectibles</code>
|
|
<pre class="inline-args">{:token String :symbol String}</pre>
|
|
</li>
|
|
</ul>
|
|
<h6>Events</h6>
|
|
<ul>
|
|
<li>
|
|
<code>alert</code>
|
|
<pre class="inline-args">{:value String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>log</code>
|
|
<pre class="inline-args">{:value String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>store/put</code>
|
|
<pre class="inline-args">{:key String :value String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>store/append</code>
|
|
<pre class="inline-args">{:key String :value String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>store/clear</code>
|
|
<pre class="inline-args">{:key String}</pre>
|
|
</li>
|
|
<li>
|
|
<code>http/get</code>
|
|
<pre>{:url String
|
|
:timeout? String
|
|
:on-success Event
|
|
:on-failure? Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>http/post</code>
|
|
<pre>{:url String
|
|
:body String
|
|
:timeout? String
|
|
:on-success Event
|
|
:on-failure? Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>ipfs/cat</code>
|
|
<pre>{:hash String
|
|
:on-success Event
|
|
:on-failure? Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>ethereum/send-transaction</code>
|
|
<pre>{:to String
|
|
:gas? String
|
|
:gas-price? String
|
|
:value? String
|
|
:method? String
|
|
:params? Vector
|
|
:nonce? String
|
|
:on-result? Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>ethereum/logs</code>
|
|
<pre>{:fromBlock? String
|
|
:toBlock? String
|
|
:address? Vector
|
|
:topics? Vector
|
|
:blockhash? String
|
|
:on-result Event}</pre>
|
|
</li>
|
|
<li>
|
|
<code>ethereum/call</code>
|
|
<pre>{:to String
|
|
:method String
|
|
:params? Vector
|
|
:on-result? Event}</pre>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</aside>
|
|
</div>
|
|
<script>
|
|
const codeMirror = CodeMirror(document.getElementById("content"));
|
|
codeMirror.setValue("Loading content ...");
|
|
codeMirror.on("change", function(c, change) {
|
|
clearErrors();
|
|
clearQR();
|
|
clearHash();
|
|
const read = pluto.reader.read(codeMirror.getValue());
|
|
const readJS = pluto.js.from_clj(read);
|
|
displayErrors(readJS.errors);
|
|
if (readJS.errors == null) {
|
|
const parsed = pluto.js.parse(read);
|
|
const parsedJS = pluto.js.from_clj(parsed);
|
|
displayErrors(parsedJS.errors);
|
|
}
|
|
});
|
|
parinferCodeMirror.init(codeMirror);
|
|
</script>
|
|
</body>
|
|
</html>
|