shapeshift controller

This commit is contained in:
Sebastiaan Pasma 2018-08-06 18:06:10 +02:00
commit caafec4625
No known key found for this signature in database
GPG key ID: 9A2B0C8B95A1D26F
5 changed files with 89 additions and 90 deletions

View file

@ -217,7 +217,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
}; };
function goBack() { function goBack() {
if (vm.shapeshiftOrderId) { if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') {
$state.go('tabs.send').then(function() { $state.go('tabs.send').then(function() {
$ionicHistory.clearHistory(); $ionicHistory.clearHistory();
$state.go('tabs.home').then(function() { $state.go('tabs.home').then(function() {
@ -483,29 +483,6 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
if (!confirmData.fromWalletId) { if (!confirmData.fromWalletId) {
$state.transitionTo('tabs.paymentRequest.confirm', confirmData); $state.transitionTo('tabs.paymentRequest.confirm', confirmData);
} else { } else {
if (vm.shapeshiftOrderId) {
var shapeshiftOrderUrl = 'https://www.shapeshift.io/#/status/';
shapeshiftOrderUrl += vm.shapeshiftOrderId;
confirmData.description = shapeshiftOrderUrl;
if (confirmData.sendMax) {
var wallet = lodash.find(profileService.getWallets({ coin: coin }),
function(w) {
return w.id == passthroughParams.fromWalletId;
});
var balance = parseFloat(wallet.cachedBalance.substring(0, wallet.cachedBalance.length-4));
if (balance < vm.minAmount * 1.04) {
confirmData.sendMax = false;
confirmData.amount = vm.minAmount * unitToSatoshi;
} else if (balance > vm.maxAmount) {
confirmData.sendMax = false;
confirmData.amount = vm.maxAmount * unitToSatoshi * 0.99;
}
}
}
$state.transitionTo('tabs.send.review', confirmData); $state.transitionTo('tabs.send.review', confirmData);
$scope.useSendMax = null; $scope.useSendMax = null;
} }

View file

@ -4,7 +4,7 @@ angular
.module('copayApp.controllers') .module('copayApp.controllers')
.controller('reviewController', reviewController); .controller('reviewController', reviewController);
function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, configService, feeService, gettextCatalog, $ionicHistory, $ionicLoading, $ionicModal, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) { function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, configService, feeService, gettextCatalog, $ionicHistory, $ionicLoading, $ionicModal, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) {
var vm = this; var vm = this;
vm.buttonText = ''; vm.buttonText = '';
@ -82,7 +82,20 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
if (!vm.thirdParty.data) { if (!vm.thirdParty.data) {
vm.thirdParty.data = {}; vm.thirdParty.data = {};
} }
vm.thirdParty.data['fromWalletId'] = vm.fromWalletId;
var toWallet = profileService.getWallet(data.stateParams.toWalletId);
$ionicLoading.show();
walletService.getAddress(vm.originWallet, false, function onWalletAddress(err, returnAddr) {
walletService.getAddress(toWallet, false, function onWalletAddress(err, withdrawalAddr) {
$ionicLoading.hide();
shapeshiftService.shiftIt(vm.originWallet.coin, toWallet.coin, withdrawalAddr, returnAddr, function(shapeshiftData) {
vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/'+shapeshiftData.orderId;
toAddress = shapeshiftData.toAddress;
vm.destination.address = toAddress;
vm.destination.kind = 'shapeshift';
});
});
});
} }
if (vm.thirdParty.id === 'bip70') { if (vm.thirdParty.id === 'bip70') {
if (vm.thirdParty.memo) { if (vm.thirdParty.memo) {
@ -115,8 +128,6 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
if (vm.thirdParty.id === 'shapeshift') { if (vm.thirdParty.id === 'shapeshift') {
shapeshiftService.shiftIt(); shapeshiftService.shiftIt();
return; return;
}
if (!tx || !vm.originWallet) return; if (!tx || !vm.originWallet) return;
if ($scope.paymentExpired) { if ($scope.paymentExpired) {

View file

@ -103,6 +103,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
function handleThirdPartyIfShapeshift() { function handleThirdPartyIfShapeshift() {
if ($scope.thirdParty.id === 'shapeshift' && $scope.type === 'destination') { // Shapeshift wants to know the if ($scope.thirdParty.id === 'shapeshift' && $scope.type === 'destination') { // Shapeshift wants to know the
$scope.coin = profileService.getWallet(fromWalletId).coin;
if ($scope.coin === 'bch') { if ($scope.coin === 'bch') {
$scope.coin = 'btc'; $scope.coin = 'btc';
} else { } else {

View file

@ -2,10 +2,12 @@
angular.module('copayApp.services').factory('shapeshiftService', function ($http, $interval, $log, lodash, moment, ongoingProcess, shapeshiftApiService, storageService, configService, incomingData, platformInfo, servicesService) { angular.module('copayApp.services').factory('shapeshiftService', function ($http, $interval, $log, lodash, moment, ongoingProcess, shapeshiftApiService, storageService, configService, incomingData, platformInfo, servicesService) {
var root = {}; var root = {};
root.ShiftState = 'Shift'; root.ShiftState = 'Shift';
root.withdrawalAddress = '' root.coinIn = '';
root.returnAddress = '' root.coinOut = '';
root.withdrawalAddress = '';
root.returnAddress = '';
root.amount = ''; root.amount = '';
root.marketData = {} root.marketData = {};
root.withdrawalAddress = function (address) { root.withdrawalAddress = function (address) {
root.withdrawalAddress = address; root.withdrawalAddress = address;
}; };
@ -15,12 +17,6 @@ angular.module('copayApp.services').factory('shapeshiftService', function($http,
root.amount = function (amount) { root.amount = function (amount) {
root.amount = amount; root.amount = amount;
}; };
root.fromWalletId = function(id) {
root.fromWalletId = id;
};
root.toWalletId = function(id) {
root.toWalletId = id;
};
root.coinIn = function (coinIn) { root.coinIn = function (coinIn) {
root.coinIn = coinIn.toUpperCase(); root.coinIn = coinIn.toUpperCase();
}; };
@ -68,14 +64,17 @@ angular.module('copayApp.services').factory('shapeshiftService', function($http,
return false; return false;
} }
root.shiftIt = function(){ root.shiftIt = function (coinIn, coinOut, withdrawalAddress, returnAddress, cb) {
ongoingProcess.set('connectingShapeshift', true); ongoingProcess.set('connectingShapeshift', true);
var validate=shapeshiftApiService.ValidateAddress(root.withdrawalAddress, root.coinOut); root.withdrawalAddress(withdrawalAddress);
root.returnAddress(returnAddress);
var validate = shapeshiftApiService.ValidateAddress(withdrawalAddress, coinOut);
validate.then(function (valid) { validate.then(function (valid) {
//console.log(root.withdrawalAddress)
//console.log(valid)
var tx = ShapeShift(); var tx = ShapeShift();
var coin;
console.log("Starting");
tx.then(function (txData) { tx.then(function (txData) {
console.log("Got txData", txData);
if (txData['fixedTxData']) { if (txData['fixedTxData']) {
txData = txData.fixedTxData; txData = txData.fixedTxData;
if (checkForError(txData)) return; if (checkForError(txData)) return;
@ -83,19 +82,23 @@ angular.module('copayApp.services').factory('shapeshiftService', function($http,
var coinPair = txData.pair.split('_'); var coinPair = txData.pair.split('_');
txData.depositType = coinPair[0].toUpperCase(); txData.depositType = coinPair[0].toUpperCase();
txData.withdrawalType = coinPair[1].toUpperCase(); txData.withdrawalType = coinPair[1].toUpperCase();
var coin = root.coins[txData.depositType].name.toLowerCase(); coin = root.coins[txData.depositType].name.toLowerCase();
//console.log(coin)
txData.depositQR = coin + ":" + txData.deposit + "?amount=" + txData.depositAmount txData.depositQR = coin + ":" + txData.deposit + "?amount=" + txData.depositAmount;
root.txFixedPending = true; root.txFixedPending = true;
} else if (txData['normalTxData']) { } else if (txData['normalTxData']) {
txData = txData.normalTxData; txData = txData.normalTxData;
if (checkForError(txData)) return; if (checkForError(txData)) return;
var coin = root.coins[txData.depositType.toUpperCase()].name.toLowerCase(); coin = root.coins[txData.depositType.toUpperCase()].name.toLowerCase();
txData.depositQR = coin + ":" + txData.deposit; txData.depositQR = coin + ":" + txData.deposit;
} else if (txData['cancelTxData']) { } else if (txData['cancelTxData']) {
if (checkForError(txData.cancelTxData)) return; if (checkForError(txData.cancelTxData)) return;
if (root.txFixedPending) { if (root.txFixedPending) {
$interval.cancel(root.txInterval);
root.txFixedPending = false; root.txFixedPending = false;
} }
root.ShiftState = 'Shift'; root.ShiftState = 'Shift';
@ -108,22 +111,28 @@ angular.module('copayApp.services').factory('shapeshiftService', function($http,
if (sendAddress && sendAddress.indexOf('bitcoin cash') >= 0) if (sendAddress && sendAddress.indexOf('bitcoin cash') >= 0)
sendAddress = sendAddress.replace('bitcoin cash', 'bitcoincash'); sendAddress = sendAddress.replace('bitcoin cash', 'bitcoincash');
ongoingProcess.set('connectingShapeshift', false);
root.ShiftState = 'Cancel';
root.GetStatus();
root.txInterval=$interval(root.GetStatus, 8000);
var shapeshiftData = { var shapeshiftData = {
fromWalletId: root.fromWalletId, coinIn: coinIn,
coinOut: coinOut,
toWalletId: root.toWalletId, toWalletId: root.toWalletId,
minAmount: root.marketData.minimum, minAmount: root.marketData.minimum,
maxAmount: root.marketData.maxLimit, maxAmount: root.marketData.maxLimit,
orderId: root.depositInfo.orderId orderId: root.depositInfo.orderId,
toAddress: txData.deposit
}; };
//
if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) { // if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) {
ongoingProcess.set('connectingShapeshift', false); ongoingProcess.set('connectingShapeshift', false);
return; // return;
} // }
cb(shapeshiftData);
/*root.ShiftState = 'Cancel';
root.GetStatus();
root.txInterval=$interval(root.GetStatus, 8000);*/
}); });
}) })
}; };

View file

@ -32,13 +32,14 @@
</div> </div>
</div> </div>
</div> </div>
<div class="card card-gutter-compact"> <div class="card card-gutter-compact">
<div class="item item-compact" translate>To:</div> <div class="item item-compact" translate>To:</div>
<div class="item item-gutterless item-complex item-avatar"> <div class="item item-gutterless item-complex item-avatar">
<div class="item-content item-content-avatar" <div class="item-content item-content-avatar"
ng-if="vm.destination.kind === 'contact' || vm.destination.kind === 'wallet'"> ng-if="vm.destination.kind === 'contact' || vm.destination.kind === 'wallet'">
<img src="img/contact-placeholder.svg" class="bg" ng-if="vm.destination.kind === 'contact'"> <img src="img/contact-placeholder.svg" class="bg" ng-if="vm.destination.kind === 'contact'">
<i class="icon big-icon-svg theme-circle theme-circle-services" ng-if="vm.destination.kind === 'wallet'"> <i class="icon big-icon-svg theme-circle theme-circle-services" ng-if="vm.destination.kind === 'wallet' || vm.destination.kind === 'shapeshift'">
<div class="bg icon-wallet" <div class="bg icon-wallet"
style="background-color: {{vm.destination.color}}" style="background-color: {{vm.destination.color}}"
></div> ></div>