Skip to content

Commit

Permalink
fix: WT-2080 - Bridge should be an option for Passport users (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrearampin authored Jan 28, 2024
1 parent a784cce commit aa02978
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 98 deletions.
31 changes: 1 addition & 30 deletions packages/checkout/widgets-lib/src/views/top-up/TopUpView.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@imtbl/checkout-sdk';
import { Environment } from '@imtbl/config';
import { BigNumber } from 'ethers';
import { ExternalProvider, Web3Provider } from '@ethersproject/providers';
import { Web3Provider } from '@ethersproject/providers';
import { UserJourney } from 'context/analytics-provider/SegmentAnalyticsProvider';
import { CustomAnalyticsProvider } from 'context/analytics-provider/CustomAnalyticsProvider';
import { ViewContextTestComponent } from 'context/view-context/test-components/ViewContextTestComponent';
Expand Down Expand Up @@ -124,35 +124,6 @@ describe('Top Up View', () => {
cySmartGet('menu-item-bridge').should('not.exist');
});

it('should hide bridge option when provider is Passport', () => {
mount(
<ViewContextTestComponent>
<CustomAnalyticsProvider checkout={{} as Checkout}>
<ConnectLoaderTestComponent
initialStateOverride={{
...connectLoaderState,
provider: {
provider: { isPassport: true } as any as ExternalProvider,
} as Web3Provider,
}}
>
<TopUpView
analytics={{ userJourney: UserJourney.WALLET }}
showOnrampOption
showSwapOption
showBridgeOption={false}
widgetEvent={IMTBLWidgetEvents.IMTBL_WALLET_WIDGET_EVENT}
onCloseButtonClick={() => {}}
/>
</ConnectLoaderTestComponent>
</CustomAnalyticsProvider>
</ViewContextTestComponent>,
);
cySmartGet('menu-item-onramp').should('exist');
cySmartGet('menu-item-swap').should('exist');
cySmartGet('menu-item-bridge').should('not.exist');
});

it('should call close function when close button clicked', () => {
const closeFunction = cy.stub().as('closeFunction');
mount(
Expand Down
11 changes: 3 additions & 8 deletions packages/checkout/widgets-lib/src/views/top-up/TopUpView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
getOnRampFeeEstimation,
} from '../../lib/feeEstimation';
import { CryptoFiatActions, CryptoFiatContext } from '../../context/crypto-fiat-context/CryptoFiatContext';
import { isPassportProvider } from '../../lib/providerUtils';
import { OnRampWidgetViews } from '../../context/view-context/OnRampViewContextTypes';
import { EventTargetContext } from '../../context/event-target-context/EventTargetContext';
import { TopUpMenuItem } from './TopUpMenuItem';
Expand All @@ -52,7 +51,8 @@ interface TopUpViewProps {
export function TopUpView({
widgetEvent,
checkout,
provider,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
provider, // Keep this for future use
showOnrampOption,
showSwapOption,
showBridgeOption,
Expand All @@ -65,9 +65,6 @@ export function TopUpView({
const { t } = useTranslation();
const { userJourney } = analytics;

// const { header, topUpOptions } = text.views[SharedViews.TOP_UP_VIEW];
// const { onramp, swap, bridge } = topUpOptions;

const { viewDispatch } = useContext(ViewContext);

const { cryptoFiatState, cryptoFiatDispatch } = useContext(CryptoFiatContext);
Expand All @@ -82,8 +79,6 @@ export function TopUpView({

const { page, track } = useAnalytics();

const isPassport = isPassportProvider(provider);

useEffect(() => {
page({
userJourney,
Expand Down Expand Up @@ -263,7 +258,7 @@ export function TopUpView({
`${t('views.TOP_UP_VIEW.topUpOptions.bridge.subcaption')} ≈ $${bridgeFeesInFiat} ${fiatSymbol.toUpperCase()}`,
),
isAvailable: true,
isEnabled: showBridgeOption && !isPassport,
isEnabled: showBridgeOption,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@imtbl/checkout-sdk';
import { cy } from 'local-cypress';
import { Environment } from '@imtbl/config';
import { ExternalProvider, Web3Provider } from '@ethersproject/providers';
import { Web3Provider } from '@ethersproject/providers';
import { BigNumber } from 'ethers';
import { BalanceInfo } from 'widgets/wallet/functions/tokenBalances';
import { WalletState } from '../../context/WalletContext';
Expand Down Expand Up @@ -440,63 +440,6 @@ describe('BalanceItem', () => {
cySmartGet('balance-item-move-option').should('have.text', 'Move IMX');
});

it('should NOT show the move option when provider is Passport', () => {
cy.stub(Checkout.prototype, 'getTokenAllowList')
.as('tokenAllowListStub')
.resolves({
tokens: [
{
name: 'tIMX',
symbol: 'tIMX',
decimals: 18,
address: NATIVE,
},
],
});
const testWalletState = {
...baseWalletState,
network: {
chainId: ChainId.IMTBL_ZKEVM_TESTNET,
name: ChainName.IMTBL_ZKEVM_TESTNET,
nativeCurrency: {
name: 'IMX',
symbol: 'IMX',
decimals: 18,
},
isSupported: true,
},
tokenBalances: testTokenBalances,
supportedTopUps: {
isOnRampEnabled: true,
isSwapEnabled: true,
isBridgeEnabled: true,
},
};

mount(
<ConnectLoaderTestComponent
initialStateOverride={{
...connectLoaderState,
provider: {
provider: { isPassport: true } as any as ExternalProvider,
} as Web3Provider,
}}
>
<WalletWidgetTestComponent initialStateOverride={testWalletState}>
<BalanceItem
balanceInfo={testBalanceInfo}
bridgeToL2OnClick={() => {}}
/>
</WalletWidgetTestComponent>
</ConnectLoaderTestComponent>,
);
cySmartGet('token-menu').should('exist');
cySmartGet('token-menu').click();
cySmartGet('balance-item-add-option').should('be.visible');
cySmartGet('balance-item-swap-option').should('be.visible');
cySmartGet('balance-item-move-option').should('not.be.visible');
});

it('should NOT show menu options for the token when all top ups are disabled', () => {
const testWalletState = {
...baseWalletState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export function BalanceItem({

const enableMoveCoin = (network.chainId === getL1ChainId(checkout.config)
|| network.chainId === getL2ChainId(checkout.config))
&& (supportedTopUps?.isBridgeEnabled ?? true)
&& !isPassport;
&& (supportedTopUps?.isBridgeEnabled ?? true);
setIsBridgeEnabled(enableMoveCoin);

const enableSwapCoin = network.chainId === getL2ChainId(checkout.config)
Expand Down

0 comments on commit aa02978

Please sign in to comment.