Skip to content

Commit 9af2dde

Browse files
feat: Show network in third party image (#3174)
1 parent 35f9014 commit 9af2dde

File tree

10 files changed

+89
-14
lines changed

10 files changed

+89
-14
lines changed

src/components/Modals/CreateThirdPartyCollectionModal/CreateThirdPartyCollectionModal.tsx

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useMemo, useCallback, FC, SyntheticEvent } from 'react'
2-
import { Collection, TP_COLLECTION_NAME_MAX_LENGTH } from 'modules/collection/types'
2+
import { ContractNetwork } from '@dcl/schemas'
33
import {
44
ModalNavigation,
55
Button,
@@ -16,20 +16,12 @@ import uuid from 'uuid'
1616
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
1717
import Modal from 'decentraland-dapps/dist/containers/Modal'
1818
import { getAnalytics } from 'decentraland-dapps/dist/modules/analytics'
19+
import { Collection, TP_COLLECTION_NAME_MAX_LENGTH } from 'modules/collection/types'
1920
import { buildThirdPartyURN, decodeURN, getDefaultThirdPartyUrnSuffix } from 'lib/urn'
2021
import { shorten } from 'lib/address'
21-
import ethereumSvg from '../../../icons/ethereum.svg'
22-
import polygonSvg from '../../../icons/polygon.svg'
22+
import { imgSrcByNetwork } from 'components/NetworkIcon'
2323
import { Props } from './CreateThirdPartyCollectionModal.types'
2424
import styles from './CreateThirdPartyCollectionModal.module.css'
25-
import { ContractNetwork } from '@dcl/schemas'
26-
27-
const imgSrcByNetwork = {
28-
[ContractNetwork.MAINNET]: ethereumSvg,
29-
[ContractNetwork.MATIC]: polygonSvg,
30-
[ContractNetwork.SEPOLIA]: ethereumSvg,
31-
[ContractNetwork.AMOY]: polygonSvg
32-
}
3325

3426
export const CreateThirdPartyCollectionModal: FC<Props> = (props: Props) => {
3527
const {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Props } from './NetworkIcon.types'
2+
import { imgSrcByNetwork, NETWORK_ICON_DATA_TEST_ID } from './utils'
3+
4+
export const NetworkIcon = (props: Props) => (
5+
<img data-testid={NETWORK_ICON_DATA_TEST_ID} src={imgSrcByNetwork[props.network]} alt={props.network} className={props.className} />
6+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ContractNetwork } from '@dcl/schemas'
2+
3+
export type Props = {
4+
network: ContractNetwork
5+
className?: string
6+
}

src/components/NetworkIcon/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './NetworkIcon'
2+
export * from './utils'

src/components/NetworkIcon/utils.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ContractNetwork } from '@dcl/schemas'
2+
import ethereumSvg from '../../icons/ethereum.svg'
3+
import polygonSvg from '../../icons/polygon.svg'
4+
5+
export const NETWORK_ICON_DATA_TEST_ID = 'network-icon'
6+
7+
export const imgSrcByNetwork = {
8+
[ContractNetwork.MAINNET]: ethereumSvg,
9+
[ContractNetwork.MATIC]: polygonSvg,
10+
[ContractNetwork.SEPOLIA]: ethereumSvg,
11+
[ContractNetwork.AMOY]: polygonSvg
12+
}

src/components/ThirdPartyCollectionDetailPage/ThirdPartyCollectionDetailPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export default function ThirdPartyCollectionDetailPage({
237237
<Back absolute onClick={handleGoBack} />
238238
<div className={styles.content}>
239239
<div className={styles.title}>
240-
<ThirdPartyImage thirdPartyId={thirdParty.id} />
240+
<ThirdPartyImage thirdPartyId={thirdParty.id} network={collection.linkedContractNetwork} />
241241
<Header size="large" className={styles.name} onClick={handleEditName}>
242242
{collection.name}
243243
</Header>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
.image,
12
.main {
3+
position: relative;
24
width: 48px;
35
height: 48px;
46
}
7+
8+
.network {
9+
position: absolute;
10+
bottom: 0;
11+
right: 0;
12+
width: 24px;
13+
height: 24px;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ContractNetwork } from '@dcl/schemas'
2+
import { render } from '@testing-library/react'
3+
import { NETWORK_ICON_DATA_TEST_ID } from 'components/NetworkIcon'
4+
import { ThirdPartyImage } from './ThirdPartyImage'
5+
import { Props } from './ThirdPartyImage.types'
6+
7+
const renderThirdPartyImage = (props: Partial<Props> = {}) => render(<ThirdPartyImage thirdPartyId="aThirdPartyId" {...props} />)
8+
9+
describe('when rendering the component', () => {
10+
let props: Partial<Props>
11+
let renderedComponent: ReturnType<typeof renderThirdPartyImage>
12+
13+
beforeEach(() => {
14+
props = {}
15+
})
16+
17+
describe('without a contract network', () => {
18+
beforeEach(() => {
19+
props.network = undefined
20+
renderedComponent = renderThirdPartyImage(props)
21+
})
22+
23+
it('should not render the network image', () => {
24+
expect(renderedComponent.queryByTestId(NETWORK_ICON_DATA_TEST_ID)).not.toBeInTheDocument()
25+
})
26+
})
27+
28+
describe('with a contract network', () => {
29+
beforeEach(() => {
30+
props.network = ContractNetwork.MAINNET
31+
renderedComponent = renderThirdPartyImage(props)
32+
})
33+
34+
it('should render the network image', () => {
35+
expect(renderedComponent.getByTestId(NETWORK_ICON_DATA_TEST_ID)).toBeInTheDocument()
36+
})
37+
})
38+
})
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { Blockie } from 'decentraland-ui'
22
import classNames from 'classnames'
3+
import { NetworkIcon } from 'components/NetworkIcon'
34
import styles from './ThirdPartyImage.module.css'
45
import { Props } from './ThirdPartyImage.types'
56

67
export const ThirdPartyImage = (props: Props) => {
7-
const { thirdPartyId, className, shape } = props
8-
return <Blockie className={classNames(styles.main, className)} seed={thirdPartyId} size={8} scale={8} shape={shape ?? 'circle'} />
8+
const { thirdPartyId, network, className, shape } = props
9+
return (
10+
<div className={classNames(styles.main, className)}>
11+
<Blockie className={styles.image} seed={thirdPartyId} size={8} scale={8} shape={shape ?? 'circle'} />
12+
{network ? <NetworkIcon network={network} className={styles.network} /> : null}
13+
</div>
14+
)
915
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { ContractNetwork } from '@dcl/schemas'
2+
13
export type Props = {
24
className?: string
5+
network?: ContractNetwork
36
thirdPartyId: string
47
shape?: 'circle' | 'square'
58
}

0 commit comments

Comments
 (0)