mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 09:23:21 +01:00
[MMI] swap button redirect when account is Custody (#20234)
* wip * adds test * add value to constants * clean up
This commit is contained in:
parent
c92f3b32b2
commit
2b5c112a02
@ -133,6 +133,8 @@ export const WETH_ARBITRUM_CONTRACT_ADDRESS =
|
||||
|
||||
const SWAPS_TESTNET_CHAIN_ID = '0x539';
|
||||
|
||||
export const MMI_SWAPS_URL = 'https://metamask-institutional.io/swap';
|
||||
|
||||
export const SWAPS_API_V2_BASE_URL = 'https://swap.metaswap.codefi.network';
|
||||
export const SWAPS_DEV_API_V2_BASE_URL = 'https://swap.dev-api.cx.metamask.io';
|
||||
export const GAS_API_BASE_URL = 'https://gas-api.metaswap.codefi.network';
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
getMmiPortfolioUrl,
|
||||
} from '../../../selectors/institutional/selectors';
|
||||
///: END:ONLY_INCLUDE_IN
|
||||
|
||||
import { MMI_SWAPS_URL } from '../../../../shared/constants/swaps';
|
||||
import { I18nContext } from '../../../contexts/i18n';
|
||||
import {
|
||||
SEND_ROUTE,
|
||||
@ -25,6 +25,7 @@ import Tooltip from '../../ui/tooltip';
|
||||
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display';
|
||||
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
||||
import {
|
||||
getAccountType,
|
||||
isBalanceCached,
|
||||
getShouldShowFiat,
|
||||
getCurrentKeyring,
|
||||
@ -77,6 +78,7 @@ const EthOverview = ({ className, showAddress }) => {
|
||||
const isSwapsChain = useSelector(getIsSwapsChain);
|
||||
const defaultSwapsToken = useSelector(getSwapsDefaultToken);
|
||||
const chainId = useSelector(getCurrentChainId);
|
||||
const accountType = useSelector(getAccountType);
|
||||
|
||||
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
||||
const mmiPortfolioEnabled = useSelector(getMmiPortfolioEnabled);
|
||||
@ -254,6 +256,14 @@ const EthOverview = ({ className, showAddress }) => {
|
||||
/>
|
||||
}
|
||||
onClick={() => {
|
||||
if (accountType === 'custody') {
|
||||
global.platform.openTab({
|
||||
url: MMI_SWAPS_URL,
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSwapsChain) {
|
||||
trackEvent({
|
||||
event: MetaMetricsEventName.NavSwapButtonClicked,
|
||||
|
@ -72,6 +72,7 @@ describe('EthOverview', () => {
|
||||
const ETH_OVERVIEW_BUY = 'eth-overview-buy';
|
||||
const ETH_OVERVIEW_BRIDGE = 'eth-overview-bridge';
|
||||
const ETH_OVERVIEW_PORTFOLIO = 'eth-overview-portfolio';
|
||||
const ETH_OVERVIEW_SWAP = 'token-overview-button-swap';
|
||||
const ETH_OVERVIEW_PRIMARY_CURRENCY = 'eth-overview__primary-currency';
|
||||
const ETH_OVERVIEW_SECONDARY_CURRENCY = 'eth-overview__secondary-currency';
|
||||
|
||||
@ -191,6 +192,45 @@ describe('EthOverview', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should open the MMI PD Swaps URI when clicking on Swap button with a Custody account', async () => {
|
||||
const mockedStoreWithCustodyKeyring = {
|
||||
metamask: {
|
||||
...mockStore.metamask,
|
||||
keyrings: [
|
||||
{
|
||||
type: 'Custody',
|
||||
accounts: ['0x1'],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const mockedStore = configureMockStore([thunk])(
|
||||
mockedStoreWithCustodyKeyring,
|
||||
);
|
||||
|
||||
const { queryByTestId } = renderWithProvider(
|
||||
<EthOverview />,
|
||||
mockedStore,
|
||||
);
|
||||
|
||||
const swapButton = queryByTestId(ETH_OVERVIEW_SWAP);
|
||||
|
||||
expect(swapButton).toBeInTheDocument();
|
||||
expect(swapButton).not.toBeDisabled();
|
||||
|
||||
fireEvent.click(swapButton);
|
||||
expect(openTabSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(openTabSpy).toHaveBeenCalledWith({
|
||||
url: expect.stringContaining(
|
||||
'https://metamask-institutional.io/swap',
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should have the Bridge button disabled if chain id is not part of supported chains', () => {
|
||||
const mockedFantomStore = {
|
||||
...mockStore,
|
||||
|
Loading…
Reference in New Issue
Block a user