From efe2c333a8e2a01ec009e1c4b8c0960b11dea120 Mon Sep 17 00:00:00 2001 From: Kadir Sekha Date: Wed, 3 Jan 2018 14:41:59 +0000 Subject: [PATCH] implemented appropriate send max button for shapeshift --- src/js/controllers/amount.js | 17 ++++++++++++++++- www/views/amount.html | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index f6e94eca1..c9cdca5ec 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -395,7 +395,6 @@ angular.module('copayApp.controllers').controller('amountController', function($ } if ($scope.nextStep) { - $state.transitionTo($scope.nextStep, { id: _id, amount: $scope.useSendMax ? null : _amount, @@ -428,6 +427,22 @@ angular.module('copayApp.controllers').controller('amountController', function($ shapeshiftOrderUrl += $scope.shapeshiftOrderId; confirmData.description = shapeshiftOrderUrl; confirmData.fromWalletId = $scope.fromWalletId; + + if (confirmData.useSendMax) { + var wallet = lodash.find(profileService.getWallets({ coin: coin }), + function(w) { + return w.id == $scope.fromWalletId; + }); + + var balance = parseFloat(wallet.cachedBalance.substring(0, wallet.cachedBalance.length-4)); + if (balance < $scope.minShapeshiftAmount * 1.04) { + confirmData.useSendMax = false; + confirmData.toAmount = $scope.minShapeshiftAmount * unitToSatoshi; + } else if (balance > $scope.maxShapeshiftAmount) { + confirmData.useSendMax = false; + confirmData.toAmount = $scope.maxShapeshiftAmount * unitToSatoshi * 0.99; + } + } } $state.transitionTo('tabs.send.confirm', confirmData); diff --git a/www/views/amount.html b/www/views/amount.html index 160044dec..8fc00145d 100644 --- a/www/views/amount.html +++ b/www/views/amount.html @@ -49,7 +49,7 @@
≈ {{alternativeAmount || '0.00'}} {{alternativeUnit}}
-
-