-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2827 from cowprotocol/hotfix/1.40.6
Hotfix/1.40.6
- Loading branch information
Showing
28 changed files
with
167 additions
and
61 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,83 @@ | ||
import { PropsWithChildren } from 'react' | ||
|
||
import { SupportedChainId } from '@cowprotocol/cow-sdk' | ||
|
||
import { ExternalLink } from 'legacy/theme' | ||
import { BlockExplorerLinkType, getExplorerLabel, getEtherscanLink } from 'legacy/utils' | ||
import { getExplorerLabel, getEtherscanLink } from 'legacy/utils' | ||
import { getExplorerBaseUrl } from 'legacy/utils/explorer' | ||
import { supportedChainId } from 'legacy/utils/supportedChainId' | ||
|
||
import { useWalletInfo } from 'modules/wallet' | ||
|
||
interface Props { | ||
id: string | ||
type?: BlockExplorerLinkType | ||
interface PropsBase extends PropsWithChildren { | ||
// type?: BlockExplorerLinkType | ||
label?: string | ||
className?: string | ||
defaultChain?: SupportedChainId | ||
} | ||
|
||
interface PropsWithId extends PropsBase { | ||
type: 'transaction' | 'token' | 'address' | 'block' | 'token-transfer' | ||
id: string | ||
} | ||
|
||
interface PropsWithoutId extends PropsBase { | ||
type: 'cow-explorer-home' | ||
} | ||
|
||
export type Props = PropsWithId | PropsWithoutId | ||
|
||
/** | ||
* Creates a link to the relevant explorer: Etherscan, GP Explorer or Blockscout | ||
* @param props | ||
*/ | ||
export function ExplorerLink(props: Props) { | ||
const { id, label, type = 'transaction', className } = props | ||
const { chainId: _chainId } = useWalletInfo() | ||
const chainId = supportedChainId(_chainId) | ||
const chainId = supportedChainId(_chainId) || props.defaultChain | ||
|
||
if (!chainId) { | ||
return null | ||
} | ||
|
||
const linkLabel = label || getExplorerLabel(chainId, id, type) | ||
const url = getUrl(chainId, props) | ||
const { className } = props | ||
|
||
const linkContent = getContent(chainId, props) | ||
return ( | ||
<ExternalLink className={className} href={getEtherscanLink(chainId, id, type)}> | ||
{linkLabel} <span style={{ fontSize: '0.8em' }}>↗</span> | ||
<ExternalLink className={className} href={url}> | ||
{linkContent} | ||
</ExternalLink> | ||
) | ||
} | ||
|
||
function getUrl(chainId: SupportedChainId, props: Props) { | ||
const { type } = props | ||
|
||
if (type === 'cow-explorer-home') { | ||
return getExplorerBaseUrl(chainId) | ||
} | ||
|
||
// return | ||
return getEtherscanLink(chainId, type, props.id) | ||
} | ||
|
||
function getLabel(chainId: SupportedChainId, props: Props) { | ||
const { label, type } = props | ||
|
||
const id = type !== 'cow-explorer-home' ? props.id : undefined | ||
|
||
return label || getExplorerLabel(chainId, type, id) | ||
} | ||
function getContent(chainId: SupportedChainId, props: Props) { | ||
if (props.children) { | ||
return props.children | ||
} | ||
|
||
const linkLabel = getLabel(chainId, props) | ||
|
||
return ( | ||
<> | ||
{linkLabel} <span style={{ fontSize: '0.8em' }}>↗</span> | ||
</> | ||
) | ||
} |
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
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.