2017-12-08 18:02:30 +09:00
|
|
|
'use strict';
|
|
|
|
|
|
2018-02-28 14:15:44 +05:00
|
|
|
angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, $interval, profileService, walletService, popupService, lodash, $ionicNavBarDelegate) {
|
2018-07-30 19:28:30 +12:00
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
|
|
//vm.buyBitcion = buyBitcoin;
|
2017-12-12 17:15:39 +09:00
|
|
|
|
|
|
|
|
var walletsBtc = [];
|
|
|
|
|
var walletsBch = [];
|
|
|
|
|
|
|
|
|
|
function generateAddress(wallet, cb) {
|
|
|
|
|
if (!wallet) return;
|
|
|
|
|
walletService.getAddress(wallet, false, function(err, addr) {
|
|
|
|
|
if (err) {
|
|
|
|
|
popupService.showAlert(err);
|
|
|
|
|
}
|
|
|
|
|
return cb(addr);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showToWallets() {
|
|
|
|
|
$scope.toWallets = $scope.fromWallet.coin == 'btc' ? walletsBch : walletsBtc;
|
|
|
|
|
$scope.onToWalletSelect($scope.toWallets[0]);
|
|
|
|
|
$scope.singleToWallet = $scope.toWallets.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 19:28:30 +12:00
|
|
|
function buyBitcoin() {
|
|
|
|
|
console.log('buyBitcoin()');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.buyBitcoin = buyBitcoin;
|
|
|
|
|
|
2017-12-12 17:15:39 +09:00
|
|
|
$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) {
|
2018-07-30 19:28:30 +12:00
|
|
|
console.log('beforeEnter()');
|
2017-12-12 17:15:39 +09:00
|
|
|
walletsBtc = profileService.getWallets({coin: 'btc'});
|
|
|
|
|
walletsBch = profileService.getWallets({coin: 'bch'});
|
2017-12-14 13:26:58 +09:00
|
|
|
$scope.fromWallets = lodash.filter(walletsBtc.concat(walletsBch), function(w) {
|
|
|
|
|
return w.status.balance.availableAmount > 0;
|
|
|
|
|
});
|
2018-07-30 19:28:30 +12:00
|
|
|
console.log('Checking wallets.');
|
|
|
|
|
if ($scope.fromWallets.length == 0) {
|
|
|
|
|
// Need to go to new origin screen here, with parameters
|
|
|
|
|
var params = {
|
|
|
|
|
thirdParty: {
|
|
|
|
|
id: 'shapeshift'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
console.log('Asking for transition');
|
|
|
|
|
$state.transitionTo('tabs.send', params);
|
|
|
|
|
return
|
|
|
|
|
}
|
2017-12-12 17:15:39 +09:00
|
|
|
$scope.onFromWalletSelect($scope.fromWallets[0]);
|
|
|
|
|
$scope.onToWalletSelect($scope.toWallets[0]);
|
|
|
|
|
$scope.singleFromWallet = $scope.fromWallets.length == 1;
|
|
|
|
|
$scope.singleToWallet = $scope.toWallets.length == 1;
|
2017-12-14 13:26:58 +09:00
|
|
|
$scope.fromWalletSelectorTitle = 'From';
|
2017-12-12 17:15:39 +09:00
|
|
|
$scope.toWalletSelectorTitle = 'To';
|
|
|
|
|
$scope.showFromWallets = false;
|
|
|
|
|
$scope.showToWallets = false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-02-28 14:15:44 +05:00
|
|
|
$scope.$on("$ionicView.enter", function(event, data) {
|
|
|
|
|
$ionicNavBarDelegate.showBar(true);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-12 17:15:39 +09:00
|
|
|
$scope.showFromWalletSelector = function() {
|
|
|
|
|
$scope.showFromWallets = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.showToWalletSelector = function() {
|
|
|
|
|
$scope.showToWallets = true;
|
|
|
|
|
}
|
|
|
|
|
});
|