Fix top-up. Use coin on top-up view

This commit is contained in:
Gustavo Maximiliano Cortez 2018-02-21 19:14:23 -03:00
parent b3d5b40240
commit 62252b7103
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
3 changed files with 28 additions and 27 deletions

View File

@ -31,7 +31,6 @@ const FEE_TOO_HIGH_LIMIT_PER = 15;
}) })
export class BitPayCardTopUpPage { export class BitPayCardTopUpPage {
public coin: string;
public cardId; public cardId;
public useSendMax: boolean; public useSendMax: boolean;
public amount; public amount;
@ -74,7 +73,6 @@ export class BitPayCardTopUpPage {
private platformProvider: PlatformProvider, private platformProvider: PlatformProvider,
private feeProvider: FeeProvider private feeProvider: FeeProvider
) { ) {
this.coin = 'btc';
this.configWallet = this.configProvider.get().wallet; this.configWallet = this.configProvider.get().wallet;
this.isCordova = this.platformProvider.isCordova; this.isCordova = this.platformProvider.isCordova;
} }
@ -84,6 +82,8 @@ export class BitPayCardTopUpPage {
} }
ionViewWillEnter() { ionViewWillEnter() {
let coin = this.navParams.data.coin;
this.cardId = this.navParams.data.id; this.cardId = this.navParams.data.id;
this.useSendMax = this.navParams.data.useSendMax; this.useSendMax = this.navParams.data.useSendMax;
this.currency = this.navParams.data.currency; this.currency = this.navParams.data.currency;
@ -106,7 +106,7 @@ export class BitPayCardTopUpPage {
onlyComplete: true, onlyComplete: true,
network: this.bitPayProvider.getEnvironment().network, network: this.bitPayProvider.getEnvironment().network,
hasFunds: true, hasFunds: true,
coin: this.coin coin
}); });
if (_.isEmpty(this.wallets)) { if (_.isEmpty(this.wallets)) {
@ -148,9 +148,9 @@ export class BitPayCardTopUpPage {
}); });
} }
private satToFiat(sat: number): Promise<any> { private satToFiat(coin: string, sat: number): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.txFormatProvider.toFiat(this.coin, sat, this.currencyIsoCode).then((value: string) => { this.txFormatProvider.toFiat(coin, sat, this.currencyIsoCode).then((value: string) => {
return resolve(value); return resolve(value);
}); });
}); });
@ -174,14 +174,14 @@ export class BitPayCardTopUpPage {
}); });
} }
private setTotalAmount(amountSat: number, invoiceFeeSat: number, networkFeeSat: number) { private setTotalAmount(wallet: any, amountSat: number, invoiceFeeSat: number, networkFeeSat: number) {
this.satToFiat(amountSat).then((a: string) => { this.satToFiat(wallet.coin, amountSat).then((a: string) => {
this.amount = Number(a); this.amount = Number(a);
this.satToFiat(invoiceFeeSat).then((i: string) => { this.satToFiat(wallet.coin, invoiceFeeSat).then((i: string) => {
this.invoiceFee = Number(i); this.invoiceFee = Number(i);
this.satToFiat(networkFeeSat).then((n: string) => { this.satToFiat(wallet.coin, networkFeeSat).then((n: string) => {
this.networkFee = Number(n); this.networkFee = Number(n);
this.totalAmount = this.amount + this.invoiceFee + this.networkFee; this.totalAmount = this.amount + this.invoiceFee + this.networkFee;
}); });
@ -334,7 +334,8 @@ export class BitPayCardTopUpPage {
this.amountUnitStr = parsedAmount.amountUnitStr; this.amountUnitStr = parsedAmount.amountUnitStr;
var dataSrc = { var dataSrc = {
amount: parsedAmount.amount, amount: parsedAmount.amount,
currency: parsedAmount.currency currency: parsedAmount.currency,
buyerSelectedTransactionCurrency: wallet.coin.toUpperCase()
}; };
this.onGoingProcessProvider.set('loadingTxInfo'); this.onGoingProcessProvider.set('loadingTxInfo');
this.createInvoice(dataSrc).then((invoice) => { this.createInvoice(dataSrc).then((invoice) => {
@ -353,12 +354,12 @@ export class BitPayCardTopUpPage {
// Save TX in memory // Save TX in memory
this.createdTx = ctxp; this.createdTx = ctxp;
this.totalAmountStr = this.txFormatProvider.formatAmountStr(this.coin, ctxp.amount); this.totalAmountStr = this.txFormatProvider.formatAmountStr(wallet.coin, ctxp.amount);
// Warn: fee too high // Warn: fee too high
this.checkFeeHigh(Number(parsedAmount.amountSat), Number(invoiceFeeSat) + Number(ctxp.fee)); this.checkFeeHigh(Number(parsedAmount.amountSat), Number(invoiceFeeSat) + Number(ctxp.fee));
this.setTotalAmount(parsedAmount.amountSat, Number(invoiceFeeSat), ctxp.fee); this.setTotalAmount(wallet, parsedAmount.amountSat, Number(invoiceFeeSat), ctxp.fee);
}).catch((err) => { }).catch((err) => {
this.onGoingProcessProvider.clear(); this.onGoingProcessProvider.clear();
@ -401,9 +402,9 @@ export class BitPayCardTopUpPage {
public onWalletSelect(wallet: any): void { public onWalletSelect(wallet: any): void {
this.wallet = wallet; this.wallet = wallet;
this.onGoingProcessProvider.set('retrievingInputs'); this.onGoingProcessProvider.set('retrievingInputs');
this.calculateAmount(this.wallet).then((val: any) => { this.calculateAmount(wallet).then((val: any) => {
let parsedAmount = this.txFormatProvider.parseAmount(this.coin, val.amount, val.currency); let parsedAmount = this.txFormatProvider.parseAmount(wallet.coin, val.amount, val.currency);
this.initializeTopUp(this.wallet, parsedAmount); this.initializeTopUp(wallet, parsedAmount);
}).catch((err) => { }).catch((err) => {
this.onGoingProcessProvider.clear(); this.onGoingProcessProvider.clear();
this._resetValues(); this._resetValues();

View File

@ -191,8 +191,8 @@ export class BitPayCardPage {
this.navCtrl.push(AmountPage, { this.navCtrl.push(AmountPage, {
id: this.cardId, id: this.cardId,
nextPage: 'BitPayCardTopUpPage', nextPage: 'BitPayCardTopUpPage',
currency: 'USD', currency: this.currency,
coin: 'btc' coin: 'btc' // Force BTC for now
}); });
} }
} }

View File

@ -306,26 +306,26 @@ export class BitPayCardProvider {
if (!card) if (!card)
return cb(this._setError('Card not found')); return cb(this._setError('Card not found'));
this.bitPayProvider.post('/api/v2/' + card.token, json, (data) => { this.bitPayProvider.post('/api/v2/' + card.token, json, (res) => {
this.logger.info('BitPay TopUp: SUCCESS'); this.logger.info('BitPay TopUp: SUCCESS');
if (data.error) { if (res.error) {
return cb(data.error); return cb(res.error);
} else { } else {
return cb(null, data.invoice); return cb(null, res.data.invoice);
} }
}, (data) => { }, (res) => {
return cb(this._setError('BitPay Card Error: TopUp', data)); return cb(this._setError('BitPay Card Error: TopUp', res));
}); });
}); });
}); });
}; };
public getInvoice(id, cb) { public getInvoice(id, cb) {
this.bitPayProvider.get('/invoices/' + id, (data) => { this.bitPayProvider.get('/invoices/' + id, (res) => {
this.logger.info('BitPay Get Invoice: SUCCESS'); this.logger.info('BitPay Get Invoice: SUCCESS');
return cb(data.error, data.data); return cb(res.error, res.data);
}, (data) => { }, (res) => {
return cb(this._setError('BitPay Card Error: Get Invoice', data)); return cb(this._setError('BitPay Card Error: Get Invoice', res));
}); });
}; };