jr: can now switch between keys

This commit is contained in:
2024-03-19 03:21:29 -06:00
parent 0e6ba80983
commit 074355b07c
2 changed files with 74 additions and 31 deletions
+56 -1
View File
@@ -70,6 +70,7 @@ export {
p_get_data, p_get_data,
p_generate_keypair, p_generate_keypair,
p_get_unique_name, p_get_unique_name,
p_activate_key,
// background script api // background script api
b_main b_main
}; };
@@ -161,7 +162,7 @@ p_get_unique_name
() ()
: Promise<string> : Promise<string>
{ {
console.log('b_lib p_generate_keypair'); console.log('b_lib p_get_unique_name');
return await browser.runtime.sendMessage({frum: 'popup', return await browser.runtime.sendMessage({frum: 'popup',
data: {method : 'p_get_unique_name', data: {method : 'p_get_unique_name',
@@ -169,6 +170,22 @@ p_get_unique_name
} }
/**
* Activate given key
*/
async function
p_activate_key
(name: string)
: Promise<void>
{
console.log('b_lib p_activate_key');
return await browser.runtime.sendMessage({frum: 'popup',
data: {method : 'p_activate_key',
args : {name: name}}}) as void;
}
//============================================================================= //=============================================================================
//============================================================================= //=============================================================================
// API: BACKGROUND SCRIPT // API: BACKGROUND SCRIPT
@@ -901,6 +918,7 @@ type bi_popup_calldata
= bi_pc_p_get_data = bi_pc_p_get_data
| bi_pc_p_generate_keypair | bi_pc_p_generate_keypair
| bi_pc_p_get_unique_name | bi_pc_p_get_unique_name
| bi_pc_p_activate_key
; ;
type bi_pc_p_get_data type bi_pc_p_get_data
@@ -915,6 +933,10 @@ type bi_pc_p_get_unique_name
= {method : 'p_get_unique_name', = {method : 'p_get_unique_name',
args : {}}; args : {}};
type bi_pc_p_activate_key
= {method : 'p_activate_key',
args : {name: string}};
type bi_popup_return_data type bi_popup_return_data
= p_data = p_data
| void | void
@@ -943,6 +965,8 @@ bi_msg_handler_popup
return await bi_p_generate_keypair(msg.args); return await bi_p_generate_keypair(msg.args);
case 'p_get_unique_name': case 'p_get_unique_name':
return await bi_p_get_unique_name(msg.args); return await bi_p_get_unique_name(msg.args);
case 'p_activate_key':
return await bi_p_activate_key(msg.args);
default: default:
throw new Error('unsupported popup call method'); throw new Error('unsupported popup call method');
} }
@@ -1068,6 +1092,37 @@ bi_name_unique
} }
async function
bi_p_activate_key
(args: {name: string})
: Promise<void>
{
console.log('b_lib bi_p_activate_key ' + args.name);
// get state
let istate : bi_state = await bi_get_state();
// find key with name
// type bi_rich_keypair
// = {nacl_keypair : bi_nacl_keypair,
// name : string,
// active : boolean};
// type bi_state
// = {rich_keypairs: Array<bi_rich_keypair>};
let new_rich_keypairs : Array<bi_rich_keypair> = [];
for (let this_irkp of istate.rich_keypairs) {
// if this is the name, set active = true
if (args.name === this_irkp.name)
this_irkp.active = true;
else
this_irkp.active = false;
new_rich_keypairs.push(this_irkp);
}
let new_state : bi_state = {rich_keypairs: new_rich_keypairs};
await bi_set_state(new_state);
}
+18 -30
View File
@@ -137,37 +137,25 @@ pi_repop
// if active, make background green // if active, make background green
if (this_rkp.active) if (this_rkp.active)
this_li.style.background = 'green'; this_li.style.background = 'green';
else // otherwise make background red and add activate li
else {
this_li.style.background = 'red'; this_li.style.background = 'red';
let activate_li = document.createElement('li');
// // balance let activate_a = document.createElement('a');
// // add a br activate_a.innerHTML = 'Switch to this key';
// let br = document.createElement('br'); activate_a.style.color = 'blue';
// this_li.appendChild(br); activate_a.style.textDecoration = 'underline';
// dirty but so is your mind so go fuck yourself
// // add balance activate_a.onclick =
// this_li.innerHTML += 'Balance: '; async function () {
// let maybe_balance = await pi_balance(this_akstr); // tell controller that we want to activate this key
// // if there is a balance, show it in green await b_lib.p_activate_key(this_rkp.name);
// if (maybe_balance.ok) await pi_repop();
// { };
// let greentext = document.createElement('span'); // add li and a
// greentext.style.color = 'green'; activate_li.appendChild(activate_a);
// // @ts-ignore fuck off i know what i'm doing rkp_ul.appendChild(activate_li);
// greentext.innerHTML = '' + maybe_balance.balance; }
// this_li.appendChild(greentext);
// }
// // if not, show reason and make it red
// else
// {
// let redtext = document.createElement('span');
// redtext.style.color = 'red';
// // @ts-ignore fuck off i know what i'm doing
// redtext.innerHTML = '' + maybe_balance.reason;
// this_li.appendChild(redtext);
// }
// add it to the list // add it to the list
pubkeys_ul.appendChild(this_li); pubkeys_ul.appendChild(this_li);