Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrated institutional ui components to ts #25858

Merged
merged 35 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6932c64
chore: migrated jwt-url-form to ts
albertolive Jul 16, 2024
0cb339d
chore: migrated custody-labels to ts
albertolive Jul 16, 2024
71512f1
chore: migrated confirm-remove-jwt-modal to ts
albertolive Jul 17, 2024
af53813
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 17, 2024
d01d988
chore: migrated custody-confirm-link-modal to ts
albertolive Jul 17, 2024
645b55b
chore: migrated note-to-trader to ts
albertolive Jul 17, 2024
f6ed7e9
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 18, 2024
154ebd0
fix: fixed eslint issues
albertolive Jul 18, 2024
f145496
chore: migrated wrong-network-notification to ts
albertolive Jul 18, 2024
be6a716
chore: migrated transaction-failed-modal to ts
albertolive Jul 18, 2024
1b2a81c
chore: migrated jwt-dropdown to ts
albertolive Jul 18, 2024
bed07c8
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 18, 2024
059c7fc
fix: tests
albertolive Jul 18, 2024
a343266
chore: migrated interactive-replacement-token-modal to ts
albertolive Jul 18, 2024
61e7654
chore: migrated interactive-replacement-token-notification to ts
albertolive Jul 18, 2024
34d8cf2
fix: fixed storybook in interactive-replacement-token-notification
albertolive Jul 18, 2024
0d4bfdc
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 18, 2024
aec617b
chore: fixed ts issues
albertolive Jul 18, 2024
be8281e
fix: tests
albertolive Jul 19, 2024
5406d8c
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 19, 2024
1e36827
fix: fixed estlin issues
albertolive Jul 19, 2024
6c651be
fix: eslint issues
albertolive Jul 19, 2024
33cbaa4
fix: eslint issue
albertolive Jul 19, 2024
4e805ff
fix: removed any from files
albertolive Jul 19, 2024
41a181a
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 19, 2024
488fee0
fix: improved ts
albertolive Jul 22, 2024
a5450ac
Merge branch 'MMI-5205-mmi-ui-components-to-ts' of https://github.com…
albertolive Jul 22, 2024
3e94a7e
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 22, 2024
951cba7
feat: added metamask-institutional/types dependency
albertolive Jul 22, 2024
4893ea2
Update LavaMoat policies
metamaskbot Jul 22, 2024
5eeab7c
fix: eslint issue
albertolive Jul 22, 2024
9cb2527
fix: eslint issue
albertolive Jul 22, 2024
66f1ffc
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 23, 2024
eeba795
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 23, 2024
bc73047
Merge branch 'develop' into MMI-5205-mmi-ui-components-to-ts
albertolive Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@
"@ethereumjs/tx>@ethereumjs/util": true,
"@metamask-institutional/custody-keyring>@metamask-institutional/configuration-client": true,
"@metamask-institutional/sdk": true,
"@metamask-institutional/sdk>@metamask-institutional/types": true,
"@metamask-institutional/types": true,
"@metamask/obs-store": true,
"browserify>crypto-browserify": true,
"gulp-sass>lodash.clonedeep": true,
Expand All @@ -823,7 +823,7 @@
"packages": {
"@metamask-institutional/custody-controller": true,
"@metamask-institutional/sdk": true,
"@metamask-institutional/sdk>@metamask-institutional/types": true,
"@metamask-institutional/types": true,
"gulp-sass>lodash.clonedeep": true
}
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"@metamask-institutional/rpc-allowlist": "^1.0.3",
"@metamask-institutional/sdk": "^0.1.30",
"@metamask-institutional/transaction-update": "^0.2.5",
"@metamask-institutional/types": "^1.1.0",
"@metamask/abi-utils": "^2.0.2",
"@metamask/accounts-controller": "^17.2.0",
"@metamask/address-book-controller": "^4.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { StoryFn, Meta } from '@storybook/react';
import ConfirmRemoveJWT from '.';

export default {
Expand All @@ -24,8 +25,11 @@ export default {
{ address: '0xaD6D458402F60fD3Bd25163575031ACDce07538D', balance: '0x0' },
],
},
};
} as Meta<typeof ConfirmRemoveJWT>;

export const DefaultStory = (args) => <ConfirmRemoveJWT {...args} />;
const Template: StoryFn<typeof ConfirmRemoveJWT> = (args) => (
<ConfirmRemoveJWT {...args} />
);

