added lots of shapeshift related code
This commit is contained in:
parent
2f07290dea
commit
c4c8008573
12 changed files with 669 additions and 0 deletions
17
src/js/directives/shapeshiftCoinDepositInfo.js
Normal file
17
src/js/directives/shapeshiftCoinDepositInfo.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.directives').directive('shapeshiftCoinDepositInfo', function(shapeshiftApiService) {
|
||||
return {
|
||||
require:['^shapeshiftCoinTrader'],
|
||||
restrict: 'E',
|
||||
transclude: true,
|
||||
scope: {
|
||||
depositInfo : '=depositInfo',
|
||||
DepositStatus :'=depositStatus'
|
||||
},
|
||||
link: function(scope, element, attrs, controllers) {
|
||||
|
||||
},
|
||||
templateUrl: 'views/includes/shapeshift-coin-deposit-info.html'
|
||||
}
|
||||
});
|
||||
16
src/js/directives/shapeshiftCoinError.js
Normal file
16
src/js/directives/shapeshiftCoinError.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.directives').directive('shapeshiftCoinError', function(shapeshiftApiService) {
|
||||
return {
|
||||
require:['^shapeshiftCoinTrader'],
|
||||
restrict: 'E',
|
||||
transclude: true,
|
||||
scope: {
|
||||
depositInfo : '=ssError'
|
||||
},
|
||||
link: function(scope, element, attrs, controllers) {
|
||||
|
||||
},
|
||||
templateUrl: 'views/includes/shapeshift-coin-error.html'
|
||||
}
|
||||
});
|
||||
37
src/js/directives/shapeshiftCoinSelector.js
Normal file
37
src/js/directives/shapeshiftCoinSelector.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.directives').directive('shapeshiftCoinSelector', function(shapeshiftApiService) {
|
||||
return {
|
||||
require:['^shapeshiftCoinTrader'],
|
||||
restrict: 'E',
|
||||
transclude: false,
|
||||
scope: {
|
||||
coins: '=coins',
|
||||
label:'=label',
|
||||
selectedCoin:'=selectedCoin',
|
||||
getMarketData: '=getMarketData',
|
||||
amount:'=amount',
|
||||
marketData:'=marketData',
|
||||
coinAddress:'=coinAddress',
|
||||
direction:'=direction',
|
||||
},
|
||||
link: function(scope, element, attrs, controllers) {
|
||||
var coinTraderCtrl = controllers[0];
|
||||
|
||||
scope.selectedCoinModel = {
|
||||
coin: scope.selectedCoin
|
||||
}
|
||||
|
||||
scope.$watch('coinAddress', function(newVal){
|
||||
if(scope.direction === 'in')
|
||||
coinTraderCtrl.returnAddress(newVal);
|
||||
else if(scope.direction === 'out')
|
||||
coinTraderCtrl.withdrawalAddress(newVal);
|
||||
});
|
||||
scope.$watch('amount', function(newVal){
|
||||
coinTraderCtrl.amount(newVal)
|
||||
});
|
||||
},
|
||||
templateUrl: 'views/includes/shapeshift-coin-selector.html'
|
||||
}
|
||||
});
|
||||
17
src/js/directives/shapeshiftCoinShiftButton.js
Normal file
17
src/js/directives/shapeshiftCoinShiftButton.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.directives').directive('shapeshiftCoinShiftButton', function(shapeshiftApiService) {
|
||||
return {
|
||||
require:['^shapeshiftCoinTrader'],
|
||||
restrict: 'E',
|
||||
transclude: true,
|
||||
scope: {
|
||||
ShiftState : '=shiftState',
|
||||
shiftIt : '=shiftIt'
|
||||
},
|
||||
link: function(scope, element, attrs, controllers) {
|
||||
console.log(scope.ShiftState)
|
||||
},
|
||||
templateUrl: 'views/includes/shapeshift-coin-shift-button.html'
|
||||
}
|
||||
});
|
||||
152
src/js/directives/shapeshiftCoinTrader.js
Normal file
152
src/js/directives/shapeshiftCoinTrader.js
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function($interval, shapeshiftApiService, profileService) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
transclude: true,
|
||||
controller: function($scope, $q) {
|
||||
$scope.ShiftState = 'Shift';
|
||||
$scope.withdrawalAddress = ''
|
||||
$scope.returnAddress = ''
|
||||
$scope.amount = '';
|
||||
$scope.marketData = {}
|
||||
this.withdrawalAddress = function(address) {
|
||||
$scope.withdrawalAddress = address;
|
||||
};
|
||||
this.returnAddress = function(address) {
|
||||
$scope.returnAddress = address;
|
||||
};
|
||||
this.amount = function(amount) {
|
||||
$scope.amount = amount;
|
||||
};
|
||||
|
||||
$scope.getMarketDataIn = function(coin) {
|
||||
if(coin === $scope.coinOut) return $scope.getMarketData($scope.coinOut, $scope.coinIn);
|
||||
return $scope.getMarketData(coin, $scope.coinOut);
|
||||
};
|
||||
$scope.getMarketDataOut = function(coin) {
|
||||
if(coin === $scope.coinIn) return $scope.getMarketData($scope.coinOut, $scope.coinIn);
|
||||
return $scope.getMarketData($scope.coinIn, coin);
|
||||
};
|
||||
$scope.getMarketData = function(coinIn, coinOut) {
|
||||
$scope.coinIn = coinIn;
|
||||
$scope.coinOut= coinOut;
|
||||
if($scope.coinIn === undefined || $scope.coinOut === undefined) return;
|
||||
shapeshiftApiService
|
||||
.marketInfo($scope.coinIn, $scope.coinOut)
|
||||
.then(function(marketData){
|
||||
$scope.marketData = marketData;
|
||||
});
|
||||
};
|
||||
|
||||
/*shapeshiftApiService.coins().then(function(coins){
|
||||
$scope.coins = coins;
|
||||
$scope.coinIn = coins['BTC'].symbol;
|
||||
$scope.coinOut = coins['BCH'].symbol;
|
||||
$scope.getMarketData($scope.coinIn, $scope.coinOut);
|
||||
});*/
|
||||
|
||||
$scope.coins = {
|
||||
'BTC': { name: 'Bitcoin', symbol: 'BTC' },
|
||||
'BCH': { name: 'Bitcoin Cash', symbol: 'BCH' }
|
||||
};
|
||||
$scope.coinIn = $scope.coins['BTC'].symbol;
|
||||
$scope.coinOut = $scope.coins['BCH'].symbol;
|
||||
$scope.getMarketData($scope.coinIn, $scope.coinOut);
|
||||
|
||||
function checkForError(data){
|
||||
if(data.error) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
$scope.shiftIt = function(){
|
||||
console.log($scope.coinOut)
|
||||
var validate=shapeshiftApiService.ValidateAddress($scope.withdrawalAddress, $scope.coinOut);
|
||||
validate.then(function(valid){
|
||||
console.log($scope.withdrawalAddress)
|
||||
console.log(valid)
|
||||
var tx = ShapeShift();
|
||||
tx.then(function(txData){
|
||||
if(txData['fixedTxData']){
|
||||
txData = txData.fixedTxData;
|
||||
if(checkForError(txData)) return;
|
||||
console.log(txData)
|
||||
var coinPair=txData.pair.split('_');
|
||||
txData.depositType = coinPair[0].toUpperCase();
|
||||
txData.withdrawalType = coinPair[1].toUpperCase();
|
||||
var coin = $scope.coins[txData.depositType].name.toLowerCase();
|
||||
console.log(coin)
|
||||
txData.depositQR = coin + ":" + txData.deposit + "?amount=" + txData.depositAmount
|
||||
$scope.txFixedPending = true;
|
||||
} else if(txData['normalTxData']){
|
||||
txData = txData.normalTxData;
|
||||
if(checkForError(txData)) return;
|
||||
var coin = $scope.coins[txData.depositType.toUpperCase()].name.toLowerCase();
|
||||
txData.depositQR = coin + ":" + txData.deposit;
|
||||
|
||||
} else if(txData['cancelTxData']){
|
||||
if(checkForError(txData.cancelTxData)) return;
|
||||
if($scope.txFixedPending) {
|
||||
$interval.cancel($scope.txInterval);
|
||||
$scope.txFixedPending = false;
|
||||
}
|
||||
$scope.ShiftState = 'Shift';
|
||||
return;
|
||||
}
|
||||
$scope.depositInfo = txData;
|
||||
console.log($scope.depositInfo)
|
||||
$scope.ShiftState = 'Cancel';
|
||||
$scope.GetStatus();
|
||||
$scope.txInterval=$interval($scope.GetStatus, 8000);
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
function ShapeShift() {
|
||||
if($scope.ShiftState === 'Cancel') return shapeshiftApiService.CancelTx($scope);
|
||||
if(parseFloat($scope.amount) > 0) return shapeshiftApiService.FixedAmountTx($scope);
|
||||
return shapeshiftApiService.NormalTx($scope);
|
||||
}
|
||||
|
||||
$scope.GetStatus = function(){
|
||||
var address = $scope.depositInfo.deposit
|
||||
shapeshiftApiService.GetStatusOfDepositToAddress(address).then(function(data){
|
||||
$scope.DepositStatus = data;
|
||||
if($scope.DepositStatus.status === 'complete'){
|
||||
$interval.cancel($scope.txInterval);
|
||||
$scope.depositInfo = null;
|
||||
$scope.ShiftState = 'Shift'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$scope.walletsBtc = profileService.getWallets({coin: 'btc'});
|
||||
$scope.walletsBch = profileService.getWallets({coin: 'bch'});
|
||||
$scope.fromWallet = $scope.walletsBtc[0];
|
||||
$scope.toWallet = $scope.walletsBch[0];
|
||||
$scope.fromWalletSelectorTitle = 'From';
|
||||
$scope.toWalletSelectorTitle = 'To';
|
||||
$scope.showFromWallets = false;
|
||||
$scope.showFromWalletSelector = function() {
|
||||
$scope.showFromWallets = true;
|
||||
}
|
||||
$scope.showToWallets = false;
|
||||
$scope.showToWalletSelector = function() {
|
||||
$scope.showToWallets = true;
|
||||
}
|
||||
|
||||
$scope.onFromWalletSelect = function(wallet) {
|
||||
$scope.fromWallet = wallet;
|
||||
//setProtocolHandler();
|
||||
//$scope.setAddress();
|
||||
};
|
||||
|
||||
$scope.onToWalletSelect = function(wallet) {
|
||||
$scope.toWallet = wallet;
|
||||
//setProtocolHandler();
|
||||
//$scope.setAddress();
|
||||
}
|
||||
},
|
||||
templateUrl: 'views/includes/shapeshift-coin-trader.html'
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue