Skip to content

Commit

Permalink
editing flow
Browse files Browse the repository at this point in the history
  • Loading branch information
NidhiKJha committed Aug 23, 2024
1 parent 29030c0 commit 8ff52ad
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 5 deletions.
2 changes: 2 additions & 0 deletions test/data/mock-send-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"appState": {
"networkDropdownOpen": false,
"importNftsModal": { "open": false },
"showEditAccountsModalOpen": false,
"showEditNetworksModalOpen": false,
"gasIsLoading": false,
"isLoading": false,
"importTokensModalOpen": false,
Expand Down
2 changes: 2 additions & 0 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"importNftsModal": {
"open": false
},
"showEditAccountsModalOpen": false,
"showEditNetworksModalOpen": false,
"gasIsLoading": false,
"isLoading": false,
"modal": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { useRef, useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
PopoverRole,
PopoverPosition,
Popover,
IconName,
Text,
ModalFocus,
Box,
} from '../../../../component-library';
import { MenuItem } from '../../../../ui/menu';
import {
IconColor,
TextColor,
TextVariant,
} from '../../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
import { getPermissionsForActiveTab } from '../../../../../selectors';
import { PermissionDetailsModal } from '../../../permission-details-modal/permission-details-modal';

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const TsMenuItem = MenuItem as any;

export const SiteCellMenu = ({
isOpen,
account,
anchorElement,
disableAccountSwitcher = false,
onClose,
closeMenu,
onActionClick,
activeTabOrigin,
}: {
isOpen: boolean;
anchorElement: HTMLElement | null;
disableAccountSwitcher: boolean;
onClose: () => void;
closeMenu: () => void;
onActionClick: (message: string) => void;
activeTabOrigin: string;
}) => {
const dispatch = useDispatch();
const t = useI18nContext();
const popoverDialogRef = useRef<HTMLDivElement | null>(null);
const [showPermissionModal, setShowPermissionModal] = useState(false);
const permissions = useSelector(getPermissionsForActiveTab);

const handleClickOutside = useCallback(
(event) => {
if (
popoverDialogRef?.current &&
!popoverDialogRef.current.contains(event.target)
) {
onClose();
}
},
[onClose],
);

useEffect(() => {
document.addEventListener('mousedown', handleClickOutside);

return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [handleClickOutside]);

const handleKeyDown = useCallback(
(event) => {
if (
event.key === 'Tab' &&
popoverDialogRef?.current?.contains(event.target) &&
onClose
) {
onClose();
}
},
[onClose],
);

return (
<>
<Popover
className="multichain-connected-accounts-menu__popover"
referenceElement={anchorElement}
role={PopoverRole.Dialog}
position={PopoverPosition.Bottom}
offset={[0, 0]}
padding={0}
isOpen={isOpen}
flip
preventOverflow
isPortal
>
<ModalFocus restoreFocus initialFocusRef={{ current: anchorElement }}>
<Box onKeyDown={handleKeyDown} ref={popoverDialogRef}>
<TsMenuItem
iconName={IconName.SecurityTick}
data-testid="permission-details-menu-item"
onClick={() => {
setShowPermissionModal(true);
onClose();
}}
>
<Text variant={TextVariant.bodyMd}>
{t('permissionDetails')}
</Text>
</TsMenuItem>
</Box>
</ModalFocus>
</Popover>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ import {
} from '../../../../component-library';
import { getURLHost } from '../../../../../helpers/utils/util';
import { ConnectionListTooltip } from '../../permissions-page/connection-list-tooltip/connection-list-tooltip';
import {
showEditAccountsModal,
showEditNetworksModal,
} from '../../../../../store/actions';
import { useDispatch } from 'react-redux';

export const SiteCell = ({}) => {
const t = useI18nContext();
const dispatch = useDispatch();

return (
<>
Expand Down Expand Up @@ -94,6 +100,9 @@ export const SiteCell = ({}) => {
alignItems={AlignItems.center}
style={{ flex: '1', alignSelf: 'center' }}
gap={2}
onClick={() => {
dispatch(showEditAccountsModal());
}}
>
<Icon
display={Display.Flex}
Expand All @@ -118,7 +127,7 @@ export const SiteCell = ({}) => {
className="multichain-connection-list-item"
>
<AvatarIcon
iconName={IconName.Wallet}
iconName={IconName.Data}
size={AvatarIconSize.Md}
iconProps={{
size: IconSize.Sm,
Expand All @@ -137,7 +146,7 @@ export const SiteCell = ({}) => {
textAlign={TextAlign.Left}
ellipsis
>
{t('accountsPermissionsTitle')}
{t('permission_walletSwitchEthereumChain')}
</Text>

<Box
Expand All @@ -163,6 +172,9 @@ export const SiteCell = ({}) => {
alignItems={AlignItems.center}
style={{ flex: '1', alignSelf: 'center' }}
gap={2}
onClick={() => {
dispatch(showEditNetworksModal());
}}
>
<Icon
display={Display.Flex}
Expand Down
28 changes: 28 additions & 0 deletions ui/ducks/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type AppState = {
tokenId?: string;
ignoreErc20Token?: boolean;
};
showEditAccountsModalOpen: boolean;
showEditNetworksModalOpen: boolean;
showIpfsModalOpen: boolean;
keyringRemovalSnapModal: {
snapName: string;
Expand Down Expand Up @@ -124,6 +126,8 @@ const initialState: AppState = {
qrCodeData: null,
networkDropdownOpen: false,
importNftsModal: { open: false },
showEditAccountsModalOpen: false,
showEditNetworksModalOpen: false,
showIpfsModalOpen: false,
showBasicFunctionalityModal: false,
externalServicesOnboardingToggleState: true,
Expand Down Expand Up @@ -258,6 +262,30 @@ export default function reduceApp(
showIpfsModalOpen: false,
};

case actionConstants.SHOW_EDIT_NETWORKS_MODAL_OPEN:
return {
...appState,
showEditNetworksModalOpen: true,
};

case actionConstants.SHOW_EDIT_NETWORKS_MODAL_CLOSE:
return {
...appState,
showEditNetworksModalOpen: false,
};

case actionConstants.SHOW_EDIT_ACCOUNTS_MODAL_OPEN:
return {
...appState,
showEditAccountsModalOpen: true,
};

case actionConstants.SHOW_EDIT_ACCOUNTS_MODAL_CLOSE:
return {
...appState,
showEditAccountsModalOpen: false,
};

case actionConstants.IMPORT_TOKENS_POPOVER_OPEN:
return {
...appState,
Expand Down
24 changes: 21 additions & 3 deletions ui/pages/routes/routes.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
NetworkListMenu,
AccountDetails,
ImportNftsModal,
EditAccountsModal,
EditNetworksModal,
ImportTokensModal,
ToastContainer,
Toast,
Expand Down Expand Up @@ -189,6 +191,10 @@ export default class Routes extends Component {
accountDetailsAddress: PropTypes.string,
isImportNftsModalOpen: PropTypes.bool.isRequired,
hideImportNftsModal: PropTypes.func.isRequired,
isEditNetworksModalOpen: PropTypes.bool.isRequired,
hideEditNetworksModal: PropTypes.func.isRequired,
isEditAccountsModalOpen: PropTypes.bool.isRequired,
hideEditAccountsModal: PropTypes.func.isRequired,
isIpfsModalOpen: PropTypes.bool.isRequired,
isBasicConfigurationModalOpen: PropTypes.bool.isRequired,
hideIpfsModal: PropTypes.func.isRequired,
Expand Down Expand Up @@ -768,7 +774,7 @@ export default class Routes extends Component {
/>
) : null}

{process.env.CHAIN_PERMISSIONS ?
{process.env.CHAIN_PERMISSIONS ? (
<Toast
key="switched-network-toast"
startAdornment={
Expand All @@ -781,9 +787,10 @@ export default class Routes extends Component {
}
text="app.uniswap.org has been given access to Optimism."
actionText={this.context.t('editPermissions')}
onActionClick={() => console.log('Yo')}
onActionClick={() => this.props.history.push(REVIEW_PERMISSIONS)}
onClose={() => console.log('lo')}
/> : null}
/>
) : null}
</ToastContainer>
);
}
Expand Down Expand Up @@ -848,6 +855,10 @@ export default class Routes extends Component {
location,
isImportNftsModalOpen,
hideImportNftsModal,
isEditAccountsModalOpen,
hideEditAccountsModal,
isEditNetworksModalOpen,
hideEditNetworksModal,
isIpfsModalOpen,
isBasicConfigurationModalOpen,
hideIpfsModal,
Expand Down Expand Up @@ -953,6 +964,13 @@ export default class Routes extends Component {
{isImportNftsModalOpen ? (
<ImportNftsModal onClose={() => hideImportNftsModal()} />
) : null}
{isEditAccountsModalOpen ? (
<EditAccountsModal onClose={() => hideEditAccountsModal()} />
) : null}
{isEditNetworksModalOpen ? (
<EditNetworksModal onClose={() => hideEditNetworksModal()} />
) : null}

{isIpfsModalOpen ? (
<ToggleIpfsModal onClose={() => hideIpfsModal()} />
) : null}
Expand Down
6 changes: 6 additions & 0 deletions ui/pages/routes/routes.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import {
hideKeyringRemovalResultModal,
///: END:ONLY_INCLUDE_IF
setEditedNetwork,
hideEditAccountsModal,
hideEditNetworksModal,
} from '../../store/actions';
import { pageChanged } from '../../ducks/history/history';
import { prepareToLeaveSwaps } from '../../ducks/swaps/swaps';
Expand Down Expand Up @@ -130,6 +132,8 @@ function mapStateToProps(state) {
accountDetailsAddress: state.appState.accountDetailsAddress,
isImportNftsModalOpen: state.appState.importNftsModal.open,
isIpfsModalOpen: state.appState.showIpfsModalOpen,
isEditNetworksModalOpen: state.appState.showEditNetworksModalOpen,
isEditAccountsModalOpen: state.appState.showEditAccountsModalOpen,
switchedNetworkDetails,
useNftDetection,
showNftEnablementToast,
Expand Down Expand Up @@ -162,6 +166,8 @@ function mapDispatchToProps(dispatch) {
toggleNetworkMenu: () => dispatch(toggleNetworkMenu()),
hideImportNftsModal: () => dispatch(hideImportNftsModal()),
hideIpfsModal: () => dispatch(hideIpfsModal()),
hideEditAccountsModal: () => dispatch(hideEditAccountsModal()),
hideEditNetworksModal: () => dispatch(hideEditNetworksModal()),
hideImportTokensModal: () => dispatch(hideImportTokensModal()),
hideDeprecatedNetworkModal: () => dispatch(hideDeprecatedNetworkModal()),
addPermittedAccount: (activeTabOrigin, address) =>
Expand Down
4 changes: 4 additions & 0 deletions ui/store/actionConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const NETWORK_DROPDOWN_CLOSE = 'UI_NETWORK_DROPDOWN_CLOSE';
export const IMPORT_NFTS_MODAL_OPEN = 'UI_IMPORT_NFTS_MODAL_OPEN';
export const IMPORT_NFTS_MODAL_CLOSE = 'UI_IMPORT_NFTS_MODAL_CLOSE';
export const SHOW_IPFS_MODAL_OPEN = 'UI_IPFS_MODAL_OPEN';
export const SHOW_EDIT_ACCOUNTS_MODAL_OPEN = 'UI_EDIT_ACCOUNTS_MODAL_OPEN';
export const SHOW_EDIT_ACCOUNTS_MODAL_CLOSE = 'UI_EDIT_ACCOUNTS_MODAL_CLOSE';
export const SHOW_EDIT_NETWORKS_MODAL_OPEN = 'UI_EDIT_NETWORKS_MODAL_OPEN';
export const SHOW_EDIT_NETWORKS_MODAL_CLOSE = 'UI_EDIT_NETWORKS_MODAL_CLOSE';
export const SHOW_IPFS_MODAL_CLOSE = 'UI_IPFS_MODAL_CLOSE';
export const IMPORT_TOKENS_POPOVER_OPEN = 'UI_IMPORT_TOKENS_POPOVER_OPEN';
export const IMPORT_TOKENS_POPOVER_CLOSE = 'UI_IMPORT_TOKENS_POPOVER_CLOSE';
Expand Down
24 changes: 24 additions & 0 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2613,6 +2613,30 @@ export function hideImportNftsModal(): Action {
};
}

export function showEditAccountsModal(): Action {
return {
type: actionConstants.SHOW_EDIT_ACCOUNTS_MODAL_OPEN,
};
}

export function hideEditAccountsModal(): Action {
return {
type: actionConstants.SHOW_EDIT_ACCOUNTS_MODAL_CLOSE,
};
}

export function hideEditNetworksModal(): Action {
return {
type: actionConstants.SHOW_EDIT_NETWORKS_MODAL_CLOSE,
};
}

export function showEditNetworksModal(): Action {
return {
type: actionConstants.SHOW_EDIT_NETWORKS_MODAL_OPEN,
};
}

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function setConfirmationExchangeRates(value: Record<string, any>) {
Expand Down

0 comments on commit 8ff52ad

Please sign in to comment.