diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index ff4ec3628..8d1f65058 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -269,7 +269,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, altUnitIndex = unitIndex; 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(); } @@ -487,9 +487,9 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, var satoshis = 0; if (unit.isFiat) { - satoshis = (fromFiat(uiAmount) * unitToSatoshi).toFixed(0); + satoshis = Math.floor(fromFiat(uiAmount) * unitToSatoshi); } else { - satoshis = (uiAmount * unitToSatoshi).toFixed(0); + satoshis = Math.floor(uiAmount * unitToSatoshi); } var confirmData = { diff --git a/src/js/controllers/amount.spec.js b/src/js/controllers/amount.spec.js index d198f3591..e4083611b 100644 --- a/src/js/controllers/amount.spec.js +++ b/src/js/controllers/amount.spec.js @@ -4,6 +4,7 @@ describe('amountController', function(){ $controller, $ionicHistory, $rootScope, + ongoingProcess, platformInfo, profileService, rateService, @@ -11,6 +12,7 @@ describe('amountController', function(){ shapeshiftService, txFormatService, $scope, + $state, $stateParams; @@ -37,6 +39,8 @@ describe('amountController', function(){ $ionicHistory = jasmine.createSpyObj(['backView']); + ongoingProcess = jasmine.createSpyObj(['set']); + platformInfo = { isChromeApp: false, isAndroid: false, @@ -46,10 +50,10 @@ describe('amountController', function(){ profileService = jasmine.createSpyObj(['getWallet', 'getWallets']); rateService = jasmine.createSpyObj(['fromFiat', 'listAlternatives', 'updateRates', 'whenAvailable']); - sendFlowService = jasmine.createSpyObj(['getStateClone']); + sendFlowService = jasmine.createSpyObj(['getStateClone', 'pushState']); shapeshiftService = jasmine.createSpyObj(['getMarketData']); txFormatService = jasmine.createSpyObj(['formatAlternativeStr', 'formatAmountStr']); - + $state = jasmine.createSpyObj(['transitionTo']); $stateParams = {}; inject(function(_$controller_, _$rootScope_){ @@ -86,7 +90,7 @@ describe('amountController', function(){ $ionicModal: {}, $ionicScrollDelegate: {}, nodeWebkitService: {}, - ongoingProcess: {}, + ongoingProcess: ongoingProcess, platformInfo: platformInfo, profileService: profileService, popupService: {}, @@ -159,7 +163,7 @@ describe('amountController', function(){ $ionicModal: {}, $ionicScrollDelegate: {}, nodeWebkitService: {}, - ongoingProcess: {}, + ongoingProcess: ongoingProcess, platformInfo: platformInfo, profileService: profileService, popupService: {}, @@ -167,7 +171,7 @@ describe('amountController', function(){ $scope: $scope, sendFlowService: sendFlowService, shapeshiftService: shapeshiftService, - $state: {}, + $state: $state, $stateParams: $stateParams, txFormatService: txFormatService, walletService: {} @@ -218,8 +222,25 @@ describe('amountController', function(){ expect(amountController.showSendMaxButton).toEqual(false); 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'); }); }); diff --git a/src/js/controllers/review.controller.js b/src/js/controllers/review.controller.js index b377bef58..554774252 100644 --- a/src/js/controllers/review.controller.js +++ b/src/js/controllers/review.controller.js @@ -78,11 +78,15 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit function onBeforeEnter(event, data) { - console.log('walletSelector onBeforeEnter sendflow ', sendFlowService.state); + console.log('review onBeforeEnter sendflow ', sendFlowService.state); defaults = configService.getDefaults(); sendFlowData = sendFlowService.getStateClone(); 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; destinationWalletId = sendFlowData.toWalletId; diff --git a/src/js/services/sendFlowService.js b/src/js/services/sendFlowService.js index 62989b3c5..9981fdbcb 100644 --- a/src/js/services/sendFlowService.js +++ b/src/js/services/sendFlowService.js @@ -12,7 +12,7 @@ angular // 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") state: { - amount: '', + amount: 0, displayAddress: null, fromWalletId: '', sendMax: false, @@ -42,7 +42,7 @@ angular function clearCurrent() { console.log("sendFlow clearCurrent()"); service.state = { - amount: '', + amount: 0, displayAddress: null, fromWalletId: '', sendMax: false,