jr: add state fields for network id

This commit is contained in:
2024-03-19 16:52:52 -06:00
parent e632475f7f
commit 251d096179
+47 -21
View File
@@ -88,6 +88,14 @@ let GB_MIN = 60*GB_SEC; // [ITER]
let MSG_SIGN_TIMEOUT = 30*GB_MIN;
let TX_SIGN_TIMEOUT = 30*GB_MIN;
let NETID_GDEV : bi_netid = 'gajumaru_devnet';
let NETID_AETEST : bi_netid = 'ae_uat';
let NETID_AEMAIN : bi_netid = 'ae_mainnet';
let NETID_CUR_DEF : bi_netid = NETID_GDEV;
let NETIDS_ALT_DEF : Array<bi_netid> = [NETID_AETEST, NETID_AEMAIN];
let NETIDS_ALL : Array<bi_netid> = [NETID_GDEV, NETID_AETEST, NETID_AEMAIN];
//=============================================================================
//=============================================================================
@@ -106,7 +114,9 @@ let TX_SIGN_TIMEOUT = 30*GB_MIN;
* data that is displayed in the popup window
*/
type p_data
= {rich_pubkeys: Array<p_rich_pubkey>};
= {rich_pubkeys: Array<p_rich_pubkey>,
netid_cur : string,
netids_alt : Array<string>};
type p_rich_pubkey
@@ -311,13 +321,22 @@ type bi_rich_keypair
active : boolean};
type bi_netid
= 'gajumaru_devnet'
| 'ae_uat'
| 'ae_mainnet'
;
/**
* JR state used internally
*
* @internal
*/
type bi_state
= {rich_keypairs: Array<bi_rich_keypair>};
= {rich_keypairs : Array<bi_rich_keypair>,
netid_cur : bi_netid,
netids_alt : Array<bi_netid>};
@@ -330,7 +349,9 @@ type bi_state
* @internal
*/
type bis_state
= {jr_state: {rich_keypairs: Array<bis_rich_keypair>}};
= {jr_state: {rich_keypairs : Array<bis_rich_keypair>,
netid_cur : bi_netid,
netids_alt : Array<bi_netid>}};
type bis_rich_keypair
@@ -1066,22 +1087,22 @@ bi_p_get_data
// active : boolean};
// type bi_state
// = {rich_keypairs: Array<bi_rich_keypair>};
let jr_state : bi_state = await bi_get_state();
let istate : bi_state = await bi_get_state();
// accumulator
let p_rkps : Array<p_rich_pubkey> = [];
for (let i_rkp of jr_state.rich_keypairs) {
let this_pubkey : Uint8Array = i_rkp.nacl_keypair.publicKey;
for (let irkp of istate.rich_keypairs) {
let this_pubkey : Uint8Array = irkp.nacl_keypair.publicKey;
let this_akstr : string = await vdk_aeser.pubkey2ak_str(this_pubkey);
let this_active : boolean = i_rkp.active;
let this_name : string = i_rkp.name;
p_rkps.push({akstr : this_akstr,
active : this_active,
name : this_name});
active : irkp.active,
name : irkp.name});
}
return {rich_pubkeys: p_rkps};
return {rich_pubkeys : p_rkps,
netid_cur : istate.netid_cur,
netids_alt : istate.netids_alt};
}
@@ -1189,7 +1210,9 @@ bi_p_activate_key
new_rich_keypairs.push(this_irkp);
}
let new_state : bi_state = {rich_keypairs: new_rich_keypairs};
let new_state : bi_state = {rich_keypairs : new_rich_keypairs,
netid_cur : istate.netid_cur,
netids_alt : istate.netids_alt};
await bi_set_state(new_state);
}
@@ -1233,7 +1256,9 @@ bi_p_delete_key
new_rich_keypairs[0].active = true;
}
let new_state : bi_state = {rich_keypairs: new_rich_keypairs};
let new_state : bi_state = {rich_keypairs : new_rich_keypairs,
netid_cur : istate.netid_cur,
netids_alt : istate.netids_alt};
await bi_set_state(new_state);
}
@@ -1458,7 +1483,9 @@ bi_i2s
srkps.push(this_srkp);
}
return {jr_state : {rich_keypairs: srkps}};
return {jr_state : {rich_keypairs : srkps,
netid_cur : i_state.netid_cur,
netids_alt : i_state.netids_alt}};
}
@@ -1521,12 +1548,9 @@ bi_state_default
{
console.log('jr_state_default');
// LEGACY: if no key, generate one
// // @ts-ignore ts doesn't like that nacl is dumb. i don't like it either
// let init_keypair : bi_nacl_keypair = nacl.sign.keyPair() as bi_nacl_keypair;
// let default_state : bi_state = { keypairs: [init_keypair] };
let default_state : bi_state = { rich_keypairs: [] };
let default_state : bi_state = {rich_keypairs : [],
netid_cur : NETID_CUR_DEF,
netids_alt : NETIDS_ALT_DEF};
console.log('jr_state_default default_state', default_state);
return default_state;
}
@@ -1580,7 +1604,9 @@ bi_s2i
}
return {rich_keypairs: irkps};
return {rich_keypairs : irkps,
netid_cur : s_state.jr_state.netid_cur,
netids_alt : s_state.jr_state.netids_alt};
}