When available funds are higher than Shapeshift max limit, the send max button changes to send max limit.
This commit is contained in:
parent
52f18c3c9b
commit
b2178c84e3
2 changed files with 129 additions and 17 deletions
|
|
@ -81,11 +81,12 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
||||||
if (data.direction == "back") {
|
if (data.direction == "back") {
|
||||||
sendFlowService.popState();
|
sendFlowService.popState();
|
||||||
}
|
}
|
||||||
console.log('amount onBeforeEnter after back sendflow ', sendFlowService.state);
|
//console.log('amount onBeforeEnter after back sendflow ', sendFlowService.state);
|
||||||
|
|
||||||
initCurrencies();
|
initCurrencies();
|
||||||
|
|
||||||
passthroughParams = sendFlowService.getStateClone();
|
passthroughParams = sendFlowService.getStateClone();
|
||||||
|
console.log('sendflow Amount on BeforeEnter after back', passthroughParams);
|
||||||
|
|
||||||
vm.fromWalletId = passthroughParams.fromWalletId;
|
vm.fromWalletId = passthroughParams.fromWalletId;
|
||||||
vm.toWalletId = passthroughParams.toWalletId;
|
vm.toWalletId = passthroughParams.toWalletId;
|
||||||
|
|
@ -95,6 +96,14 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
||||||
vm.isRequestingSpecificAmount = !passthroughParams.fromWalletId;
|
vm.isRequestingSpecificAmount = !passthroughParams.fromWalletId;
|
||||||
vm.showSendMaxButton = !vm.isRequestingSpecificAmount;
|
vm.showSendMaxButton = !vm.isRequestingSpecificAmount;
|
||||||
|
|
||||||
|
var config = configService.getSync().wallet.settings;
|
||||||
|
unitToSatoshi = config.unitToSatoshi;
|
||||||
|
satToUnit = 1 / unitToSatoshi;
|
||||||
|
unitDecimals = config.unitDecimals;
|
||||||
|
|
||||||
|
setAvailableUnits();
|
||||||
|
updateUnitUI();
|
||||||
|
|
||||||
if (passthroughParams.thirdParty) {
|
if (passthroughParams.thirdParty) {
|
||||||
vm.thirdParty = passthroughParams.thirdParty; // Parse stringified JSON-object
|
vm.thirdParty = passthroughParams.thirdParty; // Parse stringified JSON-object
|
||||||
if (vm.thirdParty) {
|
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 reNr = /^[1234567890\.]$/;
|
||||||
var reOp = /^[\*\+\-\/]$/;
|
var reOp = /^[\*\+\-\/]$/;
|
||||||
|
|
@ -136,10 +139,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
unitToSatoshi = config.unitToSatoshi;
|
|
||||||
satToUnit = 1 / unitToSatoshi;
|
|
||||||
unitDecimals = config.unitDecimals;
|
|
||||||
|
|
||||||
resetAmount();
|
resetAmount();
|
||||||
|
|
||||||
processAmount();
|
processAmount();
|
||||||
|
|
@ -220,9 +220,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
||||||
|
|
||||||
function initForShapeshift() {
|
function initForShapeshift() {
|
||||||
if (vm.thirdParty.id === 'shapeshift') {
|
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.thirdParty.data['fromWalletId'] = vm.fromWalletId;
|
||||||
|
|
||||||
vm.fromWallet = profileService.getWallet(vm.fromWalletId);
|
vm.fromWallet = profileService.getWallet(vm.fromWalletId);
|
||||||
|
|
@ -232,6 +231,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
||||||
vm.showSendLimitMaxButton = false;
|
vm.showSendLimitMaxButton = false;
|
||||||
vm.canSendAllAvailableFunds = false;
|
vm.canSendAllAvailableFunds = false;
|
||||||
|
|
||||||
|
|
||||||
shapeshiftService.getMarketData(vm.fromWallet.coin, vm.toWallet.coin, function(data) {
|
shapeshiftService.getMarketData(vm.fromWallet.coin, vm.toWallet.coin, function(data) {
|
||||||
vm.thirdParty.data['minAmount'] = vm.minAmount = parseFloat(data.minimum);
|
vm.thirdParty.data['minAmount'] = vm.minAmount = parseFloat(data.minimum);
|
||||||
vm.thirdParty.data['maxAmount'] = vm.maxAmount = parseFloat(data.maxLimit);
|
vm.thirdParty.data['maxAmount'] = vm.maxAmount = parseFloat(data.maxLimit);
|
||||||
|
|
@ -239,6 +239,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
||||||
setMaximumButtonFromWallet(vm.fromWallet);
|
setMaximumButtonFromWallet(vm.fromWallet);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ describe('amountController', function(){
|
||||||
sendFlowService,
|
sendFlowService,
|
||||||
shapeshiftService,
|
shapeshiftService,
|
||||||
txFormatService,
|
txFormatService,
|
||||||
|
$scope,
|
||||||
$stateParams;
|
$stateParams;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -21,7 +22,7 @@ describe('amountController', function(){
|
||||||
configCache = {
|
configCache = {
|
||||||
wallet: {
|
wallet: {
|
||||||
settings: {
|
settings: {
|
||||||
|
unitToSatoshi: 100000000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -44,9 +45,9 @@ describe('amountController', function(){
|
||||||
|
|
||||||
profileService = jasmine.createSpyObj(['getWallet', 'getWallets']);
|
profileService = jasmine.createSpyObj(['getWallet', 'getWallets']);
|
||||||
|
|
||||||
rateService = jasmine.createSpyObj(['fromFiat', 'whenAvailable']);
|
rateService = jasmine.createSpyObj(['fromFiat', 'listAlternatives', 'updateRates', 'whenAvailable']);
|
||||||
sendFlowService = jasmine.createSpyObj(['getStateClone']);
|
sendFlowService = jasmine.createSpyObj(['getStateClone']);
|
||||||
shapeshiftService = jasmine.createSpyObj(['shiftIt']);
|
shapeshiftService = jasmine.createSpyObj(['getMarketData']);
|
||||||
txFormatService = jasmine.createSpyObj(['formatAlternativeStr', 'formatAmountStr']);
|
txFormatService = jasmine.createSpyObj(['formatAlternativeStr', 'formatAmountStr']);
|
||||||
|
|
||||||
$stateParams = {};
|
$stateParams = {};
|
||||||
|
|
@ -112,4 +113,114 @@ describe('amountController', function(){
|
||||||
//expect($scope.toAddress).toBe('qrup46avn8t466xxwlzs4qelht7cnwvesv2e29wf7s');
|
//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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue