mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
[MMI] Fixed remove custodian token (#20021)
This commit is contained in:
parent
805cc31e63
commit
0309858917
@ -442,25 +442,8 @@ export default class MMIController extends EventEmitter {
|
|||||||
return keyring.getTransactionDeepLink(from, custodyTxId);
|
return keyring.getTransactionDeepLink(from, custodyTxId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCustodianToken(custodianType) {
|
async getCustodianToken(address) {
|
||||||
let currentCustodyType;
|
const keyring = await this.keyringController.getKeyringForAccount(address);
|
||||||
|
|
||||||
const address = this.preferencesController.getSelectedAddress();
|
|
||||||
|
|
||||||
if (!custodianType) {
|
|
||||||
const resultCustody = this.custodyController.getCustodyTypeByAddress(
|
|
||||||
toChecksumHexAddress(address),
|
|
||||||
);
|
|
||||||
currentCustodyType = resultCustody;
|
|
||||||
}
|
|
||||||
let keyring = await this.keyringController.getKeyringsByType(
|
|
||||||
currentCustodyType || `Custody - ${custodianType}`,
|
|
||||||
)[0];
|
|
||||||
if (!keyring) {
|
|
||||||
keyring = await this.keyringController.addNewKeyring(
|
|
||||||
currentCustodyType || `Custody - ${custodianType}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const { authDetails } = keyring.getAccountDetails(address);
|
const { authDetails } = keyring.getAccountDetails(address);
|
||||||
return keyring ? authDetails.jwt || authDetails.refreshToken : '';
|
return keyring ? authDetails.jwt || authDetails.refreshToken : '';
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
exports[`Checkbox should render the Checkbox without crashing 1`] = `
|
exports[`Checkbox should render the Checkbox without crashing 1`] = `
|
||||||
<div>
|
<div>
|
||||||
<label
|
<label
|
||||||
class="box mm-text mm-checkbox mm-text--body-md box--display-inline-flex box--flex-direction-row box--align-items-center box--color-text-default"
|
class="mm-box mm-text mm-checkbox mm-text--body-md mm-box--display-inline-flex mm-box--align-items-center mm-box--color-text-default"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="mm-checkbox__input-wrapper"
|
class="mm-checkbox__input-wrapper"
|
||||||
|
@ -1,155 +1,3 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Confirm Remove JWT should render correctly 1`] = `
|
exports[`Confirm Remove JWT should render correctly 1`] = `<div />`;
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
class="modal-container"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="modal-container__header"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="modal-container__header-text"
|
|
||||||
>
|
|
||||||
Remove custodian token?
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="modal-container__header-close"
|
|
||||||
data-testid="modal-header-close"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="modal-container__content"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="box confirm-action-jwt__jwt box--padding-2 box--display-flex box--flex-direction-row box--rounded-sm"
|
|
||||||
>
|
|
||||||
...Dce07538D
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
class="box mm-text confirm-action-jwt__show-more mm-text--body-md box--margin-left-2 box--flex-direction-row box--color-goerli"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
Show more
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<h6
|
|
||||||
class="box mm-text mm-text--body-sm mm-text--text-align-center box--margin-top-2 box--flex-direction-row box--color-text-default"
|
|
||||||
>
|
|
||||||
Are you sure you want to remove this token? All accounts assigned to this token will be removed from extension as well:
|
|
||||||
</h6>
|
|
||||||
<div
|
|
||||||
class="box confirm-action-jwt__accounts-list box--flex-direction-row"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="mm-box page-container"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="mm-box page-container__content mm-box--padding-4"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="mm-box custody-account-list mm-box--display-flex mm-box--flex-direction-column mm-box--width-full"
|
|
||||||
data-testid="custody-account-list"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="mm-box custody-account-list__item mm-box--display-flex"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="mm-box mm-box--display-flex mm-box--align-items-flex-start"
|
|
||||||
data-testid="custody-account-list-item-radio-button"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class="mm-box mm-box--margin-left-2 mm-box--display-flex mm-box--flex-direction-column mm-box--width-full"
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
class="box mm-text mm-label mm-label--html-for custody-account-list__item__title mm-text--body-md mm-text--font-weight-medium box--margin-top-2 box--margin-left-2 box--display-flex box--flex-direction-row box--align-items-center box--color-text-default"
|
|
||||||
for="address-0"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="box mm-text custody-account-list__item__name mm-text--inherit box--padding-right-1 box--flex-direction-row box--color-text-default"
|
|
||||||
>
|
|
||||||
Test name account
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
<label
|
|
||||||
class="box mm-text mm-label mm-label--html-for mm-text--body-md mm-text--font-weight-medium box--margin-top-2 box--margin-right-3 box--margin-left-2 box--display-flex box--flex-direction-row box--align-items-center box--color-text-default"
|
|
||||||
for="address-0"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="box mm-text custody-account-list__item mm-text--body-md box--display-flex box--flex-direction-row box--color-text-default"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
class="box mm-text mm-button-base mm-button-link mm-button-link--size-auto mm-text--body-md-medium box--display-inline-flex box--flex-direction-row box--justify-content-center box--align-items-center box--color-primary-default box--background-color-transparent"
|
|
||||||
href="https://etherscan.io/address/0xaD6D458402F60fD3Bd25163575031ACDce07538D"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="box mm-text mm-text--inherit box--flex-direction-row box--color-primary-default"
|
|
||||||
>
|
|
||||||
0xaD6...538D
|
|
||||||
<span
|
|
||||||
class="box mm-icon mm-icon--size-md box--margin-left-1 box--display-inline-block box--flex-direction-row box--color-primary-default"
|
|
||||||
style="mask-image: url('./images/icons/undefined.svg');"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
aria-describedby="tippy-tooltip-1"
|
|
||||||
class=""
|
|
||||||
data-original-title="Copy to clipboard"
|
|
||||||
data-tooltipped=""
|
|
||||||
style="display: inline; background-color: transparent;"
|
|
||||||
tabindex="0"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
class="custody-account-list__item__clipboard"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="box mm-icon mm-icon--size-md box--display-inline-block box--flex-direction-row box--color-icon-muted"
|
|
||||||
style="mask-image: url('./images/icons/undefined.svg');"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
<div
|
|
||||||
class="mm-box mm-box--display-flex mm-box--justify-content-space-between"
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
class="box mm-text mm-label mm-label--html-for mm-text--body-md mm-text--font-weight-medium box--display-flex box--flex-direction-row box--align-items-center box--color-text-default"
|
|
||||||
for="address-0"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="modal-container__footer"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
class="button btn--rounded btn-secondary modal-container__footer-button"
|
|
||||||
role="button"
|
|
||||||
tabindex="0"
|
|
||||||
>
|
|
||||||
Nevermind
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="button btn--rounded btn-primary modal-container__footer-button"
|
|
||||||
role="button"
|
|
||||||
tabindex="0"
|
|
||||||
>
|
|
||||||
Remove
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
@ -1,16 +1,24 @@
|
|||||||
import React, { memo, useState, useEffect } from 'react';
|
import React, { memo, useState, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import Modal from '../../app/modal';
|
|
||||||
import CustodyAccountList from '../../../pages/institutional/connect-custody/account-list';
|
import CustodyAccountList from '../../../pages/institutional/connect-custody/account-list';
|
||||||
import { useI18nContext } from '../../../hooks/useI18nContext';
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
||||||
import { removeAccount } from '../../../store/actions';
|
import { removeAccount } from '../../../store/actions';
|
||||||
import withModalProps from '../../../helpers/higher-order-components/with-modal-props';
|
import withModalProps from '../../../helpers/higher-order-components/with-modal-props';
|
||||||
import { Text } from '../../component-library/text/deprecated';
|
import {
|
||||||
import Box from '../../ui/box';
|
Box,
|
||||||
|
Text,
|
||||||
|
Modal,
|
||||||
|
ModalContent,
|
||||||
|
ModalHeader,
|
||||||
|
ModalOverlay,
|
||||||
|
Button,
|
||||||
|
BUTTON_VARIANT,
|
||||||
|
BUTTON_SIZES,
|
||||||
|
} from '../../component-library';
|
||||||
import {
|
import {
|
||||||
BorderRadius,
|
BorderRadius,
|
||||||
DISPLAY,
|
Display,
|
||||||
TextAlign,
|
TextAlign,
|
||||||
TextColor,
|
TextColor,
|
||||||
TextVariant,
|
TextVariant,
|
||||||
@ -19,16 +27,25 @@ import {
|
|||||||
const ConfirmRemoveJWT = ({
|
const ConfirmRemoveJWT = ({
|
||||||
custodyAccountDetails,
|
custodyAccountDetails,
|
||||||
accounts,
|
accounts,
|
||||||
token,
|
token: propsToken,
|
||||||
hideModal,
|
hideModal,
|
||||||
}) => {
|
}) => {
|
||||||
const t = useI18nContext();
|
const t = useI18nContext();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [showMore, setShowMore] = useState(false);
|
const [showMore, setShowMore] = useState(false);
|
||||||
const [tokenAccounts, setTokenAccounts] = useState([]);
|
const [tokenAccounts, setTokenAccounts] = useState([]);
|
||||||
|
let token = null;
|
||||||
|
|
||||||
|
if (propsToken) {
|
||||||
|
if (typeof propsToken === 'object') {
|
||||||
|
token = propsToken.address;
|
||||||
|
} else {
|
||||||
|
token = propsToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const lowercasedTokenAddress = token.address.toLowerCase();
|
const lowercasedTokenAddress = token.toLowerCase();
|
||||||
|
|
||||||
const filteredAccounts = custodyAccountDetails.filter((item) => {
|
const filteredAccounts = custodyAccountDetails.filter((item) => {
|
||||||
const addressLower = item.address.toLowerCase();
|
const addressLower = item.address.toLowerCase();
|
||||||
@ -72,22 +89,19 @@ const ConfirmRemoveJWT = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal isOpen onClose={hideModal}>
|
||||||
headerText={`${t('removeJWT')}?`}
|
<ModalOverlay />
|
||||||
onClose={hideModal}
|
<ModalContent>
|
||||||
onSubmit={handleRemove}
|
<ModalHeader onClose={hideModal}>{t('removeJWT')}</ModalHeader>
|
||||||
onCancel={hideModal}
|
|
||||||
submitText={t('remove')}
|
|
||||||
cancelText={t('nevermind')}
|
|
||||||
submitType="primary"
|
|
||||||
>
|
|
||||||
<Box
|
<Box
|
||||||
display={DISPLAY.FLEX}
|
display={Display.Flex}
|
||||||
padding={2}
|
padding={2}
|
||||||
borderRadius={BorderRadius.SM}
|
borderRadius={BorderRadius.SM}
|
||||||
className="confirm-action-jwt__jwt"
|
className="confirm-action-jwt__jwt"
|
||||||
>
|
>
|
||||||
{showMore && token ? token.address : `...${token.address.slice(-9)}`}
|
<Text ellipsis>
|
||||||
|
{showMore && token ? token : `...${token.slice(-9)}`}
|
||||||
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
{!showMore && (
|
{!showMore && (
|
||||||
<Text
|
<Text
|
||||||
@ -111,13 +125,24 @@ const ConfirmRemoveJWT = ({
|
|||||||
<Box className="confirm-action-jwt__accounts-list">
|
<Box className="confirm-action-jwt__accounts-list">
|
||||||
<CustodyAccountList accounts={tokenAccounts} rawList />
|
<CustodyAccountList accounts={tokenAccounts} rawList />
|
||||||
</Box>
|
</Box>
|
||||||
|
<Box display={Display.Flex}>
|
||||||
|
<Button
|
||||||
|
block
|
||||||
|
variant={BUTTON_VARIANT.PRIMARY}
|
||||||
|
size={BUTTON_SIZES.LG}
|
||||||
|
onClick={handleRemove}
|
||||||
|
>
|
||||||
|
{t('remove')}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
ConfirmRemoveJWT.propTypes = {
|
ConfirmRemoveJWT.propTypes = {
|
||||||
hideModal: PropTypes.func.isRequired,
|
hideModal: PropTypes.func.isRequired,
|
||||||
token: PropTypes.object.isRequired,
|
token: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
|
||||||
custodyAccountDetails: PropTypes.array.isRequired,
|
custodyAccountDetails: PropTypes.array.isRequired,
|
||||||
accounts: PropTypes.array.isRequired,
|
accounts: PropTypes.array.isRequired,
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,7 @@ export default {
|
|||||||
removeAccount: () => {
|
removeAccount: () => {
|
||||||
/**/
|
/**/
|
||||||
},
|
},
|
||||||
token: { address: '0xaD6D458402F60fD3Bd25163575031ACDce07538D' },
|
token: '0xaD6D458402F60fD3Bd25163575031ACDce07538D',
|
||||||
custodyAccountDetails: [
|
custodyAccountDetails: [
|
||||||
{
|
{
|
||||||
address: '0xaD6D458402F60fD3Bd25163575031ACDce07538D',
|
address: '0xaD6D458402F60fD3Bd25163575031ACDce07538D',
|
||||||
|
@ -3,7 +3,7 @@ import { fireEvent, waitFor } from '@testing-library/react';
|
|||||||
import configureMockStore from 'redux-mock-store';
|
import configureMockStore from 'redux-mock-store';
|
||||||
import thunk from 'redux-thunk';
|
import thunk from 'redux-thunk';
|
||||||
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
||||||
import testData from '../../../../.storybook/test-data';
|
import mockState from '../../../../test/data/mock-state.json';
|
||||||
import ConfirmRemoveJwt from '.';
|
import ConfirmRemoveJwt from '.';
|
||||||
|
|
||||||
const mockedRemoveAccount = jest.fn();
|
const mockedRemoveAccount = jest.fn();
|
||||||
@ -18,7 +18,7 @@ const address = '0xaD6D458402F60fD3Bd25163575031ACDce07538D';
|
|||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
hideModal: mockedHideModal,
|
hideModal: mockedHideModal,
|
||||||
token: { address },
|
token: address,
|
||||||
custodyAccountDetails: [
|
custodyAccountDetails: [
|
||||||
{
|
{
|
||||||
address,
|
address,
|
||||||
@ -30,13 +30,8 @@ const props = {
|
|||||||
accounts: [{ address, balance: '0x0' }],
|
accounts: [{ address, balance: '0x0' }],
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockStore = {
|
|
||||||
...testData,
|
|
||||||
metamask: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const middleware = [thunk];
|
const middleware = [thunk];
|
||||||
const store = configureMockStore(middleware)(mockStore);
|
const store = configureMockStore(middleware)(mockState);
|
||||||
|
|
||||||
const render = () => {
|
const render = () => {
|
||||||
return renderWithProvider(<ConfirmRemoveJwt {...props} />, store);
|
return renderWithProvider(<ConfirmRemoveJwt {...props} />, store);
|
||||||
|
@ -9,5 +9,6 @@
|
|||||||
|
|
||||||
&__accounts-list {
|
&__accounts-list {
|
||||||
margin-left: -5%;
|
margin-left: -5%;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ const InteractiveReplacementTokenNotification = ({ isVisible }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = await dispatch(mmiActions.getCustodianToken());
|
const token = await dispatch(mmiActions.getCustodianToken(address));
|
||||||
const custodyAccountDetails = await dispatch(
|
const custodyAccountDetails = await dispatch(
|
||||||
mmiActions.getAllCustodianAccountsWithToken(
|
mmiActions.getAllCustodianAccountsWithToken(
|
||||||
keyring.type.split(' - ')[1],
|
keyring.type.split(' - ')[1],
|
||||||
|
@ -233,7 +233,9 @@ export const AccountListItemMenu = ({
|
|||||||
ref={removeJWTItemRef}
|
ref={removeJWTItemRef}
|
||||||
data-testid="account-options-menu__remove-jwt"
|
data-testid="account-options-menu__remove-jwt"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const token = await dispatch(mmiActions.getCustodianToken());
|
const token = await dispatch(
|
||||||
|
mmiActions.getCustodianToken(identity.address),
|
||||||
|
);
|
||||||
const custodyAccountDetails = await dispatch(
|
const custodyAccountDetails = await dispatch(
|
||||||
mmiActions.getAllCustodianAccountsWithToken(
|
mmiActions.getAllCustodianAccountsWithToken(
|
||||||
keyring.type.split(' - ')[1],
|
keyring.type.split(' - ')[1],
|
||||||
|
@ -40,7 +40,7 @@ import {
|
|||||||
CUSTODY_ACCOUNT_DONE_ROUTE,
|
CUSTODY_ACCOUNT_DONE_ROUTE,
|
||||||
DEFAULT_ROUTE,
|
DEFAULT_ROUTE,
|
||||||
} from '../../../helpers/constants/routes';
|
} from '../../../helpers/constants/routes';
|
||||||
import { getCurrentChainId } from '../../../selectors';
|
import { getCurrentChainId, getSelectedAddress } from '../../../selectors';
|
||||||
import { getMMIConfiguration } from '../../../selectors/institutional/selectors';
|
import { getMMIConfiguration } from '../../../selectors/institutional/selectors';
|
||||||
import CustodyAccountList from '../connect-custody/account-list';
|
import CustodyAccountList from '../connect-custody/account-list';
|
||||||
import JwtUrlForm from '../../../components/institutional/jwt-url-form';
|
import JwtUrlForm from '../../../components/institutional/jwt-url-form';
|
||||||
@ -72,6 +72,7 @@ const CustodyPage = () => {
|
|||||||
const [chainId, setChainId] = useState(0);
|
const [chainId, setChainId] = useState(0);
|
||||||
const [connectRequest, setConnectRequest] = useState(undefined);
|
const [connectRequest, setConnectRequest] = useState(undefined);
|
||||||
const [accounts, setAccounts] = useState();
|
const [accounts, setAccounts] = useState();
|
||||||
|
const address = useSelector(getSelectedAddress);
|
||||||
|
|
||||||
const custodianButtons = useMemo(() => {
|
const custodianButtons = useMemo(() => {
|
||||||
const custodianItems = [];
|
const custodianItems = [];
|
||||||
@ -259,7 +260,8 @@ const CustodyPage = () => {
|
|||||||
if (Object.keys(connectRequestValue).length) {
|
if (Object.keys(connectRequestValue).length) {
|
||||||
setConnectRequest(connectRequestValue);
|
setConnectRequest(connectRequestValue);
|
||||||
setCurrentJwt(
|
setCurrentJwt(
|
||||||
connectRequestValue.token || dispatch(mmiActions.getCustodianToken()),
|
connectRequestValue.token ||
|
||||||
|
(await dispatch(mmiActions.getCustodianToken(address))),
|
||||||
);
|
);
|
||||||
setSelectedCustodianType(connectRequestValue.custodianType);
|
setSelectedCustodianType(connectRequestValue.custodianType);
|
||||||
setSelectedCustodianName(connectRequestValue.custodianName);
|
setSelectedCustodianName(connectRequestValue.custodianName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user