adapt for the request specific amount. Clean comments and code, and more.

This commit is contained in:
Jean-Baptiste Dominguez 2018-08-31 16:09:31 +09:00
commit dd59169d5f
4 changed files with 126 additions and 120 deletions

View file

@ -18,10 +18,10 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
$scope.displayBalanceAsFiat = true; $scope.displayBalanceAsFiat = true;
$scope.requestSpecificAmount = function() { $scope.requestSpecificAmount = function() {
sendFlowService.pushState({ sendFlowService.start({
toWalletId: $scope.wallet.credentials.walletId toWalletId: $scope.wallet.credentials.walletId,
isRequestAmount: true
}); });
$state.go('tabs.paymentRequest.amount');
}; };
$scope.setAddress = function(newAddr, copyAddress) { $scope.setAddress = function(newAddr, copyAddress) {

View file

@ -112,6 +112,7 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
sendFlowService.start(params); sendFlowService.start(params);
} }
// data extensions for Payment Protocol with non-backwards-compatible request // data extensions for Payment Protocol with non-backwards-compatible request
if (allParsed.isValid && allParsed.coin && allParsed.url && !allParsed.testnet) { if (allParsed.isValid && allParsed.coin && allParsed.url && !allParsed.testnet) {
var coin = allParsed.coin; var coin = allParsed.coin;
@ -373,20 +374,12 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
}; };
function goToAmountPage(toAddress, coin) { function goToAmountPage(toAddress, coin) {
$state.go('tabs.send', {}, { var stateParams = {
'reload': true, toAddress: toAddress,
'notify': $state.current.name == 'tabs.send' ? false : true displayAddress: toAddress,
}); coin: coin,
$timeout(function() { };
var stateParams = { sendFlowService.start(stateParams);
toAddress: toAddress,
displayAddress: toAddress,
coin: coin,
noPrefix: 1
};
sendFlowService.pushState(stateParams);
$state.transitionTo('tabs.send.origin');
}, 100);
} }
function handlePayPro(payProData, coin) { function handlePayPro(payProData, coin) {
@ -447,15 +440,7 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
} }
scannerService.pausePreview(); scannerService.pausePreview();
$state.go('tabs.send', {}, { sendFlowService.start(stateParams);
'reload': true,
'notify': $state.current.name == 'tabs.send' ? false : true
}).then(function() {
$timeout(function() {
sendFlowService.pushState(stateParams); // Need to do more here
$state.transitionTo('tabs.send.origin');
});
});
} }
return root; return root;

View file

@ -26,18 +26,24 @@ angular
/** /**
* *
*/ */
function start() { function start() {
if ($state.current.name != 'tabs.send') { var state = sendFlowStateService.state;
$state.go('tabs.home').then(function () {
$ionicHistory.clearHistory(); if (state.isRequestAmount) {
$state.go('tabs.send').then(function () { $state.go('tabs.paymentRequest.amount');
$timeout(function () {
goNext();
}, 60);
});
});
} else { } else {
goNext(); if ($state.current.name != 'tabs.send') {
$state.go('tabs.home').then(function () {
$ionicHistory.clearHistory();
$state.go('tabs.send').then(function () {
$timeout(function () {
goNext();
}, 60);
});
});
} else {
goNext();
}
} }
} }

View file

