clean up, migrate to no-fix amount
This commit is contained in:
parent
5e034e7b8b
commit
f7cde7a071
4 changed files with 57 additions and 54 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('amountController', amountController);
|
||||
|
||||
function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, sendFlowService, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window) {
|
||||
function amountController(configService, $filter, gettextCatalog, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, sendFlowService, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window, ongoingProcess) {
|
||||
var vm = this;
|
||||
|
||||
vm.allowSend = false;
|
||||
|
|
@ -74,7 +74,6 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
initCurrencies();
|
||||
|
||||
passthroughParams = sendFlowService.state.getClone();
|
||||
|
||||
console.log('amount onBeforeEnter after back sendflow ', passthroughParams);
|
||||
|
||||
vm.fromWalletId = passthroughParams.fromWalletId;
|
||||
|
|
@ -94,9 +93,11 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
vm.fromWallet = profileService.getWallet(vm.fromWalletId);
|
||||
vm.toWallet = profileService.getWallet(vm.toWalletId);
|
||||
|
||||
ongoingProcess.set('connectingShapeshift', true);
|
||||
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);
|
||||
ongoingProcess.set('connectingShapeshift', false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -113,7 +114,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
var reOp = /^[\*\+\-\/]$/;
|
||||
|
||||
if (!isAndroid && !isIos) {
|
||||
var disableKeys = angular.element($window).on('keydown', function(e) {
|
||||
angular.element($window).on('keydown', function(e) {
|
||||
if (!e.key) return;
|
||||
if (e.which === 8) { // you can add others here inside brackets.
|
||||
if (!altCurrencyModal) {
|
||||
|
|
|
|||
|
|
@ -507,10 +507,12 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
|
|||
return;
|
||||
}
|
||||
|
||||
shapeshiftService.shiftIt(vm.originWallet.coin, toWallet.coin, withdrawalAddr, returnAddr, function onShiftIt(err, shapeshiftData) {
|
||||
// Need to use the correct service to do it.
|
||||
var amount = parseFloat(satoshis / 100000000);
|
||||
|
||||
shapeshiftService.shiftIt(vm.originWallet.coin, toWallet.coin, withdrawalAddr, returnAddr, amount, function onShiftIt(err, shapeshiftData) {
|
||||
if (err) {
|
||||
ongoingProcess.set('connectingShapeshift', false);
|
||||
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
|
||||
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err, function () {
|
||||
$ionicHistory.goBack();
|
||||
});
|
||||
} else {
|
||||
|
|
@ -520,6 +522,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
|
|||
vm.destination.address = toAddress;
|
||||
vm.destination.kind = 'shapeshift';
|
||||
}
|
||||
ongoingProcess.set('connectingShapeshift', false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -332,17 +332,19 @@ angular.module('copayApp.services').factory('shapeshiftApiService', function($q)
|
|||
console.log(fixedTx);
|
||||
SSA.FixedAmountTx(fixedTx, function (data) {
|
||||
console.log(data);
|
||||
promise.resolve(data.success);
|
||||
}, function (err) {
|
||||
promise.reject(err);
|
||||
promise.resolve(data);
|
||||
});
|
||||
return promise.promise;
|
||||
},
|
||||
NormalTx : function($scope){
|
||||
var promise = $q.defer();
|
||||
var normalTx = SSA.CreateNormalTx($scope.withdrawalAddress, $scope.coinIn, $scope.coinOut);
|
||||
|
||||
console.log('shapeshiftApiService.NormalTx()');
|
||||
console.log(normalTx);
|
||||
SSA.NormalTx(normalTx, function (data) {
|
||||
promise.resolve({ normalTxData : data });
|
||||
console.log(data);
|
||||
promise.resolve(data);
|
||||
});
|
||||
return promise.promise;
|
||||
},
|
||||
|
|
@ -363,13 +365,12 @@ angular.module('copayApp.services').factory('shapeshiftApiService', function($q)
|
|||
return promise.promise;
|
||||
},
|
||||
ValidateAddress : function(address, coin) {
|
||||
var promise = $q.defer();
|
||||
SSA.ValidateAdddress(address, coin, function onSuccess(data){
|
||||
promise.resolve(data);
|
||||
}, function onError(err) {
|
||||
promise.reject(err);
|
||||
});
|
||||
return promise.promise;
|
||||
var promise = $q.defer();
|
||||
SSA.ValidateAdddress(address, coin, function onRequest(data){
|
||||
console.log(data);
|
||||
promise.resolve(data);
|
||||
});
|
||||
return promise.promise;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('bitcoincom.services').factory('shapeshiftService', function ($http, $interval, $log, lodash, moment, ongoingProcess, shapeshiftApiService, storageService, configService, incomingDataService, platformInfo, servicesService) {
|
||||
angular.module('bitcoincom.services').factory('shapeshiftService', function (shapeshiftApiService) {
|
||||
var root = {};
|
||||
root.ShiftState = 'Shift';
|
||||
root.coinIn = '';
|
||||
|
|
@ -29,45 +29,43 @@ angular.module('bitcoincom.services').factory('shapeshiftService', function ($ht
|
|||
'BCH': {name: 'Bitcoin Cash', symbol: 'BCH'}
|
||||
};
|
||||
|
||||
root.shiftIt = function (coinIn, coinOut, withdrawalAddress, returnAddress, cb) {
|
||||
root.withdrawalAddress = withdrawalAddress;
|
||||
root.returnAddress = returnAddress;
|
||||
root.coinIn = coinIn;
|
||||
root.coinOut = coinOut;
|
||||
shapeshiftApiService.ValidateAddress(withdrawalAddress, coinOut).then(function onSuccess(data) {
|
||||
shapeshiftApiService.FixedAmountTx(root).then(function onSuccess(txData) {
|
||||
if (txData.err) {
|
||||
cb(txData.err);
|
||||
} else {
|
||||
if (!txData.orderId || !txData.deposit) {
|
||||
cb(new Error('Invalid response'));
|
||||
} else {
|
||||
var coinPair = txData.pair.split('_');
|
||||
txData.depositType = coinPair[0].toUpperCase();
|
||||
txData.withdrawalType = coinPair[1].toUpperCase();
|
||||
coin = root.coins[txData.depositType].name.toLowerCase();
|
||||
txData.depositQR = coin + ":" + txData.deposit + "?amount=" + txData.depositAmount;
|
||||
root.txFixedPending = true;
|
||||
root.depositInfo = txData;
|
||||
var shapeshiftData = {
|
||||
coinIn: coinIn,
|
||||
coinOut: coinOut,
|
||||
toWalletId: root.toWalletId,
|
||||
minAmount: root.marketData.minimum,
|
||||
maxAmount: root.marketData.maxLimit,
|
||||
orderId: txData.orderId,
|
||||
toAddress: txData.deposit
|
||||
};
|
||||
|
||||
cb(null, shapeshiftData);
|
||||
}
|
||||
}
|
||||
}, function onError(err) {
|
||||
cb(err);
|
||||
});
|
||||
}, function onError(err) {
|
||||
root.shiftIt = function (coinIn, coinOut, withdrawalAddress, returnAddress, amount, cb) {
|
||||
if (typeof amount !== 'number' || amount < root.marketData.minimum || amount > root.marketData.maxLimit) {
|
||||
var err = new Error('Invalid amount');
|
||||
cb(err);
|
||||
});
|
||||
} else {
|
||||
root.withdrawalAddress = withdrawalAddress;
|
||||
root.returnAddress = returnAddress;
|
||||
root.coinIn = coinIn;
|
||||
root.coinOut = coinOut;
|
||||
root.amount = amount;
|
||||
shapeshiftApiService.ValidateAddress(withdrawalAddress, coinOut).then(function onSuccess(data) {
|
||||
if (data && data.isvalid) {
|
||||
shapeshiftApiService.NormalTx(root).then(function onResponse(data) {
|
||||
var txData = data;
|
||||
if (!txData || !txData.orderId || !txData.deposit) {
|
||||
cb(new Error('Invalid response'));
|
||||
} else {
|
||||
root.depositInfo = txData;
|
||||
var shapeshiftData = {
|
||||
coinIn: coinIn,
|
||||
coinOut: coinOut,
|
||||
toWalletId: root.toWalletId,
|
||||
minAmount: root.marketData.minimum,
|
||||
maxAmount: root.marketData.maxLimit,
|
||||
orderId: txData.orderId,
|
||||
toAddress: txData.deposit
|
||||
};
|
||||
|
||||
cb(null, shapeshiftData);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var err = new Error('Invalid address or coin');
|
||||
cb(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue