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

View file

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

View file

@ -1,6 +1,6 @@
'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 clipboardHasContent = false;
var originalList;

View file

@ -1,6 +1,6 @@
'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 currentTxHistoryPage = 0;
@ -471,9 +471,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
$scope.goToSend = function() {
$state.go('tabs.home', {
walletId: $scope.wallet.id
}).then(function () {
sendFlowService.fromWalletId = $scope.wallet.id;
$state.go('tabs.home').then(function () {
$ionicHistory.clearHistory();
$state.go('tabs.send');
});

View file

@ -1,6 +1,6 @@
'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 priceDisplayAsFiat = false;
@ -26,10 +26,14 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
// nop
}
$scope.params = $state.params;
$scope.params = sendFlowService;
$scope.coin = false; // Wallets to show (for destination screen or contacts)
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
fromWalletId = data.stateParams && data.stateParams.fromWalletId;
$scope.type = $scope.params['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
fromWalletId = $scope.params['fromWalletId'];
if ($scope.type === 'destination' && $scope.params.toAddress) {
$state.transitionTo(getNextStep());
}
if ($scope.params.coin) {
$scope.coin = $scope.params.coin; // Contacts have a coin embedded

View file

@ -1,6 +1,6 @@
'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 = {};
@ -105,9 +105,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
params.thirdParty = [];
params.thirdParty.id = serviceId;
params.thirdParty.data = serviceData;
params.thirdParty = JSON.stringify(params.thirdParty);
sendFlowService.map(params);
$state.transitionTo('tabs.send.amount', params);
} else {
sendFlowService.map(params);
$state.transitionTo('tabs.send.origin', params);
}
}, 100);
@ -458,6 +459,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
'notify': $state.current.name == 'tabs.send' ? false : true
}).then(function() {
$timeout(function() {
sendFlowService.map(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.map = function(params) {
Object.keys(params).map(function(key, index) {
vm[key] = params[key];
});
console.log(vm);
};
return vm;
});