diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 52695e829..c8383a510 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -31,7 +31,6 @@ angular.module('copayApp.controllers').controller('amountController', function($ }); $scope.$on("$ionicView.beforeEnter", function(event, data) { - initCurrencies(); if (data.stateParams.shapeshiftOrderId && data.stateParams.shapeshiftOrderId.length > 0) { @@ -42,6 +41,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ // To get the wallet from with the new flow $scope.fromWalletId = data.stateParams.fromWalletId; + $scope.toWalletId = data.stateParams.toWalletId; if (data.stateParams.noPrefix) { $scope.showWarningMessage = data.stateParams.noPrefix != 0; @@ -156,10 +156,10 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.toEmail = data.stateParams.toEmail; $scope.toColor = data.stateParams.toColor; - if (!$scope.nextStep && !data.stateParams.toAddress) { - $log.error('Bad params at amount') - throw ('bad params'); - } + // if (!$scope.nextStep && !data.stateParams.toAddress) { + // $log.error('Bad params at amount') + // throw ('bad params'); + // } var reNr = /^[1234567890\.]$/; var reOp = /^[\*\+\-\/]$/; @@ -198,8 +198,8 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.resetAmount(); // in SAT ALWAYS - if ($stateParams.toAmount) { - $scope.amountModel.amount = (($stateParams.toAmount) * satToUnit).toFixed(unitDecimals); + if ($stateParams.amount) { + $scope.amountModel.amount = (($stateParams.amount) * satToUnit).toFixed(unitDecimals); } $scope.processAmount(); @@ -461,7 +461,8 @@ angular.module('copayApp.controllers').controller('amountController', function($ currency: unit.id.toUpperCase(), coin: coin, useSendMax: $scope.useSendMax, - fromWalletId: $scope.fromWalletId + fromWalletId: $scope.fromWalletId, + toWalletId: $scope.toWalletId }); } else { var amount = _amount; @@ -474,7 +475,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ var confirmData = { recipientType: $scope.recipientType, - toAmount: amount, + amount: amount, toAddress: $scope.toAddress, displayAddress: $scope.displayAddress || $scope.toAddress, toName: $scope.toName, @@ -482,14 +483,14 @@ angular.module('copayApp.controllers').controller('amountController', function($ toColor: $scope.toColor, coin: coin, useSendMax: $scope.useSendMax, - fromWalletId: $scope.fromWalletId + fromWalletId: $scope.fromWalletId, + toWalletId: $scope.toWalletId }; if ($scope.shapeshiftOrderId) { var shapeshiftOrderUrl = 'https://www.shapeshift.io/#/status/'; shapeshiftOrderUrl += $scope.shapeshiftOrderId; confirmData.description = shapeshiftOrderUrl; - confirmData.fromWalletId = $scope.fromWalletId; if (confirmData.useSendMax) { var wallet = lodash.find(profileService.getWallets({ coin: coin }), @@ -500,10 +501,10 @@ angular.module('copayApp.controllers').controller('amountController', function($ 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; + confirmData.amount = $scope.minShapeshiftAmount * unitToSatoshi; } else if (balance > $scope.maxShapeshiftAmount) { confirmData.useSendMax = false; - confirmData.toAmount = $scope.maxShapeshiftAmount * unitToSatoshi * 0.99; + confirmData.amount = $scope.maxShapeshiftAmount * unitToSatoshi * 0.99; } } } diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 03af26fd1..74b86e623 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService, soundService) { +angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, $ionicLoading, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService, soundService) { var countDown = null; var FEE_TOO_HIGH_LIMIT_PER = 15; @@ -68,82 +68,95 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); }; + var setWalletSelector = function(coin, network, minAmount, cb) { + + // no min amount? (sendMax) => look for no empty wallets + minAmount = minAmount || 1; + + $scope.wallets = profileService.getWallets({ + onlyComplete: true, + network: network, + coin: coin + }); + + if (tx.fromWalletId) { + $scope.wallets = lodash.filter($scope.wallets, function (w) { + return w.id == tx.fromWalletId; + }); + } + + + if (!$scope.wallets || !$scope.wallets.length) { + setNoWallet(gettextCatalog.getString('No wallets available'), true); + return cb(); + } + + var filteredWallets = []; + var index = 0; + var walletsUpdated = 0; + + lodash.each($scope.wallets, function (w) { + walletService.getStatus(w, {}, function (err, status) { + if (err || !status) { + $log.error(err); + } else { + walletsUpdated++; + w.status = status; + + if (!status.availableBalanceSat) + $log.debug('No balance available in: ' + w.name); + + if (status.availableBalanceSat > minAmount) { + filteredWallets.push(w); + } + } + + if (++index == $scope.wallets.length) { + if (!walletsUpdated) + return cb('Could not update any wallet'); + + if (lodash.isEmpty(filteredWallets)) { + setNoWallet(gettextCatalog.getString('Insufficient confirmed funds'), true); + } + $scope.wallets = lodash.clone(filteredWallets); + return cb(); + } + }); + }); + }; $scope.$on("$ionicView.beforeEnter", function(event, data) { - - function setWalletSelector(coin, network, minAmount, cb) { - - // no min amount? (sendMax) => look for no empty wallets - minAmount = minAmount || 1; - - $scope.wallets = profileService.getWallets({ - onlyComplete: true, - network: network, - coin: coin - }); - - if (tx.fromWalletId) { - $scope.wallets = lodash.filter($scope.wallets, function(w) { - return w.id == tx.fromWalletId; - }); - } - - - - if (!$scope.wallets || !$scope.wallets.length) { - setNoWallet(gettextCatalog.getString('No wallets available'), true); - return cb(); - } - - var filteredWallets = []; - var index = 0; - var walletsUpdated = 0; - - lodash.each($scope.wallets, function(w) { - walletService.getStatus(w, {}, function(err, status) { - if (err || !status) { - $log.error(err); - } else { - walletsUpdated++; - w.status = status; - - if (!status.availableBalanceSat) - $log.debug('No balance available in: ' + w.name); - - if (status.availableBalanceSat > minAmount) { - filteredWallets.push(w); - } - } - - if (++index == $scope.wallets.length) { - if (!walletsUpdated) - return cb('Could not update any wallet'); - - if (lodash.isEmpty(filteredWallets)) { - setNoWallet(gettextCatalog.getString('Insufficient confirmed funds'), true); - } - $scope.wallets = lodash.clone(filteredWallets); - return cb(); - } - }); - }); - }; - // Setup $scope var B = data.stateParams.coin == 'bch' ? bitcoreCash : bitcore; var networkName; + $scope.fromWallet = profileService.getWallet(data.stateParams.fromWalletId); + $scope.recipientType = null; + try { - networkName = (new B.Address(data.stateParams.toAddress)).network.name; - } catch(e) { + if (data.stateParams.toWalletId) { + $scope.recipientType = 'wallet'; // set type to wallet-to-wallet + $ionicLoading.show(); + var wallet = profileService.getWallet(data.stateParams.toWalletId); + walletService.getAddress(wallet, true, function (err, addr) { + $ionicLoading.hide(); + data.stateParams.toAddress = addr; + networkName = (new B.Address(data.stateParams.toAddress)).network.name; + vanityTx(networkName, data); + }); + } else if (data.stateParams.toAddress) { + networkName = (new B.Address(data.stateParams.toAddress)).network.name; + vanityTx(networkName, data); + } + } catch (e) { var message = gettextCatalog.getString('Invalid address'); var backText = gettextCatalog.getString('Go back'); var learnText = gettextCatalog.getString('Learn more'); - popupService.showConfirm(null, message, backText, learnText, function(back) { + popupService.showConfirm(null, message, backText, learnText, function (back) { $ionicHistory.nextViewOptions({ disableAnimate: true, historyRoot: true }); - $state.go('tabs.send').then(function() { + $state.go('tabs.send').then(function () { $ionicHistory.clearHistory(); if (!back) { var url = 'https://support.bitpay.com/hc/en-us/articles/115004671663'; @@ -153,27 +166,24 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); return; } - + }); + var vanityTx = function(networkName, data) { // Grab stateParams tx = { - toAmount: parseInt(data.stateParams.toAmount), + amount: parseInt(data.stateParams.amount), sendMax: data.stateParams.useSendMax == 'true' ? true : false, fromWalletId: data.stateParams.fromWalletId, toAddress: data.stateParams.toAddress, - displayAddress: data.stateParams.displayAddress, - description: data.stateParams.description, - paypro: data.stateParams.paypro, - feeLevel: configFeeLevel, spendUnconfirmed: walletConfig.spendUnconfirmed, // Vanity tx info (not in the real tx) - recipientType: data.stateParams.recipientType || null, + recipientType: $scope.recipientType || null, toName: data.stateParams.toName, toEmail: data.stateParams.toEmail, toColor: data.stateParams.toColor, network: networkName, - coin: data.stateParams.coin, + coin: $scope.fromWallet.coin, txp: {}, }; @@ -188,12 +198,10 @@ angular.module('copayApp.controllers').controller('confirmController', function( // Other Scope vars $scope.isCordova = isCordova; - $scope.isWindowsPhoneApp = isWindowsPhoneApp; $scope.showAddress = false; - $scope.walletSelectorTitle = gettextCatalog.getString('Send from'); - setWalletSelector(tx.coin, tx.network, tx.toAmount, function(err) { + setWalletSelector(tx.coin, tx.network, tx.amount, function(err) { if (err) { return exitWithError('Could not update wallets'); } @@ -207,7 +215,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.displayBalanceAsFiat = walletConfig.settings.priceDisplay === 'fiat'; - }); + }; function getSendMaxInfo(tx, wallet, cb) { @@ -231,7 +239,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( return setSendError(msg); } - if (tx.toAmount > Number.MAX_SAFE_INTEGER) { + if (tx.amount > Number.MAX_SAFE_INTEGER) { var msg = gettextCatalog.getString('Amount too big'); $log.warn(msg); return setSendError(msg); @@ -241,7 +249,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( txp.outputs = [{ 'toAddress': tx.toAddress, - 'amount': tx.toAmount, + 'amount': tx.amount, 'message': tx.description }]; @@ -280,13 +288,13 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.tx = tx; function updateAmount() { - if (!tx.toAmount) return; + if (!tx.amount) return; // Amount - tx.amountStr = txFormatService.formatAmountStr(wallet.coin, tx.toAmount); + tx.amountStr = txFormatService.formatAmountStr(wallet.coin, tx.amount); tx.amountValueStr = tx.amountStr.split(' ')[0]; tx.amountUnitStr = tx.amountStr.split(' ')[1]; - txFormatService.formatAlternativeStr(wallet.coin, tx.toAmount, function(v) { + txFormatService.formatAlternativeStr(wallet.coin, tx.amount, function(v) { var parts = v.split(' '); tx.alternativeAmountStr = v; tx.alternativeAmountValueStr = parts[0]; @@ -342,7 +350,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( } tx.sendMaxInfo = sendMaxInfo; - tx.toAmount = tx.sendMaxInfo.amount; + tx.amount = tx.sendMaxInfo.amount; updateAmount(); ongoingProcess.set('calculatingFee', false); $timeout(function() { @@ -393,7 +401,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( function useSelectedWallet() { if (!$scope.useSendMax) { - showAmount(tx.toAmount); + showAmount(tx.amount); } $scope.onWalletSelect($scope.wallet); diff --git a/src/js/controllers/sendFlowController.js b/src/js/controllers/sendFlowController.js index ec29d7b50..d6f2b707d 100644 --- a/src/js/controllers/sendFlowController.js +++ b/src/js/controllers/sendFlowController.js @@ -6,34 +6,34 @@ angular.module('copayApp.controllers').controller('sendFlowController', function var satToUnit; var unitDecimals; var satToBtc; + var nextStep = ''; $scope.$on("$ionicView.beforeEnter", function(event, data) { var config = configService.getSync().wallet.settings; - + $scope.params = $stateParams; $scope.specificAmount = $scope.specificAlternativeAmount = ''; unitToSatoshi = config.unitToSatoshi; satToUnit = 1 / unitToSatoshi; satToBtc = 1 / 100000000; unitDecimals = config.unitDecimals; - // in SAT ALWAYS - if ($stateParams.toAmount) { - $scope.requestAmount = (($stateParams.toAmount) * satToUnit).toFixed(unitDecimals); + if ($scope.params.amount) { + console.log("is Payment Request", $scope.params.amount); + + $scope.requestAmount = (($stateParams.amount) * satToUnit).toFixed(unitDecimals); $scope.isPaymentRequest = true; } - - console.log(data, $stateParams); - - $scope.params = $stateParams; }); $scope.$on("$ionicView.enter", function(event, data) { console.log(data, $stateParams); - $scope.type = data.stateParams.fromWalletId ? 'destination' : 'origin'; // origin || destination + $scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination $scope.coin = false; // Wallets to show (for destination screen) $scope.walletsEmpty = []; // Show price-header + console.log("current type: "+$scope.type); + if ($scope.type === 'origin') { $scope.headerTitle = gettextCatalog.getString('Choose a wallet to send from'); $scope.walletsEmpty = profileService.getWallets({coin: $scope.coin, hasNoFunds: true}); @@ -57,13 +57,22 @@ angular.module('copayApp.controllers').controller('sendFlowController', function }); }); + function getNextStep() { + if (!$scope.params.toWalletId && !$scope.params.toAddress) { + return 'tabs.send.destination'; + } else if (!$scope.params.amount) { + return 'tabs.send.amount'; + } else { + return 'tabs.send.confirm'; + } + } + $scope.useWallet = function(wallet) { if ($scope.type === 'origin') { $scope.params['fromWalletId'] = wallet.id; - $state.transitionTo('tabs.send.destination', $scope.params); } else { $scope.params['toWalletId'] = wallet.id; - $state.transitionTo('tabs.send.amount', $scope.params); } + $state.transitionTo(getNextStep(), $scope.params); }; }); \ No newline at end of file diff --git a/src/js/routes.js b/src/js/routes.js index 29273d444..de77a34d5 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -270,24 +270,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } } }) - .state('tabs.send.origin', { - url: '/origin/:thirdParty/:amount/:toAddress/:toWalletId', - views: { - 'tab-send@tabs': { - controller: 'sendFlowController', - templateUrl: 'views/wallet-origin-destination.html', - } - } - }) - .state('tabs.send.destination', { - url: '/destination/:fromWalletId/:thirdParty/:amount', - views: { - 'tab-send@tabs': { - controller: 'sendFlowController', - templateUrl: 'views/wallet-origin-destination.html', - } - } - }) .state('tabs.settings', { url: '/settings', views: { @@ -305,7 +287,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr */ .state('tabs.send.amount', { - url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin/:fixedUnit/:fromWalletId/:minShapeshiftAmount/:maxShapeshiftAmount/:shapeshiftOrderId/:displayAddress/:noPrefix', + url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin/:fixedUnit/:fromWalletId/:toWalletId/:minShapeshiftAmount/:maxShapeshiftAmount/:shapeshiftOrderId/:displayAddress/:noPrefix', views: { 'tab-send@tabs': { controller: 'amountController', @@ -318,12 +300,30 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr views: { 'tab-send@tabs': { controller: 'sendFlowController', - templateUrl: 'views/wallet-to-wallet-transfer.html' + templateUrl: 'views/wallet-origin-destination.html' + } + } + }) + .state('tabs.send.origin', { + url: '/origin/:thirdParty/:amount/:toAddress/:toWalletId', + views: { + 'tab-send@tabs': { + controller: 'sendFlowController', + templateUrl: 'views/wallet-origin-destination.html', + } + } + }) + .state('tabs.send.destination', { + url: '/destination/:thirdParty/:amount/:fromWalletId', + views: { + 'tab-send@tabs': { + controller: 'sendFlowController', + templateUrl: 'views/wallet-origin-destination.html', } } }) .state('tabs.send.confirm', { - url: '/confirm/:recipientType/:toAddress/:toName/:toAmount/:toEmail/:toColor/:description/:coin/:useSendMax/:fromWalletId/:displayAddress/:requiredFeeRate', + url: '/confirm/:thirdParty/:amount/:fromWalletId/:toWalletId/:toAddress', views: { 'tab-send@tabs': { controller: 'confirmController', diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js index fc3d37d47..e12cc2255 100644 --- a/src/js/services/incomingData.js +++ b/src/js/services/incomingData.js @@ -84,7 +84,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat $timeout(function() { if (amount) { $state.transitionTo('tabs.send.origin', { - toAmount: amount, + amount: amount, toAddress: addr, displayAddress: originalAddress ? originalAddress : addr, description: message, @@ -409,7 +409,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat function handlePayPro(payProDetails, coin) { var stateParams = { - toAmount: payProDetails.amount, + amount: payProDetails.amount, toAddress: payProDetails.toAddress, description: payProDetails.memo, paypro: payProDetails, diff --git a/src/sass/views/wallet-origin-destination.scss b/src/sass/views/wallet-origin-destination.scss index 94fbe8e4b..1c6016862 100644 --- a/src/sass/views/wallet-origin-destination.scss +++ b/src/sass/views/wallet-origin-destination.scss @@ -28,7 +28,6 @@ } } .wallets-header { - font-size: 12px; margin: 20px 14px 0px; .title { @@ -43,7 +42,11 @@ margin: 20px 14px 0px; .item-heading { + .subtitle { + font-size: 12px; + } font-weight: 600; + } &-insufficient {