Add hover state to top tokens
This commit is contained in:
@@ -26,21 +26,54 @@ export const TopTokens: React.StatelessComponent<TopTokensProps> = (props: TopTo
|
|||||||
{_.map(props.tokens, (tokenInfo: WebsiteBackendTokenInfo, index: number) => {
|
{_.map(props.tokens, (tokenInfo: WebsiteBackendTokenInfo, index: number) => {
|
||||||
const firstItemStyle = { ...styles.tokenLabel, ...styles.followingTokenLabel };
|
const firstItemStyle = { ...styles.tokenLabel, ...styles.followingTokenLabel };
|
||||||
const style = index !== 0 ? firstItemStyle : styles.tokenLabel;
|
const style = index !== 0 ? firstItemStyle : styles.tokenLabel;
|
||||||
return (
|
return <TokenLink tokenInfo={tokenInfo} style={style} networkId={props.networkId} />;
|
||||||
<a
|
|
||||||
key={tokenInfo.address}
|
|
||||||
href={tokenLinkFromToken(tokenInfo, props.networkId)}
|
|
||||||
target="_blank"
|
|
||||||
style={style}
|
|
||||||
>
|
|
||||||
{tokenInfo.symbol}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface TokenLinkProps {
|
||||||
|
tokenInfo: WebsiteBackendTokenInfo;
|
||||||
|
style: React.CSSProperties;
|
||||||
|
networkId: number;
|
||||||
|
}
|
||||||
|
interface TokenLinkState {
|
||||||
|
isHovering: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
class TokenLink extends React.Component<TokenLinkProps, TokenLinkState> {
|
||||||
|
constructor(props: TokenLinkProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
isHovering: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public render(): React.ReactNode {
|
||||||
|
const style = {
|
||||||
|
...this.props.style,
|
||||||
|
cursor: 'pointer',
|
||||||
|
opacity: this.state.isHovering ? 0.5 : 1,
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
key={this.props.tokenInfo.address}
|
||||||
|
href={tokenLinkFromToken(this.props.tokenInfo, this.props.networkId)}
|
||||||
|
target="_blank"
|
||||||
|
style={style}
|
||||||
|
onMouseEnter={this._onToggleHover.bind(this, true)}
|
||||||
|
onMouseLeave={this._onToggleHover.bind(this, false)}
|
||||||
|
>
|
||||||
|
{this.props.tokenInfo.symbol}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
private _onToggleHover(isHovering: boolean): void {
|
||||||
|
this.setState({
|
||||||
|
isHovering,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function tokenLinkFromToken(tokenInfo: WebsiteBackendTokenInfo, networkId: number): string {
|
function tokenLinkFromToken(tokenInfo: WebsiteBackendTokenInfo, networkId: number): string {
|
||||||
return sharedUtils.getEtherScanLinkIfExists(tokenInfo.address, networkId, EtherscanLinkSuffixes.Address);
|
return sharedUtils.getEtherScanLinkIfExists(tokenInfo.address, networkId, EtherscanLinkSuffixes.Address);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user