From bcdfe736f8ef8f672d1e10516a1e185923eeb6d6 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Tue, 20 Feb 2018 16:24:37 -0500 Subject: [PATCH] lint: reenable tslint prefer-conditional-expression, fix --- src/pages/backup/backup-game/backup-game.ts | 8 ++++---- .../bitpay-card-topup/bitpay-card-topup.ts | 10 +++------- .../mercado-libre-card-details.ts | 7 +++---- src/pages/send/amount/amount.ts | 16 ++++------------ .../send/choose-fee-level/choose-fee-level.ts | 15 +++++---------- src/pages/settings/addressbook/view/view.ts | 8 ++------ src/pages/tx-details/tx-details.ts | 8 +++----- src/pages/wallet-details/wallet-details.ts | 9 ++------- src/providers/amazon/amazon.ts | 9 +++------ src/providers/bwc-error/bwc-error.ts | 12 +++--------- src/providers/coinbase/coinbase.ts | 8 +++----- src/providers/language/language.ts | 6 ++---- src/providers/logger/logger.ts | 3 +-- src/providers/mercado-libre/mercado-libre.ts | 9 +++------ src/providers/persistence/persistence.ts | 8 +++----- src/providers/shapeshift/shapeshift.ts | 10 +++------- tslint.json | 1 - 17 files changed, 47 insertions(+), 100 deletions(-) diff --git a/src/pages/backup/backup-game/backup-game.ts b/src/pages/backup/backup-game/backup-game.ts index 8e4db7e47..88dbfbeaa 100644 --- a/src/pages/backup/backup-game/backup-game.ts +++ b/src/pages/backup/backup-game/backup-game.ts @@ -113,10 +113,10 @@ export class BackupGamePage { }; private shouldContinue(): void { - if (this.customWords.length == this.shuffledMnemonicWords.length) - this.selectComplete = true; - else - this.selectComplete = false; + this.selectComplete = + this.customWords.length === this.shuffledMnemonicWords.length + ? true + : false; }; private showBackupResult(): void { diff --git a/src/pages/integrations/bitpay-card/bitpay-card-topup/bitpay-card-topup.ts b/src/pages/integrations/bitpay-card/bitpay-card-topup/bitpay-card-topup.ts index c4adeef06..04c7616c2 100644 --- a/src/pages/integrations/bitpay-card/bitpay-card-topup/bitpay-card-topup.ts +++ b/src/pages/integrations/bitpay-card/bitpay-card-topup/bitpay-card-topup.ts @@ -421,13 +421,9 @@ export class BitPayCardTopUpPage { } private openFinishModal(): void { - let finishComment: string; - if (this.wallet.credentials.m == 1) { - finishComment = this.translate.instant('Funds were added to debit card'); - } - else { - finishComment = this.translate.instant('Transaction initiated'); - } + const finishComment = this.wallet.credentials.m === 1 + ? this.translate.instant('Funds were added to debit card') + : this.translate.instant('Transaction initiated'); let finishText = ''; let modal = this.modalCtrl.create(FinishModalPage, { finishText, finishComment }, { showBackdrop: true, enableBackdropDismiss: false }); modal.present(); diff --git a/src/pages/integrations/mercado-libre/mercado-libre-card-details/mercado-libre-card-details.ts b/src/pages/integrations/mercado-libre/mercado-libre-card-details/mercado-libre-card-details.ts index 65c1c4d58..84f4022cd 100644 --- a/src/pages/integrations/mercado-libre/mercado-libre-card-details/mercado-libre-card-details.ts +++ b/src/pages/integrations/mercado-libre/mercado-libre-card-details/mercado-libre-card-details.ts @@ -45,10 +45,9 @@ export class MercadoLibreCardDetailsPage { } public openRedeemLink() { - let url; - let isSandbox = this.mercadoLibreProvider.getNetwork() == 'testnet' ? true : false; - if (isSandbox) url = 'https://beta.mercadolivre.com.br/vale-presente/resgate'; - else url = 'https://www.mercadolivre.com.br/vale-presente/resgate'; + const url = this.mercadoLibreProvider.getNetwork() === 'testnet' + ? 'https://beta.mercadolivre.com.br/vale-presente/resgate' + : 'https://www.mercadolivre.com.br/vale-presente/resgate'; this.openExternalLink(url); } diff --git a/src/pages/send/amount/amount.ts b/src/pages/send/amount/amount.ts index ac0386dc6..a8675b56a 100644 --- a/src/pages/send/amount/amount.ts +++ b/src/pages/send/amount/amount.ts @@ -355,11 +355,7 @@ export class AmountPage { if (a) { this.alternativeAmount = this.txFormatProvider.formatAmount(a * this.unitToSatoshi, true); } else { - if (result) { - this.alternativeAmount = 'N/A'; - } else { - this.alternativeAmount = null; - } + this.alternativeAmount = result ? 'N/A' : null; this.allowSend = false; } } else { @@ -426,13 +422,9 @@ export class AmountPage { }; } else { let amount = _amount; - - if (unit.isFiat) { - amount = (this.fromFiat(amount) * this.unitToSatoshi).toFixed(0); - } else { - amount = (amount * this.unitToSatoshi).toFixed(0); - } - + amount = unit.isFiat + ? (this.fromFiat(amount) * this.unitToSatoshi).toFixed(0) + : (amount * this.unitToSatoshi).toFixed(0); data = { recipientType: this.recipientType, amount, diff --git a/src/pages/send/choose-fee-level/choose-fee-level.ts b/src/pages/send/choose-fee-level/choose-fee-level.ts index b21c851d9..a7507e6f9 100644 --- a/src/pages/send/choose-fee-level/choose-fee-level.ts +++ b/src/pages/send/choose-fee-level/choose-fee-level.ts @@ -131,16 +131,11 @@ export class ChooseFeeLevelPage { public checkFees(feePerSatByte: string): void { let fee = Number(feePerSatByte); - - - if (fee <= this.minFeeAllowed) this.showError = true; - else this.showError = false; - - if (fee > this.minFeeAllowed && fee < this.minFeeRecommended) this.showMinWarning = true; - else this.showMinWarning = false; - - if (fee < this.maxFeeAllowed && fee > this.maxFeeRecommended) this.showMaxWarning = true; - else this.showMaxWarning = false; + this.showError = fee <= this.minFeeAllowed ? true : false; + this.showMinWarning = + fee > this.minFeeAllowed && fee < this.minFeeRecommended ? true : false; + this.showMaxWarning = + fee < this.maxFeeAllowed && fee > this.maxFeeRecommended ? true : false; } public ok(): void { diff --git a/src/pages/settings/addressbook/view/view.ts b/src/pages/settings/addressbook/view/view.ts index 99b1883a2..2fb1b3ed6 100644 --- a/src/pages/settings/addressbook/view/view.ts +++ b/src/pages/settings/addressbook/view/view.ts @@ -40,12 +40,8 @@ export class AddressbookViewPage { this.name = this.navParams.data.contact.name; this.email = this.navParams.data.contact.email; - var cashAddress = this.bitcoreCash.Address.isValid(this.address, 'livenet'); - if (cashAddress) { - this.coin = 'bch'; - } else { - this.coin = 'btc'; - } + const cashAddress = this.bitcoreCash.Address.isValid(this.address, 'livenet'); + this.coin = cashAddress ? 'bch' : 'btc'; } ionViewDidLoad() { diff --git a/src/pages/tx-details/tx-details.ts b/src/pages/tx-details/tx-details.ts index aecb865dc..9a40486d6 100644 --- a/src/pages/tx-details/tx-details.ts +++ b/src/pages/tx-details/tx-details.ts @@ -65,11 +65,9 @@ export class TxDetailsPage { this.txsUnsubscribedForNotifications = this.config.confirmedTxsNotifications ? !this.config.confirmedTxsNotifications.enabled : true; let defaults = this.configProvider.getDefaults(); - if (this.wallet.coin == 'bch') { - this.blockexplorerUrl = defaults.blockExplorerUrl.bch; - } else { - this.blockexplorerUrl = defaults.blockExplorerUrl.btc; - } + this.blockexplorerUrl = this.wallet.coin === 'bch' + ? defaults.blockExplorerUrl.bch + : defaults.blockExplorerUrl.btc; this.txConfirmNotificationProvider.checkIfEnabled(this.txId).then((res: any) => { this.txNotification = { diff --git a/src/pages/wallet-details/wallet-details.ts b/src/pages/wallet-details/wallet-details.ts index eb7283a8e..256db8c0f 100644 --- a/src/pages/wallet-details/wallet-details.ts +++ b/src/pages/wallet-details/wallet-details.ts @@ -122,11 +122,7 @@ export class WalletDetailsPage { // }; // lodash.times(15, addOutput); // txps.push(txp); - if (!txps) { - this.txps = []; - } else { - this.txps = _.sortBy(txps, 'createdOn').reverse(); - } + this.txps = !txps ? [] : _.sortBy(txps, 'createdOn').reverse(); } private updateTxHistory() { @@ -146,8 +142,7 @@ export class WalletDetailsPage { this.updatingTxHistory = false; let hasTx = txHistory[0]; - if (hasTx) this.showNoTransactionsYetMsg = false; - else this.showNoTransactionsYetMsg = true; + this.showNoTransactionsYetMsg = hasTx ? false : true; this.wallet.completeHistory = txHistory; this.showHistory(); diff --git a/src/providers/amazon/amazon.ts b/src/providers/amazon/amazon.ts index f39fe1e75..c328f94ec 100644 --- a/src/providers/amazon/amazon.ts +++ b/src/providers/amazon/amazon.ts @@ -28,12 +28,9 @@ export class AmazonProvider { * Production: 'livenet' */ this.credentials.NETWORK = 'livenet'; - // TODO this.credentials.NETWORK = 'testnet'; - if (this.credentials.NETWORK == 'testnet') { - this.credentials.BITPAY_API_URL = "https://test.bitpay.com"; - } else { - this.credentials.BITPAY_API_URL = "https://bitpay.com"; - }; + this.credentials.BITPAY_API_URL = this.credentials.NETWORK === 'testnet' + ? "https://test.bitpay.com" + : "https://bitpay.com"; this.limitPerDay = 2000; this.homeItem = { name: 'amazon', diff --git a/src/providers/bwc-error/bwc-error.ts b/src/providers/bwc-error/bwc-error.ts index e77fd9a22..07b62f8a6 100644 --- a/src/providers/bwc-error/bwc-error.ts +++ b/src/providers/bwc-error/bwc-error.ts @@ -12,15 +12,9 @@ export class BwcErrorProvider { if (!err) return 'Unknown error'; - let name; - - if (err.name) { - if (err.name == 'Error') - name = err.message - else - name = err.name.replace(/^bwc.Error/g, ''); - } else - name = err; + const name = err.name ? + (err.name === 'Error' ? err.message : err.name.replace(/^bwc.Error/g, '')) + : err; let body = ''; prefix = prefix || ''; diff --git a/src/providers/coinbase/coinbase.ts b/src/providers/coinbase/coinbase.ts index 19940eaaf..1ff700b5e 100644 --- a/src/providers/coinbase/coinbase.ts +++ b/src/providers/coinbase/coinbase.ts @@ -100,11 +100,9 @@ export class CoinbaseProvider { 'wallet:payment-methods:read'; // NW has a bug with Window Object - if (this.isCordova) { - this.credentials.REDIRECT_URI = coinbase.redirect_uri.mobile; - } else { - this.credentials.REDIRECT_URI = coinbase.redirect_uri.desktop; - } + this.credentials.REDIRECT_URI = this.isCordova + ? coinbase.redirect_uri.mobile + : coinbase.redirect_uri.desktop; if (this.credentials.NETWORK == 'testnet') { this.credentials.HOST = coinbase.sandbox.host; diff --git a/src/providers/language/language.ts b/src/providers/language/language.ts index 2ff96adcf..2b1fa2d52 100644 --- a/src/providers/language/language.ts +++ b/src/providers/language/language.ts @@ -61,10 +61,8 @@ export class LanguageProvider { if (!_.isEmpty(lang)) this.current = lang; else { // Get from browser - let browserLang = this.translate.getBrowserLang(); - let validBrowserLang = this.getName(browserLang) ? true : false; - if (validBrowserLang) this.current = browserLang; - else this.current = this.getDefault(); + const browserLang = this.translate.getBrowserLang(); + this.current = this.getName(browserLang) ? browserLang : this.getDefault(); } this.logger.info('Default language: ' + this.current); this.translate.setDefaultLang(this.current); diff --git a/src/providers/logger/logger.ts b/src/providers/logger/logger.ts index 9486f4b72..876afa914 100644 --- a/src/providers/logger/logger.ts +++ b/src/providers/logger/logger.ts @@ -92,8 +92,7 @@ export class Logger { if (typeof v == 'undefined') v = 'undefined'; if (!v) v = 'null'; if (typeof v == 'object') { - if (v.message) v = v.message; - else v = JSON.stringify(v); + v = v.message ? v.message : JSON.stringify(v); } } catch (e) { // tslint:disable-next-line:no-console diff --git a/src/providers/mercado-libre/mercado-libre.ts b/src/providers/mercado-libre/mercado-libre.ts index eea78654d..891880341 100644 --- a/src/providers/mercado-libre/mercado-libre.ts +++ b/src/providers/mercado-libre/mercado-libre.ts @@ -36,12 +36,9 @@ export class MercadoLibreProvider { */ this.credentials = {}; this.credentials.NETWORK = 'livenet'; - // TODO this.credentials.NETWORK = 'testnet'; - if (this.credentials.NETWORK == 'testnet') { - this.credentials.BITPAY_API_URL = "https://test.bitpay.com"; - } else { - this.credentials.BITPAY_API_URL = "https://bitpay.com"; - } + this.credentials.BITPAY_API_URL = this.credentials.NETWORK === 'testnet' + ? "https://test.bitpay.com" + : "https://bitpay.com"; this.homeItem = { name: 'mercadoLibre', diff --git a/src/providers/persistence/persistence.ts b/src/providers/persistence/persistence.ts index 09b60b278..303f389a9 100644 --- a/src/providers/persistence/persistence.ts +++ b/src/providers/persistence/persistence.ts @@ -58,11 +58,9 @@ export class PersistenceProvider { }; public load() { - if (this.platform.isCordova) { - this.storage = new FileStorage(this.file, this.logger); - } else { - this.storage = new LocalStorage(); - } + this.storage = this.platform.isCordova + ? new FileStorage(this.file, this.logger) + : new LocalStorage(); } storeNewProfile(profile): Promise { diff --git a/src/providers/shapeshift/shapeshift.ts b/src/providers/shapeshift/shapeshift.ts index 698021a83..97cb6d09a 100644 --- a/src/providers/shapeshift/shapeshift.ts +++ b/src/providers/shapeshift/shapeshift.ts @@ -34,14 +34,10 @@ export class ShapeshiftProvider { * Production: 'livenet' */ this.credentials.NETWORK = 'livenet'; - // TODO this.credentials.NETWORK = 'testnet'; - - if (this.credentials.NETWORK == 'testnet') { - this.credentials.API_URL = ""; - } else { + this.credentials.API_URL = this.credentials.NETWORK === 'testnet' + ? "" // CORS: cors.shapeshift.io - this.credentials.API_URL = "https://shapeshift.io"; - } + : "https://shapeshift.io"; this.homeItem = { name: 'shapeshift', diff --git a/tslint.json b/tslint.json index 5a91bb7a8..f5eb43a3d 100644 --- a/tslint.json +++ b/tslint.json @@ -20,7 +20,6 @@ "no-implicit-dependencies": false, "object-literal-sort-keys": false, "interface-name": false, - "prefer-conditional-expression": false, "prefer-for-of": false, "forin": false, "prefer-const": false,