sendflow service integrated into flow

This commit is contained in:
Sebastiaan Pasma 2018-08-08 17:10:47 +02:00
commit f7ecdb2f2f
No known key found for this signature in database
GPG key ID: 9A2B0C8B95A1D26F
7 changed files with 73 additions and 60 deletions

View file

@ -2,7 +2,7 @@
angular.module('copayApp.controllers').controller('amountController', amountController); angular.module('copayApp.controllers').controller('amountController', amountController);
function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window) { function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, sendFlowService, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window) {
var vm = this; var vm = this;
vm.allowSend = false; vm.allowSend = false;
@ -69,12 +69,12 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
initCurrencies(); initCurrencies();
passthroughParams = data.stateParams; passthroughParams = sendFlowService;
vm.fromWalletId = data.stateParams.fromWalletId; vm.fromWalletId = passthroughParams.fromWalletId;
vm.toWalletId = data.stateParams.toWalletId; vm.toWalletId = passthroughParams.toWalletId;
vm.minAmount = parseFloat(data.stateParams.minAmount); vm.minAmount = parseFloat(passthroughParams.minAmount);
vm.maxAmount = parseFloat(data.stateParams.maxAmount); vm.maxAmount = parseFloat(passthroughParams.maxAmount);
if (passthroughParams.thirdParty) { if (passthroughParams.thirdParty) {
vm.thirdParty = JSON.parse(passthroughParams.thirdParty); // Parse stringified JSON-object vm.thirdParty = JSON.parse(passthroughParams.thirdParty); // Parse stringified JSON-object
@ -96,7 +96,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
} }
} }
vm.isRequestingSpecificAmount = !data.stateParams.fromWalletId; vm.isRequestingSpecificAmount = !passthroughParams.fromWalletId;
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
@ -177,8 +177,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
// currency have preference // currency have preference
var fiatName; var fiatName;
if (data.stateParams.currency) { if (passthroughParams.currency) {
fiatCode = data.stateParams.currency; fiatCode = passthroughParams.currency;
altUnitIndex = unitIndex altUnitIndex = unitIndex
unitIndex = availableUnits.length; unitIndex = availableUnits.length;
} else { } else {
@ -205,8 +205,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
var fromWallet = profileService.getWallet(passthroughParams.fromWalletId); var fromWallet = profileService.getWallet(passthroughParams.fromWalletId);
updateAvailableFundsFromWallet(fromWallet); updateAvailableFundsFromWallet(fromWallet);
} }
}; }
}; }
function goBack() { function goBack() {
if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') { if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') {
@ -227,18 +227,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
}; }
function processClipboard() { function processClipboard() {
if (!isNW) return; if (!isNW) return;
var value = nodeWebkitService.readFromClipboard(); var value = nodeWebkitService.readFromClipboard();
if (value && evaluate(value) > 0) paste(evaluate(value)); if (value && evaluate(value) > 0) paste(evaluate(value));
}; }
function sendMax() { function sendMax() {
useSendMax = true; useSendMax = true;
finish(); finish();
}; }
function updateUnitUI() { function updateUnitUI() {
vm.unit = availableUnits[unitIndex].shortName; vm.unit = availableUnits[unitIndex].shortName;
@ -246,7 +246,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
processAmount(); processAmount();
$log.debug('Update unit coin @amount unit:' + vm.unit + " alternativeUnit:" + vm.alternativeUnit); $log.debug('Update unit coin @amount unit:' + vm.unit + " alternativeUnit:" + vm.alternativeUnit);
}; }
function changeUnit() { function changeUnit() {
@ -267,7 +267,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
updateAvailableFundsStringIfNeeded(); updateAvailableFundsStringIfNeeded();
updateUnitUI(); updateUnitUI();
}; }
function pushDigit(digit) { function pushDigit(digit) {
if (vm.amount && digit != '.') { if (vm.amount && digit != '.') {
@ -291,7 +291,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
vm.amount = (vm.amount + digit).replace('..', '.'); vm.amount = (vm.amount + digit).replace('..', '.');
processAmount(); processAmount();
}; }
function pushOperator(operator) { function pushOperator(operator) {
if (!vm.amount || vm.amount.length == 0) return; if (!vm.amount || vm.amount.length == 0) return;
@ -303,18 +303,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
} else { } else {
return val.slice(0, -1) + operator; return val.slice(0, -1) + operator;
} }
}; }
}; }
function isOperator(val) { function isOperator(val) {
var regex = /[\/\-\+\x\*]/; var regex = /[\/\-\+\x\*]/;
return regex.test(val); return regex.test(val);
}; }
function isExpression(val) { function isExpression(val) {
var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/; var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
return regex.test(val); return regex.test(val);
}; }
function removeDigit() { function removeDigit() {
vm.amount = (vm.amount).toString().slice(0, -1); vm.amount = (vm.amount).toString().slice(0, -1);
@ -339,7 +339,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
function close() { function close() {
altCurrencyModal.remove(); altCurrencyModal.remove();
altCurrencyModal = null; altCurrencyModal = null;
}; }
function processAmount() { function processAmount() {
var formatedValue = format(vm.amount); var formatedValue = format(vm.amount);
@ -409,22 +409,22 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
} else { } else {
vm.errorMessage = ''; vm.errorMessage = '';
} }
}; }
function processResult(val) { function processResult(val) {
if (availableUnits[unitIndex].isFiat) return $filter('formatFiatAmount')(val); if (availableUnits[unitIndex].isFiat) return $filter('formatFiatAmount')(val);
else return txFormatService.formatAmount(val.toFixed(unitDecimals) * unitToSatoshi, true); else return txFormatService.formatAmount(val.toFixed(unitDecimals) * unitToSatoshi, true);
}; }
function fromFiat(val) { function fromFiat(val) {
return parseFloat((rateService.fromFiat(val, fiatCode, availableUnits[altUnitIndex].id) * satToUnit).toFixed(unitDecimals)); return parseFloat((rateService.fromFiat(val, fiatCode, availableUnits[altUnitIndex].id) * satToUnit).toFixed(unitDecimals));
}; }
function toFiat(val) { function toFiat(val) {
if (!rateService.getRate(fiatCode)) return; if (!rateService.getRate(fiatCode)) return;
return parseFloat((rateService.toFiat(val * unitToSatoshi, fiatCode, availableUnits[unitIndex].id)).toFixed(2)); return parseFloat((rateService.toFiat(val * unitToSatoshi, fiatCode, availableUnits[unitIndex].id)).toFixed(2));
}; }
function evaluate(val) { function evaluate(val) {
var result; var result;
@ -435,7 +435,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
} }
if (!lodash.isFinite(result)) return 0; if (!lodash.isFinite(result)) return 0;
return result; return result;
}; }
function format(val) { function format(val) {
if (!val) return; if (!val) return;
@ -445,7 +445,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
if (isOperator(lodash.last(val))) result = result.slice(0, -1); if (isOperator(lodash.last(val))) result = result.slice(0, -1);
return result.replace('x', '*'); return result.replace('x', '*');
}; }
function finish() { function finish() {
var unit = availableUnits[unitIndex]; var unit = availableUnits[unitIndex];
@ -467,16 +467,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
}; };
if (vm.thirdParty) { if (vm.thirdParty) {
confirmData['thirdParty'] = JSON.stringify(this.thirdParty); confirmData['thirdParty'] = this.thirdParty;
} }
sendFlowService.map(confirmData);
if (!confirmData.fromWalletId) { if (!confirmData.fromWalletId) {
$state.transitionTo('tabs.paymentRequest.confirm', confirmData); $state.transitionTo('tabs.paymentRequest.confirm', confirmData);
} else { } else {
$state.transitionTo('tabs.send.review', confirmData); $state.transitionTo('tabs.send.review', confirmData);
$scope.useSendMax = null; $scope.useSendMax = null;
} }
}; }
// Currency // Currency
@ -495,7 +497,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
{isoCode: 'CNY', order: 7}, {isoCode: 'CNY', order: 7},
{isoCode: 'KRW', order: 8}, {isoCode: 'KRW', order: 8},
{isoCode: 'HKD', order: 9}, {isoCode: 'HKD', order: 9},
] ];
function initCurrencies() { function initCurrencies() {
var unusedCurrencyList = [{ var unusedCurrencyList = [{
@ -558,7 +560,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
}; }
function save(newAltCurrency) { function save(newAltCurrency) {
var opts = { var opts = {
@ -584,7 +586,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
updateUnitUI(); updateUnitUI();
close(); close();
}); });
}; }
function updateAvailableFundsStringIfNeeded() { function updateAvailableFundsStringIfNeeded() {
if (passthroughParams.fromWalletId && availableSatoshis !== null) { if (passthroughParams.fromWalletId && availableSatoshis !== null) {
@ -639,5 +641,4 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
vm.availableFunds = availableFundsInCrypto; vm.availableFunds = availableFundsInCrypto;
} }
} }
} }

