Skip to content

Commit

Permalink
Create HTML files for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gantunesr committed Nov 17, 2022
1 parent f328854 commit 54f6f40
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 0 deletions.
47 changes: 47 additions & 0 deletions app/components/Views/Snaps/content/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<script>
function killSnap(snapId) {
const frame = document.getElementById(snapId);
if (frame) {
frame.parentNode.removeChild(frame);
}
}

function createIframe(snapId, sourceCode) {

}

window.addEventListener("message", message => {
const { method, snapId, args } = JSON.parse(message.data);
switch (method) {
case 'start_snap':
// create iframe
return;
case 'execute_snap':
const response = document.getElementById(snapId).contentWindow.snap.onRpcRequest(args);
sendDataToReactNativeApp(JSON.stringify(response))
return;
case 'kill_snap':
killSnap(snapId);
return;
}
});
</script>
<body
style="display: flex; justify-content: center; flex-direction: column; align-items: center;"
>
<button
onclick="sendDataToReactNativeApp()"
style="padding: 20; width: 200; font-size: 30; color: white; background-color: #6751ff;"
>
Send data to app
</button>
<div>
<p id="myContent">Basic HTML</p>
<iframe id="snap-1" name="snap-1" src="./iframe1.html"></iframe>
<iframe id="snap-2" name="snap-2" src="./iframe2.html"></iframe>
</div>
</body>

</html>
93 changes: 93 additions & 0 deletions app/components/Views/Snaps/content/iframe1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html>
<head>
<script>
(function (f) {
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = f();
} else if (typeof define === "function" && define.amd) {
define([], f);
} else {
var g;

if (typeof window !== "undefined") {
g = window;
} else if (typeof global !== "undefined") {
g = global;
} else if (typeof self !== "undefined") {
g = self;
} else {
g = this;
}

g.snap = f();
}
})(function () {
var define, module, exports;
return function () {
function r(e, n, t) {
function o(i, f) {
if (!n[i]) {
if (!e[i]) {
var c = "function" == typeof require && require;
if (!f && c) return c(i, !0);
if (u) return u(i, !0);
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}

var p = n[i] = {
exports: {}
};
e[i][0].call(p.exports, function (r) {
var n = e[i][1][r];
return o(n || r);
}, p, p.exports, r, e, n, t);
}

return n[i].exports;
}

for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);

return o;
}

return r;
}()({
1: [function (require, module, exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.onRpcRequest = exports.getMessage = void 0;

const getMessage = originString => {
return `Hello ya cunt, ${originString}!`;
};

exports.getMessage = getMessage;

const onRpcRequest = ({
origin,
request
}) => {
switch (request.method) {
case 'hello':
return 'hello from snap 1'
default:
throw new Error('Method not found.');
}
};

exports.onRpcRequest = onRpcRequest;
}, {}]
}, {}, [1])(1);
});
</script>
</head>
<body>
<p>Iframe Env - Hello World Snap 1</p>
</body>
</html>
95 changes: 95 additions & 0 deletions app/components/Views/Snaps/content/iframe2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<script>
(function (f) {
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = f();
} else if (typeof define === "function" && define.amd) {
define([], f);
} else {
var g;

if (typeof window !== "undefined") {
g = window;
} else if (typeof global !== "undefined") {
g = global;
} else if (typeof self !== "undefined") {
g = self;
} else {
g = this;
}

g.snap = f();
}
})(function () {
var define, module, exports;
return function () {
function r(e, n, t) {
function o(i, f) {
if (!n[i]) {
if (!e[i]) {
var c = "function" == typeof require && require;
if (!f && c) return c(i, !0);
if (u) return u(i, !0);
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}

var p = n[i] = {
exports: {}
};
e[i][0].call(p.exports, function (r) {
var n = e[i][1][r];
return o(n || r);
}, p, p.exports, r, e, n, t);
}

return n[i].exports;
}

for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);

return o;
}

return r;
}()({
1: [function (require, module, exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.onRpcRequest = exports.getMessage = void 0;

const getMessage = originString => {
return `Hello ya cunt, ${originString}!`;
};

exports.getMessage = getMessage;

const onRpcRequest = ({
origin,
request
}) => {
switch (request.method) {
case 'hello':
console.log('hello from snap 2');
return 'hello from snap 2'

default:
throw new Error('Method not found.');
}
};

exports.onRpcRequest = onRpcRequest;
}, {}]
}, {}, [1])(1);
});
</script>
</head>
<body>
<p>Iframe Env - Hello World Snap 2</p>
</body>
</html>

0 comments on commit 54f6f40

Please sign in to comment.