-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract AbiPlaygroundLink into a component
- Loading branch information
Showing
2 changed files
with
47 additions
and
31 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/app/components/ContractVerificationIcon/AbiPlaygroundLink.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,45 @@ | ||
import { FC } from 'react' | ||
import { Trans, useTranslation } from 'react-i18next' | ||
import Link from '@mui/material/Link' | ||
import { Layer } from '../../../oasis-nexus/api' | ||
import { SearchScope } from '../../../types/searchScope' | ||
import { Network } from '../../../types/network' | ||
import * as externalLinks from '../../utils/externalLinks' | ||
|
||
export const AbiPlaygroundLink: FC<{ | ||
address_eth: string | ||
scope: SearchScope | ||
}> = ({ address_eth, scope }) => { | ||
const { t } = useTranslation() | ||
|
||
const scopeToPlaygroundURL: Record<Network, Partial<Record<Layer, string>>> = { | ||
[Network.mainnet]: { | ||
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42262&contractAddress=${address_eth}`, | ||
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23294&contractAddress=${address_eth}`, | ||
}, | ||
[Network.testnet]: { | ||
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42261&contractAddress=${address_eth}`, | ||
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23295&contractAddress=${address_eth}`, | ||
}, | ||
} | ||
const abiPlaygroundLinkProps = { | ||
href: scopeToPlaygroundURL[scope.network]?.[scope.layer], | ||
rel: 'noopener noreferrer', | ||
target: '_blank', | ||
sx: { fontWeight: 400, color: 'inherit', textDecoration: 'underline' }, | ||
} | ||
|
||
if (!abiPlaygroundLinkProps.href) return null | ||
return ( | ||
<span> | ||
{' | '} | ||
<Trans | ||
t={t} | ||
i18nKey={'contract.verification.openInAbiPlayground'} | ||
components={{ | ||
AbiPlaygroundLink: <Link {...abiPlaygroundLinkProps} />, | ||
}} | ||
/> | ||
</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