Skip to content

Commit 04c82e8

Browse files
authored
Fix contenthash link (#1064)
* fix-faq-background * Shows eth.link address below the contenthash link
1 parent 20c5eb9 commit 04c82e8

File tree

3 files changed

+73
-28
lines changed

3 files changed

+73
-28
lines changed

src/components/Links/ContentHashLink.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react'
22
import styled from '@emotion/styled/macro'
33
import { ReactComponent as ExternalLinkIcon } from '../Icons/externalLink.svg'
44
import { decodeContenthash, encodeContenthash } from '@ensdomains/ui'
5-
import useNetworkInfo from '../NetworkInformation/useNetworkInfo'
65

76
const ContentHashLinkContainer = styled('a')`
87
display: inline-block;
@@ -29,7 +28,6 @@ const DecodedError = styled('div')`
2928
`
3029

3130
const ContentHashLink = ({ value, contentType, domain }) => {
32-
const { networkId } = useNetworkInfo()
3331
if (contentType === 'oldcontent') {
3432
return <div>{value}</div>
3533
}
@@ -40,15 +38,11 @@ const ContentHashLink = ({ value, contentType, domain }) => {
4038
if (error) {
4139
return <DecodedError>{error}</DecodedError>
4240
}
43-
const ethUrl =
44-
!!domain.name.match('.eth$') && networkId === 1
45-
? `https://${domain.name}.link`
46-
: null
4741
if (protocolType === 'ipfs') {
48-
externalLink = ethUrl || `https://dweb.link/ipfs/${decoded}` // using ipfs's secured origin gateway
42+
externalLink = `https://dweb.link/ipfs/${decoded}` // using ipfs's secured origin gateway
4943
url = `ipfs://${decoded}`
5044
} else if (protocolType === 'ipns') {
51-
externalLink = ethUrl || `https://dweb.link/ipns/${decoded}`
45+
externalLink = `https://dweb.link/ipns/${decoded}`
5246
url = `ipns://${decoded}`
5347
} else if (protocolType === 'bzz') {
5448
externalLink = `https://swarm-gateways.net/bzz://${decoded}`

src/components/SingleName/NameRegister/EthRegistrationGasPrice.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ const Input = styled(DefaultInput)`
5757

5858
const EthRegistrationGasPrice = ({ price, ethUsdPrice, gasPrice }) => {
5959
const { t } = useTranslation()
60-
console.log('***gasPrice', gasPrice)
6160
const ethVal = new EthVal(`${price}`).toEth()
6261
const registerGasSlow = new EthVal(`${TOGAL_GAS_WEI * gasPrice.slow}`).toEth()
6362
const registerGasFast = new EthVal(`${TOGAL_GAS_WEI * gasPrice.fast}`).toEth()
6463
const gasPriceToGweiSlow = new EthVal(`${gasPrice.slow}`).toGwei()
6564
const gasPriceToGweiFast = new EthVal(`${gasPrice.fast}`).toGwei()
6665
const totalSlow = ethVal.add(registerGasSlow)
6766
const totalFast = ethVal.add(registerGasFast)
68-
const totalInUsdSlow = totalSlow.mul(ethUsdPrice)
69-
const totalInUsdFast = totalFast.mul(ethUsdPrice)
67+
let totalInUsdSlow, totalInUsdFast
68+
// No price oracle on Goerli
69+
if (ethUsdPrice) {
70+
totalInUsdSlow = totalSlow.mul(ethUsdPrice)
71+
totalInUsdFast = totalFast.mul(ethUsdPrice)
72+
}
7073
return (
7174
<PriceContainer>
7275
<TotalValue>

src/components/SingleName/ResolverAndRecords/ContentHash.js

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import CopyToClipBoard from '../../CopyToClipboard/'
1919
import { useEditable } from '../../hooks'
2020
import Button from '../../Forms/Button'
2121
import RequestCertificate from './RequestCertificate'
22+
import useNetworkInfo from '../../NetworkInformation/useNetworkInfo'
23+
import { ReactComponent as ExternalLinkIcon } from '../../Icons/externalLink.svg'
2224

2325
export const RecordsItem = styled(DetailsItem)`
2426
${p => !p.hasRecord && 'display: none;'}
@@ -135,6 +137,25 @@ const NotSet = styled('div')`
135137
color: #ccc;
136138
`
137139

140+
const LinkContainer = styled('a')`
141+
display: inline-block;
142+
align-items: center;
143+
text-overflow: ellipsis;
144+
white-space: nowrap;
145+
overflow: hidden;
146+
svg {
147+
margin-left: 10px;
148+
transition: 0.1s;
149+
opacity: 0;
150+
}
151+
152+
&:hover {
153+
svg {
154+
opacity: 1;
155+
}
156+
}
157+
`
158+
138159
const Uploadable = ({ startUploading, keyName, value }) => {
139160
if (value && !value.error) {
140161
return (
@@ -172,7 +193,7 @@ const ContentHashEditable = ({
172193
}) => {
173194
const { t } = useTranslation()
174195
const { state, actions } = useEditable()
175-
196+
const { contentType } = domain
176197
const { authorized, uploading, newValue } = state
177198

178199
const {
@@ -205,14 +226,11 @@ const ContentHashEditable = ({
205226
value === 'undefined' ? (
206227
<NotSet>Not set</NotSet>
207228
) : (
208-
<>
209-
<ContentHashLink
210-
value={value}
211-
contentType={domain.contentType}
212-
domain={domain}
213-
/>
214-
<CopyToClipBoard value={value} />
215-
</>
229+
<ContentHashLinkWithEthLink
230+
value={value}
231+
contentType={contentType}
232+
domain={domain}
233+
/>
216234
)}
217235
</RecordsValue>
218236
)}
@@ -322,6 +340,39 @@ const ContentHashEditable = ({
322340
)
323341
}
324342

343+
function ContentHashLinkWithEthLink({ value, contentType, domain }) {
344+
const { networkId } = useNetworkInfo()
345+
const displayEthLink =
346+
!!domain.name.match('.eth$') && networkId === 1 && value?.match(/^ip/)
347+
return (
348+
<>
349+
<div>
350+
<ContentHashLink
351+
value={value}
352+
contentType={contentType}
353+
domain={domain}
354+
/>
355+
{displayEthLink && (
356+
<div>
357+
<LinkContainer
358+
target="_blank"
359+
rel="noopener"
360+
href={`https://${domain.name}.link`}
361+
>
362+
({`https://${domain.name}.link`})
363+
<ExternalLinkIcon />
364+
</LinkContainer>
365+
</div>
366+
)}
367+
</div>
368+
<div>
369+
<CopyToClipBoard value={value} />
370+
<div>{displayEthLink && <>&nbsp;</>}</div>
371+
</div>
372+
</>
373+
)
374+
}
375+
325376
function ContentHashViewOnly({ keyName, value, type, domain, account }) {
326377
const { name, contentType } = domain
327378
const { t } = useTranslation()
@@ -333,14 +384,11 @@ function ContentHashViewOnly({ keyName, value, type, domain, account }) {
333384
<RecordsKey>{t(`c.${keyName}`)}</RecordsKey>
334385
<RecordsValue>
335386
{value !== '' ? (
336-
<>
337-
<ContentHashLink
338-
value={value}
339-
contentType={contentType}
340-
domain={domain}
341-
/>
342-
<CopyToClipBoard value={value} />
343-
</>
387+
<ContentHashLinkWithEthLink
388+
value={value}
389+
contentType={contentType}
390+
domain={domain}
391+
/>
344392
) : (
345393
<NotSet>Not set</NotSet>
346394
)}

0 commit comments

Comments
 (0)