diff --git a/src/components/info-sheet/info-sheet.html b/src/components/info-sheet/info-sheet.html
index 68348af2f9e..f54913801a3 100644
--- a/src/components/info-sheet/info-sheet.html
+++ b/src/components/info-sheet/info-sheet.html
@@ -674,5 +674,12 @@
Successfully added {{params.name}}.
OK
+
+
+ Disabled service
+ The 1Inch exchange for token swaps is temporarily disabled in your country.
+
+ GOT IT
+
diff --git a/src/pages/exchange-crypto/exchange-crypto.ts b/src/pages/exchange-crypto/exchange-crypto.ts
index 3a95159e9ac..13b48005ba1 100644
--- a/src/pages/exchange-crypto/exchange-crypto.ts
+++ b/src/pages/exchange-crypto/exchange-crypto.ts
@@ -27,6 +27,7 @@ import { ChangellyProvider } from '../../providers/changelly/changelly';
import { CurrencyProvider } from '../../providers/currency/currency';
import { ExchangeCryptoProvider } from '../../providers/exchange-crypto/exchange-crypto';
import { FeeProvider } from '../../providers/fee/fee';
+import { LocationProvider } from '../../providers/location/location';
import { Logger } from '../../providers/logger/logger';
import { OnGoingProcessProvider } from '../../providers/on-going-process/on-going-process';
import { ProfileProvider } from '../../providers/profile/profile';
@@ -70,8 +71,8 @@ export class ExchangeCryptoPage {
public fixedRateId: string;
public rate: number;
public estimatedFee: number;
+ private country: string;
private exchangeCryptoSupportedCoins: any[];
-
private changellySupportedCoins: string[]; // Supported by Changelly and Bitpay
// One Inch
@@ -118,7 +119,8 @@ export class ExchangeCryptoPage {
private configProvider: ConfigProvider,
private externalLinkProvider: ExternalLinkProvider,
private replaceParametersProvider: ReplaceParametersProvider,
- public decimalPipe: DecimalPipe
+ public decimalPipe: DecimalPipe,
+ private locationProvider: LocationProvider
) {
this.allWallets = [];
this.toWallets = [];
@@ -213,13 +215,28 @@ export class ExchangeCryptoPage {
);
};
+ try {
+ this.country = await this.locationProvider.getCountry();
+ this.logger.debug(
+ `Setting available currencies for country: ${this.country}`
+ );
+ } catch (e) {
+ this.logger.warn("It was not possible to get the user's country.");
+ }
+
const promises = [
{
exchange: 'changelly',
- promise: this.changellyProvider.getCurrencies()
- },
- { exchange: '1inch', promise: this.oneInchProvider.getCurrencies1inch() }
+ promise: this.changellyProvider.getCurrencies(true)
+ }
];
+
+ if (this.country != 'US') {
+ promises.push({
+ exchange: '1inch',
+ promise: this.oneInchProvider.getCurrencies1inch()
+ });
+ }
const results = await Promise.all(promises.map(reflect));
const successfulPromises = results.filter(p => p.status === 'ok');
const failedPromises = results.filter(p => p.status === 'failed');
@@ -299,11 +316,16 @@ export class ExchangeCryptoPage {
_.isArray(promise.data.result) &&
promise.data.result.length > 0
) {
+ const supportedCoinsWithFixRateEnabled = promise.data.result
+ .filter(coin => coin.enabled && coin.fixRateEnabled)
+ .map(({ name }) => name);
+
+ // TODO: add support to float-rate coins supported by Changelly
this.changellySupportedCoins = _.intersection(
this.currencyProvider.getAvailableCoins(),
- promise.data.result
+ supportedCoinsWithFixRateEnabled
);
- const coinsToRemove = ['xrp', 'busd'];
+ const coinsToRemove = ['xrp'];
coinsToRemove.forEach((coin: string) => {
const index = this.changellySupportedCoins.indexOf(coin);
if (index > -1) {
@@ -548,19 +570,19 @@ export class ExchangeCryptoPage {
? this.toToken.symbol.toLowerCase()
: this.toWalletSelected.coin;
- // 1inch has priority over Changelly
+ // Changelly has priority over 1inch
if (
- this.oneInchAllSupportedCoinsSymbols.length > 0 &&
- this.oneInchAllSupportedCoinsSymbols.includes(fromCoin) &&
- this.oneInchAllSupportedCoinsSymbols.includes(toCoin)
- ) {
- this.exchangeToUse = '1inch';
- } else if (
this.changellySupportedCoins.length > 0 &&
this.changellySupportedCoins.includes(fromCoin) &&
this.changellySupportedCoins.includes(toCoin)
) {
this.exchangeToUse = 'changelly';
+ } else if (
+ this.oneInchAllSupportedCoinsSymbols.length > 0 &&
+ this.oneInchAllSupportedCoinsSymbols.includes(fromCoin) &&
+ this.oneInchAllSupportedCoinsSymbols.includes(toCoin)
+ ) {
+ this.exchangeToUse = '1inch';
} else {
let msg =
this.translate.instant(
@@ -575,6 +597,30 @@ export class ExchangeCryptoPage {
this.logger.debug('Exchange to use: ' + this.exchangeToUse);
+ if (this.exchangeToUse == '1inch' && this.country == 'US') {
+ const oneInchDisabledWarningSheet = this.actionSheetProvider.createInfoSheet(
+ '1inch-disabled-warning'
+ );
+ oneInchDisabledWarningSheet.present();
+ oneInchDisabledWarningSheet.onDidDismiss(() => {
+ // Cleaning view
+ if (!this.toWalletSelectedByDefault) {
+ this.toWalletSelected = null;
+ this.toToken = null;
+ }
+ this.fromWalletSelected = null;
+ this.fromToken = null;
+ this.amountFrom = null;
+ this.amountTo = null;
+ this.useSendMax = null;
+ this.rate = null;
+ this.fixedRateId = null;
+ this.exchangeToUse = null;
+ this.showPendingApprove = false;
+ });
+ return;
+ }
+
switch (this.exchangeToUse) {
case '1inch':
this.onGoingProcessProvider.set('Verifiyng allowances and balances...');
diff --git a/src/pages/integrations/one-inch/one-inch.ts b/src/pages/integrations/one-inch/one-inch.ts
index 4772db7728f..71a33bb0aba 100644
--- a/src/pages/integrations/one-inch/one-inch.ts
+++ b/src/pages/integrations/one-inch/one-inch.ts
@@ -5,7 +5,9 @@ import { ModalController } from 'ionic-angular';
import { OneInchDetailsPage } from './one-inch-details/one-inch-details';
// Proviers
+import { ActionSheetProvider } from '../../../providers/action-sheet/action-sheet';
import { ExternalLinkProvider } from '../../../providers/external-link/external-link';
+import { LocationProvider } from '../../../providers/location/location';
import { Logger } from '../../../providers/logger/logger';
import { OneInchProvider } from '../../../providers/one-inch/one-inch';
import { ThemeProvider } from '../../../providers/theme/theme';
@@ -22,7 +24,9 @@ export class OneInchPage {
constructor(
private logger: Logger,
+ private actionSheetProvider: ActionSheetProvider,
private externalLinkProvider: ExternalLinkProvider,
+ private locationProvider: LocationProvider,
private modalCtrl: ModalController,
private oneInchProvider: OneInchProvider,
public themeProvider: ThemeProvider
@@ -46,6 +50,15 @@ export class OneInchPage {
Object.assign(swapTxs, oneInchData);
this.swapTxs = Object.values(swapTxs);
this.loading = false;
+
+ this.locationProvider.getCountry().then(country => {
+ if (country == 'US') {
+ const oneInchDisabledWarningSheet = this.actionSheetProvider.createInfoSheet(
+ '1inch-disabled-warning'
+ );
+ oneInchDisabledWarningSheet.present();
+ }
+ });
})
.catch(err => {
this.loading = false;
diff --git a/src/pages/wallet-details/wallet-details.spec.ts b/src/pages/wallet-details/wallet-details.spec.ts
index 91994a879ce..e07c986883e 100644
--- a/src/pages/wallet-details/wallet-details.spec.ts
+++ b/src/pages/wallet-details/wallet-details.spec.ts
@@ -2,6 +2,7 @@ import { async, ComponentFixture } from '@angular/core/testing';
import { TestUtils } from '../../test';
+import { LocationProvider } from '../../providers/location/location';
import { ProfileProvider } from './../../providers/profile/profile';
import { WalletDetailsPage } from './wallet-details';
@@ -22,6 +23,9 @@ describe('WalletDetailsPage', () => {
setNotificationsInterval: () => true
};
spyOn(ProfileProvider.prototype, 'getWallet').and.returnValue(mockWallet);
+ spyOn(LocationProvider.prototype, 'getCountry').and.returnValue(
+ Promise.resolve('US')
+ );
return TestUtils.configurePageTestingModule([WalletDetailsPage]).then(
testEnv => {
fixture = testEnv.fixture;
diff --git a/src/pages/wallet-details/wallet-details.ts b/src/pages/wallet-details/wallet-details.ts
index 3db086ea643..ebca4a4a8a1 100644
--- a/src/pages/wallet-details/wallet-details.ts
+++ b/src/pages/wallet-details/wallet-details.ts
@@ -27,6 +27,7 @@ import { ExternalLinkProvider } from '../../providers/external-link/external-lin
import { GiftCardProvider } from '../../providers/gift-card/gift-card';
import { CardConfigMap } from '../../providers/gift-card/gift-card.types';
import { ActionSheetProvider, AppProvider } from '../../providers/index';
+import { LocationProvider } from '../../providers/location/location';
import { Logger } from '../../providers/logger/logger';
import { PersistenceProvider } from '../../providers/persistence/persistence';
import { PlatformProvider } from '../../providers/platform/platform';
@@ -118,7 +119,8 @@ export class WalletDetailsPage {
private buyCryptoProvider: BuyCryptoProvider,
private exchangeCryptoProvider: ExchangeCryptoProvider,
private appProvider: AppProvider,
- private persistenceProvider: PersistenceProvider
+ private persistenceProvider: PersistenceProvider,
+ private locationProvider: LocationProvider
) {
this.zone = new NgZone({ enableLongStackTrace: false });
this.isCordova = this.platformProvider.isCordova;
@@ -134,13 +136,26 @@ export class WalletDetailsPage {
) &&
(this.wallet.network == 'livenet' ||
(this.wallet.network == 'testnet' && env.name == 'development'));
- this.showExchangeCrypto =
- (_.includes(
+
+ if (
+ _.includes(
this.exchangeCryptoProvider.exchangeCoinsSupported,
this.wallet.coin
- ) ||
- this.currencyProvider.isERCToken(this.wallet.coin)) &&
- this.wallet.network == 'livenet';
+ )
+ ) {
+ this.showExchangeCrypto = this.wallet.network == 'livenet' ? true : false;
+ }
+
+ if (!this.showExchangeCrypto) {
+ this.locationProvider.getCountry().then(country => {
+ this.showExchangeCrypto =
+ country != 'US' &&
+ this.currencyProvider.isERCToken(this.wallet.coin) &&
+ this.wallet.network == 'livenet'
+ ? true
+ : false;
+ });
+ }
// Getting info from cache
if (this.navParams.data.clearCache) {
diff --git a/src/providers/action-sheet/action-sheet.ts b/src/providers/action-sheet/action-sheet.ts
index cc516cc4e8e..da7054c9d00 100644
--- a/src/providers/action-sheet/action-sheet.ts
+++ b/src/providers/action-sheet/action-sheet.ts
@@ -86,7 +86,8 @@ export type InfoSheetType =
| 'exchange-crypto-disclaimer'
| 'join-wallet-warning'
| 'token-added'
- | 'pairing-required';
+ | 'pairing-required'
+ | '1inch-disabled-warning';
export type OptionsSheetType =
| 'wallet-options'
diff --git a/src/providers/changelly/changelly.ts b/src/providers/changelly/changelly.ts
index 3c52cda9767..b128c6b6a61 100644
--- a/src/providers/changelly/changelly.ts
+++ b/src/providers/changelly/changelly.ts
@@ -27,12 +27,13 @@ export class ChangellyProvider {
'btc',
'bch',
'eth',
- 'pax',
+ 'busd',
'usdc',
- 'gusd',
'dai',
'doge',
- 'ltc'
+ 'ltc',
+ 'usdt',
+ 'bat'
];
}