async series with shapeshift & fee calculation

This commit is contained in:
Jean-Baptiste Dominguez 2018-09-05 15:32:47 +09:00
commit fa8ce4779f

View file

@ -93,10 +93,31 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
if (sendFlowData.thirdParty) { if (sendFlowData.thirdParty) {
vm.thirdParty = sendFlowData.thirdParty; vm.thirdParty = sendFlowData.thirdParty;
handleThirdPartyInitIfBip70(); switch (vm.thirdParty.id) {
handleThirdPartyInitIfShapeshift(); case 'shapeshift':
initShapeshift(function (err) {
if (err) {
// Error stop here
ongoingProcess.set('connectingShapeshift', false);
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
$ionicHistory.goBack();
});
} else {
_next(data);
}
});
break;
case 'bip70':
initBip70();
default:
_next(data);
break;
}
} else {
_next(data);
} }
function _next() {
configService.get(function onConfig(err, configCache) { configService.get(function onConfig(err, configCache) {
if (err) { if (err) {
$log.err('Error getting config.', err); $log.err('Error getting config.', err);
@ -114,6 +135,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
createVanityTransaction(data); createVanityTransaction(data);
}); });
} }
}
vm.approve = function() { vm.approve = function() {
@ -458,8 +480,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
vm.destination.balanceCurrency = balanceText.currency; vm.destination.balanceCurrency = balanceText.currency;
} }
function handleThirdPartyInitIfBip70() { function initBip70() {
if (vm.thirdParty.id === 'bip70') {
vm.sendingTitle = gettextCatalog.getString('You are paying'); vm.sendingTitle = gettextCatalog.getString('You are paying');
vm.memo = vm.thirdParty.memo; vm.memo = vm.thirdParty.memo;
vm.memoExpanded = !!vm.memo; vm.memoExpanded = !!vm.memo;
@ -474,10 +495,8 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
verified: vm.thirdParty.verified, verified: vm.thirdParty.verified,
}; };
} }
}
function handleThirdPartyInitIfShapeshift() { function initShapeshift(cb) {
if (vm.thirdParty.id === 'shapeshift') {
vm.sendingTitle = gettextCatalog.getString('You are shifting'); vm.sendingTitle = gettextCatalog.getString('You are shifting');
if (!vm.thirdParty.data) { if (!vm.thirdParty.data) {
vm.thirdParty.data = {}; vm.thirdParty.data = {};
@ -492,19 +511,11 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
ongoingProcess.set('connectingShapeshift', true); ongoingProcess.set('connectingShapeshift', true);
walletService.getAddress(vm.originWallet, false, function onReturnWalletAddress(err, returnAddr) { walletService.getAddress(vm.originWallet, false, function onReturnWalletAddress(err, returnAddr) {
if (err) { if (err) {
ongoingProcess.set('connectingShapeshift', false); return cb(err);
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
$ionicHistory.goBack();
});
return;
} }
walletService.getAddress(toWallet, false, function onWithdrawalWalletAddress(err, withdrawalAddr) { walletService.getAddress(toWallet, false, function onWithdrawalWalletAddress(err, withdrawalAddr) {
if (err) { if (err) {
ongoingProcess.set('connectingShapeshift', false); return cb(err);
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
$ionicHistory.goBack();
});
return;
} }
// Need to use the correct service to do it. // Need to use the correct service to do it.
@ -512,21 +523,19 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
shapeshiftService.shiftIt(vm.originWallet.coin, toWallet.coin, withdrawalAddr, returnAddr, amount, function onShiftIt(err, shapeshiftData) { shapeshiftService.shiftIt(vm.originWallet.coin, toWallet.coin, withdrawalAddr, returnAddr, amount, function onShiftIt(err, shapeshiftData) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err, function () { return cb(err);
$ionicHistory.goBack();
});
} else { } else {
vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId; vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId;
vm.memoExpanded = !!vm.memo; vm.memoExpanded = !!vm.memo;
tx.toAddress = shapeshiftData.toAddress; tx.toAddress = shapeshiftData.toAddress;
vm.destination.address = toAddress; vm.destination.address = toAddress;
vm.destination.kind = 'shapeshift'; vm.destination.kind = 'shapeshift';
}
ongoingProcess.set('connectingShapeshift', false); ongoingProcess.set('connectingShapeshift', false);
}); cb();
});
});
} }
});
});
});
} }
function onShareTransaction() { function onShareTransaction() {