cashAddr support 2 - tx-details

This commit is contained in:
Gabriel Masclef 2018-01-16 10:17:28 -03:00
parent 154883baf1
commit 454db6b968
No known key found for this signature in database
GPG Key ID: DD6D7EAADE12280D
5 changed files with 33 additions and 10 deletions

View File

@ -109,7 +109,6 @@ export class ConfirmPage {
this.tx.toAddress = this.bitcoreCash.Address(this.tx.toAddress).toString();
}
this.tx.feeLevel = 'normal';
this.tx.feeLevelName = this.feeProvider.feeOpts[this.tx.feeLevel];
this.showAddress = false;
this.walletSelectorTitle = 'Send from'; // TODO gettextCatalog

View File

@ -63,7 +63,11 @@ export class TxDetailsPage {
this.txsUnsubscribedForNotifications = this.config.confirmedTxsNotifications ? !this.config.confirmedTxsNotifications.enabled : true;
if (this.wallet.coin == 'bch') {
this.blockexplorerUrl = 'bch-insight.bitpay.com';
if (this.walletProvider.useLegacyAddress(this.wallet)) {
this.blockexplorerUrl = 'bch-insight.bitpay.com';
} else {
this.blockexplorerUrl = 'blockdozer.com/insight';
}
} else {
this.blockexplorerUrl = 'insight.bitpay.com';
}
@ -153,7 +157,7 @@ export class TxDetailsPage {
this.walletProvider.getTx(this.wallet, this.txId).then((tx: any) => {
if (!opts.hideLoading) this.onGoingProcess.set('loadingTxInfo', false);
this.btx = this.txFormatProvider.processTx(this.wallet.coin, tx);
this.btx = this.txFormatProvider.processTx(this.wallet.coin, tx, this.walletProvider.useLegacyAddress(this.wallet));
let v: string = this.txFormatProvider.formatAlternativeStr(this.wallet.coin, tx.fees);
this.btx.feeFiatStr = v;
this.btx.feeRateStr = (this.btx.fees / (this.btx.amount + this.btx.fees) * 100).toFixed(2) + '%';

View File

@ -81,7 +81,7 @@ export class IncomingDataProvider {
parsed = this.bwcProvider.getBitcoreCash().URI(data);
addr = parsed.address ? parsed.address.toString() : '';
// keep address in original formal
// keep address in original format
if (parsed.address && data.indexOf(addr) < 0) {
addr = parsed.address.toCashAddress();
};

View File

@ -10,17 +10,30 @@ import * as _ from "lodash";
@Injectable()
export class TxFormatProvider {
private bitcoreCash: any;
// TODO: implement configService
public pendingTxProposalsCountForUs: number
constructor(
private bwc: BwcProvider,
private bwcProvider: BwcProvider,
private rate: RateProvider,
private config: ConfigProvider,
private filter: FilterProvider,
private logger: Logger
) {
this.logger.info('TxFormatProvider initialized.');
this.bitcoreCash = this.bwcProvider.getBitcoreCash();
}
public toCashAddress(address: string, withPrefix?: boolean): string {
let cashAddr: string = (this.bitcoreCash.Address(address)).toCashAddress();
if (withPrefix) {
return cashAddr;
}
return cashAddr.split(':')[1]; // rm prefix
}
public formatAmount(satoshis: number, fullPrecision?: boolean): number {
@ -32,7 +45,7 @@ export class TxFormatProvider {
var opts = {
fullPrecision: !!fullPrecision
};
return this.bwc.getUtils().formatAmount(satoshis, settings.unitCode, opts);
return this.bwcProvider.getUtils().formatAmount(satoshis, settings.unitCode, opts);
}
public formatAmountStr(coin: string, satoshis: number): string {
@ -78,7 +91,7 @@ export class TxFormatProvider {
return val();
};
public processTx(coin: string, tx: any): any {
public processTx(coin: string, tx: any, useLegacyAddress: boolean): any {
if (!tx || tx.action == 'invalid')
return tx;
@ -99,6 +112,11 @@ export class TxFormatProvider {
}, 0);
}
tx.toAddress = tx.outputs[0].toAddress;
// toDo: translate all tx.outputs[x].toAddress ?
if (tx.toAddress && coin == 'bch' && !useLegacyAddress) {
tx.toAddress = this.toCashAddress(tx.toAddress);
}
}
tx.amountStr = this.formatAmountStr(coin, tx.amount);
@ -110,6 +128,10 @@ export class TxFormatProvider {
tx.amountUnitStr = tx.amountStr.split(' ')[1];
}
if (tx.addressTo && coin == 'bch' && !useLegacyAddress) {
tx.addressTo = this.toCashAddress(tx.addressTo);
}
return tx;
};

View File

@ -334,9 +334,7 @@ export class WalletProvider {
public getAddressView(wallet: any, address: string): string {
if (wallet.coin != 'bch' || this.useLegacyAddress(wallet)) return address;
let cashAddr = (this.bitcoreCash.Address(address)).toCashAddress();;
return cashAddr.split(':')[1]; // rm prefix
return this.txFormatProvider.toCashAddress(address);
}
public getAddress(wallet: any, forceNew: boolean): Promise<any> {