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.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) {
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -27,17 +27,23 @@ 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 BIP70
|
||||||
*/
|
*/
|
||||||
if (res.url) {
|
if (res.url) {
|
||||||
var url = res.url;
|
var url = res.url;
|
||||||
var coin = res.coin || '';
|
var coin = res.coin || '';
|
||||||
await new Promise(function (resolve) {
|
payproService.getPayProDetails(url, coin, function onGetPayProDetails(err, payProData) {
|
||||||
payproService.getPayProDetails(url, coin, function onGetPayProDetails(err, payProData) {
|
if (err) {
|
||||||
if (err) {
|
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
} else {
|
||||||
} else {
|
// Fill in the params
|
||||||
// Fill in the params
|
var toAddr = payProData.toAddress;
|
||||||
var toAddr = payProData.toAddress;
|
var amount = payProData.amount;
|
||||||
var amount = payProData.amount;
|
var paymentUrl = payProData.url;
|
||||||
var paymentUrl = payProData.url;
|
var expires = payProData.expires;
|
||||||
var expires = payProData.expires;
|
var time = payProData.time;
|
||||||
var time = payProData.time;
|
var name = payProData.domain;
|
||||||
var name = payProData.domain;
|
|
||||||
|
|
||||||
// Detect some merchant that we know
|
// Detect some merchant that we know
|
||||||
if (payProData.memo.indexOf('eGifter') > -1) {
|
if (payProData.memo.indexOf('eGifter') > -1) {
|
||||||
name = 'eGifter'
|
name = 'eGifter'
|
||||||
} else if (paymentUrl.indexOf('https://bitpay.com') > -1) {
|
} else if (paymentUrl.indexOf('https://bitpay.com') > -1) {
|
||||||
name = 'BitPay';
|
name = 'BitPay';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init thirdParty
|
// Init thirdParty
|
||||||
var thirdPartyData = {
|
var thirdPartyData = {
|
||||||
id: 'bip70',
|
id: 'bip70',
|
||||||
amount: amount,
|
amount: amount,
|
||||||
caTrusted: true,
|
caTrusted: true,
|
||||||
name: name,
|
name: name,
|
||||||
domain: payProData.domain,
|
domain: payProData.domain,
|
||||||
expires: expires,
|
expires: expires,
|
||||||
memo: payProData.memo,
|
memo: payProData.memo,
|
||||||
network: 'livenet',
|
network: 'livenet',
|
||||||
requiredFeeRate: payProData.requiredFeeRate,
|
requiredFeeRate: payProData.requiredFeeRate,
|
||||||
selfSigned: 0,
|
selfSigned: 0,
|
||||||
time: time,
|
time: time,
|
||||||
toAddress: toAddr,
|
toAddress: toAddr,
|
||||||
url: paymentUrl,
|
url: paymentUrl,
|
||||||
verified: true
|
verified: true
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill in params
|
* Fill in params
|
||||||
*/
|
*/
|
||||||
params.amount = thirdPartyData.amount,
|
params.amount = thirdPartyData.amount,
|
||||||
params.toAddress = thirdPartyData.toAddress,
|
params.toAddress = thirdPartyData.toAddress,
|
||||||
params.coin = coin,
|
params.coin = coin,
|
||||||
params.thirdParty = thirdPartyData
|
params.thirdParty = thirdPartyData
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve
|
* Resolve
|
||||||
*/
|
*/
|
||||||
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
|
* Routing strategy to -> send-flow-router.service
|
||||||
*/
|
*/
|
||||||
sendFlowRouterService.start();
|
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();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue