From 53442413b3c5e10fbdfed729716f9abe3148543d Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 5 Feb 2019 11:24:25 +0800 Subject: [PATCH 1/5] Explicitly set page_url --- src/common/elevio.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/elevio.js b/src/common/elevio.js index c1a6ad9f31..ceb81c9fd1 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -13,6 +13,9 @@ const Elevio = (() => { // if (availableElevLanguages.indexOf(currentLanguage) !== -1) { // window._elev.setLanguage(currentLanguage); // eslint-disable-line no-underscore-dangle // } + window._elev.setSettings({ + page_url: document.location.hostname, + }); setUserInfo(elev); setTranslations(elev); }); From 549705dcb6c0cd61c13fba22cef5a2897e88515e Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Tue, 5 Feb 2019 11:53:29 +0800 Subject: [PATCH 2/5] Add path to page_url, add eslint exception --- src/common/elevio.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/elevio.js b/src/common/elevio.js index ceb81c9fd1..d87a04b2a0 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -13,8 +13,9 @@ const Elevio = (() => { // if (availableElevLanguages.indexOf(currentLanguage) !== -1) { // window._elev.setLanguage(currentLanguage); // eslint-disable-line no-underscore-dangle // } + // eslint-disable-next-line no-underscore-dangle window._elev.setSettings({ - page_url: document.location.hostname, + page_url: document.location.hostname + document.location.pathname, }); setUserInfo(elev); setTranslations(elev); From 5d2e971ae41b7a9487cb344acc63c4ea12ca24f6 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Thu, 7 Feb 2019 10:35:03 +0800 Subject: [PATCH 3/5] Add protocol to Elevio page_url --- src/common/elevio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/elevio.js b/src/common/elevio.js index d87a04b2a0..fbadf6b5f3 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -15,7 +15,7 @@ const Elevio = (() => { // } // eslint-disable-next-line no-underscore-dangle window._elev.setSettings({ - page_url: document.location.hostname + document.location.pathname, + page_url: `${document.location.protocol }//${ document.location.hostname }${document.location.pathname}`, }); setUserInfo(elev); setTranslations(elev); From 3b9b18bbc8c76211e55f3b5d3821f46d2d160648 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Thu, 7 Feb 2019 10:50:36 +0800 Subject: [PATCH 4/5] Fix eslint's random spacing --- src/common/elevio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/elevio.js b/src/common/elevio.js index fbadf6b5f3..726eaeb596 100644 --- a/src/common/elevio.js +++ b/src/common/elevio.js @@ -15,7 +15,7 @@ const Elevio = (() => { // } // eslint-disable-next-line no-underscore-dangle window._elev.setSettings({ - page_url: `${document.location.protocol }//${ document.location.hostname }${document.location.pathname}`, + page_url: `${document.location.protocol}//${document.location.hostname}${document.location.pathname}`, }); setUserInfo(elev); setTranslations(elev); From 49e4b55372f8fc1ad1aa1f54e32511bae0a7e8f8 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Thu, 7 Feb 2019 15:27:58 +0800 Subject: [PATCH 5/5] Refactor ServerTime and sync server_time every 30 secs --- src/botPage/view/View.js | 5 +-- .../view/react-components/HeaderWidgets.js | 38 ++++++++++++------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/botPage/view/View.js b/src/botPage/view/View.js index 165f5a6645..4dd5886e3f 100644 --- a/src/botPage/view/View.js +++ b/src/botPage/view/View.js @@ -56,10 +56,6 @@ api.events.on('website_status', response => { } }); -api.send({ time: '1' }).then(response => { - ReactDOM.render(, $('#server-time')[0]); -}); - api.events.on('balance', response => { const { balance: { balance: b, currency }, @@ -648,6 +644,7 @@ function initRealityCheck(stopCallback) { ); } function renderReactComponents() { + ReactDOM.render(, $('#server-time')[0]); ReactDOM.render(, $('#tour')[0]); ReactDOM.render( { + props.api.send({ time: '1' }).then(response => + this.setState( + { + date: new Date(response.time * 1000), + }, + this.updateTime() + ) + ); + }; + getServerTime(); + setInterval(() => this.updateTime(), 1000); + setInterval(() => getServerTime(), 30000); } updateTime() { - this.date.setSeconds(this.date.getSeconds() + 1); - const year = this.date.getUTCFullYear(); - const month = `0${this.date.getMonth() + 1}`.slice(-2); - const date = `0${this.date.getUTCDate()}`.slice(-2); - const hours = `0${this.date.getUTCHours()}`.slice(-2); - const minutes = `0${this.date.getMinutes()}`.slice(-2); - const seconds = `0${this.date.getSeconds()}`.slice(-2); - this.setState({ date: `${year}-${month}-${date} ${hours}:${minutes}:${seconds} GMT` }); - } - componentWillMount() { - this.date = new Date(this.props.startTime * 1000); - setInterval(() => this.updateTime(), 1000); + if (!this.state.date) return; + this.state.date.setSeconds(this.state.date.getSeconds() + 1); + const year = this.state.date.getUTCFullYear(); + const month = `0${this.state.date.getMonth() + 1}`.slice(-2); + const day = `0${this.state.date.getUTCDate()}`.slice(-2); + const hours = `0${this.state.date.getUTCHours()}`.slice(-2); + const minutes = `0${this.state.date.getMinutes()}`.slice(-2); + const seconds = `0${this.state.date.getSeconds()}`.slice(-2); + this.setState({ dateString: `${year}-${month}-${day} ${hours}:${minutes}:${seconds} GMT` }); } render() { - return {this.state.date}; + return {this.state.dateString}; } }