View file

@ -4,7 +4,7 @@ angular
.module('copayApp.controllers') .module('copayApp.controllers')
.controller('reviewController', reviewController); .controller('reviewController', reviewController);
function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicModal, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) { function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicModal, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, sendFlowService, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) {
var vm = this; var vm = this;
vm.buttonText = ''; vm.buttonText = '';
@ -51,7 +51,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
// Functions // Functions
vm.onSuccessConfirm = onSuccessConfirm; vm.onSuccessConfirm = onSuccessConfirm;
var sendFlowData;
var config = null; var config = null;
var countDown = null; var countDown = null;
var defaults = {}; var defaults = {};
@ -75,17 +75,18 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
function onBeforeEnter(event, data) { function onBeforeEnter(event, data) {
defaults = configService.getDefaults(); defaults = configService.getDefaults();
originWalletId = data.stateParams.fromWalletId; sendFlowData = sendFlowService;
satoshis = parseInt(data.stateParams.amount, 10); originWalletId = sendFlowData.fromWalletId;
toAddress = data.stateParams.toAddress; satoshis = parseInt(sendFlowData.amount, 10);
destinationWalletId = data.stateParams.toWalletId; toAddress = sendFlowData.toAddress;
destinationWalletId = sendFlowData.toWalletId;
vm.originWallet = profileService.getWallet(originWalletId); vm.originWallet = profileService.getWallet(originWalletId);
vm.origin.currency = vm.originWallet.coin.toUpperCase(); vm.origin.currency = vm.originWallet.coin.toUpperCase();
coin = vm.originWallet.coin; coin = vm.originWallet.coin;
if (data.stateParams.thirdParty) { if (sendFlowData.thirdParty) {
vm.thirdParty = JSON.parse(data.stateParams.thirdParty); // Parse stringified JSON-object // vm.thirdParty = JSON.parse(sendFlowData.thirdParty); // Parse stringified JSON-object
if (vm.thirdParty) { if (vm.thirdParty) {
handleThirdPartyInitIfBip70(); handleThirdPartyInitIfBip70();
handleThirdPartyInitIfShapeshift(); handleThirdPartyInitIfShapeshift();
@ -105,7 +106,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
updateSendAmounts(); updateSendAmounts();
getOriginWalletBalance(vm.originWallet); getOriginWalletBalance(vm.originWallet);
handleDestinationAsAddress(toAddress, coin); handleDestinationAsAddress(toAddress, coin);
handleDestinationAsWallet(data.stateParams.toWalletId); handleDestinationAsWallet(sendFlowData.toWalletId);
createVanityTransaction(data); createVanityTransaction(data);
}); });
} }
@ -221,10 +222,10 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
// Grab stateParams // Grab stateParams
tx = { tx = {
amount: parseInt(data.stateParams.amount), amount: parseInt(sendFlowData.amount),
sendMax: data.stateParams.sendMax === 'true' ? true : false, sendMax: sendFlowData.sendMax === 'true' ? true : false,
fromWalletId: data.stateParams.fromWalletId, fromWalletId: sendFlowData.fromWalletId,
toAddress: data.stateParams.toAddress, toAddress: sendFlowData.toAddress,
paypro: txPayproData, paypro: txPayproData,
feeLevel: configFeeLevel, feeLevel: configFeeLevel,
@ -241,7 +242,6 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
}; };
if (data.stateParams.requiredFeeRate) { if (data.stateParams.requiredFeeRate) {
vm.usingMerchantFee = true; vm.usingMerchantFee = true;
tx.feeRate = parseInt(data.stateParams.requiredFeeRate); tx.feeRate = parseInt(data.stateParams.requiredFeeRate);
@ -251,7 +251,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
tx.feeLevel = 'normal'; tx.feeLevel = 'normal';
} }
var B = data.stateParams.coin === 'bch' ? bitcoreCash : bitcore; var B = tx.coin === 'bch' ? bitcoreCash : bitcore;
var networkName; var networkName;
try { try {
if (vm.destination.kind === 'wallet') { // This is a wallet-to-wallet transfer if (vm.destination.kind === 'wallet') { // This is a wallet-to-wallet transfer

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) { angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, sendFlowService, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) {
var clipboardHasAddress = false; var clipboardHasAddress = false;
var clipboardHasContent = false; var clipboardHasContent = false;
var originalList; var originalList;

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService) { angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, sendFlowService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService) {
var HISTORY_SHOW_LIMIT = 10; var HISTORY_SHOW_LIMIT = 10;
var currentTxHistoryPage = 0; var currentTxHistoryPage = 0;
@ -471,9 +471,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
} }
$scope.goToSend = function() { $scope.goToSend = function() {
$state.go('tabs.home', { sendFlowService.fromWalletId = $scope.wallet.id;
walletId: $scope.wallet.id $state.go('tabs.home').then(function () {
}).then(function () {
$ionicHistory.clearHistory(); $ionicHistory.clearHistory();
$state.go('tabs.send'); $state.go('tabs.send');
}); });

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, configService, gettextCatalog, profileService, txFormatService) { angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, sendFlowService, configService, gettextCatalog, profileService, txFormatService) {
var fromWalletId = ''; var fromWalletId = '';
var priceDisplayAsFiat = false; var priceDisplayAsFiat = false;
@ -26,10 +26,14 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
// nop // nop
} }
$scope.params = $state.params; $scope.params = sendFlowService;
$scope.coin = false; // Wallets to show (for destination screen or contacts) $scope.coin = false; // Wallets to show (for destination screen or contacts)
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination $scope.type = $scope.params['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
fromWalletId = data.stateParams && data.stateParams.fromWalletId; fromWalletId = $scope.params['fromWalletId'];
if ($scope.type === 'destination' && $scope.params.toAddress) {
$state.transitionTo(getNextStep());
}
if ($scope.params.coin) { if ($scope.params.coin) {
$scope.coin = $scope.params.coin; // Contacts have a coin embedded $scope.coin = $scope.params.coin; // Contacts have a coin embedded

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.services').factory('incomingData', function($log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) { angular.module('copayApp.services').factory('incomingData', function($log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, sendFlowService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) {
var root = {}; var root = {};
@ -105,9 +105,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
params.thirdParty = []; params.thirdParty = [];
params.thirdParty.id = serviceId; params.thirdParty.id = serviceId;
params.thirdParty.data = serviceData; params.thirdParty.data = serviceData;
params.thirdParty = JSON.stringify(params.thirdParty); sendFlowService.map(params);
$state.transitionTo('tabs.send.amount', params); $state.transitionTo('tabs.send.amount', params);
} else { } else {
sendFlowService.map(params);
$state.transitionTo('tabs.send.origin', params); $state.transitionTo('tabs.send.origin', params);
} }
}, 100); }, 100);
@ -458,6 +459,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
'notify': $state.current.name == 'tabs.send' ? false : true 'notify': $state.current.name == 'tabs.send' ? false : true
}).then(function() { }).then(function() {
$timeout(function() { $timeout(function() {
sendFlowService.map(stateParams);
$state.transitionTo('tabs.send.origin', stateParams); $state.transitionTo('tabs.send.origin', stateParams);
}); });
}); });

View file

@ -20,5 +20,12 @@ angular.module('copayApp.services').factory('sendFlowService', function ($log) {
vm.toWalletId = false; vm.toWalletId = false;
}; };
vm.map = function(params) {
Object.keys(params).map(function(key, index) {
vm[key] = params[key];
});
console.log(vm);
};
return vm; return vm;
}); });