Wallet/src/js/controllers/shapeshift.js

85 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-12-08 18:02:30 +09:00
'use strict';
angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, sendFlowService, $state, $timeout, $ionicHistory, profileService, walletService, popupService, lodash, $ionicNavBarDelegate) {
2017-12-12 17:15:39 +09:00
var walletsBtc = [];
var walletsBch = [];
2018-08-17 11:59:27 +12:00
$scope.showMyAddress = showMyAddress;
2017-12-12 17:15:39 +09:00
function generateAddress(wallet, cb) {
if (!wallet) return;
walletService.getAddress(wallet, false, function(err, addr) {
if (err) {
popupService.showAlert(err);
}
return cb(addr);
});
}
function showToWallets() {
2018-07-31 15:03:20 +02:00
$scope.toWallets = $scope.fromWallet.coin === 'btc' ? walletsBch : walletsBtc;
2017-12-12 17:15:39 +09:00
$scope.onToWalletSelect($scope.toWallets[0]);
2018-07-31 15:03:20 +02:00
$scope.singleToWallet = $scope.toWallets.length === 1;
}
2017-12-12 17:15:39 +09:00
$scope.$on("$ionicView.beforeEnter", function(event, data) {
walletsBtc = profileService.getWallets({coin: 'btc'});
walletsBch = profileService.getWallets({coin: 'bch'});
$scope.fromWallets = lodash.filter(walletsBtc.concat(walletsBch), function(w) {
return w.status.balance.availableAmount > 0;
});
2018-07-31 15:03:20 +02:00
$scope.singleFromWallet = $scope.fromWallets.length === 1;
$scope.fromWalletSelectorTitle = 'From';
2017-12-12 17:15:39 +09:00
$scope.toWalletSelectorTitle = 'To';
$scope.showFromWallets = false;
$scope.showToWallets = false;
2018-07-31 15:03:20 +02:00
$scope.walletsWithFunds = profileService.getWallets({onlyComplete: true, hasFunds: true});
$scope.wallets = profileService.getWallets({onlyComplete: true});
$scope.hasWallets = !lodash.isEmpty($scope.wallets);
2017-12-12 17:15:39 +09:00
});
$scope.$on("$ionicView.enter", function(event, data) {
$ionicNavBarDelegate.showBar(true);
});
2018-07-31 15:03:20 +02:00
// This could probably be enhanced refactoring the routes abstract states
$scope.createWallet = function() {
$state.go('tabs.home').then(function() {
$state.go('tabs.add.create-personal');
});
};
$scope.buyBitcoin = function() {
$state.go('tabs.home').then(function() {
$state.go('tabs.buyandsell');
});
};
$scope.shapeshift = function() {
var stateParams = {
thirdParty: {
id: 'shapeshift'
}
2018-07-31 15:03:20 +02:00
};
2018-08-08 22:32:18 +09:00
// Starting new send flow, so ensure everything is reset
sendFlowService.clear();
2018-07-31 15:03:20 +02:00
$state.go('tabs.home').then(function() {
2018-08-08 22:32:18 +09:00
$ionicHistory.clearHistory();
$state.go('tabs.send').then(function() {
$timeout(function () {
sendFlowService.pushState(stateParams);
$state.transitionTo('tabs.send.origin');
2018-08-08 22:32:18 +09:00
}, 60);
});
2018-07-31 15:03:20 +02:00
});
2017-12-12 17:15:39 +09:00
}
2018-08-17 11:59:27 +12:00
function showMyAddress() {
$state.go('tabs.home').then(function() {
$state.go('tabs.receive');
});
}
2017-12-12 17:15:39 +09:00
});