Skip to content

Commit

Permalink
Merge pull request #11990 from Gamboster/fix/enableXrpForNonUsCountries
Browse files Browse the repository at this point in the history
Fix: enable buy and swap xrp for non-US countries only
  • Loading branch information
cmgustavo committed Dec 28, 2021
2 parents 9982817 + c4a5316 commit 78ce1d9
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 28 deletions.
28 changes: 21 additions & 7 deletions src/pages/buy-crypto/crypto-order-summary/crypto-order-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,21 @@ export class CryptoOrderSummaryPage {
const supportedCoins = this.isPromotionActiveForCountry(
this.selectedCountry
)
? this.buyCryptoProvider.getExchangeCoinsSupported('simplex')
: this.buyCryptoProvider.getExchangeCoinsSupported();
? _.clone(this.buyCryptoProvider.getExchangeCoinsSupported('simplex'))
: _.clone(this.buyCryptoProvider.getExchangeCoinsSupported());

if (this.selectedCountry.shortCode == 'US') {
const coinsToRemove = ['xrp'];
coinsToRemove.forEach((coin: string) => {
const index = supportedCoins.indexOf(coin);
if (index > -1) {
this.logger.debug(
`Removing ${coin.toUpperCase()} from Buy crypto supported coins`
);
supportedCoins.splice(index, 1);
}
});
}

let modal = this.modalCtrl.create(
CoinAndWalletSelectorPage,
Expand Down Expand Up @@ -367,11 +380,12 @@ export class CryptoOrderSummaryPage {

private isCoinSupportedByCountry(): boolean {
if (
this.isPromotionActiveForCountry(this.selectedCountry) &&
!_.includes(
this.buyCryptoProvider.getExchangeCoinsSupported('simplex'),
this.coin
)
(this.isPromotionActiveForCountry(this.selectedCountry) &&
!_.includes(
this.buyCryptoProvider.getExchangeCoinsSupported('simplex'),
this.coin
)) ||
(this.coin == 'xrp' && this.selectedCountry.shortCode == 'US')
) {
this.logger.debug(
`Selected coin: ${this.coin} is not currently available for selected country: ${this.selectedCountry.name}. Show warning.`
Expand Down
5 changes: 3 additions & 2 deletions src/pages/exchange-crypto/exchange-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export class ExchangeCryptoPage {
}

private async getExchangesCurrencies() {
let country;
const reflect = promiseObj => {
return promiseObj.promise.then(
v => {
Expand All @@ -231,7 +232,7 @@ export class ExchangeCryptoPage {
];

try {
const country = await this.locationProvider.getCountry();
country = await this.locationProvider.getCountry();
const opts = { country };
this.logger.debug(`Setting available currencies for country: ${country}`);

Expand Down Expand Up @@ -338,7 +339,7 @@ export class ExchangeCryptoPage {
this.currencyProvider.getAvailableCoins(),
supportedCoinsWithFixRateEnabled
);
const coinsToRemove = ['xrp'];
const coinsToRemove = country == 'US' ? ['xrp'] : [];
coinsToRemove.forEach((coin: string) => {
const index = this.changellySupportedCoins.indexOf(coin);
if (index > -1) {
Expand Down
58 changes: 41 additions & 17 deletions src/pages/wallet-details/wallet-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class WalletDetailsPage {
this.buyCryptoProvider.exchangeCoinsSupported,
this.wallet.coin
) &&
!['xrp'].includes(this.wallet.coin) &&
(this.wallet.network == 'livenet' ||
(this.wallet.network == 'testnet' && env.name == 'development'));

Expand All @@ -143,26 +144,49 @@ export class WalletDetailsPage {
this.wallet.coin
)
) {
this.showExchangeCrypto = this.wallet.network == 'livenet' ? true : false;
this.showExchangeCrypto =
this.wallet.network == 'livenet' && !['xrp'].includes(this.wallet.coin)
? true
: false;
}

if (!this.showExchangeCrypto) {
if (!this.showExchangeCrypto || !this.showBuyCrypto) {
this.locationProvider.getCountry().then(country => {
const opts = { country };
this.exchangeCryptoProvider
.checkServiceAvailability('1inch', opts)
.then(isAvailable => {
if (isAvailable) {
this.showExchangeCrypto =
this.currencyProvider.isERCToken(this.wallet.coin) &&
this.wallet.network == 'livenet'
? true
: false;
}
})
.catch(err => {
if (err) this.logger.error(err);
});
if (!this.showBuyCrypto) {
if (
country != 'US' &&
this.wallet.network == 'livenet' &&
['xrp'].includes(this.wallet.coin)
) {
this.showBuyCrypto = true;
}
}

if (!this.showExchangeCrypto) {
if (
country != 'US' &&
this.wallet.network == 'livenet' &&
['xrp'].includes(this.wallet.coin)
) {
this.showExchangeCrypto = true;
} else {
const opts = { country };
this.exchangeCryptoProvider
.checkServiceAvailability('1inch', opts)
.then(isAvailable => {
if (isAvailable) {
this.showExchangeCrypto =
this.currencyProvider.isERCToken(this.wallet.coin) &&
this.wallet.network == 'livenet'
? true
: false;
}
})
.catch(err => {
if (err) this.logger.error(err);
});
}
}
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/providers/changelly/changelly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class ChangellyProvider {
'ltc',
'usdt',
'bat',
'shib'
'shib',
'xrp'
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/providers/simplex/simplex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export class SimplexProvider {
'dai',
'usdc',
'ltc',
'shib'
'shib',
'xrp'
];
this.fiatAmountLimits = {
min: 50,
Expand Down

0 comments on commit 78ce1d9

Please sign in to comment.