Skip to content

Commit 694b23e

Browse files
committed
remove lodash.isEmpty() calls
find packages/ -type f -exec sed -i -E \ -e 's/!_\.isEmpty\(([a-zA-Z.]+)\)/\1.length !== 0/g' {} + find packages/ -type f -exec sed -i -E \ -e 's/_\.isEmpty\(([a-zA-Z.]+)\)/\1.length === 0/g' {} +
1 parent 1b440e7 commit 694b23e

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

packages/bitcore-wallet-service/src/lib/chain/btc/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class BtcChain implements IChain {
100100
return -input.satoshis;
101101
});
102102

103-
if (_.isEmpty(inputs)) return cb(null, info);
103+
if (inputs.length === 0) return cb(null, info);
104104

105105
server._getFeePerKb(wallet, opts, (err, feePerKb) => {
106106
if (err) return cb(err);
@@ -139,7 +139,7 @@ export class BtcChain implements IChain {
139139
txp.inputs.push(input);
140140
});
141141

142-
if (_.isEmpty(txp.inputs)) return cb(null, info);
142+
if (txp.inputs.length === 0) return cb(null, info);
143143

144144
const fee = this.getEstimatedFee(txp, { conservativeEstimation: true });
145145
const amount = _.sumBy(txp.inputs, 'satoshis') - fee;
@@ -173,7 +173,7 @@ export class BtcChain implements IChain {
173173
if (wallet.singleAddress) {
174174
server.storage.fetchAddresses(server.walletId, (err, addresses) => {
175175
if (err) return cb(err);
176-
if (_.isEmpty(addresses)) return cb(new ClientError('The wallet has no addresses'));
176+
if (addresses.length === 0) return cb(new ClientError('The wallet has no addresses'));
177177
return cb(null, _.head(addresses));
178178
});
179179
} else {
@@ -486,7 +486,7 @@ export class BtcChain implements IChain {
486486
}
487487
}
488488

489-
if (_.isEmpty(txp.inputPaths)) return Errors.NO_INPUT_PATHS;
489+
if (txp.inputPaths.length === 0) return Errors.NO_INPUT_PATHS;
490490

491491
try {
492492
const bitcoreTx = this.getBitcoreTx(txp);
@@ -565,7 +565,7 @@ export class BtcChain implements IChain {
565565
const MAX_TX_SIZE_IN_KB = Defaults.MAX_TX_SIZE_IN_KB_BTC;
566566

567567
// todo: check inputs are ours and have enough value
568-
if (txp.inputs && !_.isEmpty(txp.inputs) && !txp.replaceTxByFee) {
568+
if (txp.inputs && txp.inputs.length !== 0 && !txp.replaceTxByFee) {
569569
if (!_.isNumber(txp.fee)) txp.fee = this.getEstimatedFee(txp, { conservativeEstimation: true });
570570
return cb(this.checkTx(txp));
571571
}
@@ -706,7 +706,7 @@ export class BtcChain implements IChain {
706706
return false;
707707
}
708708

709-
if (!_.isEmpty(bigInputs)) {
709+
if (bigInputs.length !== 0) {
710710
if (amountVsUtxoRatio < Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) {
711711
// logger.debug('Breaking because utxo is too small compared to tx amount');
712712
return false;
@@ -757,7 +757,7 @@ export class BtcChain implements IChain {
757757
);
758758

759759
selected = [];
760-
if (!_.isEmpty(bigInputs)) {
760+
if (bigInputs.length !== 0) {
761761
const input = _.head(bigInputs);
762762
logger.debug('Using big input: %o', Utils.formatUtxos(input));
763763
total = input.satoshis;
@@ -767,7 +767,7 @@ export class BtcChain implements IChain {
767767
}
768768
}
769769

770-
if (_.isEmpty(selected)) {
770+
if (selected.length === 0) {
771771
// logger.debug('Could not find enough funds within this utxo subset');
772772
return cb(
773773
error ||
@@ -826,7 +826,7 @@ export class BtcChain implements IChain {
826826
let lastGroupLength;
827827
async.whilst(
828828
() => {
829-
return i < groups.length && _.isEmpty(inputs);
829+
return i < groups.length && inputs.length === 0;
830830
},
831831
next => {
832832
const group = groups[i++];
@@ -880,7 +880,7 @@ export class BtcChain implements IChain {
880880
},
881881
err => {
882882
if (err) return cb(err);
883-
if (selectionError || _.isEmpty(inputs))
883+
if (selectionError || inputs.length === 0)
884884
return cb(selectionError || new Error('Could not select tx inputs'));
885885

886886
txp.setInputs(_.shuffle(inputs));
@@ -907,7 +907,7 @@ export class BtcChain implements IChain {
907907
}
908908

909909
checkUtxos(opts) {
910-
if (_.isNumber(opts.fee) && _.isEmpty(opts.inputs)) return true;
910+
if (_.isNumber(opts.fee) && opts.inputs.length === 0) return true;
911911
}
912912

913913
checkValidTxAmount(output): boolean {

packages/bitcore-wallet-service/src/lib/chain/doge/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class DogeChain extends BtcChain implements IChain {
2222
const MAX_TX_SIZE_IN_KB = Defaults.MAX_TX_SIZE_IN_KB_DOGE;
2323

2424
// todo: check inputs are ours and have enough value
25-
if (txp.inputs && !_.isEmpty(txp.inputs)) {
25+
if (txp.inputs && txp.inputs.length !== 0) {
2626
if (!_.isNumber(txp.fee)) txp.fee = this.getEstimatedFee(txp, { conservativeEstimation: true });
2727
return cb(this.checkTx(txp));
2828
}
@@ -146,7 +146,7 @@ export class DogeChain extends BtcChain implements IChain {
146146
return false;
147147
}
148148

149-
if (!_.isEmpty(bigInputs)) {
149+
if (bigInputs.length !== 0) {
150150
if (amountVsUtxoRatio < Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) {
151151
// logger.debug('Breaking because utxo is too small compared to tx amount');
152152
return false;
@@ -197,7 +197,7 @@ export class DogeChain extends BtcChain implements IChain {
197197
);
198198

199199
selected = [];
200-
if (!_.isEmpty(bigInputs)) {
200+
if (bigInputs.length !== 0) {
201201
const input = _.head(bigInputs);
202202
logger.debug('Using big input: %o', Utils.formatUtxos(input));
203203
total = input.satoshis;
@@ -208,7 +208,7 @@ export class DogeChain extends BtcChain implements IChain {
208208
}
209209
}
210210

211-
if (_.isEmpty(selected)) {
211+
if (selected.length === 0) {
212212
// logger.debug('Could not find enough funds within this utxo subset');
213213
return cb(
214214
error ||
@@ -261,7 +261,7 @@ export class DogeChain extends BtcChain implements IChain {
261261
let lastGroupLength;
262262
async.whilst(
263263
() => {
264-
return i < groups.length && _.isEmpty(inputs);
264+
return i < groups.length && inputs.length === 0;
265265
},
266266
next => {
267267
const group = groups[i++];
@@ -301,7 +301,7 @@ export class DogeChain extends BtcChain implements IChain {
301301
},
302302
err => {
303303
if (err) return cb(err);
304-
if (selectionError || _.isEmpty(inputs)) return cb(selectionError || new Error('Could not select tx inputs'));
304+
if (selectionError || inputs.length === 0) return cb(selectionError || new Error('Could not select tx inputs'));
305305

306306
txp.setInputs(_.shuffle(inputs));
307307
txp.fee = fee;
@@ -351,7 +351,7 @@ export class DogeChain extends BtcChain implements IChain {
351351
return -input.satoshis;
352352
});
353353

354-
if (_.isEmpty(inputs)) return cb(null, info);
354+
if (inputs.length === 0) return cb(null, info);
355355

356356
server._getFeePerKb(wallet, opts, (err, feePerKb) => {
357357
if (err) return cb(err);
@@ -390,7 +390,7 @@ export class DogeChain extends BtcChain implements IChain {
390390
txp.inputs.push(input);
391391
});
392392

393-
if (_.isEmpty(txp.inputs)) return cb(null, info);
393+
if (txp.inputs.length === 0) return cb(null, info);
394394

395395
const fee = this.getEstimatedFee(txp, { conservativeEstimation: true });
396396
const amount = _.sumBy(txp.inputs, 'satoshis') - fee;

packages/bitcore-wallet-service/src/lib/model/addressmanager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class AddressManager {
125125
}
126126

127127
getNextSkippedPath() {
128-
if (_.isEmpty(this.skippedPaths)) return null;
128+
if (this.skippedPaths.length === 0) return null;
129129

130130
const ret = this.skippedPaths.pop();
131131
return ret;

packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export class PushNotificationsService {
383383

384384
this.storage.fetchPreferences<Preferences[]>(notification.walletId, null, (err, preferences) => {
385385
if (err) logger.error('%o', err);
386-
if (_.isEmpty(preferences)) preferences = [];
386+
if (preferences.length === 0) preferences = [];
387387

388388
const recipientPreferences = _.compact(
389389
preferences.map(p => {

packages/bitcore-wallet-service/src/lib/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ export class WalletService implements IWalletService {
22742274
}
22752275

22762276
_validateOutputs(opts, wallet, cb) {
2277-
if (_.isEmpty(opts.outputs)) return new ClientError('No outputs were specified');
2277+
if (opts.outputs.length === 0) return new ClientError('No outputs were specified');
22782278

22792279
for (let i = 0; i < opts.outputs.length; i++) {
22802280
const output = opts.outputs[i];

packages/bitcore-wallet-service/src/lib/storage.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export class Storage {
459459
const filter: { walletId: string; createdOn?: typeof tsFilter } = {
460460
walletId
461461
};
462-
if (!_.isEmpty(tsFilter)) filter.createdOn = tsFilter;
462+
if (tsFilter.length !== 0) filter.createdOn = tsFilter;
463463

464464
const mods: { limit?: number } = {};
465465
if (_.isNumber(opts.limit)) mods.limit = opts.limit;
@@ -503,7 +503,7 @@ export class Storage {
503503
walletId,
504504
status: 'broadcasted'
505505
};
506-
if (!_.isEmpty(tsFilter)) filter.broadcastedOn = tsFilter;
506+
if (tsFilter.length !== 0) filter.broadcastedOn = tsFilter;
507507

508508
const mods: { limit?: number } = {};
509509
if (_.isNumber(opts.limit)) mods.limit = opts.limit;
@@ -775,7 +775,7 @@ export class Storage {
775775

776776
storeAddressAndWallet(wallet, addresses, cb) {
777777
const clonedAddresses = [].concat(addresses);
778-
if (_.isEmpty(addresses)) return cb();
778+
if (addresses.length === 0) return cb();
779779
let duplicate;
780780

781781
this.db.collection(collections.ADDRESSES).insertMany(
@@ -843,7 +843,7 @@ export class Storage {
843843
})
844844
.toArray((err, result) => {
845845
if (err) return cb(err);
846-
if (!result || _.isEmpty(result)) return cb();
846+
if (!result || result.length === 0) return cb();
847847
if (result.length > 1) {
848848
result = _.find(result, address => {
849849
return chain == (address.chain || address.coin || 'btc');
@@ -921,7 +921,7 @@ export class Storage {
921921
})
922922
.toArray((err, result) => {
923923
if (err) return cb(err);
924-
if (!result || _.isEmpty(result)) return cb(null, []);
924+
if (!result || result.length === 0) return cb(null, []);
925925

926926
const emails = result.map(x => {
927927
return Email.fromObj(x);
@@ -1253,7 +1253,7 @@ export class Storage {
12531253
})
12541254
.limit(1)
12551255
.toArray((err, result) => {
1256-
if (err || _.isEmpty(result)) return cb(err);
1256+
if (err || result.length === 0) return cb(err);
12571257
return cb(null, result[0]);
12581258
});
12591259
}
@@ -1272,7 +1272,7 @@ export class Storage {
12721272
ts: -1
12731273
})
12741274
.toArray((err, result) => {
1275-
if (err || _.isEmpty(result)) return cb(err);
1275+
if (err || result.length === 0) return cb(err);
12761276
return cb(null, result);
12771277
});
12781278
}

packages/bitcore-wallet-service/test/integration/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ helpers.createTxsV8 = function(nr, bcHeight, txs) {
489489
// 3. => 3... / bcHeight - 2 / txid3
490490

491491
var i = 0;
492-
if (_.isEmpty(txs)) {
492+
if (txs.length === 0) {
493493
while(i < nr) {
494494
txs.push({
495495
id: 'id' + i,

packages/bitcore-wallet/bin/cli-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Utils.renderAmount = function(satoshis, coin, opts) {
351351
};
352352

353353
Utils.renderTxProposals = function(txps) {
354-
if (_.isEmpty(txps))
354+
if (txps.length === 0)
355355
return;
356356

357357
console.log("* TX Proposals:")
@@ -362,7 +362,7 @@ Utils.renderTxProposals = function(txps) {
362362
}).length;
363363
console.log("\t%s [\"%s\" by %s] %s => %s", Utils.shortID(x.id), x.message, x.creatorName, Utils.renderAmount(x.amount), x.outputs[0].toAddress);
364364

365-
if (!_.isEmpty(x.actions)) {
365+
if (x.actions.length !== 0) {
366366
console.log('\t\tActions: ', x.actions.map(a => {
367367
return a.copayerName + ' ' + (a.type == 'accept' ? '✓' : '✗') + (a.comment ? ' (' + a.comment + ')' : '');
368368
}).join('. '));

0 commit comments

Comments
 (0)