From e6a6f0eff27267f1d84ceb8dfd18a8fbb58d693e Mon Sep 17 00:00:00 2001 From: Oleg Makarenko Date: Thu, 25 Feb 2021 19:18:41 +0200 Subject: [PATCH 01/43] NRC handle empty history --- .../NodeRewardsWidget/NodeRewardsClient.vue | 41 +++++++++++-------- .../widgets/NodeRewardsWidget/i18n/en.json | 1 + .../widgets/NodeRewardsWidget/model/index.js | 12 +++++- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/components/widgets/NodeRewardsWidget/NodeRewardsClient.vue b/src/components/widgets/NodeRewardsWidget/NodeRewardsClient.vue index 21118ab39..951286336 100644 --- a/src/components/widgets/NodeRewardsWidget/NodeRewardsClient.vue +++ b/src/components/widgets/NodeRewardsWidget/NodeRewardsClient.vue @@ -36,7 +36,7 @@ />
-

{{translate(language, 'error')}}

+

{{translate(language, 'error')}}

{{errorMessage}}

@@ -119,7 +119,8 @@ export default { component: 'PayoutList' } }, - isModelError: false + isModelError: false, + noHistory: false }; }, @@ -140,16 +141,7 @@ export default { formattedData() { if (this.data) { - try { - return new NodeRewardInfo(this.data); - } - catch (e) { - // eslint-disable-next-line - this.isModelError = true; - console.error('Node Rewards Widget. Failed to parse data'); - - return {}; - } + return this.formatData(this.data); } else return {}; @@ -164,13 +156,17 @@ export default { }, isError() { - return this.manager.error || this.isModelError; + return this.manager.error || this.isModelError || this.noHistory; }, errorMessage() { - return this.manager.error - ? translate(this.language, 'errorFailedToFetch') - : translate(this.language, 'errorFailedToParseData'); + if (this.manager.error) + return translate(this.language, 'errorFailedToFetch'); + + if (this.noHistory) + return translate(this.language, 'errorNoHistory'); + + return translate(this.language, 'errorFailedToParseData'); }, nodeMonitorEndpoint() { @@ -187,6 +183,19 @@ export default { methods: { getter(name) { return this.$store.getters[name]; + }, + + formatData(data) { + try { + return new NodeRewardInfo(data); + } + catch (e) { + if (e.message === 'empty_histoty') + this.noHistory = true; + else + this.isModelError = true; + return {}; + } } } }; diff --git a/src/components/widgets/NodeRewardsWidget/i18n/en.json b/src/components/widgets/NodeRewardsWidget/i18n/en.json index ba4cf5b24..8130e8364 100644 --- a/src/components/widgets/NodeRewardsWidget/i18n/en.json +++ b/src/components/widgets/NodeRewardsWidget/i18n/en.json @@ -4,6 +4,7 @@ "error": "Error", "errorFailedToFetch": "Failed to fetch data", "errorFailedToParseData": "Failed to parse data", + "errorNoHistory": "Node has not been included to the round yet", "notASupernode": "This node doesn't participate in the Node Rewards Program", "na": "n/a", diff --git a/src/components/widgets/NodeRewardsWidget/model/index.js b/src/components/widgets/NodeRewardsWidget/model/index.js index bb2bd8faf..55e6fa043 100644 --- a/src/components/widgets/NodeRewardsWidget/model/index.js +++ b/src/components/widgets/NodeRewardsWidget/model/index.js @@ -33,7 +33,6 @@ export class NodeRewardInfo { this.main = new Main(res); this.chainInfo = new ChainInfo(res.testResultInfo); this.performance = new Performance(res.testResultInfo); - this.payout = res.payout; } }; @@ -42,11 +41,19 @@ export class Main { this.friendlyName = res.nodeInfo.name; this.host = res.nodeInfo.restGatewayUrl; this.rewardProgram = res.nodeInfo.rewardProgram; - this.round = res.testResults[0] && res.testResults[0].round; this.history = History.fromRes(res); + this.round = Round.fromRes(res); } } +export class Round { + static fromRes(res) { + if(res?.testResults?.length) + return res.testResults[0] && res.testResults[0].round; + else throw Error('empty_histoty'); + } +}; + export class History { static fromRes(res) { const rawHistoty = res.testResults; @@ -63,6 +70,7 @@ export class History { })) .reverse(); } + else throw Error('empty_histoty'); return formattedHistoty; } From a9c7aa8109ad6eb8568537bb9e3f266ff8d2616b Mon Sep 17 00:00:00 2001 From: Oleg Makarenko Date: Thu, 25 Feb 2021 19:31:46 +0200 Subject: [PATCH 02/43] lint --- .../widgets/NodeRewardsWidget/NodeRewardsClient.vue | 4 ++-- src/components/widgets/NodeRewardsWidget/model/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/widgets/NodeRewardsWidget/NodeRewardsClient.vue b/src/components/widgets/NodeRewardsWidget/NodeRewardsClient.vue index 951286336..de4f561f6 100644 --- a/src/components/widgets/NodeRewardsWidget/NodeRewardsClient.vue +++ b/src/components/widgets/NodeRewardsWidget/NodeRewardsClient.vue @@ -140,9 +140,9 @@ export default { }, formattedData() { - if (this.data) { + if (this.data) return this.formatData(this.data); - } + else return {}; }, diff --git a/src/components/widgets/NodeRewardsWidget/model/index.js b/src/components/widgets/NodeRewardsWidget/model/index.js index 55e6fa043..d5ad8a487 100644 --- a/src/components/widgets/NodeRewardsWidget/model/index.js +++ b/src/components/widgets/NodeRewardsWidget/model/index.js @@ -48,7 +48,7 @@ export class Main { export class Round { static fromRes(res) { - if(res?.testResults?.length) + if (res?.testResults?.length) return res.testResults[0] && res.testResults[0].round; else throw Error('empty_histoty'); } From 8f59abe284db69d6023afe0789c637640839d094 Mon Sep 17 00:00:00 2001 From: Oleg Makarenko Date: Thu, 25 Feb 2021 19:37:32 +0200 Subject: [PATCH 03/43] fix home page layout --- src/views/Home.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index d0347dfd2..b545958d9 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -19,17 +19,17 @@