Skip to content

Commit

Permalink
demo pages. Run request button added
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaipov committed Feb 11, 2019
1 parent baf8429 commit 95aa899
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 22 deletions.
42 changes: 31 additions & 11 deletions docs/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ <h1>KeyChain Demo</h1>
<label class="form-label" for="response">Response</label>
<textarea class="form-input" id="response" placeholder="{}" rows="9"></textarea>
</div>
<div class="column col-4">
</div>
<div class="column col-2 mt-1">
<button class="btn btn-primary input-group-btn" id="btn_RUN_REQUEST">Run request</button>
</div>
<div class="column col-6">
</div>
<div class="column my-2">
<div class="toast toast-warning text-center">
Warning! <code>unlock_time</code> parameter is experimental and optional
Expand Down Expand Up @@ -182,6 +189,16 @@ <h1>KeyChain Demo</h1>
attachListener('VERSION');
document.getElementById('checkbox_SIGN_HEX').addEventListener('click', function(e) {
document.getElementById('unlock_time_SIGN_HEX').readOnly = !e.target.checked;
});
document.getElementById('btn_RUN_REQUEST').addEventListener('click', function() {
let request;
try {
request = JSON.parse(document.getElementById('request').value);
} catch (e) {
document.getElementById('response').value = e;
return;
}
runRequest(request);
})
};

Expand All @@ -197,21 +214,24 @@ <h1>KeyChain Demo</h1>
}
}
}

document.getElementById('request').value = JSON.stringify(request, undefined, 2);
keychain.command(request, function(data) {
document.getElementById('response').value = JSON.stringify(data, undefined, 2);
if (commandName === 'SELECT_KEY' && data.result) {
document.getElementById('public_key_UNLOCK').value = data.result;
document.getElementById('public_key_SIGN_HASH').value = data.result;
document.getElementById('public_key_SIGN_HEX').value = data.result;
document.getElementById('selectedKey').value = '0x' + data.result;
document.getElementById('address').value = '0x' + ethereumjs.Util.publicToAddress('0x' + data.result).toString('hex');
}
})
runRequest(request);
});
}

function runRequest(request) {
keychain.command(request, function(data) {
document.getElementById('response').value = JSON.stringify(data, undefined, 2);
if (request.command === 'select_key' && data.result) {
document.getElementById('public_key_UNLOCK').value = data.result;
document.getElementById('public_key_SIGN_HASH').value = data.result;
document.getElementById('public_key_SIGN_HEX').value = data.result;
document.getElementById('selectedKey').value = '0x' + data.result;
document.getElementById('address').value = '0x' + ethereumjs.Util.publicToAddress('0x' + data.result).toString('hex');
}
})
}

const COMMANDS = {
UNLOCK: {
command: "unlock",
Expand Down
42 changes: 31 additions & 11 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ <h1>KeyChain Demo</h1>
<label class="form-label" for="response">Response</label>
<textarea class="form-input" id="response" placeholder="{}" rows="9"></textarea>
</div>
<div class="column col-4">
</div>
<div class="column col-2 mt-1">
<button class="btn btn-primary input-group-btn" id="btn_RUN_REQUEST">Run request</button>
</div>
<div class="column col-6">
</div>
<div class="column my-2">
<div class="toast toast-warning text-center">
Warning! <code>unlock_time</code> parameter is experimental and optional
Expand Down Expand Up @@ -182,6 +189,16 @@ <h1>KeyChain Demo</h1>
attachListener('VERSION');
document.getElementById('checkbox_SIGN_HEX').addEventListener('click', function(e) {
document.getElementById('unlock_time_SIGN_HEX').readOnly = !e.target.checked;
});
document.getElementById('btn_RUN_REQUEST').addEventListener('click', function() {
let request;
try {
request = JSON.parse(document.getElementById('request').value);
} catch (e) {
document.getElementById('response').value = e;
return;
}
runRequest(request);
})
};

Expand All @@ -197,21 +214,24 @@ <h1>KeyChain Demo</h1>
}
}
}

document.getElementById('request').value = JSON.stringify(request, undefined, 2);
keychain.command(request, function(data) {
document.getElementById('response').value = JSON.stringify(data, undefined, 2);
if (commandName === 'SELECT_KEY' && data.result) {
document.getElementById('public_key_UNLOCK').value = data.result;
document.getElementById('public_key_SIGN_HASH').value = data.result;
document.getElementById('public_key_SIGN_HEX').value = data.result;
document.getElementById('selectedKey').value = '0x' + data.result;
document.getElementById('address').value = '0x' + ethereumjs.Util.publicToAddress('0x' + data.result).toString('hex');
}
})
runRequest(request);
});
}

function runRequest(request) {
keychain.command(request, function(data) {
document.getElementById('response').value = JSON.stringify(data, undefined, 2);
if (request.command === 'select_key' && data.result) {
document.getElementById('public_key_UNLOCK').value = data.result;
document.getElementById('public_key_SIGN_HASH').value = data.result;
document.getElementById('public_key_SIGN_HEX').value = data.result;
document.getElementById('selectedKey').value = '0x' + data.result;
document.getElementById('address').value = '0x' + ethereumjs.Util.publicToAddress('0x' + data.result).toString('hex');
}
})
}

const COMMANDS = {
UNLOCK: {
command: "unlock",
Expand Down

0 comments on commit 95aa899

Please sign in to comment.