mirror of https://github.com/BTCPrivate/copay.git
Feat: support required fee in paypro
This commit is contained in:
parent
fab77e0a8b
commit
f3c622997d
|
@ -115,7 +115,7 @@
|
|||
"@types/papaparse": "^4.1.33",
|
||||
"angular2-moment": "^1.7.1",
|
||||
"bitauth": "git+https://github.com/bitpay/bitauth.git#copay",
|
||||
"bitcore-wallet-client": "^6.6.4",
|
||||
"bitcore-wallet-client": "6.7.1",
|
||||
"buffer-compare": "^1.1.1",
|
||||
"cordova-android": "7.0.0",
|
||||
"cordova-clipboard": "^1.1.1",
|
||||
|
@ -235,4 +235,4 @@
|
|||
"prettier": {
|
||||
"singleQuote": true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,4 +17,4 @@
|
|||
"url": "git://github.com/bitpay/copay.git",
|
||||
"type": "git"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -58,6 +58,7 @@ export class ConfirmPage {
|
|||
|
||||
// custom fee flag
|
||||
public usingCustomFee: boolean = false;
|
||||
public usingMerchantFee: boolean = false;
|
||||
|
||||
constructor(
|
||||
private bwcProvider: BwcProvider,
|
||||
|
@ -127,6 +128,13 @@ export class ConfirmPage {
|
|||
};
|
||||
this.tx.origToAddress = this.tx.toAddress;
|
||||
|
||||
if (this.navParams.data.requiredFeeRate) {
|
||||
this.usingMerchantFee = true;
|
||||
this.tx.feeRate = parseInt(this.navParams.data.requiredFeeRate, 10);
|
||||
} else {
|
||||
this.tx.feeLevel = (this.tx.coin && this.tx.coin == 'bch') ? 'normal ' : this.configFeeLevel;
|
||||
}
|
||||
|
||||
if (this.tx.coin && this.tx.coin == 'bch') {
|
||||
this.tx.feeLevel = 'normal';
|
||||
|
||||
|
@ -237,7 +245,10 @@ export class ConfirmPage {
|
|||
|
||||
// If select another wallet
|
||||
this.tx.coin = this.wallet.coin;
|
||||
if (this.tx.coin == 'bch') this.tx.feeLevel = 'normal';
|
||||
|
||||
if (!this.usingCustomFee && !this.usingMerchantFee) {
|
||||
this.tx.feeLevel = wallet.coin == 'bch' ? 'normal' : this.configFeeLevel;
|
||||
}
|
||||
|
||||
this.setButtonText(this.wallet.credentials.m > 1, !!this.tx.paypro);
|
||||
|
||||
|
@ -304,9 +315,34 @@ export class ConfirmPage {
|
|||
return resolve();
|
||||
}
|
||||
|
||||
let maxAllowedMerchantFee = {
|
||||
btc: 'urgent',
|
||||
bch: 'normal',
|
||||
}
|
||||
|
||||
this.onGoingProcessProvider.set('calculatingFee');
|
||||
this.feeProvider.getFeeRate(wallet.coin, tx.network, tx.feeLevel).then((feeRate: any) => {
|
||||
if (!this.usingCustomFee) tx.feeRate = feeRate;
|
||||
this.feeProvider.getFeeRate(wallet.coin, tx.network, this.usingMerchantFee ? maxAllowedMerchantFee[wallet.coin] : this.tx.feeLevel).then((feeRate: any) => {
|
||||
|
||||
let msg;
|
||||
if (this.usingCustomFee) {
|
||||
msg = this.translate.instant('Custom');
|
||||
tx.feeLevelName = msg;
|
||||
} else if (this.usingMerchantFee) {
|
||||
|
||||
let maxAllowedfee = feeRate * 2;
|
||||
this.logger.info('Using Merchant Fee:' + tx.feeRate + ' vs. referent level:' + maxAllowedfee);
|
||||
if (tx.feeRate > maxAllowedfee) {
|
||||
this.onGoingProcessProvider.set('calculatingFee');
|
||||
this.setNoWallet(this.translate.instant('Merchant fee to high. Payment rejected'), true);
|
||||
return reject('fee_too_high');
|
||||
}
|
||||
|
||||
msg = this.translate.instant('Suggested by Merchant');
|
||||
tx.feeLevelName = msg;
|
||||
} else {
|
||||
tx.feeLevelName = this.feeProvider.feeOpts[tx.feeLevel];
|
||||
tx.feeRate = feeRate;
|
||||
}
|
||||
|
||||
// call getSendMaxInfo if was selected from amount view
|
||||
if (tx.sendMax) {
|
||||
|
@ -394,7 +430,13 @@ export class ConfirmPage {
|
|||
this.logger.debug('Confirm. TX Fully Updated for wallet:' + wallet.id, JSON.stringify(tx));
|
||||
return resolve();
|
||||
}).catch((err: any) => {
|
||||
return reject(err);
|
||||
if (err.message == 'Insufficient funds') {
|
||||
this.setNoWallet(this.translate.instant('Insufficient funds'));
|
||||
this.popupProvider.ionicAlert(this.translate.instant('Error'), this.translate.instant('Not enough funds for fee'));
|
||||
return reject('no_funds');
|
||||
} else {
|
||||
return reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -477,7 +519,7 @@ export class ConfirmPage {
|
|||
txp.inputs = tx.sendMaxInfo.inputs;
|
||||
txp.fee = tx.sendMaxInfo.fee;
|
||||
} else {
|
||||
if (this.usingCustomFee) {
|
||||
if (this.usingCustomFee || this.usingMerchantFee) {
|
||||
txp.feePerKb = tx.feeRate;
|
||||
} else txp.feeLevel = tx.feeLevel;
|
||||
}
|
||||
|
@ -628,6 +670,7 @@ export class ConfirmPage {
|
|||
public chooseFeeLevel(): void {
|
||||
|
||||
if (this.tx.coin == 'bch') return;
|
||||
if (this.usingMerchantFee) return; // ToDo: should we allow overwride?
|
||||
|
||||
let txObject: any = {};
|
||||
txObject.network = this.tx.network;
|
||||
|
|
|
@ -322,13 +322,17 @@ export class IncomingDataProvider {
|
|||
}
|
||||
|
||||
private handlePayPro(payProDetails: any, coin?: string): void {
|
||||
let stateParams = {
|
||||
let stateParams: any = {
|
||||
amount: payProDetails.amount,
|
||||
toAddress: payProDetails.toAddress,
|
||||
description: payProDetails.memo,
|
||||
paypro: payProDetails,
|
||||
coin
|
||||
};
|
||||
// fee
|
||||
if (payProDetails.requiredFeeRate) {
|
||||
stateParams.requiredFeeRate = payProDetails.requiredFeeRate * 1024;
|
||||
}
|
||||
this.scanProvider.pausePreview();
|
||||
this.navCtrl.push(ConfirmPage, stateParams);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,8 @@ export class Logger {
|
|||
}
|
||||
|
||||
public add(level, msg): any {
|
||||
msg = msg.replace('/xpriv.*/', 'xpriv[Hidden]');
|
||||
msg = msg.replace('/xpriv.*/', '[...]');
|
||||
msg = msg.replace('/walletPrivKey.*/', 'walletPrivKey:[...]');
|
||||
this.logs.push({
|
||||
timestamp: new Date().toISOString(),
|
||||
level,
|
||||
|
|
|
@ -35,7 +35,7 @@ export class PayproProvider {
|
|||
payProUrl: uri,
|
||||
}, (err, paypro) => {
|
||||
if (!disableLoader) this.onGoingProcessProvider.clear();
|
||||
if (err) return reject(err);
|
||||
if (err) return reject(this.translate.instant('Could Not Fetch Payment: Check if it is still valid'));
|
||||
else if (!paypro.verified) {
|
||||
this.logger.warn('Failed to verify payment protocol signatures');
|
||||
return reject(this.translate.instant('Payment Protocol Invalid'));
|
||||
|
|
Loading…
Reference in New Issue