From c4a5316d8b916247875edac44081c263b6b6b2af Mon Sep 17 00:00:00 2001 From: Gabriel Masclef Date: Mon, 27 Dec 2021 16:58:37 -0500 Subject: [PATCH] Fix: enable buy and swap xrp for non-US countries only --- .../crypto-order-summary.ts | 28 ++++++--- src/pages/exchange-crypto/exchange-crypto.ts | 5 +- src/pages/wallet-details/wallet-details.ts | 58 +++++++++++++------ src/providers/changelly/changelly.ts | 3 +- src/providers/simplex/simplex.ts | 3 +- 5 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/pages/buy-crypto/crypto-order-summary/crypto-order-summary.ts b/src/pages/buy-crypto/crypto-order-summary/crypto-order-summary.ts index d423b1495cb..be35a926c1f 100644 --- a/src/pages/buy-crypto/crypto-order-summary/crypto-order-summary.ts +++ b/src/pages/buy-crypto/crypto-order-summary/crypto-order-summary.ts @@ -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, @@ -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.` diff --git a/src/pages/exchange-crypto/exchange-crypto.ts b/src/pages/exchange-crypto/exchange-crypto.ts index 24dc683c591..6d22a74126e 100644 --- a/src/pages/exchange-crypto/exchange-crypto.ts +++ b/src/pages/exchange-crypto/exchange-crypto.ts @@ -208,6 +208,7 @@ export class ExchangeCryptoPage { } private async getExchangesCurrencies() { + let country; const reflect = promiseObj => { return promiseObj.promise.then( v => { @@ -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}`); @@ -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) { diff --git a/src/pages/wallet-details/wallet-details.ts b/src/pages/wallet-details/wallet-details.ts index 89123a4d965..1dbab8206a9 100644 --- a/src/pages/wallet-details/wallet-details.ts +++ b/src/pages/wallet-details/wallet-details.ts @@ -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')); @@ -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); + }); + } + } }); } diff --git a/src/providers/changelly/changelly.ts b/src/providers/changelly/changelly.ts index 4ecd3b57c6c..197d42f8837 100644 --- a/src/providers/changelly/changelly.ts +++ b/src/providers/changelly/changelly.ts @@ -34,7 +34,8 @@ export class ChangellyProvider { 'ltc', 'usdt', 'bat', - 'shib' + 'shib', + 'xrp' ]; } diff --git a/src/providers/simplex/simplex.ts b/src/providers/simplex/simplex.ts index 26394be9396..431d3c28951 100644 --- a/src/providers/simplex/simplex.ts +++ b/src/providers/simplex/simplex.ts @@ -103,7 +103,8 @@ export class SimplexProvider { 'dai', 'usdc', 'ltc', - 'shib' + 'shib', + 'xrp' ]; this.fiatAmountLimits = { min: 50,