Skip to content
Snippets Groups Projects
Commit 2a5aa09a authored by Jono Wenger's avatar Jono Wenger
Browse files

Create javascript utils file

parent 12f3ec06
No related branches found
No related tags found
1 merge request!6XX-4050 / Send E2E test
......@@ -15,6 +15,7 @@
<link rel="shortcut icon" type="image/x-icon" href="receiver-favicon.ico"/>
<script type="text/javascript" src="xxdk.js"></script>
<script type="text/javascript" src="../utils.js"></script>
<script type="text/javascript" src="../wasm_exec.js"></script>
<script>
const go = new Go();
......@@ -39,7 +40,7 @@
// Client specific parameters
const recipientContactFile = '';
const myContactFileName = 'receiverContact.xxc';
const statePath = 'statePathRecipient2';
const statePath = 'statePathRecipient';
const statePass = 'password';
document.getElementById('ndfInput').addEventListener('change', e => {
......
......@@ -15,6 +15,7 @@
<link rel="shortcut icon" type="image/x-icon" href="sender-favicon.ico"/>
<script type="text/javascript" src="xxdk.js"></script>
<script type="text/javascript" src="../utils.js"></script>
<script type="text/javascript" src="../wasm_exec.js"></script>
<script>
const go = new Go();
......@@ -39,7 +40,7 @@
// Client specific parameters
const recipientContactFile = '<xxc(2)I71lyX8LvKP6cJhedliFLIKzXN/2ArmBAfAxkk1QapADrgZ7Ugdw/BAr6RDo4K2MfHn7e06Kru7jW05ROtaaoNSyMIB3R77BIJy7xB/fvkzteTpxxmHtZdXPt9UpYVA9WKzbM57vkmy+U6BlRJIrN97tAlWbODIG1FGpjWI/BCdqwaLgu0wTYLzzEw38NNyax0E2MnvURgQoSfnX5V+m+Qd2sJBqfBKi9tlLuNcaFI+TGyKGbZdSs4AZdiL/Xm94w1/id4SDEoV73RaJb3RH+W+rEMIl1SnZ4U6Ifo39cZfRKevL2mXUZj/SE0NWGl4+10Jovy0Hp6NoW2iMH4zB30xv3fqyp8ATAYXYYO5ToFmHvP1fRLq7TKa+WtGnO70uiykBaYl219WcGYIz4jXDYyN3yNnOhihKo2tauyC0qGeGCSoACDxvzLGTHxHkS/cDA92L0MEsiXy3HIuv5+OYZBuiWl1dLxjkUKKo4f3VyDUaWjrlUFqVO95X29+Zuw++AK1TVnWtt/F4J+L91hwEfDGxYn5f2I6tNKLXnyXlPVDpa1EE6+d1LWznfXVHHzL58lBIK0Yk9MKGHQAAAgA7OaXVXCYpP2SfHIEp3s0tRA==xxc>';
const myContactFileName = '';
const statePath = 'statePathSender2';
const statePath = 'statePathSender';
const statePass = 'password';
document.getElementById('ndfInput').addEventListener('change', e => {
......
......@@ -223,46 +223,3 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf,
htmlConsole.log("No recipient specified. Waiting for request")
}
}
\ No newline at end of file
function download(filename, text) {
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
const sleepUntil = async (f, timeoutMs) => {
return new Promise((resolve, reject) => {
const timeWas = new Date();
const wait = setInterval(function() {
if (f()) {
console.log("resolved after", new Date() - timeWas, "ms");
clearInterval(wait);
resolve();
} else if (new Date() - timeWas > timeoutMs) { // Timeout
console.log("rejected after", new Date() - timeWas, "ms");
clearInterval(wait);
reject();
}
}, 20);
});
}
function newHtmlConsole(node) {
return {
log: function (message) {
console.log(message)
node.innerHTML += "<p>" + message + "</p>"
},
error: function (message) {
console.error(message)
node.innerHTML += "<p class='error'>" + message + "</p>"
}
};
}
\ No newline at end of file
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 xx foundation //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
// Function to download data to a file.
function download(filename, data) {
const file = new Blob([data], {type: 'text/plain'});
let a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
// sleepUntil waits until the condition f is met or until the timeout is
// reached.
async function sleepUntil(f, timeoutMs) {
return new Promise((resolve, reject) => {
const timeWas = new Date();
const wait = setInterval(function() {
if (f()) {
console.log("resolved after", new Date() - timeWas, "ms");
clearInterval(wait);
resolve();
} else if (new Date() - timeWas > timeoutMs) { // Timeout
console.log("rejected after", new Date() - timeWas, "ms");
clearInterval(wait);
reject();
}
}, 20);
});
}
// newHtmlConsole returns an object that allows for printing log messages or
// error messages to an element.
function newHtmlConsole(elem) {
return {
log: function (message) {
console.log(message)
elem.innerHTML += "<p>" + message + "</p>"
},
error: function (message) {
console.error(message)
elem.innerHTML += "<p class='error'>" + message + "</p>"
}
};
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment