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