updated code to work with bitpay bch payments
This commit is contained in:
parent
8d4bf711eb
commit
381a4e9f78
5 changed files with 51 additions and 12 deletions
|
|
@ -23,7 +23,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||||
|
|
||||||
//custom fee flag
|
//custom fee flag
|
||||||
var usingCustomFee = null;
|
var usingCustomFee = false;
|
||||||
|
var usingMerchantFee = false;
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|
@ -177,7 +178,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
txp: {},
|
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
|
// Other Scope vars
|
||||||
$scope.isCordova = isCordova;
|
$scope.isCordova = isCordova;
|
||||||
|
|
@ -240,7 +248,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
txp.inputs = tx.sendMaxInfo.inputs;
|
txp.inputs = tx.sendMaxInfo.inputs;
|
||||||
txp.fee = tx.sendMaxInfo.fee;
|
txp.fee = tx.sendMaxInfo.fee;
|
||||||
} else {
|
} else {
|
||||||
if (usingCustomFee) {
|
if (usingCustomFee || usingMerchantFee) {
|
||||||
txp.feePerKb = tx.feeRate;
|
txp.feePerKb = tx.feeRate;
|
||||||
} else txp.feeLevel = tx.feeLevel;
|
} else txp.feeLevel = tx.feeLevel;
|
||||||
}
|
}
|
||||||
|
|
@ -291,14 +299,29 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
return cb();
|
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) {
|
if (err) {
|
||||||
ongoingProcess.set('calculatingFee', false);
|
ongoingProcess.set('calculatingFee', false);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usingCustomFee) tx.feeRate = feeRate;
|
var msg;
|
||||||
tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
|
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) {
|
getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -337,7 +360,12 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) {
|
getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) {
|
||||||
ongoingProcess.set('calculatingFee', false);
|
ongoingProcess.set('calculatingFee', false);
|
||||||
if (err) {
|
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);
|
txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee);
|
||||||
|
|
@ -487,8 +515,11 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
|
|
||||||
// If select another wallet
|
// If select another wallet
|
||||||
tx.coin = wallet.coin;
|
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);
|
setButtonText(wallet.credentials.m > 1, !!tx.paypro);
|
||||||
|
|
||||||
|
|
@ -637,6 +668,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
$scope.chooseFeeLevel = function(tx, wallet) {
|
$scope.chooseFeeLevel = function(tx, wallet) {
|
||||||
|
|
||||||
if (wallet.coin == 'bch') return;
|
if (wallet.coin == 'bch') return;
|
||||||
|
if (usingMerchantFee) return;
|
||||||
|
|
||||||
var scope = $rootScope.$new(true);
|
var scope = $rootScope.$new(true);
|
||||||
scope.network = tx.network;
|
scope.network = tx.network;
|
||||||
|
|
|
||||||
|
|
@ -296,7 +296,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.send.confirm', {
|
.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: {
|
views: {
|
||||||
'tab-send@tabs': {
|
'tab-send@tabs': {
|
||||||
controller: 'confirmController',
|
controller: 'confirmController',
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.add = function(level, msg) {
|
root.add = function(level, msg) {
|
||||||
msg = msg.replace('/xpriv.*/', 'xpriv[Hidden]');
|
msg = msg.replace('/xpriv.*/', '[...]');
|
||||||
|
msg = msg.replace('/walletPrivKey.*/', 'walletPrivKey:[...]');
|
||||||
logs.push({
|
logs.push({
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
level: level,
|
level: level,
|
||||||
|
|
|
||||||
|
|
@ -380,6 +380,12 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
||||||
paypro: payProDetails,
|
paypro: payProDetails,
|
||||||
coin: coin,
|
coin: coin,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// fee
|
||||||
|
if (payProDetails.requiredFeeRate) {
|
||||||
|
stateParams.requiredFeeRate = payProDetails.requiredFeeRate * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
scannerService.pausePreview();
|
scannerService.pausePreview();
|
||||||
$state.go('tabs.send', {}, {
|
$state.go('tabs.send', {}, {
|
||||||
'reload': true,
|
'reload': true,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ angular.module('copayApp.services').factory('payproService',
|
||||||
payProUrl: uri,
|
payProUrl: uri,
|
||||||
}, function(err, paypro) {
|
}, function(err, paypro) {
|
||||||
if (!disableLoader) ongoingProcess.set('fetchingPayPro', false);
|
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) {
|
else if (!paypro.verified) {
|
||||||
$log.warn('Failed to verify payment protocol signatures');
|
$log.warn('Failed to verify payment protocol signatures');
|
||||||
return cb(gettextCatalog.getString('Payment Protocol Invalid'));
|
return cb(gettextCatalog.getString('Payment Protocol Invalid'));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue