-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b074537
commit a03a42a
Showing
13 changed files
with
67 additions
and
203 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1 @@ | ||
import React, { useMemo } from 'react'; | ||
import { View, ViewProps } from 'react-native'; | ||
import ContractInteraction from '../../assets/contractInteraction.png'; | ||
import { useTheme } from '../../theme/ThemeContext'; | ||
import ChainBadge from './ChainBadge'; | ||
import { CoinIconFallback } from './CoinIconFallback'; | ||
import { Network } from '@/networks/types'; | ||
import { useColorForAsset } from '@/hooks'; | ||
import { ImgixImage } from '@/components/images'; | ||
import styled from '@/styled-thing'; | ||
import { ethereumUtils, isETH, magicMemo, CoinIcon as ReactCoinIcon } from '@/utils'; | ||
import { ChainBadgeType } from '@/components/coin-icon/ChainBadgeSizeConfigs'; | ||
|
||
export const CoinIconSize = 40; | ||
|
||
const ContractInteractionIcon = styled(ImgixImage)(({ size }: { size: number }) => ({ | ||
height: size, | ||
width: size, | ||
})); | ||
|
||
const StyledCoinIcon = styled(ReactCoinIcon)({ | ||
opacity: ({ isHidden }: { isHidden?: boolean }) => (isHidden ? 0.4 : 1), | ||
}); | ||
|
||
type Props = { | ||
address?: string; | ||
badgeXPosition?: number; | ||
badgeYPosition?: number; | ||
badgeSize?: ChainBadgeType; | ||
ignoreBadge?: boolean; | ||
forcedShadowColor?: string; | ||
size?: number; | ||
symbol?: string; | ||
network: string; | ||
mainnet_address?: string; | ||
shadowOpacity?: number; | ||
} & Pick<ViewProps, 'testID' | 'style'>; | ||
|
||
const CoinIcon: React.FC<Props> = ({ | ||
address = 'eth', | ||
badgeXPosition, | ||
badgeYPosition, | ||
badgeSize, | ||
ignoreBadge = false, | ||
forcedShadowColor, | ||
size = CoinIconSize, | ||
symbol = '', | ||
network, | ||
mainnet_address, | ||
...props | ||
}) => { | ||
const color = useColorForAsset({ | ||
address: mainnet_address || address, | ||
}); | ||
const { colors, isDarkMode } = useTheme(); | ||
const forceFallback = !isETH(mainnet_address || address); | ||
const isNotContractInteraction = useMemo(() => symbol !== 'contract', [symbol]); | ||
|
||
const theme = useTheme(); | ||
|
||
return ( | ||
<View> | ||
{isNotContractInteraction ? ( | ||
<StyledCoinIcon | ||
{...props} | ||
address={mainnet_address || address} | ||
color={color} | ||
fallbackRenderer={CoinIconFallback} | ||
forceFallback={true} | ||
// force update on change symbol due to ImageCache strategy | ||
key={symbol} | ||
shadowColor={forcedShadowColor || (isDarkMode ? colors.shadow : color)} | ||
size={size} | ||
symbol={symbol} | ||
network={mainnet_address ? Network.mainnet : network} | ||
theme={theme} | ||
/> | ||
) : ( | ||
<ContractInteractionIcon size={size} source={ContractInteraction} /> | ||
)} | ||
{!ignoreBadge && <ChainBadge network={network} badgeXPosition={badgeXPosition} badgeYPosition={badgeYPosition} size={badgeSize} />} | ||
</View> | ||
); | ||
}; | ||
|
||
export default magicMemo(CoinIcon, ['address', 'isHidden', 'isPinned', 'size', 'network', 'symbol', 'shadowColor']); |
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
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
Oops, something went wrong.