Fix - Search with popularCurrencyList as well
This commit is contained in:
parent
fa291c757d
commit
1ec2bf7ba0
3 changed files with 91 additions and 209 deletions
|
|
@ -517,103 +517,104 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
// Currency
|
// Currency
|
||||||
|
|
||||||
var next = 10;
|
var next = 10;
|
||||||
var completeAlternativeList = [];
|
var completeAlternativeList = [];
|
||||||
|
|
||||||
var popularCurrencyList = [
|
var popularCurrencyList = [
|
||||||
{isoCode: 'USD', order: 0},
|
{isoCode: 'USD', order: 0},
|
||||||
{isoCode: 'EUR', order: 1},
|
{isoCode: 'EUR', order: 1},
|
||||||
{isoCode: 'JPY', order: 2},
|
{isoCode: 'JPY', order: 2},
|
||||||
{isoCode: 'GBP', order: 3},
|
{isoCode: 'GBP', order: 3},
|
||||||
{isoCode: 'AUD', order: 4},
|
{isoCode: 'AUD', order: 4},
|
||||||
{isoCode: 'CAD', order: 5},
|
{isoCode: 'CAD', order: 5},
|
||||||
{isoCode: 'CHF', order: 6},
|
{isoCode: 'CHF', order: 6},
|
||||||
{isoCode: 'CNY', order: 7},
|
{isoCode: 'CNY', order: 7},
|
||||||
{isoCode: 'KRW', order: 8},
|
{isoCode: 'KRW', order: 8},
|
||||||
{isoCode: 'HKD', order: 9},
|
{isoCode: 'HKD', order: 9},
|
||||||
]
|
]
|
||||||
|
|
||||||
function initCurrencies() {
|
function initCurrencies() {
|
||||||
var unusedCurrencyList = [{
|
var unusedCurrencyList = [{
|
||||||
isoCode: 'LTL'
|
isoCode: 'LTL'
|
||||||
}, {
|
}, {
|
||||||
isoCode: 'BTC'
|
isoCode: 'BTC'
|
||||||
}, {
|
}, {
|
||||||
isoCode: 'BCC'
|
isoCode: 'BCC'
|
||||||
}, {
|
}, {
|
||||||
isoCode: 'BCH_BTC'
|
isoCode: 'BCH_BTC'
|
||||||
}, {
|
}, {
|
||||||
isoCode: 'BCH'
|
isoCode: 'BCH'
|
||||||
}];
|
}];
|
||||||
rateService.whenAvailable(function() {
|
rateService.whenAvailable(function() {
|
||||||
|
|
||||||
$scope.listComplete = false;
|
$scope.listComplete = false;
|
||||||
|
|
||||||
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
||||||
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
|
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
|
||||||
var idx3 = lodash.indexBy(popularCurrencyList, 'isoCode');
|
var idx3 = lodash.indexBy(popularCurrencyList, 'isoCode');
|
||||||
var alternatives = rateService.listAlternatives(true);
|
var alternatives = rateService.listAlternatives(true);
|
||||||
|
|
||||||
lodash.each(alternatives, function(c) {
|
lodash.each(alternatives, function(c) {
|
||||||
if (idx3[c.isoCode]) {
|
if (idx3[c.isoCode]) {
|
||||||
idx3[c.isoCode].name = c.name;
|
idx3[c.isoCode].name = c.name;
|
||||||
}
|
}
|
||||||
if (!idx[c.isoCode] && !idx2[c.isoCode] && !idx3[c.isoCode]) {
|
if (!idx[c.isoCode] && !idx2[c.isoCode] && !idx3[c.isoCode]) {
|
||||||
completeAlternativeList.push(c);
|
completeAlternativeList.push(c);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
$scope.altCurrencyList = completeAlternativeList.slice(0, 10);
|
|
||||||
$scope.lastUsedPopularList = lodash.unique(lodash.union($scope.lastUsedAltCurrencyList, popularCurrencyList), 'isoCode');
|
|
||||||
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.$apply();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
$scope.loadMore = function() {
|
$scope.altCurrencyList = completeAlternativeList.slice(0, 10);
|
||||||
$timeout(function() {
|
$scope.lastUsedPopularList = lodash.unique(lodash.union($scope.lastUsedAltCurrencyList, popularCurrencyList), 'isoCode');
|
||||||
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
|
|
||||||
next += 10;
|
|
||||||
$scope.listComplete = $scope.altCurrencyList.length >= completeAlternativeList.length;
|
|
||||||
$scope.$broadcast('scroll.infiniteScrollComplete');
|
|
||||||
}, 100);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.findCurrency = function(search) {
|
|
||||||
if (!search) initCurrencies();
|
|
||||||
$scope.altCurrencyList = lodash.filter(completeAlternativeList, function(item) {
|
|
||||||
var val = item.name
|
|
||||||
var val2 = item.isoCode;
|
|
||||||
return lodash.includes(val.toLowerCase(), search.toLowerCase()) || lodash.includes(val2.toLowerCase(), search.toLowerCase());
|
|
||||||
});
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$scope.save = function(newAltCurrency) {
|
$scope.loadMore = function() {
|
||||||
var opts = {
|
$timeout(function() {
|
||||||
wallet: {
|
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
|
||||||
settings: {
|
next += 10;
|
||||||
alternativeName: newAltCurrency.name,
|
$scope.listComplete = $scope.altCurrencyList.length >= completeAlternativeList.length;
|
||||||
alternativeIsoCode: newAltCurrency.isoCode,
|
$scope.$broadcast('scroll.infiniteScrollComplete');
|
||||||
}
|
}, 100);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.findCurrency = function(search) {
|
||||||
|
if (!search) initCurrencies();
|
||||||
|
var list = lodash.unique(lodash.union(completeAlternativeList, lodash.union($scope.lastUsedAltCurrencyList, popularCurrencyList)), 'isoCode');
|
||||||
|
$scope.altCurrencyList = lodash.filter(list, function(item) {
|
||||||
|
var val = item.name
|
||||||
|
var val2 = item.isoCode;
|
||||||
|
return lodash.includes(val.toLowerCase(), search.toLowerCase()) || lodash.includes(val2.toLowerCase(), search.toLowerCase());
|
||||||
|
});
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.save = function(newAltCurrency) {
|
||||||
|
var opts = {
|
||||||
|
wallet: {
|
||||||
|
settings: {
|
||||||
|
alternativeName: newAltCurrency.name,
|
||||||
|
alternativeIsoCode: newAltCurrency.isoCode,
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
configService.set(opts, function(err) {
|
|
||||||
if (err) $log.warn(err);
|
|
||||||
walletService.updateRemotePreferences(profileService.getWallets());
|
|
||||||
var altUnitIndex = lodash.findIndex(availableUnits, {
|
|
||||||
isFiat: true
|
|
||||||
});
|
|
||||||
availableUnits[altUnitIndex].id = newAltCurrency.isoCode;
|
|
||||||
availableUnits[altUnitIndex].name = newAltCurrency.isoCode;
|
|
||||||
availableUnits[altUnitIndex].shortName = newAltCurrency.isoCode;
|
|
||||||
fiatCode = newAltCurrency.isoCode;
|
|
||||||
updateUnitUI();
|
|
||||||
$scope.close();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
configService.set(opts, function(err) {
|
||||||
|
if (err) $log.warn(err);
|
||||||
|
walletService.updateRemotePreferences(profileService.getWallets());
|
||||||
|
var altUnitIndex = lodash.findIndex(availableUnits, {
|
||||||
|
isFiat: true
|
||||||
|
});
|
||||||
|
availableUnits[altUnitIndex].id = newAltCurrency.isoCode;
|
||||||
|
availableUnits[altUnitIndex].name = newAltCurrency.isoCode;
|
||||||
|
availableUnits[altUnitIndex].shortName = newAltCurrency.isoCode;
|
||||||
|
fiatCode = newAltCurrency.isoCode;
|
||||||
|
updateUnitUI();
|
||||||
|
$scope.close();
|
||||||
|
});
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,119 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('altCurrencyController',
|
|
||||||
function($scope, $log, $timeout, $ionicHistory, $ionicModal, configService, rateService, lodash, profileService, walletService, storageService, $ionicNavBarDelegate) {
|
|
||||||
|
|
||||||
$scope.close = function () {
|
|
||||||
$ionicModal.close();
|
|
||||||
};
|
|
||||||
|
|
||||||
var next = 10;
|
|
||||||
var completeAlternativeList = [];
|
|
||||||
|
|
||||||
var popularCurrencyList = [
|
|
||||||
{isoCode: 'USD', order: 0},
|
|
||||||
{isoCode: 'EUR', order: 1},
|
|
||||||
{isoCode: 'JPY', order: 2},
|
|
||||||
{isoCode: 'GBP', order: 3},
|
|
||||||
{isoCode: 'AUD', order: 4},
|
|
||||||
{isoCode: 'CAD', order: 5},
|
|
||||||
{isoCode: 'CHF', order: 6},
|
|
||||||
{isoCode: 'CNY', order: 7},
|
|
||||||
{isoCode: 'KRW', order: 8},
|
|
||||||
{isoCode: 'HKD', order: 9},
|
|
||||||
]
|
|
||||||
|
|
||||||
function initCurrencies() {
|
|
||||||
var unusedCurrencyList = [{
|
|
||||||
isoCode: 'LTL'
|
|
||||||
}, {
|
|
||||||
isoCode: 'BTC'
|
|
||||||
}, {
|
|
||||||
isoCode: 'BCC'
|
|
||||||
}, {
|
|
||||||
isoCode: 'BCH_BTC'
|
|
||||||
}, {
|
|
||||||
isoCode: 'BCH'
|
|
||||||
}];
|
|
||||||
rateService.whenAvailable(function() {
|
|
||||||
|
|
||||||
$scope.listComplete = false;
|
|
||||||
|
|
||||||
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
|
||||||
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
|
|
||||||
var idx3 = lodash.indexBy(popularCurrencyList, 'isoCode');
|
|
||||||
var alternatives = rateService.listAlternatives(true);
|
|
||||||
|
|
||||||
lodash.each(alternatives, function(c) {
|
|
||||||
if (idx3[c.isoCode]) {
|
|
||||||
idx3[c.isoCode].name = c.name;
|
|
||||||
}
|
|
||||||
if (!idx[c.isoCode] && !idx2[c.isoCode] && !idx3[c.isoCode]) {
|
|
||||||
completeAlternativeList.push(c);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.altCurrencyList = completeAlternativeList.slice(0, 10);
|
|
||||||
$scope.lastUsedPopularList = lodash.unique(lodash.union($scope.lastUsedAltCurrencyList, popularCurrencyList), 'isoCode');
|
|
||||||
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.$apply();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.loadMore = function() {
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
|
|
||||||
next += 10;
|
|
||||||
$scope.listComplete = $scope.altCurrencyList.length >= completeAlternativeList.length;
|
|
||||||
$scope.$broadcast('scroll.infiniteScrollComplete');
|
|
||||||
}, 100);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.findCurrency = function(search) {
|
|
||||||
if (!search) initCurrencies();
|
|
||||||
$scope.altCurrencyList = lodash.filter(completeAlternativeList, function(item) {
|
|
||||||
var val = item.name
|
|
||||||
var val2 = item.isoCode;
|
|
||||||
return lodash.includes(val.toLowerCase(), search.toLowerCase()) || lodash.includes(val2.toLowerCase(), search.toLowerCase());
|
|
||||||
});
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.$apply();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.save = function(newAltCurrency) {
|
|
||||||
var opts = {
|
|
||||||
wallet: {
|
|
||||||
settings: {
|
|
||||||
alternativeName: newAltCurrency.name,
|
|
||||||
alternativeIsoCode: newAltCurrency.isoCode,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
configService.set(opts, function(err) {
|
|
||||||
if (err) $log.warn(err);
|
|
||||||
saveLastUsed(newAltCurrency);
|
|
||||||
walletService.updateRemotePreferences(profileService.getWallets());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function saveLastUsed(newAltCurrency) {
|
|
||||||
$scope.lastUsedAltCurrencyList.unshift(newAltCurrency);
|
|
||||||
$scope.lastUsedAltCurrencyList = lodash.uniq($scope.lastUsedAltCurrencyList, 'isoCode');
|
|
||||||
$scope.lastUsedAltCurrencyList = $scope.lastUsedAltCurrencyList.slice(0, 3);
|
|
||||||
storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
|
||||||
var config = configService.getSync();
|
|
||||||
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
|
|
||||||
|
|
||||||
storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) {
|
|
||||||
$scope.lastUsedAltCurrencyList = lastUsedAltCurrency ? JSON.parse(lastUsedAltCurrency) : [];
|
|
||||||
initCurrencies();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
placeholder="{{'Search your currency' | translate}}">
|
placeholder="{{'Search your currency' | translate}}">
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="list" ng-if="lastUsedPopularList[0]">
|
<div class="list" ng-if="lastUsedPopularList[0] && searchedAltCurrency.length == 0">
|
||||||
<ion-radio class="alt-currency-radio" ng-repeat="lastUsedAltCurrency in lastUsedPopularList" ng-value="lastUsedAltCurrency.isoCode" ng-model="currentCurrency"
|
<ion-radio class="alt-currency-radio" ng-repeat="lastUsedAltCurrency in lastUsedPopularList" ng-value="lastUsedAltCurrency.isoCode" ng-model="currentCurrency"
|
||||||
ng-click="save(lastUsedAltCurrency)">{{lastUsedAltCurrency.name}} <span class="item-note">{{lastUsedAltCurrency.isoCode}}</span>
|
ng-click="save(lastUsedAltCurrency)">{{lastUsedAltCurrency.name}} <span class="item-note">{{lastUsedAltCurrency.isoCode}}</span>
|
||||||
</ion-radio>
|
</ion-radio>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue