Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: BN and rates for BCH/LTC and Stable Coin. Removed AmazonCard from Home view #12063

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ export class HomePage {
break;
case 'giftcards':
this.showShoppingOption = true;
this.setGiftCardAdvertisement();
break;
case 'coinbase':
this.showCoinbase =
Expand All @@ -569,28 +568,6 @@ export class HomePage {
});
}

private setGiftCardAdvertisement() {
const alreadyVisible = this.advertisements.find(
a => a.name === 'amazon-gift-cards'
);
!alreadyVisible &&
!this.platformProvider.isMacApp() &&
this.advertisements.unshift({
name: 'amazon-gift-cards',
title: this.translate.instant('Shop at Amazon'),
body: this.translate.instant(
'Leverage your crypto with an amazon.com gift card.'
),
app: 'bitpay',
linkText: this.translate.instant('Buy Now'),
link: CardCatalogPage,
isTesting: false,
imgSrc: 'assets/img/amazon.svg',
dismissible: true
});
this.showAdvertisements = true;
}

private addCardReferralAdvertisement() {
if (!this.isCordova) return;
this.persistenceProvider
Expand Down
22 changes: 17 additions & 5 deletions src/pages/send/confirm/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,10 @@ export class ConfirmPage {

txp.outputs.push({
toAddress: recipient.toAddress,
amount: recipient.amount,
amount: this.currencyProvider.parseAmount(
tx.coin,
recipient.amount
),
message: tx.description,
data: tx.data
});
Expand Down Expand Up @@ -1203,13 +1206,16 @@ export class ConfirmPage {
break;
}
tx.fee = estimatedFee;
tx.amount = tx.amount - estimatedFee;
tx.amount = this.currencyProvider.parseAmount(
tx.coin,
tx.amount - estimatedFee
);
}

txp.outputs = [
{
toAddress: tx.toAddress,
amount: tx.amount,
amount: this.currencyProvider.parseAmount(tx.coin, tx.amount),
message: tx.description,
data: tx.data,
gasLimit: tx.gasLimit // wallet connect needs exact gasLimit value
Expand Down Expand Up @@ -1272,7 +1278,13 @@ export class ConfirmPage {
.Transactions.get({ chain: 'ERC20' })
.encodeData({
recipients: [
{ address: output.toAddress, amount: output.amount }
{
address: output.toAddress,
amount: this.currencyProvider.parseAmount(
tx.coin,
output.amount
)
}
],
tokenAddress: tx.tokenAddress
});
Expand Down Expand Up @@ -1669,7 +1681,7 @@ export class ConfirmPage {
): void {
let msg: string;
if (!error) return;
this.logger.warn('ERROR:', error);
this.logger.error(error);
if (this.isCordova) this.slideButton.isConfirmed(false);

if (
Expand Down
57 changes: 41 additions & 16 deletions src/providers/currency/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ export class CurrencyProvider {
}

getLogoURI(coin: string): string {
return this.coinOpts[coin].logoURI || 'assets/img/default-token.svg';
return (
(this.coinOpts[coin] && this.coinOpts[coin].logoURI) ||
'assets/img/default-token.svg'
);
}

defaultLogoURI(img) {
Expand All @@ -201,23 +204,25 @@ export class CurrencyProvider {
}

isUtxoCoin(coin: string): boolean {
return !!this.coinOpts[coin].properties.isUtxo;
return this.coinOpts[coin] && !!this.coinOpts[coin].properties.isUtxo;
}

isSingleAddress(coin: string): boolean {
return !!this.coinOpts[coin].properties.singleAddress;
return (
this.coinOpts[coin] && !!this.coinOpts[coin].properties.singleAddress
);
}

isSharedCoin(coin: string): boolean {
return !!this.coinOpts[coin].properties.hasMultiSig;
return this.coinOpts[coin] && !!this.coinOpts[coin].properties.hasMultiSig;
}

isERCToken(coin: string): boolean {
return !!this.coinOpts[coin].properties.isERCToken;
return this.coinOpts[coin] && !!this.coinOpts[coin].properties.isERCToken;
}

isStableCoin(coin: string): boolean {
return !!this.coinOpts[coin].properties.isStableCoin;
return this.coinOpts[coin] && !!this.coinOpts[coin].properties.isStableCoin;
}

isCustomERCToken(coin: string) {
Expand All @@ -233,14 +238,18 @@ export class CurrencyProvider {
}

getLinkedEthWallet(coin: string, walletId: string, m: number): string {
if (!this.coinOpts[coin].properties.isERCToken && coin !== 'eth')
if (
this.coinOpts[coin] &&
!this.coinOpts[coin].properties.isERCToken &&
coin !== 'eth'
)
return null;
if (coin === 'eth' && m === 1) return null;
return walletId.replace(/-0x.*$/, '');
}

isMultiSend(coin: string): boolean {
return !!this.coinOpts[coin].properties.hasMultiSend;
return this.coinOpts[coin] && !!this.coinOpts[coin].properties.hasMultiSend;
}

getAvailableCoins(): string[] {
Expand Down Expand Up @@ -279,11 +288,11 @@ export class CurrencyProvider {
}

getCoinName(coin: string): string {
return this.coinOpts[coin].name;
return this.coinOpts[coin] && this.coinOpts[coin].name;
}

getChain(coin: string): string {
return this.coinOpts[coin].chain;
return this.coinOpts[coin] && this.coinOpts[coin].chain;
}

getRatesApi() {
Expand All @@ -299,27 +308,30 @@ export class CurrencyProvider {
}

getPaymentCode(coin: string): string {
return this.coinOpts[coin].paymentInfo.paymentCode;
return this.coinOpts[coin] && this.coinOpts[coin].paymentInfo.paymentCode;
}

getPrecision(coin: string) {
return this.coinOpts[coin].unitInfo;
return this.coinOpts[coin] && this.coinOpts[coin].unitInfo;
}

getProtocolPrefix(coin: string, network: string) {
return this.coinOpts[coin].paymentInfo.protocolPrefix[network];
return (
this.coinOpts[coin] &&
this.coinOpts[coin].paymentInfo.protocolPrefix[network]
);
}

getFeeUnits(coin: string) {
return this.coinOpts[coin].feeInfo;
return this.coinOpts[coin] && this.coinOpts[coin].feeInfo;
}

getMaxMerchantFee(coin: string): string {
return this.coinOpts[coin].feeInfo.maxMerchantFee;
return this.coinOpts[coin] && this.coinOpts[coin].feeInfo.maxMerchantFee;
}

getTheme(coin: string) {
return this.coinOpts[coin].theme;
return this.coinOpts[coin] && this.coinOpts[coin].theme;
}

getTokenAddress(coin) {
Expand All @@ -332,4 +344,17 @@ export class CurrencyProvider {
getPopularErc20Tokens() {
return _.orderBy(this.popularERC20TokensSymbols);
}

parseAmount(coin: string, amount: any): any {
if (
this.coinOpts[coin] &&
this.coinOpts[coin].unitInfo.unitDecimals >= 18
) {
return amount.toLocaleString('fullwide', {
useGrouping: false,
maximumFractionDigits: 0
});
}
return amount;
}
}
2 changes: 2 additions & 0 deletions src/providers/rate/rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export class RateProvider {
return this.getRates()
.then(res => {
_.map(res, (rates, coin) => {
// Compatibility new coin scheme for ETH network
coin = coin.replace('_e', '');
const coinRates = {};
_.each(rates, r => {
if (r.code && r.rate) {
Expand Down