Skip to content

Commit

Permalink
Merge pull request #1326 from oasisprotocol/mz/contractIcon
Browse files Browse the repository at this point in the history
Make contract verification icon a link to Sourcify
  • Loading branch information
buberdds authored Mar 14, 2024
2 parents d82e471 + 2a7f2cf commit 3710ea1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions .changelog/1326.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make verification icon clickable when rendering a link to Sourcify
30 changes: 17 additions & 13 deletions src/app/components/ContractVerificationIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const statusIcon: Record<VerificationStatus, ReactNode> = {

export const verificationIconBoxHeight = 28

const StyledBox = styled(Box, {
shouldForwardProp: prop => prop !== 'verified',
const StyledPill = styled(Box, {
shouldForwardProp: prop => prop !== 'verified' && prop !== 'address_eth',
})(({ verified }: { verified: boolean; address_eth: string }) => {
const status: VerificationStatus = verified ? 'verified' : 'unverified'
return {
Expand All @@ -45,6 +45,9 @@ const StyledBox = styled(Box, {
padding: 4,
paddingLeft: 10,
paddingRight: 5,
'&&': {
textDecoration: 'none',
},
}
})

Expand Down Expand Up @@ -84,14 +87,23 @@ export const VerificationIcon: FC<{ address_eth: string; verified: boolean; noLi
verified: t('contract.verification.isVerified'),
unverified: t('contract.verification.isNotVerified'),
}
const linkProps = {
href: `https://sourcify.dev/#/lookup/${address_eth}`,
rel: 'noopener noreferrer',
target: '_blank',
sx: { fontWeight: 400, color: 'inherit', textDecoration: 'underline' },
onClick: verified ? undefined : () => setExplainDelay(true),
}
const Component = noLink ? Box : Link
const componentProps = noLink ? {} : linkProps

return (
<>
<StyledBox verified={verified} address_eth={address_eth}>
<StyledPill component={Component} verified={verified} address_eth={address_eth} {...componentProps}>
{statusLabel[status]}
&nbsp; &nbsp;
{statusIcon[status]}
</StyledBox>
</StyledPill>
&nbsp; &nbsp;
{!noLink && (
<Typography component="span" sx={{ fontSize: '12px', color: COLORS.brandExtraDark }}>
Expand All @@ -101,15 +113,7 @@ export const VerificationIcon: FC<{ address_eth: string; verified: boolean; noLi
verified ? 'contract.verification.openInSourcify' : 'contract.verification.verifyInSourcify'
}
components={{
SourcifyLink: (
<Link
href={`https://sourcify.dev/#/lookup/${address_eth}`}
rel="noopener noreferrer"
target="_blank"
sx={{ fontWeight: 400, color: 'inherit', textDecoration: 'underline' }}
onClick={verified ? undefined : () => setExplainDelay(true)}
/>
),
SourcifyLink: <Link {...linkProps} />,
}}
/>{' '}
{explainDelay && t('contract.verification.explainVerificationDelay')}
Expand Down

0 comments on commit 3710ea1

Please sign in to comment.