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 availableUnits = [];
|
||||||
var fiatCode;
|
var fiatCode;
|
||||||
|
|
||||||
|
var fixedUnit;
|
||||||
|
|
||||||
$scope.isChromeApp = platformInfo.isChromeApp;
|
$scope.isChromeApp = platformInfo.isChromeApp;
|
||||||
|
|
||||||
$scope.$on('$ionicView.leave', function() {
|
$scope.$on('$ionicView.leave', function() {
|
||||||
|
|
@ -34,7 +36,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
||||||
var anyCashWallet = true; // TODO!!
|
var anyCashWallet = true; // TODO!!
|
||||||
if (anyCashWallet) {
|
if (anyCashWallet) {
|
||||||
availableUnits.push({
|
availableUnits.push({
|
||||||
name: 'Bitcoin Cash',
|
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;
|
var fiat;
|
||||||
if (data.stateParams.currency) {
|
if (data.stateParams.currency) {
|
||||||
fiat = data.stateParams.currency;
|
fiat = data.stateParams.currency;
|
||||||
|
altUnitIndex = unitIndex
|
||||||
|
unitIndex = availableUnits.length;
|
||||||
} else {
|
} else {
|
||||||
fiat = config.fiat || 'USD';
|
fiat = config.fiat || 'USD';
|
||||||
|
altUnitIndex = availableUnits.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
availableUnits.push({
|
availableUnits.push({
|
||||||
|
|
@ -58,27 +86,17 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
isFiat: true,
|
isFiat: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
unitIndex = 0;
|
|
||||||
altUnitIndex = availableUnits.length - 1;
|
|
||||||
fiatCode = fiat;
|
fiatCode = fiat;
|
||||||
|
|
||||||
|
if (data.stateParams.fixedUnit) {
|
||||||
|
fixedUnit = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Go to...
|
// Go to...
|
||||||
_id = data.stateParams.id; // Optional (BitPay Card ID or Wallet ID)
|
_id = data.stateParams.id; // Optional (BitPay Card ID or Wallet ID)
|
||||||
$scope.nextStep = data.stateParams.nextStep;
|
$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();
|
setAvailableUnits();
|
||||||
updateUnitUI();
|
updateUnitUI();
|
||||||
|
|
@ -175,16 +193,15 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateUnitUI() {
|
function updateUnitUI() {
|
||||||
|
|
||||||
$scope.unit = availableUnits[unitIndex].shortName;
|
$scope.unit = availableUnits[unitIndex].shortName;
|
||||||
$scope.alternativeUnit = availableUnits[altUnitIndex].shortName;
|
$scope.alternativeUnit = availableUnits[altUnitIndex].shortName;
|
||||||
|
|
||||||
processAmount();
|
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() {
|
$scope.changeUnit = function() {
|
||||||
if ($scope.forceCurrency || $scope.forceCoin) return;
|
if (fixedUnit) return;
|
||||||
|
|
||||||
unitIndex++;
|
unitIndex++;
|
||||||
if (unitIndex >= availableUnits.length) unitIndex = 0;
|
if (unitIndex >= availableUnits.length) unitIndex = 0;
|
||||||
|
|
@ -204,7 +221,6 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
|
|
||||||
$scope.changeAlternativeUnit = function() {
|
$scope.changeAlternativeUnit = function() {
|
||||||
console.log('[amount.js.215:changeAlternativeUnit:]'); //TODO
|
|
||||||
|
|
||||||
// Do nothing is fiat is not main unit
|
// Do nothing is fiat is not main unit
|
||||||
if (!availableUnits[unitIndex].isFiat) return;
|
if (!availableUnits[unitIndex].isFiat) return;
|
||||||
|
|
@ -332,7 +348,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
var coin = unit.id;
|
var coin = unit.id;
|
||||||
if (unit.isFiat) {
|
if (unit.isFiat) {
|
||||||
coin = availableUnits[altUnitIndex].id;
|
coin = availableUnits[altUnitIndex].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$state.transitionTo($scope.nextStep, {
|
$state.transitionTo($scope.nextStep, {
|
||||||
|
|
@ -347,7 +363,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
if (unit.isFiat) {
|
if (unit.isFiat) {
|
||||||
amount = fromFiat(_amount);
|
amount = fromFiat(_amount);
|
||||||
} else if ($scope.useSendMax){
|
} else if ($scope.useSendMax) {
|
||||||
amount = (amount * unitToSatoshi).toFixed(0);
|
amount = (amount * unitToSatoshi).toFixed(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.state('tabs.send.amount', {
|
.state('tabs.send.amount', {
|
||||||
url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin',
|
url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin/:fixedUnit',
|
||||||
views: {
|
views: {
|
||||||
'tab-send@tabs': {
|
'tab-send@tabs': {
|
||||||
controller: 'amountController',
|
controller: 'amountController',
|
||||||
|
|
@ -668,7 +668,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
params: {
|
params: {
|
||||||
id: null,
|
id: null,
|
||||||
nextStep: 'tabs.paymentRequest.confirm',
|
nextStep: 'tabs.paymentRequest.confirm',
|
||||||
forceCoin: true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -918,7 +917,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
coin: 'btc',
|
coin: 'btc',
|
||||||
forceCoin: true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.buyandsell.glidera.amount', {
|
.state('tabs.buyandsell.glidera.amount', {
|
||||||
|
|
@ -975,7 +973,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
coin: 'btc',
|
coin: 'btc',
|
||||||
forceCoin: true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.preferences.coinbase', {
|
.state('tabs.preferences.coinbase', {
|
||||||
|
|
@ -1064,9 +1061,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
params: {
|
params: {
|
||||||
nextStep: 'tabs.giftcards.mercadoLibre.buy',
|
nextStep: 'tabs.giftcards.mercadoLibre.buy',
|
||||||
currency: 'BRL',
|
currency: 'BRL',
|
||||||
forceCurrency: true,
|
|
||||||
coin: 'btc',
|
coin: 'btc',
|
||||||
forceCoin: true
|
fixedUnit: 1,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.giftcards.mercadoLibre.buy', {
|
.state('tabs.giftcards.mercadoLibre.buy', {
|
||||||
|
|
@ -1117,9 +1113,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
params: {
|
params: {
|
||||||
nextStep: 'tabs.giftcards.amazon.buy',
|
nextStep: 'tabs.giftcards.amazon.buy',
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
forceCurrency: true,
|
|
||||||
coin: 'btc',
|
coin: 'btc',
|
||||||
forceCoin: true
|
fixedUnit: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.giftcards.amazon.buy', {
|
.state('tabs.giftcards.amazon.buy', {
|
||||||
|
|
@ -1160,7 +1155,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
id: null,
|
id: null,
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
coin: 'btc',
|
coin: 'btc',
|
||||||
forceCoin: true,
|
|
||||||
useSendMax: null
|
useSendMax: null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue