Skip to content

Commit

Permalink
Merge pull request #11922 from Gamboster/ref/oneInchDisabledForUS
Browse files Browse the repository at this point in the history
Ref: oneInch temporarily disabled for us
  • Loading branch information
cmgustavo committed Oct 13, 2021
2 parents 0317f91 + c7de739 commit 9597117
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 24 deletions.
7 changes: 7 additions & 0 deletions src/components/info-sheet/info-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -674,5 +674,12 @@
<span sheet-text translate>Successfully added {{params.name}}.</span>
<span sheet-button-text translate>OK</span>
</info-sheet-template>

<info-sheet-template *ngSwitchCase="'1inch-disabled-warning'" type="warning">
<span sheet-title-text translate>Disabled service</span>
<span sheet-text translate>The 1Inch exchange for token swaps is temporarily disabled in your country.
</span>
<span sheet-second-button-text translate>GOT IT</span>
</info-sheet-template>
</div>
</action-sheet>
74 changes: 60 additions & 14 deletions src/pages/exchange-crypto/exchange-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -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...');
Expand Down
13 changes: 13 additions & 0 deletions src/pages/integrations/one-inch/one-inch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/pages/wallet-details/wallet-details.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
Expand Down
27 changes: 21 additions & 6 deletions src/pages/wallet-details/wallet-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/providers/action-sheet/action-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 4 additions & 3 deletions src/providers/changelly/changelly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export class ChangellyProvider {
'btc',
'bch',
'eth',
'pax',
'busd',
'usdc',
'gusd',
'dai',
'doge',
'ltc'
'ltc',
'usdt',
'bat'
];
}

Expand Down

0 comments on commit 9597117

Please sign in to comment.