diff --git a/app-template/bitcoincom/css/bitcoin.com.css b/app-template/bitcoincom/css/bitcoin.com.css index 44ac6ed99..4fe29bd55 100644 --- a/app-template/bitcoincom/css/bitcoin.com.css +++ b/app-template/bitcoincom/css/bitcoin.com.css @@ -206,3 +206,17 @@ div.onboarding-topic { .light-green { color:#26B03C; } + +.shapeshift-banner { + background: url(../img/shapeshiftbg.jpg) center center no-repeat #28394d; + padding: 10px; + box-shadow: 0px 5px 10px 0px #cccccc; + height: 5em; +} + +.shapeshift-logo { + display: block; + float: left; + max-height: 100%; + max-width: 100%; +} diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index e5fcf07e6..d5ac39001 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -1,6 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, popupService, bwcError, payproService, profileService, bitcore, amazonService, nodeWebkitService) { + var _id; var unitToSatoshi; var satToUnit; @@ -24,6 +25,12 @@ angular.module('copayApp.controllers').controller('amountController', function($ }); $scope.$on("$ionicView.beforeEnter", function(event, data) { + + if (data.stateParams.minShapeshiftAmount.length > 0 && data.stateParams.maxShapeshiftAmount.length > 0) { + $scope.minShapeshiftAmount = parseFloat(data.stateParams.minShapeshiftAmount); + $scope.maxShapeshiftAmount = parseFloat(data.stateParams.maxShapeshiftAmount); + } + var config = configService.getSync().wallet.settings; function setAvailableUnits() { @@ -297,7 +304,11 @@ angular.module('copayApp.controllers').controller('amountController', function($ function processAmount() { var formatedValue = format($scope.amount); var result = evaluate(formatedValue); - $scope.allowSend = lodash.isNumber(result) && +result > 0; + $scope.allowSend = lodash.isNumber(result) && +result > 0 + && ((!$scope.minShapeshiftAmount && !$scope.maxShapeshiftAmount) + || ($scope.minShapeshiftAmount && $scope.maxShapeshiftAmount + && result >= $scope.minShapeshiftAmount && result <= $scope.maxShapeshiftAmount)); + if (lodash.isNumber(result)) { $scope.globalResult = isExpression($scope.amount) ? '= ' + processResult(result) : ''; diff --git a/src/js/controllers/shapeshift.js b/src/js/controllers/shapeshift.js index 29e5a70a2..2d43c0ec1 100644 --- a/src/js/controllers/shapeshift.js +++ b/src/js/controllers/shapeshift.js @@ -1,3 +1,80 @@ 'use strict'; -angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, $interval){ }); +angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, $interval, profileService, walletService, popupService) { + + 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; + } + + $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'}); + $scope.fromWallets = walletsBtc.concat(walletsBch); + $scope.toWallets = walletsBch; + if ($scope.fromWallets.length == 0 || $scope.toWallets.length == 0) return; + $scope.onFromWalletSelect($scope.fromWallets[0]); + $scope.onToWalletSelect($scope.toWallets[0]); + $scope.singleFromWallet = $scope.fromWallets.length == 1; + $scope.singleToWallet = $scope.toWallets.length == 1; + $scope.toWalletSelectorTitle = 'To'; + $scope.showFromWallets = false; + $scope.showToWallets = false; + }); + + $scope.showFromWalletSelector = function() { + $scope.showFromWallets = true; + } + + $scope.showToWalletSelector = function() { + $scope.showToWallets = true; + } + + /*var setAddress = function(newAddr) { + $scope.addr = null; + if (!$scope.wallet || $scope.generatingAddress || !$scope.wallet.isComplete()) return; + $scope.generatingAddress = true; + walletService.getAddress($scope.wallet, newAddr, function(err, addr) { + $scope.generatingAddress = false; + + if (err) { + //Error is already formated + popupService.showAlert(err); + } + + $scope.addr = addr; + $timeout(function() { + $scope.$apply(); + }, 10); + }); + };*/ +}); diff --git a/src/js/directives/shapeshiftCoinSelector.js b/src/js/directives/shapeshiftCoinSelector.js index a5601be6b..93ac02c1b 100644 --- a/src/js/directives/shapeshiftCoinSelector.js +++ b/src/js/directives/shapeshiftCoinSelector.js @@ -22,13 +22,17 @@ angular.module('copayApp.directives').directive('shapeshiftCoinSelector', functi coin: scope.selectedCoin } - scope.$watch('coinAddress', function(newVal){ + scope.$watch('selectedCoin', function(newVal) { + scope.getMarketData(newVal); + }); + + 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){ + scope.$watch('amount', function(newVal) { coinTraderCtrl.amount(newVal) }); }, diff --git a/src/js/directives/shapeshiftCoinTrader.js b/src/js/directives/shapeshiftCoinTrader.js index deab44dfe..9b66129fc 100644 --- a/src/js/directives/shapeshiftCoinTrader.js +++ b/src/js/directives/shapeshiftCoinTrader.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function($interval, shapeshiftApiService, profileService) { +angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function($interval, shapeshiftApiService, profileService, incomingData) { return { restrict: 'E', transclude: true, @@ -36,6 +36,7 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function .marketInfo($scope.coinIn, $scope.coinOut) .then(function(marketData){ $scope.marketData = marketData; + $scope.rateString = $scope.marketData.rate.toString() + ' ' + coinOut.toUpperCase() + '/' + coinIn.toUpperCase(); }); }; @@ -50,9 +51,6 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function '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; @@ -60,22 +58,21 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function } $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) + //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) + //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) + //console.log(coin) txData.depositQR = coin + ":" + txData.deposit + "?amount=" + txData.depositAmount $scope.txFixedPending = true; } else if(txData['normalTxData']){ @@ -94,7 +91,20 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function return; } $scope.depositInfo = txData; - console.log($scope.depositInfo) + console.log($scope.marketData); + console.log($scope.depositInfo); + var sendAddress = txData.depositQR; + if (sendAddress && sendAddress.indexOf('bitcoin cash') >= 0) + sendAddress = sendAddress.replace('bitcoin cash', 'bitcoincash'); + + var shapeshiftData = { + minAmount: $scope.marketData.minimum, + maxAmount: $scope.marketData.maxLimit + }; + + if (incomingData.redir(sendAddress, shapeshiftData)) + return; + $scope.ShiftState = 'Cancel'; $scope.GetStatus(); $scope.txInterval=$interval($scope.GetStatus, 8000); @@ -119,33 +129,6 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function } }); } - - $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' } diff --git a/src/js/routes.js b/src/js/routes.js index fc7d83df0..a9ce5e8bc 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -287,7 +287,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr */ .state('tabs.send.amount', { - url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin/:fixedUnit', + url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin/:fixedUnit/:minShapeshiftAmount/:maxShapeshiftAmount', views: { 'tab-send@tabs': { controller: 'amountController', diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js index 00772131d..53efba66d 100644 --- a/src/js/services/incomingData.js +++ b/src/js/services/incomingData.js @@ -8,7 +8,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat $rootScope.$broadcast('incomingDataMenu.showMenu', data); }; - root.redir = function(data) { + root.redir = function(data, shapeshiftData) { $log.debug('Processing incoming data: ' + data); function sanitizeUri(data) { @@ -46,7 +46,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat return true; } - function goSend(addr, amount, message, coin) { + function goSend(addr, amount, message, coin, shapeshiftData) { $state.go('tabs.send', {}, { 'reload': true, 'notify': $state.current.name == 'tabs.send' ? false : true @@ -61,10 +61,12 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat coin: coin }); } else { - $state.transitionTo('tabs.send.amount', { - toAddress: addr, - coin: coin - }); + var params = { toAddress: addr, coin: coin }; + if (shapeshiftData) { + params['minShapeshiftAmount'] = shapeshiftData.minAmount; + params['maxShapeshiftAmount'] = shapeshiftData.maxAmount; + } + $state.transitionTo('tabs.send.amount', params); } }, 100); } @@ -97,12 +99,12 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat if (parsed.r) { payproService.getPayProDetails(parsed.r, function(err, details) { if (err) { - if (addr && amount) goSend(addr, amount, message, coin); + if (addr && amount) goSend(addr, amount, message, coin, shapeshiftData); else popupService.showAlert(gettextCatalog.getString('Error'), err); } else handlePayPro(details); }); } else { - goSend(addr, amount, message, coin); + goSend(addr, amount, message, coin, shapeshiftData); } return true; // Cash URI @@ -120,14 +122,14 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat payproService.getPayProDetails(parsed.r, function(err, details) { if (err) { if (addr && amount) - goSend(addr, amount, message, coin); + goSend(addr, amount, message, coin, shapeshiftData); else popupService.showAlert(gettextCatalog.getString('Error'), err); } handlePayPro(details, coin); }); } else { - goSend(addr, amount, message, coin); + goSend(addr, amount, message, coin, shapeshiftData); } return true; @@ -163,14 +165,14 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat payproService.getPayProDetails(parsed.r, function(err, details) { if (err) { if (addr && amount) - goSend(addr, amount, message, coin); + goSend(addr, amount, message, coin, shapeshiftData); else popupService.showAlert(gettextCatalog.getString('Error'), err); } handlePayPro(details, coin); }); } else { - goSend(addr, amount, message, coin); + goSend(addr, amount, message, coin, shapeshiftData); } } ); diff --git a/www/views/amount.html b/www/views/amount.html index a522d712c..8ff3baad4 100644 --- a/www/views/amount.html +++ b/www/views/amount.html @@ -45,6 +45,11 @@ +
+ Minimum amount: {{minShapeshiftAmount}}
+ Maximum amount: {{maxShapeshiftAmount}} +
+
{{amount || "0.00" }} diff --git a/www/views/includes/fromWalletIcon.html b/www/views/includes/fromWalletIcon.html new file mode 100644 index 000000000..e5488fb73 --- /dev/null +++ b/www/views/includes/fromWalletIcon.html @@ -0,0 +1,2 @@ + + diff --git a/www/views/includes/shapeshift-coin-selector.html b/www/views/includes/shapeshift-coin-selector.html index d60c25773..68143900b 100644 --- a/www/views/includes/shapeshift-coin-selector.html +++ b/www/views/includes/shapeshift-coin-selector.html @@ -1,4 +1,4 @@ -
+
-
+
-
Deposit Limit: {{marketData.limit}}
Minimum Amount: {{marketData.minimum}}
+
Maximum Amount: {{marketData.limit}}
MinerFee: {{marketData.minerFee}}
Rate: {{marketData.rate}}
diff --git a/www/views/includes/shapeshift-coin-shift-button.html b/www/views/includes/shapeshift-coin-shift-button.html index 398289dde..d44216fd3 100644 --- a/www/views/includes/shapeshift-coin-shift-button.html +++ b/www/views/includes/shapeshift-coin-shift-button.html @@ -1,5 +1,7 @@
- +
diff --git a/www/views/includes/toWalletIcon.html b/www/views/includes/toWalletIcon.html new file mode 100644 index 000000000..edbf8598e --- /dev/null +++ b/www/views/includes/toWalletIcon.html @@ -0,0 +1,2 @@ + + diff --git a/www/views/shapeshift.html b/www/views/shapeshift.html new file mode 100644 index 000000000..0ed4e4e63 --- /dev/null +++ b/www/views/shapeshift.html @@ -0,0 +1,104 @@ + + + + {{'Shapeshift'|translate}} + + + + + + +
+ +
+ + + + +
+ + + + + +
+
+ + + + + + +
diff --git a/www/views/tab-home.html b/www/views/tab-home.html index 0ba8e8eb2..68a049fcd 100644 --- a/www/views/tab-home.html +++ b/www/views/tab-home.html @@ -97,5 +97,8 @@
+