@ -8,7 +8,7 @@ angular
function sendFlowService( function sendFlowService(
sendFlowStateService, sendFlowRouterService sendFlowStateService, sendFlowRouterService
, bitcoinUriService, payproService , bitcoinUriService, payproService, bitcoinCashJsService
, popupService , popupService
, $state , $state
) { ) {
@ -30,88 +30,111 @@ angular
/** /**
* Clears all previous state * Clears all previous state
*/ */
async function start(params) { function start(params) {
console.log('start()'); console.log('start()');
if (params) { if (params && params.data) {
if (params.data) { var res = bitcoinUriService.parse(params.data);
var res = bitcoinUriService.parse(params.data);
if (res.isValid) {
/** if (res.isValid) {
* If BIP70
*/
if (res.url) {
var url = res.url;
var coin = res.coin || '';
await new Promise(function (resolve) {
payproService.getPayProDetails(url, coin, function onGetPayProDetails(err, payProData) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
} else {
// Fill in the params
var toAddr = payProData.toAddress;
var amount = payProData.amount;
var paymentUrl = payProData.url;
var expires = payProData.expires;
var time = payProData.time;
var name = payProData.domain;
// Detect some merchant that we know
if (payProData.memo.indexOf('eGifter') > -1) {
name = 'eGifter'
} else if (paymentUrl.indexOf('https://bitpay.com') > -1) {
name = 'BitPay';
}
// Init thirdParty /**
var thirdPartyData = { * If BIP70
id: 'bip70', */
amount: amount, if (res.url) {
caTrusted: true, var url = res.url;
name: name, var coin = res.coin || '';
domain: payProData.domain, payproService.getPayProDetails(url, coin, function onGetPayProDetails(err, payProData) {
expires: expires, if (err) {
memo: payProData.memo, popupService.showAlert(gettextCatalog.getString('Error'), err);
network: 'livenet', } else {
requiredFeeRate: payProData.requiredFeeRate, // Fill in the params
selfSigned: 0, var toAddr = payProData.toAddress;
time: time, var amount = payProData.amount;
toAddress: toAddr, var paymentUrl = payProData.url;
url: paymentUrl, var expires = payProData.expires;
verified: true var time = payProData.time;
}; var name = payProData.domain;
// Detect some merchant that we know
if (payProData.memo.indexOf('eGifter') > -1) {
name = 'eGifter'
} else if (paymentUrl.indexOf('https://bitpay.com') > -1) {
name = 'BitPay';
}
/** // Init thirdParty
* Fill in params var thirdPartyData = {
*/ id: 'bip70',
params.amount = thirdPartyData.amount, amount: amount,
params.toAddress = thirdPartyData.toAddress, caTrusted: true,
params.coin = coin, name: name,
params.thirdParty = thirdPartyData domain: payProData.domain,
} expires: expires,
memo: payProData.memo,
/** network: 'livenet',
* Resolve requiredFeeRate: payProData.requiredFeeRate,
*/ selfSigned: 0,
resolve(); time: time,
}); toAddress: toAddr,
}); url: paymentUrl,
verified: true
};
/**
* Fill in params
*/
params.amount = thirdPartyData.amount,
params.toAddress = thirdPartyData.toAddress,
params.coin = coin,
params.thirdParty = thirdPartyData
}
/**
* Resolve
*/
_next();
});
} else {
if (res.coin) {
params.coin = res.coin;
} }
if (res.amount) {
params.amount = res.amount;
}
if (res.publicAddress) {
var prefix = res.testnet ? 'bchtest:' : 'bitcoincash:';
params.displayAddress = (prefix + res.publicAddress.cashAddr) || res.publicAddress.legacy || res.publicAddress.bitpay;
params.toAddress = bitcoinCashJsService.readAddress(params.displayAddress).legacy;
}
_next();
} }
} else {
_next();
} }
} else {
_next();
}
// Next used for sync the async task
function _next() {
/** /**
* Init the state if params is defined * Init the state if params is defined
*/ */
sendFlowStateService.init(params); if (params) {
sendFlowStateService.init(params);
}
/**
* Routing strategy to -> send-flow-router.service
*/
sendFlowRouterService.start();
} }
/**
* Routing strategy to -> send-flow-router.service
*/
sendFlowRouterService.start();
} }
function goNext(state) { function goNext(state) {
@ -121,25 +144,17 @@ angular
state.route = $state.current.name; state.route = $state.current.name;
/** /**
* Push the new state * Save the state and redirect the user
*/ */
sendFlowStateService.push(state); sendFlowStateService.push(state);
/**
* Go next
*/
sendFlowRouterService.goNext(); sendFlowRouterService.goNext();
} }
function goBack() { function goBack() {
/** /**
* Pop the current state * Remove the state on top and redirect the user
*/ */
sendFlowStateService.pop(); sendFlowStateService.pop();
/**
* Go back
*/
sendFlowRouterService.goBack(); sendFlowRouterService.goBack();
} }
}; };