updated code to work with bitpay bch payments

This commit is contained in:
Kadir Sekha 2018-03-01 14:19:52 +05:00
commit 381a4e9f78
5 changed files with 51 additions and 12 deletions

View file

@ -23,7 +23,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
//custom fee flag
var usingCustomFee = null;
var usingCustomFee = false;
var usingMerchantFee = false;
function refresh() {
$timeout(function() {
@ -177,7 +178,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txp: {},
};
if (tx.coin && tx.coin == 'bch') tx.feeLevel = 'normal';
if (data.stateParams.requiredFeeRate) {
usingMerchantFee = true;
tx.feeRate = parseInt(data.stateParams.requiredFeeRate);
}
if (tx.coin && tx.coin == 'bch') {
tx.feeLevel = 'normal';
}
// Other Scope vars
$scope.isCordova = isCordova;
@ -240,7 +248,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txp.inputs = tx.sendMaxInfo.inputs;
txp.fee = tx.sendMaxInfo.fee;
} else {
if (usingCustomFee) {
if (usingCustomFee || usingMerchantFee) {
txp.feePerKb = tx.feeRate;
} else txp.feeLevel = tx.feeLevel;
}
@ -291,14 +299,29 @@ angular.module('copayApp.controllers').controller('confirmController', function(
return cb();
}
feeService.getFeeRate(wallet.coin, tx.network, tx.feeLevel, function(err, feeRate) {
feeService.getFeeRate(wallet.coin, tx.network, usingMerchantFee ? 'urgent' : tx.feeLevel, function(err, feeRate) {
if (err) {
ongoingProcess.set('calculatingFee', false);
return cb(err);
}
if (!usingCustomFee) tx.feeRate = feeRate;
tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
var msg;
if (usingCustomFee) {
msg = gettextCatalog.getString('Custom');
tx.feeLevelName = msg;
} else if (usingMerchantFee) {
$log.info('Using Merchant Fee:' + tx.feeRate + ' vs. Urgent level:' + feeRate);
if (tx.feeRate > feeRate) {
ongoingProcess.set('calculatingFee', false);
setNoWallet(gettextCatalog.getString('Merchant fee to high. Payment rejected'), true);
return cb('fee_too_high');
}
msg = gettextCatalog.getString('Suggested by Merchant');
tx.feeLevelName = msg;
} else {
tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
tx.feeRate = feeRate;
}
getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) {
if (err) {
@ -337,7 +360,12 @@ angular.module('copayApp.controllers').controller('confirmController', function(
getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) {
ongoingProcess.set('calculatingFee', false);
if (err) {
return cb(err);
if (err.message == 'Insufficient funds') {
setNoWallet(gettextCatalog.getString('Insufficient funds'));
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
return cb('no_funds');
} else
return cb(err);
}
txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee);
@ -487,8 +515,11 @@ angular.module('copayApp.controllers').controller('confirmController', function(
// If select another wallet
tx.coin = wallet.coin;
tx.feeLevel = wallet.coin == 'bch' ? 'normal' : configFeeLevel;
usingCustomFee = null;
if (usingCustomFee) {
} else {
tx.feeLevel = wallet.coin == 'bch' ? 'normal' : configFeeLevel;
}
setButtonText(wallet.credentials.m > 1, !!tx.paypro);
@ -637,6 +668,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.chooseFeeLevel = function(tx, wallet) {
if (wallet.coin == 'bch') return;
if (usingMerchantFee) return;
var scope = $rootScope.$new(true);
scope.network = tx.network;

View file

@ -296,7 +296,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('tabs.send.confirm', {
url: '/confirm/:recipientType/:toAddress/:toName/:toAmount/:toEmail/:toColor/:description/:coin/:useSendMax/:fromWalletId/:displayAddress',
url: '/confirm/:recipientType/:toAddress/:toName/:toAmount/:toEmail/:toColor/:description/:coin/:useSendMax/:fromWalletId/:displayAddress/:requiredFeeRate',
views: {
'tab-send@tabs': {
controller: 'confirmController',

View file

@ -34,7 +34,8 @@ angular.module('copayApp.services')
};
root.add = function(level, msg) {
msg = msg.replace('/xpriv.*/', 'xpriv[Hidden]');
msg = msg.replace('/xpriv.*/', '[...]');
msg = msg.replace('/walletPrivKey.*/', 'walletPrivKey:[...]');
logs.push({
timestamp: new Date().toISOString(),
level: level,

View file

@ -380,6 +380,12 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
paypro: payProDetails,
coin: coin,
};
// fee
if (payProDetails.requiredFeeRate) {
stateParams.requiredFeeRate = payProDetails.requiredFeeRate * 1024;
}
scannerService.pausePreview();
$state.go('tabs.send', {}, {
'reload': true,

View file

@ -27,7 +27,7 @@ angular.module('copayApp.services').factory('payproService',
payProUrl: uri,
}, function(err, paypro) {
if (!disableLoader) ongoingProcess.set('fetchingPayPro', false);
if (err) return cb(err);
if (err) return cb(gettextCatalog.getString('Could Not Fetch Payment: Check if it is still valid'));
else if (!paypro.verified) {
$log.warn('Failed to verify payment protocol signatures');
return cb(gettextCatalog.getString('Payment Protocol Invalid'));