-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet): Network Identifications in Portfolio
- Loading branch information
1 parent
ce05c1f
commit 80ece88
Showing
12 changed files
with
182 additions
and
26 deletions.
There are no files selected for viewing
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
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
77 changes: 77 additions & 0 deletions
77
components/brave_wallet_ui/components/shared/create-network-icon/index.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,77 @@ | ||
import * as React from 'react' | ||
import { BraveWallet } from '../../../constants/types' | ||
import { IconWrapper, Placeholder, NetworkIcon } from './style' | ||
import { stripERC20TokenImageURL, isRemoteImageURL, isValidIconExtension } from '../../../utils/string-utils' | ||
import { create } from 'ethereum-blockies' | ||
import { | ||
ETHIconUrl | ||
} from '../../../assets/asset-icons' | ||
|
||
interface Props { | ||
network: BraveWallet.EthereumChain | ||
marginRight: number | ||
} | ||
|
||
function CreateNetworkIcon (props: Props) { | ||
const { network, marginRight } = props | ||
if (!network) { | ||
return null | ||
} | ||
const networkImageURL = stripERC20TokenImageURL(network?.iconUrls[0]) | ||
const isRemoteURL = isRemoteImageURL(networkImageURL) | ||
const isDataURL = network.iconUrls[0]?.startsWith('chrome://erc-token-images/') | ||
const isStorybook = network.iconUrls[0]?.startsWith('static/media/components/brave_wallet_ui/') | ||
|
||
const isValidIcon = React.useMemo(() => { | ||
if (isRemoteURL || isDataURL) { | ||
const url = new URL(network.iconUrls[0]) | ||
return isValidIconExtension(url.pathname) | ||
} | ||
if (isStorybook) { | ||
return true | ||
} | ||
return false | ||
}, [isRemoteURL, isDataURL, networkImageURL]) | ||
|
||
// Will remove these hardcoded chainId's. | ||
// We need to return a normal Ethereum Icon URL for Ethereum Mainnet | ||
// and return a grayed out Ethereum Icon Url for Ethereum Test Networks from the backend. | ||
const testNetworkList = ['0x4', '0x3', '0x5', '0x2a', '0x539'] | ||
const needsPlaceholder = !['0x1', ...testNetworkList].includes(network.chainId) && (networkImageURL === '' || !isValidIcon) | ||
|
||
const orb = React.useMemo(() => { | ||
if (needsPlaceholder) { | ||
return create({ seed: network.chainName, size: 8, scale: 16 }).toDataURL() | ||
} | ||
}, [network]) | ||
|
||
const remoteImage = React.useMemo(() => { | ||
if (isRemoteURL) { | ||
return `chrome://image?${networkImageURL}` | ||
} | ||
return '' | ||
}, [networkImageURL]) | ||
|
||
if (needsPlaceholder) { | ||
return ( | ||
<IconWrapper | ||
marginRight={marginRight ?? 0} | ||
isTestnet={false} | ||
> | ||
<Placeholder | ||
orb={orb} | ||
/> | ||
</IconWrapper> | ||
) | ||
} | ||
return ( | ||
<IconWrapper | ||
marginRight={marginRight ?? 0} | ||
isTestnet={testNetworkList.includes(network.chainId)} | ||
> | ||
<NetworkIcon icon={['0x1', ...testNetworkList].includes(network.chainId) ? ETHIconUrl : isRemoteURL ? remoteImage : network.iconUrls[0]} /> | ||
</IconWrapper> | ||
) | ||
} | ||
|
||
export default CreateNetworkIcon |
32 changes: 32 additions & 0 deletions
32
components/brave_wallet_ui/components/shared/create-network-icon/style.ts
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,32 @@ | ||
import styled from 'styled-components' | ||
import { AssetIconFactory, AssetIconProps } from '../style' | ||
|
||
interface StyleProps { | ||
marginRight: number | ||
isTestnet: boolean | ||
orb: string | ||
} | ||
|
||
export const IconWrapper = styled.div<Partial<StyleProps>>` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
width: 15px; | ||
height: 15px; | ||
margin-right: ${(p) => `${p.marginRight}px`}; | ||
filter: ${(p) => p.isTestnet ? 'grayscale(100%)' : 'none'}; | ||
` | ||
|
||
export const Placeholder = styled.div<Partial<StyleProps>>` | ||
width: 10px; | ||
height: 10px; | ||
border-radius: 100%; | ||
background-image: url(${(p) => p.orb}); | ||
background-size: cover; | ||
` | ||
|
||
export const NetworkIcon = AssetIconFactory<AssetIconProps>({ | ||
width: '15px', | ||
height: 'auto' | ||
}) |
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
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