Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

EtherscanButton #45

Merged
merged 4 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/ethereum/EtherscanButton/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import styled from 'styled-components';

import EtherscanButton from './index';
import { Text } from '../..';

export default {
title: 'Ethereum/EtherscanButton',
component: EtherscanButton,
parameters: {},
};

const StyledText = styled(Text)`
margin-right: 5px;
`;

export const SimpleEtherscanButton = (): React.ReactElement => (
<>
<StyledText size="md">An Address example</StyledText>
<br />
<EtherscanButton
type="address"
value="0xda6786379ff88729264d31d472fa917f5e561443"
/>
<br />
<StyledText size="md">A Transaction example</StyledText>
<br />
<EtherscanButton
type="tx"
value="0xc276be3ffccc2398d3b82a0e375a94f67b8ad81c68f8625a5d516567dfe3de29"
/>
</>
);
46 changes: 46 additions & 0 deletions src/ethereum/EtherscanButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';

import { Icon } from '../..';

type Network = 'mainnet' | 'rinkeby';

type Props = {
className?: string;
network?: Network;
type: 'address' | 'tx';
value: string;
};

const getNetwork = (network: Network) => {
const lowerCaseNetwork = network.toLowerCase();
return lowerCaseNetwork === 'mainnet' ? '' : `${lowerCaseNetwork}.`;
};

const EtherscanButton = ({
className,
type,
value,
network = 'mainnet',
}: Props): React.ReactElement => {
const etherscanLink = `https://${getNetwork(
network
)}etherscan.io/${type}/${value}`;

return (
<a
className={className}
aria-label="Show details on Etherscan"
href={etherscanLink}
rel="noopener noreferrer"
target="_blank">
<Icon
size="sm"
color="icon"
type="externalLink"
tooltip="Show details on Etherscan"
/>
</a>
);
};

export default EtherscanButton;
1 change: 1 addition & 0 deletions src/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as EtherscanButton } from './EtherscanButton';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from './dataDisplay';
export * from './inputs';
export * from './feedback';
export * from './navigation';
//export * from './layouts'
export * from './ethereum';
//export * from './surfaces';
export * from './utils';
export { default as theme } from './theme';