Adding Bootstrap-UI
This commit is contained in:
parent
fb914d2ae7
commit
44bd69c7c8
447
index.html
447
index.html
@ -1,210 +1,289 @@
|
|||||||
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>BTC webWallet</title>
|
<title>BTC webWallet</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
|
||||||
background-color: grey;
|
|
||||||
}
|
|
||||||
|
|
||||||
table,
|
|
||||||
tr,
|
|
||||||
td,
|
|
||||||
th {
|
|
||||||
border: 1px solid black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.unconfirmed-tx {
|
.unconfirmed-tx {
|
||||||
color: darkred;
|
color: red;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="lib.js"></script>
|
<script type="text/javascript" src="lib.js"></script>
|
||||||
<script type="text/javascript" src="lib_btc.js"></script>
|
<script type="text/javascript" src="lib_btc.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<form id="generate-address">
|
<nav class="navbar navbar-default">
|
||||||
<fieldset>
|
<div class="container-fluid">
|
||||||
<legend>generate-address</legend>
|
<div class="navbar-header">
|
||||||
<input type="button" value="generate" onclick="generateNew();">
|
<a class="navbar-brand"><i class="glyphicon glyphicon-bitcoin"></i>itcoin WebWallet</a>
|
||||||
Address: <input name="address" type="text" placeholder="Address" disabled /><br />
|
</div>
|
||||||
SegwitAddress: <input name="segwit" type="text" placeholder="SegwitAddress" disabled /><br />
|
<ul id="menu" class="nav navbar-nav">
|
||||||
Bech32Address: <input name="bech32" type="text" placeholder="Bech32Address" disabled /><br />
|
<li data-n="1"><a href="#">Address</a></li>
|
||||||
PrivateKey: <input name="private" type="text" placeholder="Private-Key" disabled /><br />
|
<li data-n="2"><a href="#">Send</a></li>
|
||||||
</fieldset>
|
<li data-n="3" class="active"><a href="#">Details</a></li>
|
||||||
</form>
|
</ul>
|
||||||
<form id="retrieve-address">
|
</div>
|
||||||
<fieldset>
|
</nav>
|
||||||
<legend>retrieve-address</legend>
|
<div class="container-fluid">
|
||||||
<input name="private" type="text" placeholder="Private-Key" />
|
<div name="panels" data-n="1" id="address-gen-panel" class="panel panel-default hide">
|
||||||
<input type="button" value="retrieve" onclick="retrieveAddress();"><br />
|
<div class="panel-heading">Address Generator</div>
|
||||||
Address: <input name="address" type="text" placeholder="Address" disabled /><br />
|
<div class="panel-body">
|
||||||
SegwitAddress: <input name="segwit" type="text" placeholder="SegwitAddress" disabled /><br />
|
<form id="generate-address" autocomplete="off">
|
||||||
Bech32Address: <input name="bech32" type="text" placeholder="Bech32Address" disabled /><br />
|
<div class="form-group">
|
||||||
</fieldset>
|
<label class="radio-inline"><input type="radio" name="gen-radio" value="generate" checked>Generate</label>
|
||||||
</form>
|
<label class="radio-inline"><input type="radio" name="gen-radio" value="retrieve">Retrieve</label>
|
||||||
<form id="send-tx">
|
<button type="button" name="submit" class="btn btn-default">Go</button>
|
||||||
<fieldset>
|
</div>
|
||||||
<legend>send-tx</legend>
|
<div class="input-group">
|
||||||
<input name="sender" type="text" placeholder="Sender" />
|
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i>Private</span>
|
||||||
<input name="receiver" type="text" placeholder="Receiver" />
|
<input type="password" class="form-control" name="private" placeholder="PrivateKey" disabled>
|
||||||
<input name="amount" type="number" placeholder="Amount" step="0.01" />
|
<div class="input-group-btn">
|
||||||
<input name="fee" type="number" placeholder="fee" step="0.000001" />
|
<button class="btn btn-default" name="eye" type="button">
|
||||||
<input type="button" value="send" onclick="sendTx();">
|
<i class="glyphicon glyphicon-eye-close"></i>
|
||||||
</fieldset>
|
</button>
|
||||||
</form>
|
</div>
|
||||||
<form id="address-details">
|
</div>
|
||||||
<fieldset>
|
<div class="input-group">
|
||||||
<legend>address-details</legend>
|
<span class="input-group-addon"><i>Bech32</i></span>
|
||||||
<input name="address" type="text" placeholder="Address" />
|
<input type="text" class="form-control" name="bech32" placeholder="Bech32Address" disabled>
|
||||||
<input type="button" value="balance" onclick="checkBalance();">
|
</div>
|
||||||
<input type="button" value="details" onclick="viewAddress();">
|
<div class="input-group">
|
||||||
<div>Balance: <input name="balance" disabled /></div>
|
<span class="input-group-addon"><i>Segwit</i></span>
|
||||||
<table>
|
<input type="text" class="form-control" name="segwit" placeholder="SegwitAddress" disabled>
|
||||||
<thead>
|
</div>
|
||||||
<tr>
|
<div class="input-group">
|
||||||
<th></th>
|
<span class="input-group-addon"><i>Legacy</i></span>
|
||||||
<th>address</th>
|
<input type="text" class="form-control" name="legacy" placeholder="LegacyAddress" disabled>
|
||||||
<th>amount</th>
|
</div>
|
||||||
<th>time</th>
|
</form>
|
||||||
<th>txid</th>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
</thead>
|
<div name="panels" data-n="2" id="send-tx-panel" class="panel panel-default hide">
|
||||||
<tbody id="view-details"></tbody>
|
<div class="panel-heading">Send Transaction</div>
|
||||||
</table>
|
<div class="panel-body">
|
||||||
</fieldset>
|
<form id="send-tx">
|
||||||
</form>
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i>Sender</i></span>
|
||||||
|
<input type="text" class="form-control" name="sender" placeholder="Sender ID">
|
||||||
|
</div>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-btn">
|
||||||
|
<button class="btn btn-default" name="check-balance" type="button">Balance</button>
|
||||||
|
</div>
|
||||||
|
<input type="number" class="form-control" name="balance" placeholder="Check Balance" disabled>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i>Receiver</i></span>
|
||||||
|
<input type="text" class="form-control" name="receiver" placeholder="Receiver ID">
|
||||||
|
</div>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i>Amount</i></span>
|
||||||
|
<input type="number" class="form-control" name="amount" placeholder="Amount" min="0" step="0.01">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i>Fee</i></span>
|
||||||
|
<input type="number" class="form-control" name="fee" placeholder="Fee" min="0" step="0.000001">
|
||||||
|
</div>
|
||||||
|
<button type="button" name="submit" class="btn btn-default btn-block"><b>Send</b></button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div name="panels" data-n="3" id="view-details-panel" class="panel panel-default">
|
||||||
|
<div class="panel-heading">Address Details</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<form id="address-details">
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i>Address</i></span>
|
||||||
|
<input type="text" class="form-control" name="address" placeholder="Address">
|
||||||
|
<div class="input-group-btn">
|
||||||
|
<button class="btn btn-default" name="submit" type="button"><b class="glyphicon glyphicon-search"></b></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i class="glyphicon glyphicon-bitcoin"></i></span>
|
||||||
|
<input type="number" class="form-control" name="balance" placeholder="Balance" disabled>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Address</th>
|
||||||
|
<th>Amount</th>
|
||||||
|
<th>Time</th>
|
||||||
|
<th>TxID</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="view-details"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
function generateNew() {
|
(function() {
|
||||||
let newKeys = btc_api.newKeys;
|
|
||||||
let form = document.forms['generate-address'];
|
|
||||||
form['private'].value = newKeys.wif;
|
|
||||||
form['address'].value = newKeys.address;
|
|
||||||
form['segwit'].value = newKeys.segwitAddress;
|
|
||||||
form['bech32'].value = newKeys.bech32Address;
|
|
||||||
}
|
|
||||||
|
|
||||||
function retrieveAddress() {
|
let menu = document.getElementById('menu').children;
|
||||||
let form = document.forms['retrieve-address'];
|
let panels = document.getElementsByName('panels');
|
||||||
let wif = form['private'].value;
|
for (let i = 0; i < menu.length; i++) {
|
||||||
form['address'].value = btc_api.address(wif);
|
menu[i].onclick = evt => {
|
||||||
form['segwit'].value = btc_api.segwitAddress(wif);
|
let n = evt.target.parentElement.dataset.n;
|
||||||
form['bech32'].value = btc_api.bech32Address(wif);
|
for (let j = 0; j < menu.length; j++)
|
||||||
}
|
if (menu[j].dataset.n == n)
|
||||||
|
menu[j].classList.add('active');
|
||||||
|
else
|
||||||
|
menu[j].classList.remove('active');
|
||||||
|
for (let p = 0; p < panels.length; p++)
|
||||||
|
if (panels[p].dataset.n == n)
|
||||||
|
panels[p].classList.remove('hide');
|
||||||
|
else
|
||||||
|
panels[p].classList.add('hide');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function checkBalance() {
|
let addressForm = document.forms['generate-address'];
|
||||||
let form = document.forms['address-details'];
|
for (let i = 0; i < addressForm['gen-radio'].length; i++)
|
||||||
let address = form["address"].value;
|
addressForm['gen-radio'][i].addEventListener('change', evt => addressForm['private'].disabled = evt.target.value === "generate");
|
||||||
btc_api.getBalance(address)
|
addressForm['eye'].onclick = evt => {
|
||||||
.then(result => form["balance"].value = result)
|
if (addressForm['private'].type === "password")
|
||||||
.catch(error => console.error(error))
|
addressForm['private'].type = "text";
|
||||||
}
|
else
|
||||||
|
addressForm['private'].type = "password";
|
||||||
function sendTx() {
|
}
|
||||||
let form = document.forms['send-tx'];
|
addressForm['submit'].onclick = evt => {
|
||||||
let sender = form["sender"].value,
|
switch (addressForm['gen-radio'].value) {
|
||||||
receiver = form["receiver"].value,
|
case "generate": {
|
||||||
amount = parseFloat(form["amount"].value),
|
let newKeys = btc_api.newKeys;
|
||||||
fee = parseFloat(form["fee"].value);
|
addressForm['private'].value = newKeys.wif;
|
||||||
let privKey = prompt("Enter Private Key:");
|
addressForm['legacy'].value = newKeys.address;
|
||||||
btc_api.sendTx(sender, privKey, receiver, amount, fee).then(result => {
|
addressForm['segwit'].value = newKeys.segwitAddress;
|
||||||
console.log(result);
|
addressForm['bech32'].value = newKeys.bech32Address;
|
||||||
alert("transaction id: " + result.txid);
|
break;
|
||||||
}).catch(error => console.error(error))
|
|
||||||
}
|
|
||||||
|
|
||||||
function viewAddress() {
|
|
||||||
let form = document.forms['address-details']
|
|
||||||
let address = form['address'].value;
|
|
||||||
let table = document.getElementById("view-details");
|
|
||||||
table.innerHTML = '';
|
|
||||||
form['balance'].value = '';
|
|
||||||
getAddressDetails(address).then(result => {
|
|
||||||
console.debug(result);
|
|
||||||
form['balance'].value = result.balance;
|
|
||||||
result.txs.forEach(tx => {
|
|
||||||
let row = table.insertRow();
|
|
||||||
if (tx.type === "out") {
|
|
||||||
row.insertCell().innerHTML = '↗';
|
|
||||||
row.insertCell().textContent = tx.receiver;
|
|
||||||
} else if (tx.type === "in") {
|
|
||||||
row.insertCell().innerHTML = '↙';
|
|
||||||
row.insertCell().textContent = tx.sender;
|
|
||||||
} else if (tx.type === "self") {
|
|
||||||
row.insertCell().innerHTML = '⟲';
|
|
||||||
row.insertCell().textContent = tx.address;
|
|
||||||
}
|
}
|
||||||
row.insertCell().textContent = tx.amount;
|
case "retrieve": {
|
||||||
row.insertCell().textContent = tx.time;
|
let wif = addressForm['private'].value;
|
||||||
row.insertCell().textContent = tx.txid;
|
addressForm['legacy'].value = btc_api.address(wif);
|
||||||
if (tx.block === null)
|
addressForm['segwit'].value = btc_api.segwitAddress(wif);
|
||||||
row.className = 'unconfirmed-tx';
|
addressForm['bech32'].value = btc_api.bech32Address(wif);
|
||||||
});
|
break;
|
||||||
}).catch(error => console.error(error))
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getAddressDetails(address) {
|
let sendForm = document.forms['send-tx'];
|
||||||
return new Promise((resolve, reject) => {
|
sendForm['check-balance'].onclick = evt => {
|
||||||
btc_api.getAddressData(address).then(data => {
|
let address = sendForm["sender"].value;
|
||||||
console.debug(data);
|
sendForm['check-balance'].disabled = true;
|
||||||
let details = {};
|
btc_api.getBalance(address)
|
||||||
details.balance = data.balance;
|
.then(result => sendForm["balance"].value = result)
|
||||||
details.address = data.address;
|
.catch(error => console.error(error))
|
||||||
details.txs = data.txs.map(tx => {
|
.finally(_ => sendForm['check-balance'].disabled = false)
|
||||||
let d = {
|
}
|
||||||
txid: tx.txid,
|
sendForm['submit'].onclick = evt => {
|
||||||
time: tx.time,
|
let sender = sendForm["sender"].value,
|
||||||
block: tx.block_no
|
receiver = sendForm["receiver"].value,
|
||||||
|
amount = parseFloat(sendForm["amount"].value),
|
||||||
|
fee = parseFloat(sendForm["fee"].value);
|
||||||
|
console.debug(sender, receiver, amount, fee)
|
||||||
|
let privKey = prompt("Enter Private Key:");
|
||||||
|
sendForm['submit'].disabled = true;
|
||||||
|
btc_api.sendTx(sender, privKey, receiver, amount, fee).then(result => {
|
||||||
|
console.log(result);
|
||||||
|
alert("transaction id: " + result.txid);
|
||||||
|
}).catch(error => console.error(error)).finally(_ => sendForm['submit'].disabled = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
let detailsForm = document.forms['address-details'];
|
||||||
|
detailsForm['submit'].onclick = evt => {
|
||||||
|
detailsForm['submit'].disabled = true;
|
||||||
|
let address = detailsForm['address'].value;
|
||||||
|
let table = document.getElementById("view-details");
|
||||||
|
table.innerHTML = '';
|
||||||
|
detailsForm['balance'].value = '';
|
||||||
|
getAddressDetails(address).then(result => {
|
||||||
|
console.debug(result);
|
||||||
|
detailsForm['balance'].value = result.balance;
|
||||||
|
result.txs.forEach(tx => {
|
||||||
|
let row = table.insertRow();
|
||||||
|
if (tx.type === "out") {
|
||||||
|
row.insertCell().innerHTML = '↗';
|
||||||
|
row.insertCell().textContent = tx.receiver;
|
||||||
|
} else if (tx.type === "in") {
|
||||||
|
row.insertCell().innerHTML = '↙';
|
||||||
|
row.insertCell().textContent = tx.sender;
|
||||||
|
} else if (tx.type === "self") {
|
||||||
|
row.insertCell().innerHTML = '⟲';
|
||||||
|
row.insertCell().textContent = tx.address;
|
||||||
}
|
}
|
||||||
if (tx.outgoing) {
|
row.insertCell().textContent = tx.amount;
|
||||||
d.type = "out";
|
row.insertCell().textContent = tx.time;
|
||||||
d.amount = 0;
|
row.insertCell().textContent = tx.txid;
|
||||||
d.receiver = new Set();
|
if (tx.block === null)
|
||||||
let change = 0;
|
row.className = 'unconfirmed-tx';
|
||||||
tx.outgoing.outputs.forEach(o => {
|
});
|
||||||
if (o.address !== address) {
|
}).catch(error => console.error(error)).finally(_ => detailsForm['submit'].disabled = false)
|
||||||
d.receiver.add(o.address)
|
}
|
||||||
d.amount += parseFloat(o.value)
|
|
||||||
} else
|
function getAddressDetails(address) {
|
||||||
change += parseFloat(o.value)
|
return new Promise((resolve, reject) => {
|
||||||
});
|
btc_api.getAddressData(address).then(data => {
|
||||||
d.receiver = Array.from(d.receiver);
|
console.debug(data);
|
||||||
d.fee = parseFloat((tx.outgoing.value - (d.amount + change)).toFixed(8))
|
let details = {};
|
||||||
if (!d.amount && change > 0) {
|
details.balance = data.balance;
|
||||||
d.type = "self";
|
details.address = data.address;
|
||||||
d.amount = change
|
details.txs = data.txs.map(tx => {
|
||||||
delete d.receiver;
|
let d = {
|
||||||
d.address = address;
|
txid: tx.txid,
|
||||||
|
time: tx.time,
|
||||||
|
block: tx.block_no
|
||||||
}
|
}
|
||||||
} else if (tx.incoming) {
|
if (tx.outgoing) {
|
||||||
d.type = "in";
|
d.type = "out";
|
||||||
d.amount = parseFloat(tx.incoming.value);
|
d.amount = 0;
|
||||||
d.sender = Array.from(new Set(tx.incoming.inputs.map(i => i.address)));
|
d.receiver = new Set();
|
||||||
}
|
let change = 0;
|
||||||
return d;
|
tx.outgoing.outputs.forEach(o => {
|
||||||
})
|
if (o.address !== address) {
|
||||||
resolve(details);
|
d.receiver.add(o.address)
|
||||||
}).catch(error => reject(error))
|
d.amount += parseFloat(o.value)
|
||||||
})
|
} else
|
||||||
}
|
change += parseFloat(o.value)
|
||||||
|
});
|
||||||
|
d.receiver = Array.from(d.receiver);
|
||||||
|
d.fee = parseFloat((tx.outgoing.value - (d.amount + change)).toFixed(8))
|
||||||
|
if (!d.amount && change > 0) {
|
||||||
|
d.type = "self";
|
||||||
|
d.amount = change
|
||||||
|
delete d.receiver;
|
||||||
|
d.address = address;
|
||||||
|
}
|
||||||
|
} else if (tx.incoming) {
|
||||||
|
d.type = "in";
|
||||||
|
d.amount = parseFloat(tx.incoming.value);
|
||||||
|
d.sender = Array.from(new Set(tx.incoming.inputs.map(i => i.address)));
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
})
|
||||||
|
resolve(details);
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function testGenerator() {
|
})();
|
||||||
let n = btc_api.newKeys;
|
|
||||||
let a1 = btc_api.address(n.wif);
|
|
||||||
let b1 = btc_api.bech32Address(n.wif);
|
|
||||||
let c1 = btc_api.segwitAddress(n.wif);
|
|
||||||
let p1 = btc_api.pubkey(n.wif);
|
|
||||||
let a2 = btc_api.address(n.privkey);
|
|
||||||
let b2 = btc_api.bech32Address(n.privkey);
|
|
||||||
let c2 = btc_api.segwitAddress(n.privkey);
|
|
||||||
let p2 = btc_api.pubkey(n.privkey);
|
|
||||||
console.log(n.pubkey === p1 && p2 === p1);
|
|
||||||
console.log(n.address === a1 && a1 === a2);
|
|
||||||
console.log(n.segwitAddress === c1 && c2 === c1);
|
|
||||||
console.log(n.bech32Address === b1 && b1 === b2);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user