diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 60912e42b..05c4b9d8b 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -81,11 +81,12 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, if (data.direction == "back") { sendFlowService.popState(); } - console.log('amount onBeforeEnter after back sendflow ', sendFlowService.state); + //console.log('amount onBeforeEnter after back sendflow ', sendFlowService.state); initCurrencies(); passthroughParams = sendFlowService.getStateClone(); + console.log('sendflow Amount on BeforeEnter after back', passthroughParams); vm.fromWalletId = passthroughParams.fromWalletId; vm.toWalletId = passthroughParams.toWalletId; @@ -95,6 +96,14 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, vm.isRequestingSpecificAmount = !passthroughParams.fromWalletId; vm.showSendMaxButton = !vm.isRequestingSpecificAmount; + var config = configService.getSync().wallet.settings; + unitToSatoshi = config.unitToSatoshi; + satToUnit = 1 / unitToSatoshi; + unitDecimals = config.unitDecimals; + + setAvailableUnits(); + updateUnitUI(); + if (passthroughParams.thirdParty) { vm.thirdParty = passthroughParams.thirdParty; // Parse stringified JSON-object if (vm.thirdParty) { @@ -102,12 +111,6 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } } - - - var config = configService.getSync().wallet.settings; - - setAvailableUnits(); - updateUnitUI(); var reNr = /^[1234567890\.]$/; var reOp = /^[\*\+\-\/]$/; @@ -136,10 +139,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, }); } - unitToSatoshi = config.unitToSatoshi; - satToUnit = 1 / unitToSatoshi; - unitDecimals = config.unitDecimals; - + resetAmount(); processAmount(); @@ -220,9 +220,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, function initForShapeshift() { if (vm.thirdParty.id === 'shapeshift') { - if (!vm.thirdParty.data) { - vm.thirdParty.data = {}; - } + vm.thirdParty.data = vm.thirdParty.data || {}; + vm.thirdParty.data['fromWalletId'] = vm.fromWalletId; vm.fromWallet = profileService.getWallet(vm.fromWalletId); @@ -232,6 +231,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, vm.showSendLimitMaxButton = false; vm.canSendAllAvailableFunds = false; + shapeshiftService.getMarketData(vm.fromWallet.coin, vm.toWallet.coin, function(data) { vm.thirdParty.data['minAmount'] = vm.minAmount = parseFloat(data.minimum); vm.thirdParty.data['maxAmount'] = vm.maxAmount = parseFloat(data.maxLimit); @@ -239,6 +239,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, setMaximumButtonFromWallet(vm.fromWallet); }); + } } diff --git a/src/js/controllers/amount.spec.js b/src/js/controllers/amount.spec.js index 00d82e520..d198f3591 100644 --- a/src/js/controllers/amount.spec.js +++ b/src/js/controllers/amount.spec.js @@ -10,6 +10,7 @@ describe('amountController', function(){ sendFlowService, shapeshiftService, txFormatService, + $scope, $stateParams; @@ -21,7 +22,7 @@ describe('amountController', function(){ configCache = { wallet: { settings: { - + unitToSatoshi: 100000000 } } }; @@ -44,9 +45,9 @@ describe('amountController', function(){ profileService = jasmine.createSpyObj(['getWallet', 'getWallets']); - rateService = jasmine.createSpyObj(['fromFiat', 'whenAvailable']); + rateService = jasmine.createSpyObj(['fromFiat', 'listAlternatives', 'updateRates', 'whenAvailable']); sendFlowService = jasmine.createSpyObj(['getStateClone']); - shapeshiftService = jasmine.createSpyObj(['shiftIt']); + shapeshiftService = jasmine.createSpyObj(['getMarketData']); txFormatService = jasmine.createSpyObj(['formatAlternativeStr', 'formatAmountStr']); $stateParams = {}; @@ -112,4 +113,114 @@ describe('amountController', function(){ //expect($scope.toAddress).toBe('qrup46avn8t466xxwlzs4qelht7cnwvesv2e29wf7s'); }); + describe('Shapeshift', function() { + var walletFrom; + var walletTo; + + beforeEach(function(){ + walletFrom = {}; + walletTo = {}; + + profileService.getWallet.and.callFake(function(walletId){ + if (walletId === '4cd7673e-7320-4dfa-86e5-d4edb51d460a') { + return walletFrom; + } else if (walletId === 'bf00af8f-0788-4b57-b30a-0390747407e9') { + return walletTo; + } else { + return null; + } + }); + + rateService.listAlternatives.and.returnValue([ + {name: "Australian Dollar", isoCode: "AUD"}, + {name: "United States Dollar", isoCode: "USD"} + ]); + + }); + + fit ('with available balance higher than max does not allow sendMax', function() { + + walletFrom.coin = 'btc'; + walletFrom.status = { + isValid: true, + spendableAmount: 123456789 + }; + walletTo.coin = 'bch'; + + profileService.getWallets.and.returnValue([{}]); + rateService.fromFiat.and.returnValue(12); // satoshis or coins? + + var $scope = $rootScope.$new(); + + var amountController = $controller('amountController', { + configService: configService, + gettextCatalog: {}, + $ionicHistory: $ionicHistory, + $ionicModal: {}, + $ionicScrollDelegate: {}, + nodeWebkitService: {}, + ongoingProcess: {}, + platformInfo: platformInfo, + profileService: profileService, + popupService: {}, + rateService: rateService, + $scope: $scope, + sendFlowService: sendFlowService, + shapeshiftService: shapeshiftService, + $state: {}, + $stateParams: $stateParams, + txFormatService: txFormatService, + walletService: {} + }); + + rateService.whenAvailable.and.callFake(function(cb){ + cb(); + }); + + var sendFlowState = { + amount: '', + displayAddress: null, + fromWalletId: '4cd7673e-7320-4dfa-86e5-d4edb51d460a', + sendMax: false, + thirdParty: { + id: 'shapeshift', + data: { + fromWalletId: "4cd7673e-7320-4dfa-86e5-d4edb51d460a" + }, + }, + toAddress: '', + toWalletId: 'bf00af8f-0788-4b57-b30a-0390747407e9' + }; + + sendFlowService.getStateClone.and.returnValue(sendFlowState); + + var reqCoinIn = ''; + var reqCoinOut = ''; + shapeshiftService.getMarketData.and.callFake(function(coinIn, coinOut, cb){ + reqCoinIn = coinIn; + reqCoinOut = coinOut; + cb({ + maxLimit: '0.6846239', + minimum: '0.00013692' + }); + }); + + $scope.$emit('$ionicView.beforeEnter', {}); + + expect(rateService.updateRates.calls.any()).toEqual(true); + + expect(reqCoinIn).toBe('btc'); + expect(reqCoinOut).toBe('bch'); + + expect(amountController.maxAmount).toBe(0.6846239); + expect(amountController.minAmount).toBe(0.00013692); + + expect(amountController.showSendMaxButton).toEqual(false); + expect(amountController.showSendLimitMaxButton).toEqual(true); + + + + }); + }); + }); \ No newline at end of file