From 6fd61d186d29488ec77760752462a3ca57caeb35 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Tue, 14 Jan 2020 16:23:07 -0500 Subject: [PATCH 1/9] better naming --- js/views/components/moderators/Moderators.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/views/components/moderators/Moderators.js b/js/views/components/moderators/Moderators.js index 5ab732937..abbd9a6ca 100644 --- a/js/views/components/moderators/Moderators.js +++ b/js/views/components/moderators/Moderators.js @@ -146,13 +146,13 @@ export default class extends baseVw { processMod(data) { // Don't add profiles that are not moderators unless showInvalid is true. The ID list may have // peerIDs that are out of date, and are no longer moderators. - const validMod = data.moderator && data.moderatorInfo; + const isAMod = data.moderator && data.moderatorInfo; // If the moderator has an invalid currency, remove them from the list. // With multi-wallet, this should be a very rare occurrence. const modCurs = data.moderatorInfo && data.moderatorInfo.acceptedCurrencies || []; - const validCur = anySupportedByWallet(modCurs); + const supportedCur = anySupportedByWallet(modCurs); - if ((!!validMod && validCur || this.options.showInvalid)) { + if ((!!isAMod && supportedCur || this.options.showInvalid)) { const newMod = new Moderator(data, { parse: true }); if (newMod.isValid()) this.moderatorsCol.add(newMod); this.removeNotFetched(data.peerID); From 04d5e278a4944c1115b4160e0ffbaacf7f40933d Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Wed, 15 Jan 2020 12:22:36 -0500 Subject: [PATCH 2/9] tweak language --- js/languages/en_US.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/languages/en_US.json b/js/languages/en_US.json index fdcf39202..152f375a9 100644 --- a/js/languages/en_US.json +++ b/js/languages/en_US.json @@ -402,7 +402,7 @@ "PERCENTAGE": "%{percentage}%*", "FIXED_PLUS_PERCENTAGE": "%{amount} (+%{percentage}%)*", "failed": "The information for this moderator failed to load.", - "invalid": "This user is not currently a moderator.", + "invalid": "This user is not currently a valid moderator.", "noCoinSupport": "This moderator does not accept any of the coins your wallet supports.", "noPreferredSupport": "This moderator does not accept any of your preferred coins. They can only moderate transactions in the following currencies: %{coins}.", "languages": "%{lang}, and %{smart_count} other language. |||| %{lang}, and %{smart_count} other languages." @@ -5740,4 +5740,4 @@ "zu": "Zulu", "zu-ZA": "Zulu (South Africa)" } -} \ No newline at end of file +} From 7f58e577e3165791bbc7b0fcb5abe966b78d218a Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Wed, 15 Jan 2020 12:34:41 -0500 Subject: [PATCH 3/9] check validity in template --- js/templates/components/moderators/card.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/templates/components/moderators/card.html b/js/templates/components/moderators/card.html index 21bcf27cd..a5866eb00 100644 --- a/js/templates/components/moderators/card.html +++ b/js/templates/components/moderators/card.html @@ -3,7 +3,8 @@ const loaded = !!ob.name; /* Disable the card if it is invalid and the controls should be shown, and it is not selected. This allow the user to de-select invalid cards. The view should prevent the invalid card from being selected again, disabling it is redundant but important visually. */ - const isDisabled = (!ob.valid && !ob.controlsOnInvalid ) || (!ob.valid && ob.controlsOnInvalid && ob.selectedState !== 'selected') || !loaded ? 'disabled' : ''; + const isOKMod = ob.valid && ob.isMod; + const isDisabled = (!isOKMod && !ob.controlsOnInvalid ) || (!isOKMod && ob.controlsOnInvalid && ob.selectedState !== 'selected') || !loaded ? 'disabled' : ''; const style = ob.verified ? 'verified clrBrAlert2 clrBAlert2Grad' : ''; %> @@ -29,7 +30,7 @@ <%= ob.handle ? `@${ob.handle}` : '' %>
- <% if (ob.valid) { %> + <% if (isOKMod) { %>
<%=ob.moderatorInfo.description %>
<% if (ob.modLanguages && ob.modLanguages.length) { %>
@@ -72,9 +73,9 @@ <% } %>
- <% if (ob.valid || ob.controlsOnInvalid) { %> + <% if (isOKMod || ob.controlsOnInvalid) { %>
- <% if (ob.valid) { %> + <% if (isOKMod) { %> From 0b08f4c73483445bcbcab286d32e3c6a9ad124f8 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Wed, 15 Jan 2020 12:35:12 -0500 Subject: [PATCH 4/9] validate the card --- js/views/components/moderators/Card.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/js/views/components/moderators/Card.js b/js/views/components/moderators/Card.js index 38db7c9fd..eb9d4ed75 100644 --- a/js/views/components/moderators/Card.js +++ b/js/views/components/moderators/Card.js @@ -7,6 +7,7 @@ import VerifiedMod, { getModeratorOptions } from '../VerifiedMod'; import { handleLinks } from '../../../utils/dom'; import { launchModeratorDetailsModal } from '../../../utils/modalManager'; import { anySupportedByWallet } from '../../../data/walletCurrencies'; +import { isFiatCur} from "../../../data/currencies"; import { getLangByCode } from '../../../data/languages'; export default class extends BaseVw { @@ -44,6 +45,10 @@ export default class extends BaseVw { const modInfo = this.model.get('moderatorInfo'); this.modCurs = modInfo && modInfo.get('acceptedCurrencies') || []; + const fee = modInfo && modInfo.get('fee'); + const fixedFee = fee && fee.get('fixedFee'); + this.fixedFeeCur = fixedFee && fixedFee.get('currencyCode'); + this.modLanguages = []; if (this.model.isModerator) { this.modLanguages = this.model.get('moderatorInfo') @@ -86,7 +91,8 @@ export default class extends BaseVw { } get hasValidCurrency() { - return anySupportedByWallet(this.modCurs); + const validFeeCur = isFiatCur(this.fixedFeeCur) || anySupportedByWallet([this.fixedFeeCur]); + return validFeeCur && anySupportedByWallet(this.modCurs); } get hasPreferredCur() { @@ -125,8 +131,9 @@ export default class extends BaseVw { loadTemplate('components/moderators/card.html', (t) => { this.$el.html(t({ + valid: !!this.model.isValid(), displayCurrency: app.settings.get('localCurrency'), - valid: this.model.isModerator, + isMod: this.model.isModerator, hasValidCurrency: this.hasValidCurrency, radioStyle: this.options.radioStyle, controlsOnInvalid: this.options.controlsOnInvalid, From b83fe78befed9fed49b66272ffb671fd98bd8f72 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Wed, 15 Jan 2020 12:35:45 -0500 Subject: [PATCH 5/9] only add invalid if flag is true --- js/views/components/moderators/Moderators.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/views/components/moderators/Moderators.js b/js/views/components/moderators/Moderators.js index abbd9a6ca..53436660b 100644 --- a/js/views/components/moderators/Moderators.js +++ b/js/views/components/moderators/Moderators.js @@ -150,11 +150,11 @@ export default class extends baseVw { // If the moderator has an invalid currency, remove them from the list. // With multi-wallet, this should be a very rare occurrence. const modCurs = data.moderatorInfo && data.moderatorInfo.acceptedCurrencies || []; - const supportedCur = anySupportedByWallet(modCurs); + const hasSupportedCur = anySupportedByWallet(modCurs); + const newMod = new Moderator(data, { parse: true }); - if ((!!isAMod && supportedCur || this.options.showInvalid)) { - const newMod = new Moderator(data, { parse: true }); - if (newMod.isValid()) this.moderatorsCol.add(newMod); + if ((!!isAMod && hasSupportedCur && newMod.isValid() || this.options.showInvalid)) { + this.moderatorsCol.add(newMod); this.removeNotFetched(data.peerID); } else { // remove the invalid moderator from the notFetched list From 7621599e761bf9de04dda7ddd00f5538a575df39 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Wed, 15 Jan 2020 13:53:03 -0500 Subject: [PATCH 6/9] remove isValid check in card --- js/templates/components/moderators/card.html | 9 ++++----- js/views/components/moderators/Card.js | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/js/templates/components/moderators/card.html b/js/templates/components/moderators/card.html index a5866eb00..b281b2dd8 100644 --- a/js/templates/components/moderators/card.html +++ b/js/templates/components/moderators/card.html @@ -3,8 +3,7 @@ const loaded = !!ob.name; /* Disable the card if it is invalid and the controls should be shown, and it is not selected. This allow the user to de-select invalid cards. The view should prevent the invalid card from being selected again, disabling it is redundant but important visually. */ - const isOKMod = ob.valid && ob.isMod; - const isDisabled = (!isOKMod && !ob.controlsOnInvalid ) || (!isOKMod && ob.controlsOnInvalid && ob.selectedState !== 'selected') || !loaded ? 'disabled' : ''; + const isDisabled = (!ob.isMod && !ob.controlsOnInvalid ) || (!ob.isMod && ob.controlsOnInvalid && ob.selectedState !== 'selected') || !loaded ? 'disabled' : ''; const style = ob.verified ? 'verified clrBrAlert2 clrBAlert2Grad' : ''; %> @@ -30,7 +29,7 @@ <%= ob.handle ? `@${ob.handle}` : '' %>
- <% if (isOKMod) { %> + <% if (ob.isMod) { %>
<%=ob.moderatorInfo.description %>
<% if (ob.modLanguages && ob.modLanguages.length) { %>
@@ -73,9 +72,9 @@ <% } %>
- <% if (isOKMod || ob.controlsOnInvalid) { %> + <% if (ob.isMod || ob.controlsOnInvalid) { %>
- <% if (isOKMod) { %> + <% if (ob.isMod) { %> diff --git a/js/views/components/moderators/Card.js b/js/views/components/moderators/Card.js index eb9d4ed75..ff3cc2e76 100644 --- a/js/views/components/moderators/Card.js +++ b/js/views/components/moderators/Card.js @@ -91,7 +91,9 @@ export default class extends BaseVw { } get hasValidCurrency() { - const validFeeCur = isFiatCur(this.fixedFeeCur) || anySupportedByWallet([this.fixedFeeCur]); + const isFeeFiat = this.fixedFeeCur && isFiatCur(this.fixedFeeCur); + const isFeeCrypto = this.fixedFeeCur && anySupportedByWallet([this.fixedFeeCur]); + const validFeeCur = isFeeFiat || isFeeCrypto; return validFeeCur && anySupportedByWallet(this.modCurs); } @@ -131,7 +133,6 @@ export default class extends BaseVw { loadTemplate('components/moderators/card.html', (t) => { this.$el.html(t({ - valid: !!this.model.isValid(), displayCurrency: app.settings.get('localCurrency'), isMod: this.model.isModerator, hasValidCurrency: this.hasValidCurrency, From e4a8a6c07d2f3bcbb4791ede7e89b9677401bc84 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Wed, 15 Jan 2020 14:11:16 -0500 Subject: [PATCH 7/9] put back card isValid check --- js/templates/components/moderators/card.html | 9 +++++---- js/views/components/moderators/Card.js | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/js/templates/components/moderators/card.html b/js/templates/components/moderators/card.html index b281b2dd8..a5866eb00 100644 --- a/js/templates/components/moderators/card.html +++ b/js/templates/components/moderators/card.html @@ -3,7 +3,8 @@ const loaded = !!ob.name; /* Disable the card if it is invalid and the controls should be shown, and it is not selected. This allow the user to de-select invalid cards. The view should prevent the invalid card from being selected again, disabling it is redundant but important visually. */ - const isDisabled = (!ob.isMod && !ob.controlsOnInvalid ) || (!ob.isMod && ob.controlsOnInvalid && ob.selectedState !== 'selected') || !loaded ? 'disabled' : ''; + const isOKMod = ob.valid && ob.isMod; + const isDisabled = (!isOKMod && !ob.controlsOnInvalid ) || (!isOKMod && ob.controlsOnInvalid && ob.selectedState !== 'selected') || !loaded ? 'disabled' : ''; const style = ob.verified ? 'verified clrBrAlert2 clrBAlert2Grad' : ''; %> @@ -29,7 +30,7 @@ <%= ob.handle ? `@${ob.handle}` : '' %>
- <% if (ob.isMod) { %> + <% if (isOKMod) { %>
<%=ob.moderatorInfo.description %>
<% if (ob.modLanguages && ob.modLanguages.length) { %>
@@ -72,9 +73,9 @@ <% } %>
- <% if (ob.isMod || ob.controlsOnInvalid) { %> + <% if (isOKMod || ob.controlsOnInvalid) { %>
- <% if (ob.isMod) { %> + <% if (isOKMod) { %> diff --git a/js/views/components/moderators/Card.js b/js/views/components/moderators/Card.js index ff3cc2e76..79cef02e2 100644 --- a/js/views/components/moderators/Card.js +++ b/js/views/components/moderators/Card.js @@ -133,6 +133,7 @@ export default class extends BaseVw { loadTemplate('components/moderators/card.html', (t) => { this.$el.html(t({ + valid: !!this.model.isValid(), displayCurrency: app.settings.get('localCurrency'), isMod: this.model.isModerator, hasValidCurrency: this.hasValidCurrency, From 613ab7b1d6c03fc55df06b9d7a2b74e060d168f7 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Wed, 15 Jan 2020 14:43:55 -0500 Subject: [PATCH 8/9] Show errors if data is bad --- js/languages/en_US.json | 3 ++- js/templates/components/moderators/card.html | 9 +++++++++ js/views/components/moderators/Card.js | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/js/languages/en_US.json b/js/languages/en_US.json index 152f375a9..7a7e7b6e4 100644 --- a/js/languages/en_US.json +++ b/js/languages/en_US.json @@ -2055,7 +2055,8 @@ "descriptionLength": "Descriptions must be no more than 300 characters", "noTerms": "Please provide your terms of service.", "termsLength": "Terms of service must be no more than 10,000 characters", - "noLanguages": "Please list at least one language you can communicate in." + "noLanguages": "Please list at least one language you can communicate in.", + "invalidData": "The value for %{field} is invalid or missing." }, "feeModelErrors": { "noFeeType": "Please set a valid fee type", diff --git a/js/templates/components/moderators/card.html b/js/templates/components/moderators/card.html index a5866eb00..bf49e445b 100644 --- a/js/templates/components/moderators/card.html +++ b/js/templates/components/moderators/card.html @@ -63,6 +63,15 @@ <% } %> <% } else { %> <%= ob.polyT('moderatorCard.invalid') %> + <% + if (ob.modelErrors) { + const translatedErrs = []; + Object.keys(ob.modelErrors).forEach(field => { + translatedErrs.push(ob.polyT('moderatorModelErrors.invalidData', { field })); + }); + print(ob.formErrorTmpl({ errors: translatedErrs })); + } + %> <% } %>
<% } else { %> diff --git a/js/views/components/moderators/Card.js b/js/views/components/moderators/Card.js index 79cef02e2..b1992ac73 100644 --- a/js/views/components/moderators/Card.js +++ b/js/views/components/moderators/Card.js @@ -134,6 +134,7 @@ export default class extends BaseVw { loadTemplate('components/moderators/card.html', (t) => { this.$el.html(t({ valid: !!this.model.isValid(), + modelErrors: this.model.validationError, displayCurrency: app.settings.get('localCurrency'), isMod: this.model.isModerator, hasValidCurrency: this.hasValidCurrency, From 2a22a5c10b9da5f32bd8393e87ad858cfba7be22 Mon Sep 17 00:00:00 2001 From: jjeffryes Date: Wed, 15 Jan 2020 16:29:39 -0500 Subject: [PATCH 9/9] fix lint issue --- js/views/components/moderators/Card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/views/components/moderators/Card.js b/js/views/components/moderators/Card.js index b1992ac73..3be5bba4d 100644 --- a/js/views/components/moderators/Card.js +++ b/js/views/components/moderators/Card.js @@ -7,7 +7,7 @@ import VerifiedMod, { getModeratorOptions } from '../VerifiedMod'; import { handleLinks } from '../../../utils/dom'; import { launchModeratorDetailsModal } from '../../../utils/modalManager'; import { anySupportedByWallet } from '../../../data/walletCurrencies'; -import { isFiatCur} from "../../../data/currencies"; +import { isFiatCur } from '../../../data/currencies'; import { getLangByCode } from '../../../data/languages'; export default class extends BaseVw {