2023-09-03 14:52:14 +02:00
|
|
|
var STATE = {
|
|
|
|
LOCAL_KEY: 1 << 0,
|
|
|
|
LOCAL_KEY_PROBE: 1 << 1,
|
|
|
|
LOCAL_KEY_REQUEST: 1 << 2,
|
|
|
|
LOCAL_KEY_REJECT: 1 << 3,
|
|
|
|
LOCAL_KEY_UNLOCK: 1 << 4,
|
|
|
|
LOCAL_KEY_LOCK: 1 << 5,
|
|
|
|
RPC_CONNECT: 1 << 6,
|
|
|
|
RPC_CHANGE: 1 << 7,
|
|
|
|
RPC_GONE: 1 << 8,
|
|
|
|
RPC_PING: 1 << 9,
|
|
|
|
EVM_BALANCE_LOW: 1 << 10,
|
2023-09-05 04:19:53 +02:00
|
|
|
EVM_REGISTRY: 1 << 11,
|
|
|
|
PROMISE_NEW: 1 << 12,
|
|
|
|
PROMISE_PERSIST: 1 << 13,
|
2023-09-03 14:52:14 +02:00
|
|
|
};
|
|
|
|
const STATE_KEYS = Object.keys(STATE);
|
|
|
|
var g_state = 0;
|
2023-09-05 04:19:53 +02:00
|
|
|
var g_chainId = 0;
|
2023-09-03 14:52:14 +02:00
|
|
|
var g_balance = 0;
|
|
|
|
var g_minBalance = 10000000;
|
2023-09-05 04:19:53 +02:00
|
|
|
var g_poll_wallet = 3000;
|
|
|
|
var g_poll_rpc = 1000;
|
2023-09-03 14:52:14 +02:00
|
|
|
var g_registry = '0xb708175e3f6cd850643aaf7b32212afad50e2549';
|
2023-09-05 04:19:53 +02:00
|
|
|
var g_persist = []
|
|
|
|
var g_persistIndex = [];
|
2023-09-03 14:52:14 +02:00
|
|
|
|
|
|
|
const DEBUG = true;
|
|
|
|
const SESSION_ID = 'gasgasgas';
|
|
|
|
const KEY_STORAGEKEY = 'sessionKey_' + SESSION_ID;
|
2023-09-05 04:19:53 +02:00
|
|
|
const PERSIST_STORAGEKEY = 'persistKey_' + SESSION_ID; // replace with addressdeclarator
|
2023-09-03 14:52:14 +02:00
|
|
|
|
|
|
|
const qp = new URLSearchParams(window.location.search);
|
2023-09-05 04:19:53 +02:00
|
|
|
console.debug('uuid', qp.get("u"));
|
2023-09-03 14:52:14 +02:00
|
|
|
|
|
|
|
// borrowed from forro
|
|
|
|
async function stateChange(s, set_states, rst_states) {
|
|
|
|
if (!set_states) {
|
|
|
|
set_states = [];
|
|
|
|
} else if (!Array.isArray(set_states)) {
|
|
|
|
set_states = [set_states];
|
|
|
|
}
|
|
|
|
if (!rst_states) {
|
|
|
|
rst_states = [];
|
|
|
|
} else if (!Array.isArray(rst_states)) {
|
|
|
|
rst_states = [rst_states];
|
|
|
|
}
|
|
|
|
let new_state = g_state;
|
|
|
|
for (let i = 0; i < set_states.length; i++) {
|
|
|
|
let state = parseInt(set_states[i]);
|
|
|
|
new_state |= state;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < rst_states.length; i++) {
|
|
|
|
let state = parseInt(set_states[i]);
|
|
|
|
new_state = new_state & (0xffffffff & ~rst_states[i]);
|
|
|
|
}
|
|
|
|
old_state = g_state;
|
|
|
|
g_state = new_state;
|
|
|
|
|
|
|
|
const ev = new CustomEvent('messagestatechange', {
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: false,
|
|
|
|
composed: true,
|
|
|
|
detail: {
|
|
|
|
s: s,
|
|
|
|
old_state: old_state,
|
|
|
|
state: new_state,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
window.dispatchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkState(bit_check, bit_field) {
|
|
|
|
if (bit_field != 0 && !bit_field) {
|
|
|
|
bit_field = g_state;
|
|
|
|
}
|
|
|
|
return (bit_check & bit_field) > 0;
|
|
|
|
}
|