Skip to content

Commit

Permalink
Fix: gpr-519 fix onramp default fiat currency (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimi-imtbl authored Mar 27, 2024
1 parent 3ba6a14 commit 33d87e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
48 changes: 30 additions & 18 deletions packages/checkout/sdk/src/fiatRamp/fiatRamp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ const defaultParams = {
apiKey: 'mock-api-key',
network: 'immutablezkevm',
defaultPaymentMethod: 'credit_debit_card',
disablePaymentMethods: 'sepa_bank_transfer,gbp_bank_transfer,pm_cash_app,pm_jwire,pm_paymaya,pm_bpi,pm_ubp,pm_grabpay,pm_shopeepay,pm_gcash,pm_pix,pm_astropay,pm_pse,inr_bank_transfer', // eslint-disable-line max-len
disablePaymentMethods:
'sepa_bank_transfer,gbp_bank_transfer,pm_cash_app,pm_jwire,pm_paymaya,pm_bpi,pm_ubp,pm_grabpay,pm_shopeepay,pm_gcash,pm_pix,pm_astropay,pm_pse,inr_bank_transfer', // eslint-disable-line max-len
productsAvailed: 'buy',
exchangeScreenTitle: 'Buy',
themeColor: '0D0D0D',
defaultFiatCurrency: 'usd',
};

const defaultWidgetUrl = `${defaultURL}?${new URLSearchParams(defaultParams).toString()}`;
const defaultWidgetUrl = `${defaultURL}?${new URLSearchParams(
defaultParams,
).toString()}`;

jest.mock('../config/remoteConfigFetcher');

Expand All @@ -42,11 +44,14 @@ describe('FiatRampService', () => {
},
}),
});
config = new CheckoutConfiguration({
baseConfig: {
environment: Environment.SANDBOX,
config = new CheckoutConfiguration(
{
baseConfig: {
environment: Environment.SANDBOX,
},
},
}, mockedHttpClient);
mockedHttpClient,
);
fiatRampService = new FiatRampService(config);

const result = await fiatRampService.feeEstimate();
Expand All @@ -69,11 +74,14 @@ describe('FiatRampService', () => {
},
}),
});
config = new CheckoutConfiguration({
baseConfig: {
environment: Environment.SANDBOX,
config = new CheckoutConfiguration(
{
baseConfig: {
environment: Environment.SANDBOX,
},
},
}, mockedHttpClient);
mockedHttpClient,
);
fiatRampService = new FiatRampService(config);

const result = await fiatRampService.feeEstimate();
Expand All @@ -94,11 +102,14 @@ describe('FiatRampService', () => {
},
}),
});
config = new CheckoutConfiguration({
baseConfig: {
environment: Environment.SANDBOX,
config = new CheckoutConfiguration(
{
baseConfig: {
environment: Environment.SANDBOX,
},
},
}, mockedHttpClient);
mockedHttpClient,
);
fiatRampService = new FiatRampService(config);
});
it(`should return widget url with non-configurable query params when onRampProvider is Transak' +
Expand All @@ -111,7 +122,9 @@ describe('FiatRampService', () => {
expect(result).toContain(defaultWidgetUrl);
expect(result).toContain('&defaultCryptoCurrency=IMX');
expect(result).not.toContain('&email=');
expect(result).not.toContain('&isAutoFillUserData=true&disableWalletAddressForm=true');
expect(result).not.toContain(
'&isAutoFillUserData=true&disableWalletAddressForm=true',
);
expect(result).not.toContain('&defaultCryptoAmount=');
expect(result).not.toContain('&walletAddress=');
});
Expand All @@ -131,7 +144,7 @@ describe('FiatRampService', () => {
});

it(`should return widget url with defaultFiatAmount and defaultCryptoCurrency query params when tokenAmount and
tokenSymbol are no present`, async () => {
tokenSymbol are not present`, async () => {
const params: FiatRampWidgetParams = {
exchangeType: ExchangeType.ONRAMP,
isPassport: false,
Expand All @@ -156,7 +169,6 @@ describe('FiatRampService', () => {
expect(result).toContain(defaultWidgetUrl);
expect(result).toContain('&defaultCryptoAmount=100');
expect(result).toContain('&cryptoCurrencyCode=ETH');
expect(result).toContain('&defaultFiatAmount=');
expect(result).not.toContain('&defaultCryptoCurrency=IMX');
});

Expand Down
20 changes: 15 additions & 5 deletions packages/checkout/sdk/src/fiatRamp/fiatRamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export class FiatRampService {
}

public async feeEstimate(): Promise<OnRampProviderFees> {
const config = (await this.config.remote.getConfig('onramp')) as OnRampConfig;
const config = (await this.config.remote.getConfig(
'onramp',
)) as OnRampConfig;
return config[OnRampProvider.TRANSAK]?.fees;
}

public async createWidgetUrl(params: FiatRampWidgetParams): Promise<string> {
return (await this.getTransakWidgetUrl(params));
return await this.getTransakWidgetUrl(params);
}

private async getTransakWidgetUrl(
Expand All @@ -45,13 +47,12 @@ export class FiatRampService {
apiKey: onRampConfig[OnRampProvider.TRANSAK].publishableApiKey,
network: 'immutablezkevm',
defaultPaymentMethod: 'credit_debit_card',
disablePaymentMethods: 'sepa_bank_transfer,gbp_bank_transfer,pm_cash_app,pm_jwire,pm_paymaya,'
disablePaymentMethods:
'sepa_bank_transfer,gbp_bank_transfer,pm_cash_app,pm_jwire,pm_paymaya,'
+ 'pm_bpi,pm_ubp,pm_grabpay,pm_shopeepay,pm_gcash,pm_pix,pm_astropay,pm_pse,inr_bank_transfer',
productsAvailed: 'buy',
exchangeScreenTitle: 'Buy',
themeColor: '0D0D0D',
defaultFiatCurrency: 'usd',
defaultFiatAmount: '50',
defaultCryptoCurrency: params.tokenSymbol || 'IMX',
};

Expand All @@ -64,12 +65,21 @@ export class FiatRampService {
};
}

// NOTE: only set tokenAmount and tokenSymbol if you want a fixed pre-selected token with no currency selector
// setting cryptoCurrencyCode code will force the user to buy that token, defaultCryptoAmount will not work without cryptoCurrencyCode
// setting defaultFiatAmount/fiatAmount + defaultFiatCurrency will take a higher priority over defaultCryptoAmount + cryptoCurrencyCode
if (params.tokenAmount && params.tokenSymbol) {
widgetParams = {
...widgetParams,
defaultCryptoAmount: params.tokenAmount,
cryptoCurrencyCode: params.tokenSymbol,
};
} else {
widgetParams = {
...widgetParams,
defaultFiatAmount: 50,
defaultFiatCurrency: 'usd',
};
}

if (params.walletAddress) {
Expand Down

0 comments on commit 33d87e8

Please sign in to comment.