Skip to content

Commit

Permalink
Delete addresses (#504)
Browse files Browse the repository at this point in the history
* Bump ui version to 1.1.28

* Validate other address format on adding record
  • Loading branch information
makoto authored Oct 28, 2019
1 parent ef707b0 commit 3957d41
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@ensdomains/ethregistrar": "^1.2.2",
"@ensdomains/react-ens-address": "^0.0.16",
"@ensdomains/resolver": "^0.1.11",
"@ensdomains/ui": "1.1.26",
"@ensdomains/ui": "1.1.28",
"apollo-cache-inmemory": "^1.2.9",
"apollo-client": "^2.4.5",
"apollo-link": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion src/components/SingleName/AddRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ function Editable({ domain, emptyRecords, refetch, setRecordAdded }) {
const isValid = validateRecord({
type: selectedRecord && selectedRecord.value ? selectedRecord.value : null,
value: newValue,
contentType: domain.contentType
contentType: domain.contentType,
selectedKey: selectedKey && selectedKey.value
})

const isInvalid = newValue !== '' && !isValid
Expand Down
14 changes: 6 additions & 8 deletions src/components/SingleName/Address/Address.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import React from 'react'
import { COIN_LIST } from './constants'
import KeyValueRecord from '../KeyValueRecord'
import { formatsByName } from '@ensdomains/address-encoder'
import { validateRecord } from '../../../utils/records'

const validator = (symbol, value) => {
let isValid = true
try {
formatsByName[symbol].decoder(value)
} catch {
isValid = false
}
return isValid
return validateRecord({
type: 'otherAddresses',
selectedKey: symbol,
value
})
}

export default function Address(props) {
Expand Down
20 changes: 11 additions & 9 deletions src/utils/records.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { encodeContenthash, isValidContenthash } from '@ensdomains/ui'
import { addressUtils } from 'utils/utils'
import { formatsByName } from '@ensdomains/address-encoder'

export function validateRecord(record) {
if (!record.type) {
return false
}

const { type, value } = record

if (type === 'content' && record.contentType === 'oldcontent') {
export function validateRecord({ type, value, contentType, selectedKey }) {
if (!type) return false
if (type === 'content' && contentType === 'oldcontent') {
return value.length > 32
}

Expand All @@ -26,7 +22,13 @@ export function validateRecord(record) {
case 'text':
return true
case 'otherAddresses':
return true
if (value === '') return false
try {
formatsByName[selectedKey].decoder(value)
return true
} catch {
return false
}
default:
throw new Error('Unrecognised record type')
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,10 @@
resolved "https://registry.yarnpkg.com/@ensdomains/resolver/-/resolver-0.1.9.tgz#013bc88397c2c204737aaaf602380145d845e09e"
integrity sha512-eSZIEWi2UcxNZXJhAeoTYUZr20fyly9eMUy17WQ5UjszXf0QgE1Zzh/Oj9Mhl0i8s7xqoPOsntr2ZI0JhsX78w==

"@ensdomains/ui@1.1.26":
version "1.1.26"
resolved "https://registry.yarnpkg.com/@ensdomains/ui/-/ui-1.1.26.tgz#05aeb18c818883613c969b7d5f831a3399510523"
integrity sha512-D8QsHBj+Ge+v4DONBTXFBhR+U5D/3JiYjUqEgt/DWOSjZBSIJJUeGqOv4H5cKBc8ir2+ArbH9otbz4aYwGntnA==
"@ensdomains/ui@1.1.28":
version "1.1.28"
resolved "https://registry.yarnpkg.com/@ensdomains/ui/-/ui-1.1.28.tgz#6cbee1c191d0e5ae1dea6bdfc5cf5b290cfef9b4"
integrity sha512-yOAFxdTH7ujeeRZzEtYzOFB3ML7ucvzg4I4ZMvXNuMy491EpN84MmR4R7n5DT5Sy+EnED8V8LoBYcwZszpHLSw==
dependencies:
"@0xproject/utils" "^2.0.2"
"@babel/runtime" "^7.4.4"
Expand Down

0 comments on commit 3957d41

Please sign in to comment.