added bitcoin and bitcoin cash aliases to config and use them everywhere

This commit is contained in:
Kadir Sekha 2017-11-01 16:26:42 +09:00
commit a730c8e2d2
9 changed files with 41 additions and 12 deletions

View file

@ -27,7 +27,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
var config = configService.getSync().wallet.settings;
function setAvailableUnits() {
var defaults = configService.getDefaults();
var configCache = configService.getSync();
availableUnits = [];
var hasBTCWallets = profileService.getWallets({
@ -38,22 +39,19 @@ angular.module('copayApp.controllers').controller('amountController', function($
availableUnits.push({
name: 'Bitcoin',
id: 'btc',
shortName: 'BTC',
shortName: (configCache.bitcoinAlias || defaults.bitcoinAlias).toUpperCase(),
});
}
var hasBCHWallets = profileService.getWallets({
coin: 'bch'
}).length;
if (hasBCHWallets) {
availableUnits.push({
name: 'Bitcoin Cash',
id: 'bch',
shortName: 'BCH',
shortName: (configCache.bitcoinCashAlias || defaults.bitcoinCashAlias).toUpperCase(),
});
};
@ -310,7 +308,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
$scope.alternativeAmount = txFormatService.formatAmount(a * unitToSatoshi, true);
} else {
if (result) {
$scope.alternativeAmount = 'N/A';
$scope.alternativeAmount = 'N/A';
} else {
$scope.alternativeAmount = null;
}

View file

@ -24,12 +24,15 @@ angular.module('copayApp.controllers').controller('createController',
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.formData = {};
var config = configService.getSync();
var defaults = configService.getDefaults();
var tc = $state.current.name == 'tabs.add.create-personal' ? 1 : defaults.wallet.totalCopayers;
$scope.formData.account = 1;
$scope.formData.bwsurl = data.stateParams.coin == 'btc' ? defaults.bws.url : defaults.bwscash.url;
$scope.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
$scope.formData.derivationPath = derivationPathHelper.default;
$scope.formData.coin = data.stateParams.coin;
$scope.bitcoinAlias = (config.bitcoinAlias || defaults.bitcoinAlias).toUpperCase();
$scope.bitcoinCashAlias = (config.bitcoinCashAlias || defaults.bitcoinCashAlias).toUpperCase();
if (config.cashSupport) $scope.enableCash = true;

View file

@ -23,6 +23,9 @@ angular.module('copayApp.controllers').controller('importController',
value: false
};
$scope.bitcoinAlias = (config.bitcoinAlias || defaults.bitcoinAlias).toUpperCase();
$scope.bitcoinCashAlias = (config.bitcoinCashAlias || defaults.bitcoinCashAlias).toUpperCase();
if (config.cashSupport) $scope.enableCash = true;
if ($stateParams.code)

View file

@ -13,6 +13,8 @@ angular.module('copayApp.controllers').controller('joinController',
$scope.formData.account = 1;
$scope.formData.secret = null;
$scope.formData.coin = data.stateParams.coin;
$scope.bitcoinAlias = (config.bitcoinAlias || defaults.bitcoinAlias).toUpperCase();
$scope.bitcoinCashAlias = (config.bitcoinCashAlias || defaults.bitcoinCashAlias).toUpperCase();
if (config.cashSupport) $scope.enableCash = true;
resetPasswordFields();
updateSeedSourceSelect();

View file

@ -180,6 +180,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
$scope.updateTxHistoryError = true;
return;
}
applyCurrencyAliases(txHistory);
$scope.completeTxHistory = txHistory;
$scope.showHistory();
$timeout(function() {
@ -190,6 +192,19 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
});
};
function applyCurrencyAliases(txHistory) {
var defaults = configService.getDefaults();
var configCache = configService.getSync();
lodash.each(txHistory, function(t) {
t.amountUnitStr = $scope.wallet.coin == 'btc'
? (configCache.bitcoinAlias || defaults.bitcoinAlias)
: (configCache.bitcoinCashAlias || defaults.bitcoinCashAlias);
t.amountUnitStr = t.amountUnitStr.toUpperCase();
});
}
$scope.showHistory = function() {
if ($scope.completeTxHistory) {
$scope.txHistory = $scope.completeTxHistory.slice(0, (currentTxHistoryPage + 1) * HISTORY_SHOW_LIMIT);

View file

@ -104,6 +104,9 @@ angular.module('copayApp.services').factory('configService', function(storageSer
log: {
filter: 'debug',
},
bitcoinAlias: 'btc',
bitcoinCashAlias: 'bcc'
};
var configCache = null;

View file

@ -18,8 +18,13 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
};
root.formatAmountStr = function(coin, satoshis) {
var defaults = configService.getDefaults();
var configCache = configService.getSync();
var c = coin == 'btc' ? (configCache.bitcoinAlias || defaults.bitcoinAlias)
: (configCache.bitcoinCashAlias || defaults.bitcoinCashAlias);
if (isNaN(satoshis)) return;
return root.formatAmount(satoshis) + ' ' + (coin).toUpperCase();
return root.formatAmount(satoshis) + ' ' + (c).toUpperCase();
};
root.toFiat = function(coin, satoshis, code, cb) {

View file

@ -3,7 +3,7 @@
Coin
</div>
<select ng-model="formData.coin" ng-change="coinChanged()">
<option value="btc">BTC</option>
<option value="bch">BCH</option>
<option value="btc">{{bitcoinAlias}}</option>
<option value="bch">{{bitcoinCashAlias}}</option>
</select>
</label>

View file

@ -30,7 +30,7 @@
<i class="icon"><img src="img/icon-warning.png" width="20px"></i>
<span class="comment" translate>Amount too low to spend</span>
</div>
</div>
<div ng-show="btx.action == 'sent'" class="ellipsis">
@ -65,7 +65,7 @@
(possible double spend)
</span>
<span ng-if="btx.action != 'invalid'">
{{btx.amountStr}}
{{btx.amountValueStr}} {{btx.amountUnitStr}}
</span>
</span>
<div>