async series with shapeshift & fee calculation
This commit is contained in:
parent
2c398bbe03
commit
fa8ce4779f
1 changed files with 84 additions and 75 deletions
|
|
@ -93,26 +93,48 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
configService.get(function onConfig(err, configCache) {
|
function _next() {
|
||||||
if (err) {
|
configService.get(function onConfig(err, configCache) {
|
||||||
$log.err('Error getting config.', err);
|
if (err) {
|
||||||
} else {
|
$log.err('Error getting config.', err);
|
||||||
config = configCache;
|
} else {
|
||||||
priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat';
|
config = configCache;
|
||||||
vm.origin.currencyColor = (vm.originWallet.coin === 'btc' ? defaults.bitcoinWalletColor : defaults.bitcoinCashWalletColor);
|
priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat';
|
||||||
console.log("coin", vm.originWallet.coin, vm.origin.currencyColor, config.bitcoinWalletColor, vm.originWallet.coin === 'btc');
|
vm.origin.currencyColor = (vm.originWallet.coin === 'btc' ? defaults.bitcoinWalletColor : defaults.bitcoinCashWalletColor);
|
||||||
unitFromSat = 1 / config.wallet.settings.unitToSatoshi;
|
console.log("coin", vm.originWallet.coin, vm.origin.currencyColor, config.bitcoinWalletColor, vm.originWallet.coin === 'btc');
|
||||||
}
|
unitFromSat = 1 / config.wallet.settings.unitToSatoshi;
|
||||||
updateSendAmounts();
|
}
|
||||||
getOriginWalletBalance(vm.originWallet);
|
updateSendAmounts();
|
||||||
handleDestinationAsAddress(toAddress, coin);
|
getOriginWalletBalance(vm.originWallet);
|
||||||
handleDestinationAsWallet(sendFlowData.toWalletId);
|
handleDestinationAsAddress(toAddress, coin);
|
||||||
createVanityTransaction(data);
|
handleDestinationAsWallet(sendFlowData.toWalletId);
|
||||||
});
|
createVanityTransaction(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vm.approve = function() {
|
vm.approve = function() {
|
||||||
|
|
@ -458,75 +480,62 @@ 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;
|
vm.destination.name = vm.thirdParty.name;
|
||||||
vm.destination.name = vm.thirdParty.name;
|
|
||||||
|
|
||||||
txPayproData = {
|
txPayproData = {
|
||||||
caTrusted: vm.thirdParty.caTrusted,
|
caTrusted: vm.thirdParty.caTrusted,
|
||||||
domain: vm.thirdParty.domain,
|
domain: vm.thirdParty.domain,
|
||||||
expires: vm.thirdParty.expires,
|
expires: vm.thirdParty.expires,
|
||||||
toAddress: toAddress,
|
toAddress: toAddress,
|
||||||
url: vm.thirdParty.url,
|
url: vm.thirdParty.url,
|
||||||
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 = {};
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var toWallet = profileService.getWallet(destinationWalletId);
|
var toWallet = profileService.getWallet(destinationWalletId);
|
||||||
vm.destination.name = toWallet.name;
|
vm.destination.name = toWallet.name;
|
||||||
vm.destination.color = toWallet.color;
|
vm.destination.color = toWallet.color;
|
||||||
vm.destination.currency = toWallet.coin.toUpperCase();
|
vm.destination.currency = toWallet.coin.toUpperCase();
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
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;
|
|
||||||
}
|
}
|
||||||
walletService.getAddress(toWallet, false, function onWithdrawalWalletAddress(err, withdrawalAddr) {
|
|
||||||
|
// 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) {
|
if (err) {
|
||||||
|
return cb(err);
|
||||||
|
} else {
|
||||||
|
vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId;
|
||||||
|
vm.memoExpanded = !!vm.memo;
|
||||||
|
tx.toAddress = shapeshiftData.toAddress;
|
||||||
|
vm.destination.address = toAddress;
|
||||||
|
vm.destination.kind = 'shapeshift';
|
||||||
ongoingProcess.set('connectingShapeshift', false);
|
ongoingProcess.set('connectingShapeshift', false);
|
||||||
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
|
cb();
|
||||||
$ionicHistory.goBack();
|
}
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err, function () {
|
|
||||||
$ionicHistory.goBack();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId;
|
|
||||||
vm.memoExpanded = !!vm.memo;
|
|
||||||
tx.toAddress = shapeshiftData.toAddress;
|
|
||||||
vm.destination.address = toAddress;
|
|
||||||
vm.destination.kind = 'shapeshift';
|
|
||||||
}
|
|
||||||
ongoingProcess.set('connectingShapeshift', false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onShareTransaction() {
|
function onShareTransaction() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue