fix attempt reconnect

pull/19/head
Niko PLP 12 months ago
parent dc5810489f
commit a2af2676e9
  1. 21
      ng-app/src/store.ts

@ -21,7 +21,9 @@ export const wallets = writable({});
export const connections = writable({}); export const connections = writable({});
let next_reconnect = 0; export const active_session = writable(undefined);
let next_reconnect = null;
export const online = derived(connections,($connections) => { export const online = derived(connections,($connections) => {
for (const cnx of Object.keys($connections)) { for (const cnx of Object.keys($connections)) {
@ -32,12 +34,14 @@ export const online = derived(connections,($connections) => {
return c; return c;
}); });
return true; } return true; }
else if ($connections[cnx].error=="ConnectionError" && !$connections[cnx].connecting && next_reconnect==0) { else if ($connections[cnx].error=="ConnectionError" && !$connections[cnx].connecting && next_reconnect==null) {
console.log("will try reconnect in 1 min"); console.log("will try reconnect in 1 min");
next_reconnect = 60; next_reconnect = setTimeout(async ()=> {
setTimeout(async ()=> { next_reconnect = null;
next_reconnect = 0; if (get(active_session)) {
console.log("attempting to connect...");
await reconnect(); await reconnect();
}
},60000); },60000);
} }
} }
@ -46,7 +50,7 @@ export const online = derived(connections,($connections) => {
export const has_wallets = derived(wallets,($wallets) => Object.keys($wallets).length); export const has_wallets = derived(wallets,($wallets) => Object.keys($wallets).length);
export const active_session = writable(undefined);
export const set_active_session = function(session) { export const set_active_session = function(session) {
active_session.set(session.users); active_session.set(session.users);
@ -55,7 +59,10 @@ export const set_active_session = function(session) {
export { writable, readonly, derived }; export { writable, readonly, derived };
export const close_active_wallet = async function() { export const close_active_wallet = async function() {
if (next_reconnect) {
clearTimeout(next_reconnect);
next_reconnect = null;
}
await close_active_session(); await close_active_session();
active_wallet.update((w) => { active_wallet.update((w) => {
delete w.wallet; delete w.wallet;

Loading…
Cancel
Save