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() {
if (vm.shapeshiftOrderId) {
if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') {
$state.go('tabs.send').then(function() {
$ionicHistory.clearHistory();
$state.go('tabs.home').then(function() {
@ -483,29 +483,6 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
if (!confirmData.fromWalletId) {
$state.transitionTo('tabs.paymentRequest.confirm', confirmData);
} 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);
$scope.useSendMax = null;
}

View file

@ -4,7 +4,7 @@ angular
.module('copayApp.controllers')
.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;
vm.buttonText = '';
@ -82,7 +82,20 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
if (!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.memo) {
@ -115,8 +128,6 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
if (vm.thirdParty.id === 'shapeshift') {
shapeshiftService.shiftIt();
return;
}
if (!tx || !vm.originWallet) return;
if ($scope.paymentExpired) {

View file

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