The Enter Amount screen now correctly sets the amount when sendMax() is called when available funds exceed the max limit.

This commit is contained in:
Brendon Duncan 2018-09-04 12:52:54 +12:00
commit 4315d16f73
4 changed files with 37 additions and 12 deletions

View file

@ -269,7 +269,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
altUnitIndex = unitIndex; altUnitIndex = unitIndex;
unitIndex = tempIndex; unitIndex = tempIndex;
} }
vm.amount = (transactionSendableAmount.satoshis * unitToSatoshi).toFixed(LENGTH_AFTER_COMMA_EXPRESSION_LIMIT); vm.amount = (transactionSendableAmount.satoshis * satToUnit).toFixed(LENGTH_AFTER_COMMA_EXPRESSION_LIMIT);
} }
finish(); finish();
} }
@ -487,9 +487,9 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
var satoshis = 0; var satoshis = 0;
if (unit.isFiat) { if (unit.isFiat) {
satoshis = (fromFiat(uiAmount) * unitToSatoshi).toFixed(0); satoshis = Math.floor(fromFiat(uiAmount) * unitToSatoshi);
} else { } else {
satoshis = (uiAmount * unitToSatoshi).toFixed(0); satoshis = Math.floor(uiAmount * unitToSatoshi);
} }
var confirmData = { var confirmData = {

View file

@ -4,6 +4,7 @@ describe('amountController', function(){
$controller, $controller,
$ionicHistory, $ionicHistory,
$rootScope, $rootScope,
ongoingProcess,
platformInfo, platformInfo,
profileService, profileService,
rateService, rateService,
@ -11,6 +12,7 @@ describe('amountController', function(){
shapeshiftService, shapeshiftService,
txFormatService, txFormatService,
$scope, $scope,
$state,
$stateParams; $stateParams;
@ -37,6 +39,8 @@ describe('amountController', function(){
$ionicHistory = jasmine.createSpyObj(['backView']); $ionicHistory = jasmine.createSpyObj(['backView']);
ongoingProcess = jasmine.createSpyObj(['set']);
platformInfo = { platformInfo = {
isChromeApp: false, isChromeApp: false,
isAndroid: false, isAndroid: false,
@ -46,10 +50,10 @@ describe('amountController', function(){
profileService = jasmine.createSpyObj(['getWallet', 'getWallets']); profileService = jasmine.createSpyObj(['getWallet', 'getWallets']);
rateService = jasmine.createSpyObj(['fromFiat', 'listAlternatives', 'updateRates', 'whenAvailable']); rateService = jasmine.createSpyObj(['fromFiat', 'listAlternatives', 'updateRates', 'whenAvailable']);
sendFlowService = jasmine.createSpyObj(['getStateClone']); sendFlowService = jasmine.createSpyObj(['getStateClone', 'pushState']);
shapeshiftService = jasmine.createSpyObj(['getMarketData']); shapeshiftService = jasmine.createSpyObj(['getMarketData']);
txFormatService = jasmine.createSpyObj(['formatAlternativeStr', 'formatAmountStr']); txFormatService = jasmine.createSpyObj(['formatAlternativeStr', 'formatAmountStr']);
$state = jasmine.createSpyObj(['transitionTo']);
$stateParams = {}; $stateParams = {};
inject(function(_$controller_, _$rootScope_){ inject(function(_$controller_, _$rootScope_){
@ -86,7 +90,7 @@ describe('amountController', function(){
$ionicModal: {}, $ionicModal: {},
$ionicScrollDelegate: {}, $ionicScrollDelegate: {},
nodeWebkitService: {}, nodeWebkitService: {},
ongoingProcess: {}, ongoingProcess: ongoingProcess,
platformInfo: platformInfo, platformInfo: platformInfo,
profileService: profileService, profileService: profileService,
popupService: {}, popupService: {},
@ -159,7 +163,7 @@ describe('amountController', function(){
$ionicModal: {}, $ionicModal: {},
$ionicScrollDelegate: {}, $ionicScrollDelegate: {},
nodeWebkitService: {}, nodeWebkitService: {},
ongoingProcess: {}, ongoingProcess: ongoingProcess,
platformInfo: platformInfo, platformInfo: platformInfo,
profileService: profileService, profileService: profileService,
popupService: {}, popupService: {},
@ -167,7 +171,7 @@ describe('amountController', function(){
$scope: $scope, $scope: $scope,
sendFlowService: sendFlowService, sendFlowService: sendFlowService,
shapeshiftService: shapeshiftService, shapeshiftService: shapeshiftService,
$state: {}, $state: $state,
$stateParams: $stateParams, $stateParams: $stateParams,
txFormatService: txFormatService, txFormatService: txFormatService,
walletService: {} walletService: {}
@ -218,8 +222,25 @@ describe('amountController', function(){
expect(amountController.showSendMaxButton).toEqual(false); expect(amountController.showSendMaxButton).toEqual(false);
expect(amountController.showSendLimitMaxButton).toEqual(true); expect(amountController.showSendLimitMaxButton).toEqual(true);
// Now hit the Send Max button
var pushedState = null;
sendFlowService.pushState.and.callFake(function (sendFlowState){
pushedState = sendFlowState;
});
amountController.sendMax();
expect(pushedState.amount).toEqual(68462390);
expect(pushedState.fromWalletId).toEqual('4cd7673e-7320-4dfa-86e5-d4edb51d460a');
expect(pushedState.sendMax).toEqual(false);
expect(pushedState.toWalletId).toEqual('bf00af8f-0788-4b57-b30a-0390747407e9');
expect(pushedState.thirdParty.id).toEqual('shapeshift');
expect(pushedState.thirdParty.data.maxAmount).toEqual(0.6846239);
expect(pushedState.thirdParty.data.minAmount).toEqual(0.00013692);
expect($state.transitionTo.calls.count()).toEqual(1);
expect($state.transitionTo.calls.argsFor(0)[0]).toEqual('tabs.send.review');
}); });
}); });

View file

@ -78,11 +78,15 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
function onBeforeEnter(event, data) { function onBeforeEnter(event, data) {
console.log('walletSelector onBeforeEnter sendflow ', sendFlowService.state); console.log('review onBeforeEnter sendflow ', sendFlowService.state);
defaults = configService.getDefaults(); defaults = configService.getDefaults();
sendFlowData = sendFlowService.getStateClone(); sendFlowData = sendFlowService.getStateClone();
originWalletId = sendFlowData.fromWalletId; originWalletId = sendFlowData.fromWalletId;
satoshis = parseInt(sendFlowData.amount, 10); if (typeof sendFlowData.amount === 'string') {
satoshis = parseInt(sendFlowData.amount, 10);
} else {
satoshis = sendFlowData.amount;
}
toAddress = sendFlowData.toAddress; toAddress = sendFlowData.toAddress;
destinationWalletId = sendFlowData.toWalletId; destinationWalletId = sendFlowData.toWalletId;

View file

@ -12,7 +12,7 @@ angular
// A separate state variable so we can ensure it is cleared of everything, // A separate state variable so we can ensure it is cleared of everything,
// even other properties added that this service does not know about. (such as "coin") // even other properties added that this service does not know about. (such as "coin")
state: { state: {
amount: '', amount: 0,
displayAddress: null, displayAddress: null,
fromWalletId: '', fromWalletId: '',
sendMax: false, sendMax: false,
@ -42,7 +42,7 @@ angular
function clearCurrent() { function clearCurrent() {
console.log("sendFlow clearCurrent()"); console.log("sendFlow clearCurrent()");
service.state = { service.state = {
amount: '', amount: 0,
displayAddress: null, displayAddress: null,
fromWalletId: '', fromWalletId: '',
sendMax: false, sendMax: false,