lodash changed for _

This commit is contained in:
Gabriel Masclef 2017-10-19 12:50:19 -03:00
parent fd6ffef015
commit 8b9cdc309a
No known key found for this signature in database
GPG Key ID: DD6D7EAADE12280D
2 changed files with 40 additions and 40 deletions

View File

@ -4,7 +4,7 @@ import { Events } from 'ionic-angular';
import { PersistenceProvider } from '../persistence/persistence'; import { PersistenceProvider } from '../persistence/persistence';
import { PlatformProvider } from '../platform/platform'; import { PlatformProvider } from '../platform/platform';
import * as lodash from "lodash"; import * as _ from "lodash";
@Injectable() @Injectable()
export class ConfigProvider { export class ConfigProvider {
@ -110,20 +110,20 @@ export class ConfigProvider {
public load() { public load() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.persistence.getConfig().then((config: object) => { this.persistence.getConfig().then((config: object) => {
if (!lodash.isEmpty(config)) this.configCache = lodash.clone(config); if (!_.isEmpty(config)) this.configCache = _.clone(config);
else this.configCache = lodash.clone(this.configDefault); else this.configCache = _.clone(this.configDefault);
resolve(this.configCache); resolve(this.configCache);
}); });
}); });
} }
public set(newOpts: object) { public set(newOpts: object) {
let config = lodash.cloneDeep(this.configDefault); let config = _.cloneDeep(this.configDefault);
if (lodash.isString(newOpts)) { if (_.isString(newOpts)) {
newOpts = JSON.parse(newOpts); newOpts = JSON.parse(newOpts);
} }
lodash.merge(config, this.configCache, newOpts); _.merge(config, this.configCache, newOpts);
this.configCache = config; this.configCache = config;
this.events.publish('config:updated', this.configCache); this.events.publish('config:updated', this.configCache);

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Logger } from '@nsalaun/ng-logger'; import { Logger } from '@nsalaun/ng-logger';
import * as lodash from 'lodash'; import * as _ from 'lodash';
import { PersistenceProvider } from '../persistence/persistence'; import { PersistenceProvider } from '../persistence/persistence';
import { ConfigProvider } from '../config/config'; import { ConfigProvider } from '../config/config';
import { BwcProvider } from '../bwc/bwc'; import { BwcProvider } from '../bwc/bwc';
@ -35,7 +35,7 @@ export class ProfileProvider {
private languageProvider: LanguageProvider, private languageProvider: LanguageProvider,
private txFormatProvider: TxFormatProvider private txFormatProvider: TxFormatProvider
) { ) {
this.throttledBwsEvent = lodash.throttle((n, wallet) => { this.throttledBwsEvent = _.throttle((n, wallet) => {
this.newBwsEvent(n, wallet); this.newBwsEvent(n, wallet);
}, 10000); }, 10000);
} }
@ -385,7 +385,7 @@ export class ProfileProvider {
} catch (ex) { } catch (ex) {
this.logger.warn(ex); this.logger.warn(ex);
} }
let mergeAddressBook = lodash.merge(addressBook, localAddressBook1); let mergeAddressBook = _.merge(addressBook, localAddressBook1);
this.persistenceProvider.setAddressbook(wallet.credentials.network, JSON.stringify(addressBook)).then(() => { this.persistenceProvider.setAddressbook(wallet.credentials.network, JSON.stringify(addressBook)).then(() => {
return resolve(); return resolve();
}).catch((err: any) => { }).catch((err: any) => {
@ -516,7 +516,7 @@ export class ProfileProvider {
}); });
}).catch((err) => { }).catch((err) => {
if (err && err.toString().match('NONAGREEDDISCLAIMER')) { if (err && err.toString().match('NONAGREEDDISCLAIMER')) {
return resolve(); return reject();
} }
return reject(err); return reject(err);
}); });
@ -538,7 +538,7 @@ export class ProfileProvider {
return resolve(); return resolve();
} }
lodash.each(profile.credentials, (credentials) => { _.each(profile.credentials, (credentials) => {
this.bindWallet(credentials).then((bound: number) => { this.bindWallet(credentials).then((bound: number) => {
i++; i++;
totalBound += bound; totalBound += bound;
@ -709,7 +709,7 @@ export class ProfileProvider {
private doCreateWallet(opts: any): Promise<any> { private doCreateWallet(opts: any): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let showOpts = lodash.clone(opts); let showOpts = _.clone(opts);
if (showOpts.extendedPrivateKey) showOpts.extendedPrivateKey = '[hidden]'; if (showOpts.extendedPrivateKey) showOpts.extendedPrivateKey = '[hidden]';
if (showOpts.mnemonic) showOpts.mnemonic = '[hidden]'; if (showOpts.mnemonic) showOpts.mnemonic = '[hidden]';
@ -767,7 +767,7 @@ export class ProfileProvider {
var walletData = this.bwcProvider.parseSecret(opts.secret); var walletData = this.bwcProvider.parseSecret(opts.secret);
// check if exist // check if exist
if (lodash.find(this.profile.credentials, { if (_.find(this.profile.credentials, {
'walletId': walletData.walletId 'walletId': walletData.walletId
})) { })) {
return reject('Cannot join the same wallet more that once'); // TODO getTextCatalog return reject('Cannot join the same wallet more that once'); // TODO getTextCatalog
@ -859,63 +859,63 @@ export class ProfileProvider {
public getWallets(opts?: any) { public getWallets(opts?: any) {
if (opts && !lodash.isObject(opts)) throw "bad argument"; if (opts && !_.isObject(opts)) throw "bad argument";
opts = opts || {}; opts = opts || {};
let ret = lodash.values(this.wallet); let ret = _.values(this.wallet);
if (opts.coin) { if (opts.coin) {
ret = lodash.filter(ret, (x: any) => { ret = _.filter(ret, (x: any) => {
return (x.credentials.coin == opts.coin); return (x.credentials.coin == opts.coin);
}); });
} }
if (opts.network) { if (opts.network) {
ret = lodash.filter(ret, (x: any) => { ret = _.filter(ret, (x: any) => {
return (x.credentials.network == opts.network); return (x.credentials.network == opts.network);
}); });
} }
if (opts.n) { if (opts.n) {
ret = lodash.filter(ret, (w: any) => { ret = _.filter(ret, (w: any) => {
return (w.credentials.n == opts.n); return (w.credentials.n == opts.n);
}); });
} }
if (opts.m) { if (opts.m) {
ret = lodash.filter(ret, (w: any) => { ret = _.filter(ret, (w: any) => {
return (w.credentials.m == opts.m); return (w.credentials.m == opts.m);
}); });
} }
if (opts.hasFunds) { if (opts.hasFunds) {
ret = lodash.filter(ret, (w: any) => { ret = _.filter(ret, (w: any) => {
if (!w.status) return; if (!w.status) return;
return (w.status.availableBalanceSat > 0); return (w.status.availableBalanceSat > 0);
}); });
} }
if (opts.minAmount) { if (opts.minAmount) {
ret = lodash.filter(ret, (w: any) => { ret = _.filter(ret, (w: any) => {
if (!w.status) return; if (!w.status) return;
return (w.status.availableBalanceSat > opts.minAmount); return (w.status.availableBalanceSat > opts.minAmount);
}); });
} }
if (opts.onlyComplete) { if (opts.onlyComplete) {
ret = lodash.filter(ret, (w: any) => { ret = _.filter(ret, (w: any) => {
return w.isComplete(); return w.isComplete();
}); });
} else { } } else { }
// Add cached balance async // Add cached balance async
lodash.each(ret, (x: any) => { _.each(ret, (x: any) => {
this.addLastKnownBalance(x); this.addLastKnownBalance(x);
}); });
return lodash.sortBy(ret, [(x: any) => { return _.sortBy(ret, [(x: any) => {
return x.isComplete(); return x.isComplete();
}, 'createdOn']); }, 'createdOn']);
} }
@ -944,7 +944,7 @@ export class ProfileProvider {
}; };
let w = this.getWallets(); let w = this.getWallets();
if (lodash.isEmpty(w)) return resolve(); if (_.isEmpty(w)) return resolve();
let l = w.length; let l = w.length;
let j = 0; let j = 0;
@ -983,11 +983,11 @@ export class ProfileProvider {
let process = (notifications: any): Array<any> => { let process = (notifications: any): Array<any> => {
if (!notifications) return []; if (!notifications) return [];
let shown = lodash.sortBy(notifications, 'createdOn').reverse(); let shown = _.sortBy(notifications, 'createdOn').reverse();
shown = shown.splice(0, opts.limit || MAX); shown = shown.splice(0, opts.limit || MAX);
lodash.each(shown, (x: any) => { _.each(shown, (x: any) => {
x.txpId = x.data ? x.data.txProposalId : null; x.txpId = x.data ? x.data.txProposalId : null;
x.txid = x.data ? x.data.txid : null; x.txid = x.data ? x.data.txid : null;
x.types = [x.type]; x.types = [x.type];
@ -1013,10 +1013,10 @@ export class ProfileProvider {
// Item grouping... DISABLED. // Item grouping... DISABLED.
// REMOVE (if we want 1-to-1 notification) ???? // REMOVE (if we want 1-to-1 notification) ????
lodash.each(shown, (x: any) => { _.each(shown, (x: any) => {
if (prev && prev.walletId === x.walletId && prev.txpId && prev.txpId === x.txpId && prev.creatorId && prev.creatorId === x.creatorId) { if (prev && prev.walletId === x.walletId && prev.txpId && prev.txpId === x.txpId && prev.creatorId && prev.creatorId === x.creatorId) {
prev.types.push(x.type); prev.types.push(x.type);
prev.data = lodash.assign(prev.data, x.data); prev.data = _.assign(prev.data, x.data);
prev.txid = prev.txid || x.txid; prev.txid = prev.txid || x.txid;
prev.amountStr = prev.amountStr || x.amountStr; prev.amountStr = prev.amountStr || x.amountStr;
prev.creatorName = prev.creatorName || x.creatorName; prev.creatorName = prev.creatorName || x.creatorName;
@ -1027,7 +1027,7 @@ export class ProfileProvider {
}); });
let u = this.bwcProvider.getUtils(); let u = this.bwcProvider.getUtils();
lodash.each(finale, (x: any) => { _.each(finale, (x: any) => {
if (x.data && x.data.message && x.wallet && x.wallet.credentials.sharedEncryptingKey) { if (x.data && x.data.message && x.wallet && x.wallet.credentials.sharedEncryptingKey) {
// TODO TODO TODO => BWC // TODO TODO TODO => BWC
x.message = u.decryptMessage(x.data.message, x.wallet.credentials.sharedEncryptingKey); x.message = u.decryptMessage(x.data.message, x.wallet.credentials.sharedEncryptingKey);
@ -1037,21 +1037,21 @@ export class ProfileProvider {
return finale; return finale;
} }
lodash.each(w, (wallet: any) => { _.each(w, (wallet: any) => {
updateNotifications(wallet).then(() => { updateNotifications(wallet).then(() => {
j++; j++;
let n = lodash.filter(wallet.cachedActivity.n, (x: any) => { let n = _.filter(wallet.cachedActivity.n, (x: any) => {
return typeFilter[x.type]; return typeFilter[x.type];
}); });
let idToName = {}; let idToName = {};
if (wallet.cachedStatus) { if (wallet.cachedStatus) {
lodash.each(wallet.cachedStatus.wallet.copayers, (c: any) => { _.each(wallet.cachedStatus.wallet.copayers, (c: any) => {
idToName[c.id] = c.name; idToName[c.id] = c.name;
}); });
} }
lodash.each(n, (x: any) => { _.each(n, (x: any) => {
x.wallet = wallet; x.wallet = wallet;
if (x.creatorId && wallet.cachedStatus) { if (x.creatorId && wallet.cachedStatus) {
x.creatorName = idToName[x.creatorId]; x.creatorName = idToName[x.creatorId];
@ -1061,8 +1061,8 @@ export class ProfileProvider {
notifications.push(n); notifications.push(n);
if (j == l) { if (j == l) {
notifications = lodash.sortBy(notifications, 'createdOn'); notifications = _.sortBy(notifications, 'createdOn');
notifications = lodash.compact(lodash.flatten(notifications)).slice(0, MAX); notifications = _.compact(_.flatten(notifications)).slice(0, MAX);
let total = notifications.length; let total = notifications.length;
return resolve({ processArray: process(notifications), total: total }); return resolve({ processArray: process(notifications), total: total });
}; };
@ -1079,19 +1079,19 @@ export class ProfileProvider {
opts = opts ? opts : {}; opts = opts ? opts : {};
let w = this.getWallets(); let w = this.getWallets();
if (lodash.isEmpty(w)) { if (_.isEmpty(w)) {
return reject('No wallets available'); return reject('No wallets available');
} }
let txps = []; let txps = [];
lodash.each(w, (x: any) => { _.each(w, (x: any) => {
if (x.pendingTxps) if (x.pendingTxps)
txps = txps.concat(x.pendingTxps); txps = txps.concat(x.pendingTxps);
}); });
let n = txps.length; let n = txps.length;
txps = lodash.sortBy(txps, 'pendingForUs', 'createdOn'); txps = _.sortBy(txps, 'pendingForUs', 'createdOn');
txps = lodash.compact(lodash.flatten(txps)).slice(0, opts.limit || MAX); txps = _.compact(_.flatten(txps)).slice(0, opts.limit || MAX);
return resolve({ txps: txps, n: n }); return resolve({ txps: txps, n: n });
}); });
}; };