Skip to content

Commit

Permalink
Display deprecated content (#1073)
Browse files Browse the repository at this point in the history
* fix-faq-background

* Update content-hash to 2.5.4

* Display error for invliad ipns value

* Fix bug

* Bump ui to 3.0.60

* Use getProtocolType instead of encode and decode

* Bump ui

* Add test to invalidate deprecated ipns

* Fix failing test

* Change test to use different test data
  • Loading branch information
makoto authored Feb 16, 2021
1 parent 8f14d9f commit c897757
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 25 deletions.
13 changes: 13 additions & 0 deletions cypress/integration/nameDetail.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,19 @@ describe('Name detail view', () => {
])
})

it('cannot change deprecated ipns contenthash', () => {
const url = `${NAME_ROOT}/abittooawesome4.eth`
cy.visit(url)
const DEPRECATED_CONTENT_HASH = 'ipns://app.uniswap.org'
cy.queryByText(DEPRECATED_CONTENT_HASH, { timeout: 10000 }).should('exist')

cy.getByTestId('name-details', { timeout: 10000 }).within(container => {
cy.getByText('Add/Edit Record').click({ force: true })
cy.wait(2000)
cy.queryByTestId('content-record-input-invalid')
})
})

it('can delete records', () => {
cy.visit(`${NAME_ROOT}/notsoawesome.eth`)
cy.getByTestId('name-details').within(container => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"@toruslabs/torus-embed": "^1.8.6",
"@walletconnect/web3-provider": "^1.3.1",
"@ensdomains/address-encoder": "^0.2.6",
"@ensdomains/mock": "^2.0.34",
"@ensdomains/mock": "^2.0.36",
"@ensdomains/react-ens-address": "^0.0.27",
"@ensdomains/ui": "^3.0.58",
"@ensdomains/ui": "^3.0.61",
"apollo-cache-inmemory": "^1.2.9",
"apollo-client": "^2.4.5",
"apollo-link": "^1.2.2",
Expand Down
5 changes: 3 additions & 2 deletions src/api/manager/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ const resolvers = {
records.content === ''
? emptyAddress
: records.content
? encodeContenthash(records.content)
? encodeContenthash(records.content)?.encoded
: undefined,
records.textRecords,
records.coins
Expand Down Expand Up @@ -807,7 +807,8 @@ const resolvers = {
provider
})
const content = await resolverInstanceWithoutSigner.content(namehash)
return encodeContenthash('bzz://' + content)
const { encoded } = encodeContenthash('bzz://' + content)
return encoded
}

async function getContenthash(name) {
Expand Down
16 changes: 3 additions & 13 deletions src/components/Links/ContentHashLink.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import styled from '@emotion/styled/macro'
import { ReactComponent as ExternalLinkIcon } from '../Icons/externalLink.svg'
import { decodeContenthash, encodeContenthash } from '@ensdomains/ui'
import { getProtocolType } from '@ensdomains/ui'

const ContentHashLinkContainer = styled('a')`
display: inline-block;
Expand All @@ -22,22 +22,12 @@ const ContentHashLinkContainer = styled('a')`
}
`

const DecodedError = styled('div')`
white-space: normal;
overflow: scroll;
`

const ContentHashLink = ({ value, contentType, domain }) => {
if (contentType === 'oldcontent') {
if (contentType === 'oldcontent' || !value) {
return <div>{value}</div>
}

const encoded = encodeContenthash(value)
const { protocolType, decoded, error } = decodeContenthash(encoded)
const { protocolType, decoded } = getProtocolType(value)
let externalLink, url
if (error) {
return <DecodedError>{error}</DecodedError>
}
if (protocolType === 'ipfs') {
externalLink = `https://dweb.link/ipfs/${decoded}` // using ipfs's secured origin gateway
url = `ipfs://${decoded}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const ContentHashEditable = ({
<>
<EditRecord>
<RecordInput
testId="content-record-input"
testId={`content-record-input${isInvalid ? '-invalid' : ''}`}
onChange={event => {
const value = event.target.value
setUpdatedRecords(records => ({
Expand Down
4 changes: 2 additions & 2 deletions src/utils/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function validateRecord({ type, value, contentType, selectedKey }) {
return isAddress
case 'content':
if (value === EMPTY_ADDRESS) return true // delete record
const encoded = encodeContenthash(value)
if (encoded) {
const { encoded, error: encodeError } = encodeContenthash(value)
if (!encodeError && encoded) {
return isValidContenthash(encoded)
} else {
return false
Expand Down
37 changes: 32 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,15 @@
multicodec "^1.0.4"
multihashes "^2.0.0"

"@ensdomains/content-hash@^2.5.5":
version "2.5.5"
resolved "https://registry.yarnpkg.com/@ensdomains/content-hash/-/content-hash-2.5.5.tgz#3efb64ced7bc8c76d883648519fdcaa312ad6ae9"
integrity sha512-g97tsnHku7fC+uyWAPj71TlLmgI2TsMtDEsiXAGvK73eC67aTVCsEagk6sPIZbB7+iKV3DY2wTQQos2VGBLMTw==
dependencies:
cids "^0.8.3"
multicodec "^1.0.4"
multihashes "^2.0.0"

"@ensdomains/[email protected]", "@ensdomains/contracts@^0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@ensdomains/contracts/-/contracts-0.0.1.tgz#edb841955adbd6f86bddaf9d05f6d239d25d5ab7"
Expand Down Expand Up @@ -1429,6 +1438,24 @@
table "^5.4.6"
web3 "^1.3.0"

"@ensdomains/mock@^2.0.36":
version "2.0.36"
resolved "https://registry.yarnpkg.com/@ensdomains/mock/-/mock-2.0.36.tgz#308eb17b86b58a68990a89a872d1ba249cac5d55"
integrity sha512-JNtXo4m9wfDL0SHFHbAPQbWVNEagLbNKq+UzHlUTx+OWa9wZK6wNwJFi63o2p0IQiTpQJs1zc5MC/HQATH76Vg==
dependencies:
"@0xproject/utils" "^2.0.2"
"@babel/runtime" "^7.4.4"
"@ensdomains/contracts" "^0.0.1"
"@ensdomains/dnssec-oracle-anchors" "^0.0.1"
chalk "^3.0.0"
cross-fetch "^3.0.2"
dns-packet "^5.2.1"
eth-ens-namehash "^2.0.8"
lodash "^4.17.11"
moment "^2.26.0"
table "^5.4.6"
web3 "^1.3.0"

"@ensdomains/react-ens-address@^0.0.27":
version "0.0.27"
resolved "https://registry.yarnpkg.com/@ensdomains/react-ens-address/-/react-ens-address-0.0.27.tgz#42ba9a4563ad60b146bdb2b0c260b2a1f86baa8b"
Expand Down Expand Up @@ -1465,16 +1492,16 @@
lodash "^4.17.11"
web3 "^1.3.0"

"@ensdomains/ui@^3.0.58":
version "3.0.58"
resolved "https://registry.yarnpkg.com/@ensdomains/ui/-/ui-3.0.58.tgz#b028b190f036c4151e771e2c74e91b8e279af006"
integrity sha512-EUWB2QtZQ/q8WFvk/MaxPiVB7EWaQktqTICmLYAI7MtTPSgOoxxAV/v0j2b5J+yeXzylYLavJSv9c6eHaw+JSw==
"@ensdomains/ui@^3.0.61":
version "3.0.61"
resolved "https://registry.yarnpkg.com/@ensdomains/ui/-/ui-3.0.61.tgz#8263cce026eb4496b44618de843fac42ab0fbdaa"
integrity sha512-QrweOs7dfjX0h0DG1kybm+lMEBEt2da6R9JnPxvaYLSVesN0ikT3CWwum0WopJw8p7d7D/1T4+gkHGD/o7vxkA==
dependencies:
"@0xproject/utils" "^2.0.2"
"@babel/plugin-proposal-class-properties" "^7.8.3"
"@babel/runtime" "^7.4.4"
"@ensdomains/address-encoder" "^0.2.5"
"@ensdomains/content-hash" "^2.5.3"
"@ensdomains/content-hash" "^2.5.5"
"@ensdomains/contracts" "^0.0.1"
"@ensdomains/dnsprovejs" "^0.2.0"
"@ensdomains/mock" "^2.0.34"
Expand Down

0 comments on commit c897757

Please sign in to comment.