fix fixedUnit
This commit is contained in:
parent
e040871e26
commit
42ee794c3e
2 changed files with 41 additions and 31 deletions
|
|
@ -15,6 +15,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
var availableUnits = [];
|
||||
var fiatCode;
|
||||
|
||||
var fixedUnit;
|
||||
|
||||
$scope.isChromeApp = platformInfo.isChromeApp;
|
||||
|
||||
$scope.$on('$ionicView.leave', function() {
|
||||
|
|
@ -33,8 +35,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
shortName: 'BTC',
|
||||
}];
|
||||
|
||||
|
||||
var anyCashWallet = true; // TODO!!
|
||||
|
||||
var anyCashWallet = true; // TODO!!
|
||||
if (anyCashWallet) {
|
||||
availableUnits.push({
|
||||
name: 'Bitcoin Cash',
|
||||
|
|
@ -43,12 +45,38 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
});
|
||||
};
|
||||
|
||||
unitIndex = 0;
|
||||
|
||||
if (data.stateParams.coin) {
|
||||
var coins = data.stateParams.coin.split(',');
|
||||
var newAvailableUnits = [];
|
||||
|
||||
lodash.each(coins, function(c) {
|
||||
var coin = lodash.find(availableUnits, {
|
||||
id: c
|
||||
});
|
||||
if (!coin) {
|
||||
$log.warn('Could not find desired coin:' + data.stateParams.coin)
|
||||
} else {
|
||||
newAvailableUnits.push(coin);
|
||||
}
|
||||
});
|
||||
|
||||
if (newAvailableUnits.length>0) {
|
||||
availableUnits = newAvailableUnits;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// currency have preference
|
||||
var fiat;
|
||||
if (data.stateParams.currency) {
|
||||
fiat = data.stateParams.currency;
|
||||
altUnitIndex = unitIndex
|
||||
unitIndex = availableUnits.length;
|
||||
} else {
|
||||
fiat = config.fiat || 'USD';
|
||||
altUnitIndex = availableUnits.length;
|
||||
}
|
||||
|
||||
availableUnits.push({
|
||||
|
|
@ -58,27 +86,17 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
isFiat: true,
|
||||
});
|
||||
|
||||
unitIndex = 0;
|
||||
altUnitIndex = availableUnits.length - 1;
|
||||
fiatCode = fiat;
|
||||
|
||||
if (data.stateParams.fixedUnit) {
|
||||
fixedUnit = true;
|
||||
}
|
||||
};
|
||||
|
||||
// Go to...
|
||||
_id = data.stateParams.id; // Optional (BitPay Card ID or Wallet ID)
|
||||
$scope.nextStep = data.stateParams.nextStep;
|
||||
|
||||
$scope.forceCurrency = data.stateParams.forceCurrency;
|
||||
$scope.forceCoin = data.stateParams.forceCoin;
|
||||
|
||||
if (data.stateParams.coin) {
|
||||
var index = lodash.findIndex(availableUnits, { id: data.stateParams.coin });
|
||||
|
||||
if (index < 0) {
|
||||
$log.warn('Could not find desired coin:' + data.stateParams.coin)
|
||||
} else {
|
||||
unitIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
setAvailableUnits();
|
||||
updateUnitUI();
|
||||
|
|
@ -175,16 +193,15 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
};
|
||||
|
||||
function updateUnitUI() {
|
||||
|
||||
$scope.unit = availableUnits[unitIndex].shortName;
|
||||
$scope.alternativeUnit = availableUnits[altUnitIndex].shortName;
|
||||
|
||||
processAmount();
|
||||
$log.debug('Update unit coin @amount unit:' + $scope.unit + " alternativeUnit:" + $scope.alternativeUnit); //TODO
|
||||
$log.debug('Update unit coin @amount unit:' + $scope.unit + " alternativeUnit:" + $scope.alternativeUnit);
|
||||
};
|
||||
|
||||
$scope.changeUnit = function() {
|
||||
if ($scope.forceCurrency || $scope.forceCoin) return;
|
||||
if (fixedUnit) return;
|
||||
|
||||
unitIndex++;
|
||||
if (unitIndex >= availableUnits.length) unitIndex = 0;
|
||||
|
|
@ -204,7 +221,6 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
|
||||
|
||||
$scope.changeAlternativeUnit = function() {
|
||||
console.log('[amount.js.215:changeAlternativeUnit:]'); //TODO
|
||||
|
||||
// Do nothing is fiat is not main unit
|
||||
if (!availableUnits[unitIndex].isFiat) return;
|
||||
|
|
@ -332,7 +348,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
|
||||
var coin = unit.id;
|
||||
if (unit.isFiat) {
|
||||
coin = availableUnits[altUnitIndex].id;
|
||||
coin = availableUnits[altUnitIndex].id;
|
||||
}
|
||||
|
||||
$state.transitionTo($scope.nextStep, {
|
||||
|
|
@ -347,7 +363,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
|
||||
if (unit.isFiat) {
|
||||
amount = fromFiat(_amount);
|
||||
} else if ($scope.useSendMax){
|
||||
} else if ($scope.useSendMax) {
|
||||
amount = (amount * unitToSatoshi).toFixed(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
*/
|
||||
|
||||
.state('tabs.send.amount', {
|
||||
url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin',
|
||||
url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin/:fixedUnit',
|
||||
views: {
|
||||
'tab-send@tabs': {
|
||||
controller: 'amountController',
|
||||
|
|
@ -668,7 +668,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
params: {
|
||||
id: null,
|
||||
nextStep: 'tabs.paymentRequest.confirm',
|
||||
forceCoin: true
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -918,7 +917,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
},
|
||||
params: {
|
||||
coin: 'btc',
|
||||
forceCoin: true
|
||||
}
|
||||
})
|
||||
.state('tabs.buyandsell.glidera.amount', {
|
||||
|
|
@ -975,7 +973,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
},
|
||||
params: {
|
||||
coin: 'btc',
|
||||
forceCoin: true
|
||||
}
|
||||
})
|
||||
.state('tabs.preferences.coinbase', {
|
||||
|
|
@ -1064,9 +1061,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
params: {
|
||||
nextStep: 'tabs.giftcards.mercadoLibre.buy',
|
||||
currency: 'BRL',
|
||||
forceCurrency: true,
|
||||
coin: 'btc',
|
||||
forceCoin: true
|
||||
fixedUnit: 1,
|
||||
}
|
||||
})
|
||||
.state('tabs.giftcards.mercadoLibre.buy', {
|
||||
|
|
@ -1117,9 +1113,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
params: {
|
||||
nextStep: 'tabs.giftcards.amazon.buy',
|
||||
currency: 'USD',
|
||||
forceCurrency: true,
|
||||
coin: 'btc',
|
||||
forceCoin: true
|
||||
fixedUnit: true,
|
||||
}
|
||||
})
|
||||
.state('tabs.giftcards.amazon.buy', {
|
||||
|
|
@ -1160,7 +1155,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
id: null,
|
||||
currency: 'USD',
|
||||
coin: 'btc',
|
||||
forceCoin: true,
|
||||
useSendMax: null
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue