-
Notifications
You must be signed in to change notification settings - Fork 569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iss 279 - When selecting a new Node under Settings -> Access, don't hard reload the browser #380
Changes from 3 commits
fd5f011
a37ab1b
f4707b1
647eb01
70e76b8
7d2ce3d
91fd23d
0451452
4628884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ const filterAndSortURLs = (count, latencies) => { | |
return urls; | ||
}; | ||
|
||
const willTransitionTo = (nextState, replaceState, callback) => { | ||
const willTransitionTo = (nextState, replaceState, callback, appInit=true) => { //appInit is true when node is manually selected in access settings | ||
if (connect) ss.set("latencyChecks", latencyChecks + 1); // Every 15 connect attempts we refresh the api latency list | ||
if (latencyChecks >= 15) { | ||
apiLatenciesCount = 0; | ||
|
@@ -62,26 +62,30 @@ const willTransitionTo = (nextState, replaceState, callback) => { | |
if (!connectionString) connectionString = urls[0].url; | ||
if (connectionString.indexOf("fake.automatic-selection") !== -1) connectionString = urls[0]; | ||
|
||
if (!connectionManager) connectionManager = new Manager({url: connectionString, urls}); | ||
if (nextState.location.pathname === "/init-error") { | ||
return Apis.reset(connectionString, true).init_promise | ||
.then(() => { | ||
var db; | ||
try { | ||
db = iDB.init_instance(window.openDatabase ? (shimIndexedDB || indexedDB) : indexedDB).init_promise; | ||
} catch(err) { | ||
console.log("db init error:", err); | ||
} | ||
return Promise.all([db, SettingsStore.init()]).then(() => { | ||
return callback(); | ||
}).catch((err) => { | ||
console.log("err:", err); | ||
return callback(); | ||
}); | ||
var onReset = () => { | ||
var db; | ||
try { | ||
db = iDB.init_instance(window.openDatabase ? (shimIndexedDB || indexedDB) : indexedDB).init_promise; | ||
} catch(err) { | ||
console.log("db init error:", err); | ||
} | ||
return Promise.all([db, SettingsStore.init()]).then(() => { | ||
return callback(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reset callback needs to include the promises loading the WalletDb and PrivateKeyActions data, (PrivateKeyActions.loadDbData() and WalletDb.loadDbData()), since the wallet that is loaded depends on the chain id of the websocket API you're connected to. If you switch from the mainnet to the testnet you need to load the correct wallet and private keys. I'm not sure how well those methods play with on the fly switching There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem, can refactor this so the logic is included for both. |
||
}).catch((err) => { | ||
console.log("err:", err); | ||
return callback(); | ||
}); | ||
} | ||
|
||
var onResetError = (err) => { | ||
console.log("err:", err); | ||
return callback(); | ||
} | ||
|
||
connectionManager = new Manager({url: connectionString, urls}); | ||
if (nextState.location.pathname === "/init-error") { | ||
return Apis.reset(connectionString, true).init_promise | ||
.then(onReset).catch(onResetError); | ||
|
||
} | ||
let connectionCheckPromise = !apiLatenciesCount ? connectionManager.checkConnections() : null; | ||
|
@@ -97,51 +101,56 @@ const willTransitionTo = (nextState, replaceState, callback) => { | |
} | ||
let latencies = ss.get("apiLatencies", {}); | ||
let connectionStart = new Date().getTime(); | ||
connectionManager.connectWithFallback(connect).then(() => { | ||
/* Update the latencies object and current active node */ | ||
latencies[connectionManager.url] = new Date().getTime() - connectionStart; | ||
SettingsActions.changeSetting({setting: "apiServer", value: connectionManager.url}); | ||
SettingsActions.updateLatencies(latencies); | ||
|
||
var db; | ||
try { | ||
db = iDB.init_instance(window.openDatabase ? (shimIndexedDB || indexedDB) : indexedDB).init_promise; | ||
} catch(err) { | ||
console.log("db init error:", err); | ||
} | ||
return Promise.all([db, SettingsStore.init()]).then(() => { | ||
return Promise.all([ | ||
PrivateKeyActions.loadDbData().then(()=> AccountRefsStore.loadDbData()), | ||
WalletDb.loadDbData().then(() => { | ||
// if (!WalletDb.getWallet() && nextState.location.pathname === "/") { | ||
// replaceState("/dashboard"); | ||
// } | ||
if (nextState.location.pathname.indexOf("/auth/") === 0) { | ||
replaceState("/dashboard"); | ||
} | ||
}).catch((error) => { | ||
console.error("----- WalletDb.willTransitionTo error ----->", error); | ||
replaceState("/init-error"); | ||
}), | ||
WalletManagerStore.init() | ||
]).then(()=> { | ||
ss.set("activeNode", connectionManager.url); | ||
callback(); | ||
if(appInit){ | ||
connectionManager.connectWithFallback(connect).then(() => { | ||
/* Update the latencies object and current active node */ | ||
latencies[connectionManager.url] = new Date().getTime() - connectionStart; | ||
SettingsActions.changeSetting({setting: "apiServer", value: connectionManager.url}); | ||
SettingsActions.updateLatencies(latencies); | ||
|
||
var db; | ||
try { | ||
db = iDB.init_instance(window.openDatabase ? (shimIndexedDB || indexedDB) : indexedDB).init_promise; | ||
} catch(err) { | ||
console.log("db init error:", err); | ||
} | ||
return Promise.all([db, SettingsStore.init()]).then(() => { | ||
return Promise.all([ | ||
PrivateKeyActions.loadDbData().then(()=> AccountRefsStore.loadDbData()), | ||
WalletDb.loadDbData().then(() => { | ||
// if (!WalletDb.getWallet() && nextState.location.pathname === "/") { | ||
// replaceState("/dashboard"); | ||
// } | ||
if (nextState.location.pathname.indexOf("/auth/") === 0) { | ||
replaceState("/dashboard"); | ||
} | ||
}).catch((error) => { | ||
console.error("----- WalletDb.willTransitionTo error ----->", error); | ||
replaceState("/init-error"); | ||
}), | ||
WalletManagerStore.init() | ||
]).then(()=> { | ||
ss.set("activeNode", connectionManager.url); | ||
callback(); | ||
}); | ||
}); | ||
}); | ||
}).catch( error => { | ||
console.error("----- App.willTransitionTo error ----->", error, (new Error).stack); | ||
if(error.name === "InvalidStateError") { | ||
if (__ELECTRON__) { | ||
replaceState("/dashboard"); | ||
}).catch( error => { | ||
console.error("----- App.willTransitionTo error ----->", error, (new Error).stack); | ||
if(error.name === "InvalidStateError") { | ||
if (__ELECTRON__) { | ||
replaceState("/dashboard"); | ||
} else { | ||
alert("Can't access local storage.\nPlease make sure your browser is not in private/incognito mode."); | ||
} | ||
} else { | ||
alert("Can't access local storage.\nPlease make sure your browser is not in private/incognito mode."); | ||
replaceState("/init-error"); | ||
callback(); | ||
} | ||
} else { | ||
replaceState("/init-error"); | ||
callback(); | ||
} | ||
}); | ||
}); | ||
} else { | ||
Apis.reset(connectionManager.url, true).init_promise.then(onReset).catch(onResetError); | ||
} | ||
|
||
/* Only try initialize the API with connect = true on the first onEnter */ | ||
connect = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this say that appInit is false when selecting nodes in the settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because appInit (which includes fallbacks) should only happen when it's not user choice. I'm using this to differentiate between user picking a server and server being chosen when the app is loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, so when a user picks a server appInit is false, but on first load of the app it is true, which is the opposite of what the comment says. You are calling it with false on line 36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lolz. Yea, just need to fix the comment.