export const DefaultStory = Template.bind({});
DefaultStory.storyName = 'ConfirmRemoveJWT';
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { memo, useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import CustodyAccountList from '../../../pages/institutional/connect-custody/account-list';
import { useI18nContext } from '../../../hooks/useI18nContext';
Expand All @@ -14,8 +13,8 @@ import {
ModalBody,
ModalOverlay,
Button,
BUTTON_VARIANT,
BUTTON_SIZES,
ButtonVariant,
ButtonSize,
} from '../../component-library';
import {
BorderRadius,
Expand All @@ -25,7 +24,40 @@ import {
TextVariant,
} from '../../../helpers/constants/design-system';

const ConfirmRemoveJWT = ({
type AuthDetails = {
token?: string;
jwt?: string;
refreshToken?: string;
};

type CustodyAccountDetail = {
address: string;
name: string;
labels: string[];
authDetails: AuthDetails;
};

type Account = {
address: string;
balance: string;
};

type TokenAccount = {
address: string;
name: string;
labels: string[];
balance?: string;
token?: string;
};

type ConfirmRemoveJWTProps = {
hideModal: () => void;
token: string | { address: string };
custodyAccountDetails: CustodyAccountDetail[];
accounts: Account[];
};

const ConfirmRemoveJWT: React.FC<ConfirmRemoveJWTProps> = ({
custodyAccountDetails,
accounts,
token: propsToken,
Expand All @@ -34,8 +66,8 @@ const ConfirmRemoveJWT = ({
const t = useI18nContext();
const dispatch = useDispatch();
const [showMore, setShowMore] = useState(false);
const [tokenAccounts, setTokenAccounts] = useState([]);
let token = null;
const [tokenAccounts, setTokenAccounts] = useState<TokenAccount[]>([]);
let token: string | null = null;

if (propsToken) {
if (typeof propsToken === 'object') {
Expand All @@ -46,7 +78,7 @@ const ConfirmRemoveJWT = ({
}

useEffect(() => {
const lowercasedTokenAddress = token.toLowerCase();
const lowercasedTokenAddress = token?.toLowerCase() || '';

const filteredAccounts = custodyAccountDetails.filter((item) => {
const addressLower = item.address.toLowerCase();
Expand Down Expand Up @@ -102,12 +134,12 @@ const ConfirmRemoveJWT = ({
className="confirm-action-jwt__jwt"
>
<Text ellipsis>
{showMore && token ? token : `...${token.slice(-9)}`}
{showMore && token ? token : `...${token?.slice(-9)}`}
</Text>
</Box>
{!showMore && (
<Text
color={TextColor.sepolia}
color={TextColor.primaryDefault}
marginLeft={2}
className="confirm-action-jwt__show-more"
>
Expand All @@ -131,8 +163,8 @@ const ConfirmRemoveJWT = ({
<Box display={Display.Flex} padding={4}>
<Button
block
variant={BUTTON_VARIANT.PRIMARY}
size={BUTTON_SIZES.LG}
variant={ButtonVariant.Primary}
size={ButtonSize.Lg}
onClick={handleRemove}
data-testid="remove-jwt-confirm-btn"
>
Expand All @@ -144,11 +176,4 @@ const ConfirmRemoveJWT = ({
);
};

ConfirmRemoveJWT.propTypes = {
hideModal: PropTypes.func.isRequired,
token: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
custodyAccountDetails: PropTypes.array.isRequired,
accounts: PropTypes.array.isRequired,
};

export default withModalProps(memo(ConfirmRemoveJWT));
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ const customData = {

const store = configureStore(customData);

type CustodyConfirmLinkArgs = {
hideModal: () => void;
};

export default {
title: 'Components/Institutional/CustodyConfirmLink',
decorators: [(story) => <Provider store={store}>{story()}</Provider>],
component: CustodyConfirmLink,
args: {},
};

export const DefaultStory = (args) => <CustodyConfirmLink {...args} />;
export const DefaultStory = (args: CustodyConfirmLinkArgs) => (
<CustodyConfirmLink {...args} />
);

DefaultStory.storyName = 'CustodyConfirmLink';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { fireEvent } from '@testing-library/react';
import configureStore from 'redux-mock-store';
import { KeyringTypes } from '@metamask/keyring-controller';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import testData from '../../../../.storybook/test-data';
import { hideModal } from '../../../store/actions';
Expand All @@ -24,8 +25,9 @@ const mockedCustodianName = 'saturn-dev';

describe('Custody Confirm Link', () => {
const mockInternalAccount = createMockInternalAccount({
keyringType: 'Custody Test',
keyringType: KeyringTypes.hd,
address: '0xAddress',
name: 'testCustody - Saturn',
});
const mockStore = {
...testData,
Expand Down Expand Up @@ -90,7 +92,7 @@ describe('Custody Confirm Link', () => {
let store = configureStore()(mockStore);

it('tries to open new tab with deeplink URL', () => {
global.platform = { openTab: jest.fn() };
global.platform = { openTab: jest.fn(), closeCurrentWindow: jest.fn() };
const { getByTestId } = renderWithProvider(<CustodyConfirmLink />, store);
fireEvent.click(getByTestId('custody-confirm-link__btn'));
expect(global.platform.openTab).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { useSelector, useDispatch } from 'react-redux';
import { ICustodianType } from '@metamask-institutional/types';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
MetaMetricsEventName,
Expand Down Expand Up @@ -28,16 +28,43 @@ import {
} from '../../../helpers/constants/design-system';
import {
Button,
BUTTON_VARIANT,
Modal,
ModalContent,
ModalHeader,
ModalOverlay,
Text,
Box,
ButtonVariant,
} from '../../component-library';
import { ModalContent } from '../../component-library/modal-content/deprecated';
import { ModalHeader } from '../../component-library/modal-header/deprecated';

const CustodyConfirmLink = ({ hideModal }) => {
type CustodyConfirmLinkProps = {
hideModal: () => void;
};

type ModalStateProps = {
url?: string;
ethereum?: {
accounts: string[];
};
text?: string;
action?: string;
};

type State = {
appState: {
modal: {
modalState: {
props: {
link: ModalStateProps;
};
};
};
};
};

const CustodyConfirmLink: React.FC<CustodyConfirmLinkProps> = ({
hideModal,
}) => {
const t = useI18nContext();
const dispatch = useDispatch();
const mmiActions = mmiActionsFactory();
Expand All @@ -49,9 +76,10 @@ const CustodyConfirmLink = ({ hideModal }) => {
const { custodianName } =
custodyAccountDetails[toChecksumHexAddress(address)] || {};
const { displayName, iconUrl } =
custodians.find((item) => item.envName === custodianName) || {};
custodians.find((item: ICustodianType) => item.envName === custodianName) ||
{};
const { url, ethereum, text, action } = useSelector(
(state) => state.appState.modal.modalState.props.link || {},
(state: State) => state.appState.modal.modalState.props.link || {},
);

const onClick = () => {
Expand All @@ -61,10 +89,12 @@ const CustodyConfirmLink = ({ hideModal }) => {

if (ethereum) {
const ethAccount = Object.values(mmiAccounts)
.map((internalAccount) => internalAccount.address)
.find((account) => ethereum.accounts.includes(account.toLowerCase()));
.map((internalAccount: { address: string }) => internalAccount.address)
.find((account: string) =>
ethereum.accounts.includes(account.toLowerCase()),
);

ethAccount && dispatch(setSelectedInternalAccount(ethAccount.id));
ethAccount && dispatch(setSelectedInternalAccount(ethAccount));
}

trackEvent({
Expand Down Expand Up @@ -125,7 +155,7 @@ const CustodyConfirmLink = ({ hideModal }) => {
</Text>
<Button
data-testid="custody-confirm-link__btn"
variant={BUTTON_VARIANT.PRIMARY}
variant={ButtonVariant.Primary}
className="custody-confirm-link__btn"
onClick={onClick}
>
Expand All @@ -138,8 +168,4 @@ const CustodyConfirmLink = ({ hideModal }) => {
);
};

CustodyConfirmLink.propTypes = {
hideModal: PropTypes.func.isRequired,
};

export default withModalProps(CustodyConfirmLink);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`CustodyLabels Component should render correctly 1`] = `
<div>
<label
class="mm-box mm-text mm-label mm-label--html-for mm-text--body-md mm-text--font-weight-medium mm-box--display-flex mm-box--flex-direction-row mm-box--align-items-center mm-box--color-text-default"
class="mm-box mm-text mm-label mm-label--html-for mm-text--body-md mm-text--font-weight-medium mm-box--display-flex mm-box--align-items-center mm-box--color-text-default"
for="address-index"
>
<p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ export default {
},
};

export const DefaultStory = (args) => <CustodyLabels {...args} />;
type LabelItem = {
key: string;
value: string;
};

type CustodyLabelsArgs = {
labels: LabelItem[];
index?: string;
background?: string;
hideNetwork?: boolean;
};

export const DefaultStory = (args: CustodyLabelsArgs) => (
<CustodyLabels {...args} />
);

DefaultStory.storyName = 'CustodyLabels';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('CustodyLabels Component', () => {
const props = {
labels: [{ key: 'testKey', value: 'value' }],
index: 'index',
hideNetwork: 'true',
hideNetwork: true,
};

const { container } = render(<CustodyLabels {...props} />);
Expand Down
Loading
Loading