Merge pull request #6676 from matiu/bug/amount-config
fix unit to config
This commit is contained in:
commit
649d5e6d2a
3 changed files with 351 additions and 343 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,6 +3,7 @@ i18n/po/*.mo
|
||||||
i18n/crowdin_api_key.txt
|
i18n/crowdin_api_key.txt
|
||||||
src/js/translations.js
|
src/js/translations.js
|
||||||
|
|
||||||
|
|
||||||
# cordova
|
# cordova
|
||||||
plugins
|
plugins
|
||||||
platforms
|
platforms
|
||||||
|
|
|
||||||
|
|
@ -24,20 +24,32 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
|
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
|
|
||||||
function setAvailableUnits() {
|
function setAvailableUnits() {
|
||||||
|
|
||||||
availableUnits = [{
|
availableUnits = [];
|
||||||
|
|
||||||
|
var hasBTCWallets = profileService.getWallets({
|
||||||
|
coin: 'btc'
|
||||||
|
}).length;
|
||||||
|
|
||||||
|
if (hasBTCWallets) {
|
||||||
|
availableUnits.push({
|
||||||
name: 'Bitcoin',
|
name: 'Bitcoin',
|
||||||
id: 'btc',
|
id: 'btc',
|
||||||
shortName: 'BTC',
|
shortName: 'BTC',
|
||||||
}];
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var anyCashWallet = true; // TODO!!
|
var hasBCHWallets = profileService.getWallets({
|
||||||
if (anyCashWallet) {
|
coin: 'bch'
|
||||||
|
}).length;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (hasBCHWallets) {
|
||||||
availableUnits.push({
|
availableUnits.push({
|
||||||
name: 'Bitcoin Cash',
|
name: 'Bitcoin Cash',
|
||||||
id: 'bch',
|
id: 'bch',
|
||||||
|
|
@ -81,7 +93,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
}
|
}
|
||||||
|
|
||||||
availableUnits.push({
|
availableUnits.push({
|
||||||
name: fiatName || fiatCode, // TODO
|
name: fiatName || fiatCode,
|
||||||
|
// TODO
|
||||||
id: fiatCode,
|
id: fiatCode,
|
||||||
shortName: fiatCode,
|
shortName: fiatCode,
|
||||||
isFiat: true,
|
isFiat: true,
|
||||||
|
|
@ -100,8 +113,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
setAvailableUnits();
|
setAvailableUnits();
|
||||||
updateUnitUI();
|
updateUnitUI();
|
||||||
|
|
||||||
$scope.showMenu = $ionicHistory.backView() && ($ionicHistory.backView().stateName == 'tabs.send' ||
|
$scope.showMenu = $ionicHistory.backView() && ($ionicHistory.backView().stateName == 'tabs.send' || $ionicHistory.backView().stateName == 'tabs.bitpayCard');
|
||||||
$ionicHistory.backView().stateName == 'tabs.bitpayCard');
|
|
||||||
$scope.recipientType = data.stateParams.recipientType || null;
|
$scope.recipientType = data.stateParams.recipientType || null;
|
||||||
$scope.toAddress = data.stateParams.toAddress;
|
$scope.toAddress = data.stateParams.toAddress;
|
||||||
$scope.toName = data.stateParams.toName;
|
$scope.toName = data.stateParams.toName;
|
||||||
|
|
@ -129,10 +141,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
} else if (e.key.match(reOp)) {
|
} else if (e.key.match(reOp)) {
|
||||||
$scope.pushOperator(e.key);
|
$scope.pushOperator(e.key);
|
||||||
} else if (e.keyCode === 86) {
|
} else if (e.keyCode === 86) {
|
||||||
if (e.ctrlKey || e.metaKey)
|
if (e.ctrlKey || e.metaKey) processClipboard();
|
||||||
processClipboard();
|
} else if (e.keyCode === 13) $scope.finish();
|
||||||
} else if (e.keyCode === 13)
|
|
||||||
$scope.finish();
|
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
|
@ -302,10 +312,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
};
|
};
|
||||||
|
|
||||||
function processResult(val) {
|
function processResult(val) {
|
||||||
if (availableUnits[unitIndex].isFiat)
|
if (availableUnits[unitIndex].isFiat) return $filter('formatFiatAmount')(val);
|
||||||
return $filter('formatFiatAmount')(val);
|
else return txFormatService.formatAmount(val.toFixed(unitDecimals) * unitToSatoshi, true);
|
||||||
else
|
|
||||||
return txFormatService.formatAmount(val.toFixed(unitDecimals) * unitToSatoshi, true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function fromFiat(val) {
|
function fromFiat(val) {
|
||||||
|
|
@ -332,8 +340,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
var result = val.toString();
|
var result = val.toString();
|
||||||
|
|
||||||
if (isOperator(lodash.last(val)))
|
if (isOperator(lodash.last(val))) result = result.slice(0, -1);
|
||||||
result = result.slice(0, -1);
|
|
||||||
|
|
||||||
return result.replace('x', '*');
|
return result.replace('x', '*');
|
||||||
};
|
};
|
||||||
|
|
@ -342,14 +349,13 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
var unit = availableUnits[unitIndex];
|
var unit = availableUnits[unitIndex];
|
||||||
var _amount = evaluate(format($scope.amount));
|
var _amount = evaluate(format($scope.amount));
|
||||||
|
|
||||||
if ($scope.nextStep) {
|
|
||||||
|
|
||||||
var coin = unit.id;
|
var coin = unit.id;
|
||||||
if (unit.isFiat) {
|
if (unit.isFiat) {
|
||||||
coin = availableUnits[altUnitIndex].id;
|
coin = availableUnits[altUnitIndex].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($scope.nextStep) {
|
||||||
|
|
||||||
$state.transitionTo($scope.nextStep, {
|
$state.transitionTo($scope.nextStep, {
|
||||||
id: _id,
|
id: _id,
|
||||||
amount: $scope.useSendMax ? null : _amount,
|
amount: $scope.useSendMax ? null : _amount,
|
||||||
|
|
@ -361,12 +367,11 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
var amount = _amount;
|
var amount = _amount;
|
||||||
|
|
||||||
if (unit.isFiat) {
|
if (unit.isFiat) {
|
||||||
amount = fromFiat(_amount);
|
amount = (fromFiat(amount) * unitToSatoshi).toFixed(0);
|
||||||
} else {
|
} else {
|
||||||
amount = (amount * unitToSatoshi).toFixed(0);
|
amount = (amount * unitToSatoshi).toFixed(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$state.transitionTo('tabs.send.confirm', {
|
$state.transitionTo('tabs.send.confirm', {
|
||||||
recipientType: $scope.recipientType,
|
recipientType: $scope.recipientType,
|
||||||
toAmount: amount,
|
toAmount: amount,
|
||||||
|
|
@ -374,7 +379,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
toName: $scope.toName,
|
toName: $scope.toName,
|
||||||
toEmail: $scope.toEmail,
|
toEmail: $scope.toEmail,
|
||||||
toColor: $scope.toColor,
|
toColor: $scope.toColor,
|
||||||
coin: unit.id,
|
coin: coin,
|
||||||
useSendMax: $scope.useSendMax
|
useSendMax: $scope.useSendMax
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -442,7 +442,9 @@ angular.module('copayApp.services')
|
||||||
seedWallet(opts, function(err, walletClient) {
|
seedWallet(opts, function(err, walletClient) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
walletClient.joinWallet(opts.secret, opts.myName || 'me', { coin: opts.coin }, function(err) {
|
walletClient.joinWallet(opts.secret, opts.myName || 'me', {
|
||||||
|
coin: opts.coin
|
||||||
|
}, function(err) {
|
||||||
if (err) return bwcError.cb(err, gettextCatalog.getString('Could not join wallet'), cb);
|
if (err) return bwcError.cb(err, gettextCatalog.getString('Could not join wallet'), cb);
|
||||||
addAndBindWalletClient(walletClient, {
|
addAndBindWalletClient(walletClient, {
|
||||||
bwsurl: opts.bwsurl
|
bwsurl: opts.bwsurl
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue