jr: show balances in popup window (might work?)
This commit is contained in:
+13
-1
@@ -36,7 +36,19 @@
|
|||||||
|
|
||||||
.account-inactive {
|
.account-inactive {
|
||||||
background: var(--b4);
|
background: var(--b4);
|
||||||
color: var(--g4);
|
color: var(--b7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.balance-found {
|
||||||
|
color: var(--g5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.balance-not-found {
|
||||||
|
color: var(--b7);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--g5);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
+77
-2
@@ -209,6 +209,36 @@ pi_repop
|
|||||||
// add
|
// add
|
||||||
addr_li.appendChild(addr_a);
|
addr_li.appendChild(addr_a);
|
||||||
|
|
||||||
|
// balance
|
||||||
|
let bal_li = document.createElement('li');
|
||||||
|
bal_li.innerHTML += 'Balance: ';
|
||||||
|
// old school async/await
|
||||||
|
pi_balance(this_rkp.akstr).then(
|
||||||
|
function(maybe_balance) {
|
||||||
|
// if there is a balance, show it in green
|
||||||
|
if (maybe_balance.ok)
|
||||||
|
{
|
||||||
|
let greentext = document.createElement('span');
|
||||||
|
greentext.classList.add('balance-found');
|
||||||
|
// @ts-ignore fuck off i know what i'm doing
|
||||||
|
greentext.innerHTML = '' + maybe_balance.balance;
|
||||||
|
|
||||||
|
bal_li.appendChild(greentext);
|
||||||
|
}
|
||||||
|
// if not, show reason and make it red
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let redtext = document.createElement('span');
|
||||||
|
redtext.classList.add('balance-not-found');
|
||||||
|
// @ts-ignore fuck off i know what i'm doing
|
||||||
|
redtext.innerHTML = '' + maybe_balance.reason;
|
||||||
|
|
||||||
|
bal_li.appendChild(redtext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// add delete button
|
// add delete button
|
||||||
let del_li = document.createElement('li');
|
let del_li = document.createElement('li');
|
||||||
|
|
||||||
@@ -246,10 +276,11 @@ pi_repop
|
|||||||
|
|
||||||
|
|
||||||
// add everything inside-out
|
// add everything inside-out
|
||||||
rkp_ul.appendChild(addr_li);
|
|
||||||
rkp_ul.appendChild(name_li);
|
rkp_ul.appendChild(name_li);
|
||||||
rkp_ul.appendChild(del_li);
|
rkp_ul.appendChild(addr_li);
|
||||||
|
rkp_ul.appendChild(bal_li);
|
||||||
rkp_ul.appendChild(gphrase_li);
|
rkp_ul.appendChild(gphrase_li);
|
||||||
|
rkp_ul.appendChild(del_li);
|
||||||
this_li.appendChild(rkp_ul);
|
this_li.appendChild(rkp_ul);
|
||||||
|
|
||||||
|
|
||||||
@@ -280,3 +311,47 @@ pi_repop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* get account balance of ak_... str
|
||||||
|
*/
|
||||||
|
async function
|
||||||
|
pi_balance
|
||||||
|
(akstr : string)
|
||||||
|
: Promise< {ok : true,
|
||||||
|
balance : number}
|
||||||
|
| {ok : false,
|
||||||
|
reason : string}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
let endpoint_init_url = 'https://demonet.qpq.swiss/v2/';
|
||||||
|
let this_endpoint = endpoint_init_url + '/accounts/' + akstr;
|
||||||
|
let input_params = {pubkey: akstr};
|
||||||
|
// fetch: https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
||||||
|
let response = await fetch(this_endpoint);
|
||||||
|
// 200 = ok
|
||||||
|
// 400 = pubkey malformed
|
||||||
|
// 404 = account dne
|
||||||
|
switch (response.status) {
|
||||||
|
case 200:
|
||||||
|
// unstringify the body
|
||||||
|
let return_data = response.json();
|
||||||
|
// get the balance
|
||||||
|
// @ts-ignore talking to foreign api
|
||||||
|
let balance = return_data.balance;
|
||||||
|
return {ok : true,
|
||||||
|
balance : balance};
|
||||||
|
// pubkey malformed
|
||||||
|
case 400:
|
||||||
|
return {ok : false,
|
||||||
|
reason : 'Pubkey Malformed'};
|
||||||
|
// account dne
|
||||||
|
case 404:
|
||||||
|
return {ok : false,
|
||||||
|
reason : 'Account does not exist yet'};
|
||||||
|
// wtf
|
||||||
|
default:
|
||||||
|
return {ok : false,
|
||||||
|
reason : 'Unexpected response from node'};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user