Skip to content

Commit

Permalink
Merge branch 'develop' into mrtenz/manifest-localisation
Browse files Browse the repository at this point in the history
  • Loading branch information
hmalik88 committed Mar 14, 2024
2 parents 81e7a48 + 150a666 commit 07b8470
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions ui/components/multichain/pages/connections/connections.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import {
AlignItems,
Expand All @@ -12,14 +12,18 @@ import {
TextAlign,
TextVariant,
} from '../../../../helpers/constants/design-system';
import { DEFAULT_ROUTE } from '../../../../helpers/constants/routes';
import {
CONNECT_ROUTE,
DEFAULT_ROUTE,
} from '../../../../helpers/constants/routes';
import { getURLHost } from '../../../../helpers/utils/util';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import {
getConnectedSitesList,
getInternalAccounts,
getOrderedConnectedAccountsForActiveTab,
getOriginOfCurrentTab,
getPermittedAccountsByOrigin,
getSelectedAccount,
} from '../../../../selectors';
import {
Expand All @@ -44,11 +48,13 @@ import { mergeAccounts } from '../../account-list-menu/account-list-menu';
import { AccountListItem, AccountListItemMenuTypes } from '../..';
import { Content, Footer, Header, Page } from '../page';
import { ConnectAccountsModal } from '../../connect-accounts-modal/connect-accounts-modal';
import { requestAccountsPermissionWithId } from '../../../../store/actions';
import { AccountType, ConnectedSites } from './components/connections.types';
import { NoConnectionContent } from './components/no-connection';

export const Connections = () => {
const t = useI18nContext();
const dispatch = useDispatch();
const history = useHistory();
const [showConnectAccountsModal, setShowConnectAccountsModal] =
useState(false);
Expand All @@ -57,13 +63,35 @@ export const Connections = () => {
const subjectMetadata: { [key: string]: any } = useSelector(
getConnectedSitesList,
);
const connectedSubjectsMetadata = subjectMetadata[activeTabOrigin];
const { openMetaMaskTabs } = useSelector((state: any) => state.appState);
const { id } = useSelector((state: any) => state.activeTab);

const connectedAccounts = useSelector(
getOrderedConnectedAccountsForActiveTab,
);
const selectedAccount = useSelector(getSelectedAccount);
const internalAccounts = useSelector(getInternalAccounts);
const mergedAccounts = mergeAccounts(connectedAccounts, internalAccounts);
const permittedAccountsByOrigin = useSelector(
getPermittedAccountsByOrigin,
) as { [key: string]: any[] };

const currentTabHasNoAccounts =
!permittedAccountsByOrigin[activeTabOrigin]?.length;
let tabToConnect: { origin: any } = { origin: null };
if (activeTabOrigin && currentTabHasNoAccounts && !openMetaMaskTabs[id]) {
tabToConnect = {
origin: activeTabOrigin,
};
}
const requestAccountsPermission = async () => {
const requestId = await dispatch(
requestAccountsPermissionWithId(tabToConnect.origin),
);
history.push(`${CONNECT_ROUTE}/${requestId}`);
};
const connectedSubjectsMetadata = subjectMetadata[activeTabOrigin];

return (
<Page data-testid="connections-page" className="connections-page">
<Header
Expand Down Expand Up @@ -110,7 +138,7 @@ export const Connections = () => {
</Box>
</Header>
<Content padding={0}>
{connectedSubjectsMetadata ? (
{connectedSubjectsMetadata && mergeAccounts.length > 0 ? (
<Tabs defaultActiveTabKey="connections">
{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -156,7 +184,7 @@ export const Connections = () => {
) : null}
</Content>
<Footer>
{connectedSubjectsMetadata ? (
{connectedSubjectsMetadata && mergeAccounts.length > 0 ? (
<Box
display={Display.Flex}
gap={2}
Expand Down Expand Up @@ -188,6 +216,7 @@ export const Connections = () => {
size={ButtonPrimarySize.Lg}
block
data-test-id="no-connections-button"
onClick={() => dispatch(requestAccountsPermission())}
>
{t('connectAccounts')}
</ButtonPrimary>
Expand Down

0 comments on commit 07b8470

Please sign in to comment.