Filter contacts on "starting with" instead of "contains" and some refactors
This commit is contained in:
parent
c6571c98ff
commit
7cc806b00c
2 changed files with 29 additions and 78 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicNavBarDelegate, clipboardService) {
|
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicNavBarDelegate, clipboardService) {
|
||||||
var clipboardHasAddress = false;
|
var clipboardHasAddress = false;
|
||||||
var clipboardHasContent = false;
|
var clipboardHasContent = false;
|
||||||
|
var originalList;
|
||||||
|
|
||||||
$scope.addContact = function() {
|
$scope.addContact = function() {
|
||||||
$state.go('tabs.settings').then(function() {
|
$state.go('tabs.settings').then(function() {
|
||||||
|
|
@ -50,27 +51,26 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.findContact = function(search) {
|
||||||
|
|
||||||
|
if (incomingData.redir(search)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!search || search.length < 1) {
|
||||||
|
$scope.list = originalList;
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = lodash.filter(originalList, function(item) {
|
||||||
|
var val = item.name;
|
||||||
|
return lodash.startsWith(val.toLowerCase(), search.toLowerCase());
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.list = result;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var originalList;
|
|
||||||
var CONTACTS_SHOW_LIMIT;
|
|
||||||
var currentContactsPage;
|
|
||||||
|
|
||||||
$scope.sectionDisplay = {
|
|
||||||
transferToWallet: false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var hasWallets = function() {
|
var hasWallets = function() {
|
||||||
|
|
@ -80,6 +80,8 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
$scope.hasWallets = lodash.isEmpty($scope.wallets) ? false : true;
|
$scope.hasWallets = lodash.isEmpty($scope.wallets) ? false : true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// THIS is ONLY to show the 'buy bitcoins' message
|
// THIS is ONLY to show the 'buy bitcoins' message
|
||||||
// does not has any other function.
|
// does not has any other function.
|
||||||
|
|
||||||
|
|
@ -138,12 +140,12 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
|
|
||||||
var walletList = [];
|
var walletList = [];
|
||||||
lodash.each(walletsToTransfer, function(v) {
|
lodash.each(walletsToTransfer, function(v) {
|
||||||
var displayBalanceAsFiat =
|
var displayBalanceAsFiat =
|
||||||
// BD got v.status as undefined here once during development, just
|
// BD got v.status as undefined here once during development, just
|
||||||
// after creating a new wallet.
|
// after creating a new wallet.
|
||||||
v.status &&
|
v.status &&
|
||||||
v.status.alternativeBalanceAvailable &&
|
v.status.alternativeBalanceAvailable &&
|
||||||
config.wallet.settings.priceDisplay === 'fiat';
|
config.wallet.settings.priceDisplay === 'fiat';
|
||||||
|
|
||||||
walletList.push({
|
walletList.push({
|
||||||
color: v.color,
|
color: v.color,
|
||||||
|
|
@ -152,7 +154,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
coin: v.coin,
|
coin: v.coin,
|
||||||
network: v.network,
|
network: v.network,
|
||||||
balanceString: displayBalanceAsFiat ?
|
balanceString: displayBalanceAsFiat ?
|
||||||
v.status.totalBalanceAlternative + ' ' + v.status.alternativeIsoCode :
|
v.status.totalBalanceAlternative + ' ' + v.status.alternativeIsoCode :
|
||||||
v.cachedBalance,
|
v.cachedBalance,
|
||||||
getAddress: function(cb) {
|
getAddress: function(cb) {
|
||||||
walletService.getAddress(v, false, cb);
|
walletService.getAddress(v, false, cb);
|
||||||
|
|
@ -181,16 +183,14 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
recipientType: 'contact',
|
recipientType: 'contact',
|
||||||
coin: v.coin,
|
coin: v.coin,
|
||||||
displayCoin: (v.coin == 'bch'
|
displayCoin: (v.coin == 'bch'
|
||||||
? (config.bitcoinCashAlias || defaults.bitcoinCashAlias)
|
? (config.bitcoinCashAlias || defaults.bitcoinCashAlias)
|
||||||
: (config.bitcoinAlias || defaults.bitcoinAlias)).toUpperCase(),
|
: (config.bitcoinAlias || defaults.bitcoinAlias)).toUpperCase(),
|
||||||
getAddress: function(cb) {
|
getAddress: function(cb) {
|
||||||
return cb(null, k);
|
return cb(null, k);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var contacts = completeContacts.slice(0, (currentContactsPage + 1) * CONTACTS_SHOW_LIMIT);
|
originalList = completeContacts;
|
||||||
$scope.contactsShowMore = completeContacts.length > contacts.length;
|
|
||||||
originalList = originalList.concat(contacts);
|
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -203,28 +203,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
}, 10);
|
}, 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openScanner = function() {
|
|
||||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
|
||||||
|
|
||||||
if (!isWindowsPhoneApp) {
|
|
||||||
$state.go('tabs.scan');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
scannerService.useOldScanner(function(err, contents) {
|
|
||||||
if (err) {
|
|
||||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
incomingData.redir(contents);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.showMore = function() {
|
|
||||||
currentContactsPage++;
|
|
||||||
updateWalletsList();
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.searchInFocus = function() {
|
$scope.searchInFocus = function() {
|
||||||
$scope.searchFocus = true;
|
$scope.searchFocus = true;
|
||||||
};
|
};
|
||||||
|
|
@ -235,28 +213,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.findContact = function(search) {
|
|
||||||
|
|
||||||
if (incomingData.redir(search)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!search || search.length < 2) {
|
|
||||||
$scope.list = originalList;
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.$apply();
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = lodash.filter(originalList, function(item) {
|
|
||||||
var val = item.name;
|
|
||||||
return lodash.includes(val.toLowerCase(), search.toLowerCase());
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.list = result;
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.goToAmount = function(item) {
|
$scope.goToAmount = function(item) {
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
item.getAddress(function(err, addr) {
|
item.getAddress(function(err, addr) {
|
||||||
|
|
@ -304,8 +260,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
search: null
|
search: null
|
||||||
};
|
};
|
||||||
originalList = [];
|
originalList = [];
|
||||||
CONTACTS_SHOW_LIMIT = 10;
|
|
||||||
currentContactsPage = 0;
|
|
||||||
hasWallets();
|
hasWallets();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -109,9 +109,6 @@
|
||||||
</p>
|
</p>
|
||||||
<i class="icon bp-arrow-right"></i>
|
<i class="icon bp-arrow-right"></i>
|
||||||
</a>
|
</a>
|
||||||
<div class="show-more" ng-if="contactsShowMore" ng-click="showMore()" translate>
|
|
||||||
Show more
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue