Skip to content

Commit

Permalink
Modify app init Chain to better handle sync error redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Mar 1, 2017
1 parent df9eea0 commit 740c10f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ cli/bundle.js
web/dist-prod
web/stats*
web/hash-history
docs/_build/
38 changes: 19 additions & 19 deletions web/app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import WalletUnlockModal from "./components/Wallet/WalletUnlockModal";
import BrowserSupportModal from "./components/Modal/BrowserSupportModal";
import Footer from "./components/Layout/Footer";

ChainStore.setDispatchFrequency(20);

class App extends React.Component {

constructor() {
Expand All @@ -33,10 +31,12 @@ class App extends React.Component {
const user_agent = navigator.userAgent.toLowerCase();
let isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

let syncFail = ChainStore.subError && (ChainStore.subError.message === "ChainStore sync error, please check your system clock") ? true : false;
console.log("synced:", ChainStore.subscribed, "subError:", ChainStore.subError, ChainStore.subError && ChainStore.subError.message);
this.state = {
loading: true,
synced: false,
syncFail: false,
synced: ChainStore.subscribed,
syncFail,
theme: SettingsStore.getState().settings.get("themes"),
disableChat: SettingsStore.getState().settings.get("disableChat", true),
showChat: SettingsStore.getState().viewSettings.get("showChat", false),
Expand All @@ -57,23 +57,23 @@ class App extends React.Component {
NotificationStore.listen(this._onNotificationChange.bind(this));
SettingsStore.listen(this._onSettingsChange.bind(this));

ChainStore.init().then(() => {
this.setState({synced: true});

Promise.all([
AccountStore.loadDbData(Apis.instance().chainId)
]).then(() => {
AccountStore.tryToSetCurrentAccount();
this.setState({loading: false, syncFail: false});
}).catch(error => {
console.log("[App.jsx] ----- ERROR ----->", error);
this.setState({loading: false});
});
// ChainStore.init().then(() => {


Promise.all([
AccountStore.loadDbData(Apis.instance().chainId)
]).then(() => {
AccountStore.tryToSetCurrentAccount();
this.setState({loading: false});
}).catch(error => {
console.log("[App.jsx] ----- ChainStore.init error ----->", error);
let syncFail = error.message === "ChainStore sync error, please check your system clock" ? true : false;
this.setState({loading: false, syncFail});
console.log("[App.jsx] ----- ERROR ----->", error);
this.setState({loading: false});
});
// }).catch(error => {
// console.log("[App.jsx] ----- ChainStore.init error ----->", error);
//
// this.setState({loading: false, syncFail});
// });
} catch(e) {
console.error("e:", e);
}
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/SyncError.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SyncError extends React.Component {
<p style={{marginBottom: 0}}><Translate content="sync_fail.sub_text_1" /></p>
<Icon name="clock" size="5x"/>

<p><Translate content="sync_fail.sub_text_2" /></p>
<p><Translate unsafe content="sync_fail.sub_text_2" /></p>
</div>
<div className="grid-container text-center" style={{paddingTop: "1rem", maxWidth: "40rem"}}>
<section className="block-list">
Expand Down
6 changes: 4 additions & 2 deletions web/app/routerTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SettingsStore from "stores/SettingsStore";
// Actions
import PrivateKeyActions from "actions/PrivateKeyActions";

ChainStore.setDispatchFrequency(20);

let connect = true;
const willTransitionTo = (nextState, replaceState, callback) => {
let connectionString = SettingsStore.getSetting("apiServer");
Expand All @@ -20,7 +22,7 @@ const willTransitionTo = (nextState, replaceState, callback) => {
return Apis.reset(connectionString, true).init_promise
.then(() => {
var db = iDB.init_instance(window.openDatabase ? (shimIndexedDB || indexedDB) : indexedDB).init_promise;
return Promise.all([db, SettingsStore.init(), ChainStore.init()]).then(() => {
return Promise.all([db, SettingsStore.init()]).then(() => {
return callback();
}).catch((err) => {
console.log("err:", err);
Expand All @@ -39,7 +41,7 @@ const willTransitionTo = (nextState, replaceState, callback) => {
} catch(err) {
console.log("db init error:", err);
}
return Promise.all([db, SettingsStore.init(), ChainStore.init()]).then(() => {
return Promise.all([db, SettingsStore.init(), ChainStore.init("willTransitionTo !init-error")]).then(() => {
return Promise.all([
PrivateKeyActions.loadDbData().then(()=> AccountRefsStore.loadDbData()),
WalletDb.loadDbData().then(() => {
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"alt-container": "^1.0.0",
"alt-react": "0.0.1",
"bignumber.js": "^2.1.0",
"bitsharesjs": "^1.1.3",
"bitsharesjs": "^1.1.4",
"classnames": "^2.2.1",
"cookies-js": "^1.2.1",
"counterpart": "^0.17.1",
Expand Down

0 comments on commit 740c10f

Please sign in to comment.