Third Party Service integration (Shapeshift) (CSS + translations + wallet selector + routes)
This commit is contained in:
parent
281b969fc3
commit
42d77903e1
9 changed files with 143 additions and 129 deletions
|
|
@ -20,21 +20,6 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
|
|||
$scope.singleToWallet = $scope.toWallets.length === 1;
|
||||
}
|
||||
|
||||
// $scope.onFromWalletSelect = function(wallet) {
|
||||
// $scope.fromWallet = wallet;
|
||||
// showToWallets();
|
||||
// generateAddress(wallet, function(addr) {
|
||||
// $scope.fromWalletAddress = addr;
|
||||
// });
|
||||
// };
|
||||
//
|
||||
// $scope.onToWalletSelect = function(wallet) {
|
||||
// $scope.toWallet = wallet;
|
||||
// generateAddress(wallet, function(addr) {
|
||||
// $scope.toWalletAddress = addr;
|
||||
// });
|
||||
// };
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
walletsBtc = profileService.getWallets({coin: 'btc'});
|
||||
walletsBch = profileService.getWallets({coin: 'bch'});
|
||||
|
|
@ -42,22 +27,12 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
|
|||
return w.status.balance.availableAmount > 0;
|
||||
});
|
||||
|
||||
if ($scope.fromWallets.length === 0) {
|
||||
// return
|
||||
// } else {
|
||||
// $scope.onFromWalletSelect($scope.fromWallets[0]);
|
||||
}
|
||||
|
||||
// $scope.onToWalletSelect($scope.toWallets[0]);
|
||||
|
||||
$scope.singleFromWallet = $scope.fromWallets.length === 1;
|
||||
// $scope.singleToWallet = $scope.toWallets.length == 1;
|
||||
$scope.fromWalletSelectorTitle = 'From';
|
||||
$scope.toWalletSelectorTitle = 'To';
|
||||
$scope.showFromWallets = false;
|
||||
$scope.showToWallets = false;
|
||||
$scope.walletsWithFunds = profileService.getWallets({onlyComplete: true, hasFunds: true});
|
||||
console.log($scope.walletsWithFunds);
|
||||
$scope.wallets = profileService.getWallets({onlyComplete: true});
|
||||
$scope.hasWallets = !lodash.isEmpty($scope.wallets);
|
||||
});
|
||||
|
|
@ -89,12 +64,10 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
|
|||
|
||||
$scope.shapeshift = function() {
|
||||
var params = {
|
||||
thirdParty: {
|
||||
id: 'shapeshift'
|
||||
}
|
||||
thirdParty: JSON.stringify({id: 'shapeshift'})
|
||||
};
|
||||
$state.go('tabs.home').then(function() {
|
||||
$state.transitionTo('tabs.send', params);
|
||||
$state.transitionTo('tabs.send.origin', params);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $stateParams, $log, $ionicHistory, configService, gettextCatalog, profileService) {
|
||||
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, configService, gettextCatalog, profileService) {
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
var config = configService.getSync().wallet.settings;
|
||||
$scope.sendFlowTitle = "";
|
||||
|
||||
$scope.sendFlowTitle = "";
|
||||
if ($state.current.name === 'tabs.send.wallet-to-wallet') {
|
||||
$scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer');
|
||||
}
|
||||
|
||||
$scope.params = $stateParams;
|
||||
$scope.params = $state.params;
|
||||
$scope.coin = false; // Wallets to show (for destination screen or contacts)
|
||||
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
|
||||
|
||||
|
|
@ -21,14 +21,11 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
if ($scope.params.amount) { // There is an amount, so presume that it a payment request
|
||||
$scope.sendFlowTitle = gettextCatalog.getString('Payment request');
|
||||
$scope.specificAmount = $scope.specificAlternativeAmount = '';
|
||||
$scope.requestAmount = (($stateParams.amount) * (1 / config.unitToSatoshi)).toFixed(config.unitDecimals);
|
||||
$scope.requestAmount = (($state.params.amount) * (1 / config.unitToSatoshi)).toFixed(config.unitDecimals);
|
||||
$scope.isPaymentRequest = true;
|
||||
}
|
||||
if ($scope.params.thirdParty) {
|
||||
// Third Party Service
|
||||
if ($scope.params.thirdParty.id === 'shapeshift') {
|
||||
|
||||
}
|
||||
$scope.thirdParty = JSON.parse($scope.params.thirdParty); // Parse stringified JSON-object
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -48,6 +45,19 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send to');
|
||||
}
|
||||
|
||||
if ($scope.thirdParty) {
|
||||
|
||||
// Third party services specific logic
|
||||
|
||||
if ($scope.thirdParty.id === 'shapeshift' && $scope.type === 'destination') { // Shapeshift wants to know the
|
||||
if ($scope.coin === 'bch') {
|
||||
$scope.coin = 'btc';
|
||||
} else {
|
||||
$scope.coin = 'bch';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$scope.coin || $scope.coin === 'bch') { // if no specific coin is set or coin is set to bch
|
||||
$scope.walletsBch = profileService.getWallets({coin: 'bch', hasFunds: $scope.type==='origin'});
|
||||
}
|
||||
|
|
@ -57,6 +67,9 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
});
|
||||
|
||||
function getNextStep() {
|
||||
if ($scope.thirdParty) {
|
||||
$scope.params.thirdParty = JSON.stringify($scope.thirdParty) // re-stringify JSON-object
|
||||
}
|
||||
if (!$scope.params.toWalletId && !$scope.params.toAddress) { // If we have no toAddress or fromWallet
|
||||
return 'tabs.send.destination';
|
||||
} else if (!$scope.params.amount) { // If we have no amount
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
views: {
|
||||
'tab-send@tabs': {
|
||||
controller: 'walletSelectorController',
|
||||
templateUrl: 'views/wallet-origin-destination.html'
|
||||
templateUrl: 'views/walletSelector.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -309,7 +309,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
views: {
|
||||
'tab-send@tabs': {
|
||||
controller: 'walletSelectorController',
|
||||
templateUrl: 'views/wallet-origin-destination.html',
|
||||
templateUrl: 'views/walletSelector.html',
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -318,7 +318,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
views: {
|
||||
'tab-send@tabs': {
|
||||
controller: 'walletSelectorController',
|
||||
templateUrl: 'views/wallet-origin-destination.html',
|
||||
templateUrl: 'views/walletSelector.html',
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -995,7 +995,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
|
||||
/* Shapeshift */
|
||||
.state('tabs.shapeshift', {
|
||||
url: '/shapeshift',
|
||||
url: '/shapeshift/:fromWalletId/:toWalletId',
|
||||
views: {
|
||||
'tab-home@tabs': {
|
||||
controller: 'shapeshiftController',
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
$rootScope.$broadcast('incomingDataMenu.showMenu', data);
|
||||
};
|
||||
|
||||
root.redir = function(data, shapeshiftData) {
|
||||
root.redir = function(data, serviceId, serviceData) {
|
||||
var originalAddress = null;
|
||||
var noPrefixInAddress = 0;
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
return true;
|
||||
}
|
||||
|
||||
function goSend(addr, amount, message, coin, shapeshiftData) {
|
||||
function goSend(addr, amount, message, coin, serviceId, serviceData) {
|
||||
$state.go('tabs.send', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.send' ? false : true
|
||||
|
|
@ -97,11 +97,18 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
displayAddress: originalAddress ? originalAddress : addr,
|
||||
noPrefix: noPrefixInAddress
|
||||
};
|
||||
if (shapeshiftData) {
|
||||
params['fromWalletId'] = shapeshiftData.fromWalletId;
|
||||
params['minShapeshiftAmount'] = shapeshiftData.minAmount;
|
||||
params['maxShapeshiftAmount'] = shapeshiftData.maxAmount;
|
||||
params['shapeshiftOrderId'] = shapeshiftData.orderId;
|
||||
if (serviceId) {
|
||||
if (!params['thirdParty']) {
|
||||
params['thirdParty'] = [];
|
||||
}
|
||||
params['thirdParty']['id'] = serviceId;
|
||||
}
|
||||
|
||||
if (serviceData) {
|
||||
params['thirdParty']['data'] = serviceData;
|
||||
// params['thirdParty']['minShapeshiftAmount'] = serviceData.minAmount;
|
||||
// params['thirdParty']['maxShapeshiftAmount'] = serviceData.maxAmount;
|
||||
// params['thirdParty']['shapeshiftOrderId'] = serviceData.orderId;
|
||||
$state.transitionTo('tabs.send.amount', params);
|
||||
} else {
|
||||
$state.transitionTo('tabs.send.origin', params);
|
||||
|
|
@ -148,12 +155,12 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
if (parsed.r) {
|
||||
payproService.getPayProDetails(parsed.r, coin, function(err, details) {
|
||||
if (err) {
|
||||
if (addr && amount) goSend(addr, amount, message, coin, shapeshiftData);
|
||||
if (addr && amount) goSend(addr, amount, message, coin, serviceId, serviceData);
|
||||
else popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
} else handlePayPro(details, coin);
|
||||
});
|
||||
} else {
|
||||
goSend(addr, amount, message, coin, shapeshiftData);
|
||||
goSend(addr, amount, message, coin, serviceId, serviceData);
|
||||
}
|
||||
return true;
|
||||
// Cash URI
|
||||
|
|
@ -171,14 +178,14 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
payproService.getPayProDetails(parsed.r, coin, function(err, details) {
|
||||
if (err) {
|
||||
if (addr && amount)
|
||||
goSend(addr, amount, message, coin, shapeshiftData);
|
||||
goSend(addr, amount, message, coin, serviceId, serviceData);
|
||||
else
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
}
|
||||
handlePayPro(details, coin);
|
||||
});
|
||||
} else {
|
||||
goSend(addr, amount, message, coin, shapeshiftData);
|
||||
goSend(addr, amount, message, coin, serviceId, serviceData);
|
||||
}
|
||||
return true;
|
||||
|
||||
|
|
@ -214,14 +221,14 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
payproService.getPayProDetails(parsed.r, coin, function(err, details) {
|
||||
if (err) {
|
||||
if (addr && amount)
|
||||
goSend(addr, amount, message, coin, shapeshiftData);
|
||||
goSend(addr, amount, message, coin, serviceId, serviceData);
|
||||
else
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
}
|
||||
handlePayPro(details, coin);
|
||||
});
|
||||
} else {
|
||||
goSend(addr, amount, message, coin, shapeshiftData);
|
||||
goSend(addr, amount, message, coin, serviceId, serviceData);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,17 @@
|
|||
@include absolute-center();
|
||||
}
|
||||
|
||||
.third-party-notice {
|
||||
font-size: 12px;
|
||||
margin: 0px 14px;
|
||||
font-weight: 600;
|
||||
color: #6F6F70;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
@mixin empty-case() {
|
||||
padding-top: 5vh;
|
||||
text-align: center;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue