-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'brian/network-controller-v20-merging-in-v21' of github.…
…com:MetaMask/metamask-extension into brian/network-controller-v20-merging-in-v21
- Loading branch information
Showing
16 changed files
with
416 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { parseScanContent } from './scan-util'; | ||
|
||
describe('Extract Address from string', () => { | ||
it('should correctly extract the address from the string', () => { | ||
const result = parseScanContent( | ||
'ethereum:0xCf464B40cb2419944138F24514C9aE4D1889ccC1', | ||
); | ||
expect(result).toStrictEqual('0xCf464B40cb2419944138F24514C9aE4D1889ccC1'); | ||
}); | ||
|
||
it('should correctly extract the address from the string when there is a 0x appended', () => { | ||
const result = parseScanContent( | ||
'ethereum:0xCf464B40cb2419944138F24514C9aE4D1889ccC1@0x1', | ||
); | ||
expect(result).toStrictEqual('0xCf464B40cb2419944138F24514C9aE4D1889ccC1'); | ||
}); | ||
|
||
it('should return null if there is no address to extract that matches the pattern', () => { | ||
const result = parseScanContent( | ||
'ethereum:0xCf464B40cb2419944138F24514C9aE4D1', | ||
); | ||
expect(result).toStrictEqual(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function parseScanContent(content: string): string | null { | ||
const matches = content.match(/^[a-zA-Z]+:(0x[0-9a-fA-F]{40})(?:@.*)?/u); | ||
if (!matches) { | ||
return null; | ||
} | ||
return matches[1]; | ||
} |
42 changes: 42 additions & 0 deletions
42
ui/components/multichain/funding-method-modal/funding-method-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { Box, Text, Icon, IconName } from '../../component-library'; | ||
import { | ||
Display, | ||
FlexDirection, | ||
TextVariant, | ||
TextColor, | ||
AlignItems, | ||
} from '../../../helpers/constants/design-system'; | ||
|
||
type FundingMethodItemProps = { | ||
icon: IconName; | ||
title: string; | ||
description: string; | ||
onClick: () => void; | ||
}; | ||
|
||
const FundingMethodItem: React.FC<FundingMethodItemProps> = ({ | ||
icon, | ||
title, | ||
description, | ||
onClick, | ||
}) => ( | ||
<Box | ||
display={[Display.Flex]} | ||
gap={2} | ||
alignItems={AlignItems.center} | ||
onClick={onClick} | ||
className="funding-method-item" | ||
padding={4} | ||
> | ||
<Icon name={icon} /> | ||
<Box display={[Display.Flex]} flexDirection={FlexDirection.Column}> | ||
<Text variant={TextVariant.bodyMdMedium}>{title}</Text> | ||
<Text variant={TextVariant.bodySm} color={TextColor.textAlternative}> | ||
{description} | ||
</Text> | ||
</Box> | ||
</Box> | ||
); | ||
|
||
export default FundingMethodItem; |
109 changes: 109 additions & 0 deletions
109
ui/components/multichain/funding-method-modal/funding-method-modal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { renderWithProvider } from '../../../../test/jest/rendering'; | ||
import mockState from '../../../../test/data/mock-state.json'; | ||
import useRamps from '../../../hooks/ramps/useRamps/useRamps'; | ||
import { FundingMethodModal } from './funding-method-modal'; | ||
|
||
jest.mock('../../../hooks/ramps/useRamps/useRamps', () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})); | ||
|
||
const mockStore = configureMockStore([thunk]); | ||
|
||
describe('FundingMethodModal', () => { | ||
let store = configureMockStore([thunk])(mockState); | ||
let openBuyCryptoInPdapp: jest.Mock<() => void>; | ||
|
||
beforeEach(() => { | ||
store = mockStore(mockState); | ||
openBuyCryptoInPdapp = jest.fn(); | ||
(useRamps as jest.Mock).mockReturnValue({ openBuyCryptoInPdapp }); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render the modal when isOpen is true', () => { | ||
const { getByTestId, getByText } = renderWithProvider( | ||
<FundingMethodModal | ||
isOpen={true} | ||
onClose={jest.fn()} | ||
title="Test Modal" | ||
onClickReceive={jest.fn()} | ||
/>, | ||
store, | ||
); | ||
|
||
expect(getByTestId('funding-method-modal')).toBeInTheDocument(); | ||
expect(getByText('Test Modal')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render the modal when isOpen is false', () => { | ||
const { queryByTestId } = renderWithProvider( | ||
<FundingMethodModal | ||
isOpen={false} | ||
onClose={jest.fn()} | ||
title="Test Modal" | ||
onClickReceive={jest.fn()} | ||
/>, | ||
store, | ||
); | ||
|
||
expect(queryByTestId('funding-method-modal')).toBeNull(); | ||
}); | ||
|
||
it('should call openBuyCryptoInPdapp when the Buy Crypto item is clicked', () => { | ||
const { getByText } = renderWithProvider( | ||
<FundingMethodModal | ||
isOpen={true} | ||
onClose={jest.fn()} | ||
title="Test Modal" | ||
onClickReceive={jest.fn()} | ||
/>, | ||
store, | ||
); | ||
|
||
fireEvent.click(getByText('Buy crypto')); | ||
expect(openBuyCryptoInPdapp).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onClickReceive when the Receive Crypto item is clicked', () => { | ||
const onClickReceive = jest.fn(); | ||
const { getByText } = renderWithProvider( | ||
<FundingMethodModal | ||
isOpen={true} | ||
onClose={jest.fn()} | ||
title="Test Modal" | ||
onClickReceive={onClickReceive} | ||
/>, | ||
store, | ||
); | ||
|
||
fireEvent.click(getByText('Receive crypto')); | ||
expect(onClickReceive).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should open a new tab with the correct URL when Transfer Crypto item is clicked', () => { | ||
global.platform.openTab = jest.fn(); | ||
|
||
const { getByText } = renderWithProvider( | ||
<FundingMethodModal | ||
isOpen={true} | ||
onClose={jest.fn()} | ||
title="Test Modal" | ||
onClickReceive={jest.fn()} | ||
/>, | ||
store, | ||
); | ||
|
||
fireEvent.click(getByText('Transfer crypto')); | ||
expect(global.platform.openTab).toHaveBeenCalledWith({ | ||
url: expect.stringContaining('transfer'), | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.