adapt for the request specific amount. Clean comments and code, and more.
This commit is contained in:
parent
2c0432e292
commit
dd59169d5f
4 changed files with 126 additions and 120 deletions
|
|
@ -18,10 +18,10 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
|||
$scope.displayBalanceAsFiat = true;
|
||||
|
||||
$scope.requestSpecificAmount = function() {
|
||||
sendFlowService.pushState({
|
||||
toWalletId: $scope.wallet.credentials.walletId
|
||||
sendFlowService.start({
|
||||
toWalletId: $scope.wallet.credentials.walletId,
|
||||
isRequestAmount: true
|
||||
});
|
||||
$state.go('tabs.paymentRequest.amount');
|
||||
};
|
||||
|
||||
$scope.setAddress = function(newAddr, copyAddress) {
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
|
|||
|
||||
sendFlowService.start(params);
|
||||
}
|
||||
|
||||
// data extensions for Payment Protocol with non-backwards-compatible request
|
||||
if (allParsed.isValid && allParsed.coin && allParsed.url && !allParsed.testnet) {
|
||||
var coin = allParsed.coin;
|
||||
|
|
@ -373,20 +374,12 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
|
|||
};
|
||||
|
||||
function goToAmountPage(toAddress, coin) {
|
||||
$state.go('tabs.send', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.send' ? false : true
|
||||
});
|
||||
$timeout(function() {
|
||||
var stateParams = {
|
||||
toAddress: toAddress,
|
||||
displayAddress: toAddress,
|
||||
coin: coin,
|
||||
noPrefix: 1
|
||||
};
|
||||
sendFlowService.pushState(stateParams);
|
||||
$state.transitionTo('tabs.send.origin');
|
||||
}, 100);
|
||||
var stateParams = {
|
||||
toAddress: toAddress,
|
||||
displayAddress: toAddress,
|
||||
coin: coin,
|
||||
};
|
||||
sendFlowService.start(stateParams);
|
||||
}
|
||||
|
||||
function handlePayPro(payProData, coin) {
|
||||
|
|
@ -447,15 +440,7 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
|
|||
}
|
||||
|
||||
scannerService.pausePreview();
|
||||
$state.go('tabs.send', {}, {
|
||||
'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');
|
||||
});
|
||||
});
|
||||
sendFlowService.start(stateParams);
|
||||
}
|
||||
|
||||
return root;
|
||||
|
|
|
|||
|
|
@ -26,18 +26,24 @@ angular
|
|||
/**
|
||||
*
|
||||
*/
|
||||
function start() {
|
||||
if ($state.current.name != 'tabs.send') {
|
||||
$state.go('tabs.home').then(function () {
|
||||
$ionicHistory.clearHistory();
|
||||
$state.go('tabs.send').then(function () {
|
||||
$timeout(function () {
|
||||
goNext();
|
||||
}, 60);
|
||||
});
|
||||
});
|
||||
function start() {
|
||||
var state = sendFlowStateService.state;
|
||||
|
||||
if (state.isRequestAmount) {
|
||||
$state.go('tabs.paymentRequest.amount');
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ angular
|
|||
|
||||
function sendFlowService(
|
||||
sendFlowStateService, sendFlowRouterService
|
||||
, bitcoinUriService, payproService
|
||||
, bitcoinUriService, payproService, bitcoinCashJsService
|
||||
, popupService
|
||||
, $state
|
||||
) {
|
||||
|
|
@ -30,88 +30,111 @@ angular
|
|||
/**
|
||||
* Clears all previous state
|
||||
*/
|
||||
async function start(params) {
|
||||
function start(params) {
|
||||
console.log('start()');
|
||||
|
||||
if (params) {
|
||||
if (params.data) {
|
||||
var res = bitcoinUriService.parse(params.data);
|
||||
|
||||
if (res.isValid) {
|
||||
if (params && params.data) {
|
||||
var res = bitcoinUriService.parse(params.data);
|
||||
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
if (res.isValid) {
|
||||
|
||||
// Init thirdParty
|
||||
var thirdPartyData = {
|
||||
id: 'bip70',
|
||||
amount: amount,
|
||||
caTrusted: true,
|
||||
name: name,
|
||||
domain: payProData.domain,
|
||||
expires: expires,
|
||||
memo: payProData.memo,
|
||||
network: 'livenet',
|
||||
requiredFeeRate: payProData.requiredFeeRate,
|
||||
selfSigned: 0,
|
||||
time: time,
|
||||
toAddress: toAddr,
|
||||
url: paymentUrl,
|
||||
verified: true
|
||||
};
|
||||
/**
|
||||
* If BIP70
|
||||
*/
|
||||
if (res.url) {
|
||||
var url = res.url;
|
||||
var coin = res.coin || '';
|
||||
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';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in params
|
||||
*/
|
||||
params.amount = thirdPartyData.amount,
|
||||
params.toAddress = thirdPartyData.toAddress,
|
||||
params.coin = coin,
|
||||
params.thirdParty = thirdPartyData
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve
|
||||
*/
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
// Init thirdParty
|
||||
var thirdPartyData = {
|
||||
id: 'bip70',
|
||||
amount: amount,
|
||||
caTrusted: true,
|
||||
name: name,
|
||||
domain: payProData.domain,
|
||||
expires: expires,
|
||||
memo: payProData.memo,
|
||||
network: 'livenet',
|
||||
requiredFeeRate: payProData.requiredFeeRate,
|
||||
selfSigned: 0,
|
||||
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
|
||||
*/
|
||||
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) {
|
||||
|
|
@ -121,25 +144,17 @@ angular
|
|||
state.route = $state.current.name;
|
||||
|
||||
/**
|
||||
* Push the new state
|
||||
* Save the state and redirect the user
|
||||
*/
|
||||
sendFlowStateService.push(state);
|
||||
|
||||
/**
|
||||
* Go next
|
||||
*/
|
||||
sendFlowRouterService.goNext();
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
/**
|
||||
* Pop the current state
|
||||
* Remove the state on top and redirect the user
|
||||
*/
|
||||
sendFlowStateService.pop();
|
||||
|
||||
/**
|
||||
* Go back
|
||||
*/
|
||||
sendFlowRouterService.goBack();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue