Skip to content

Commit

Permalink
Merge pull request #214 from ensdomains/dev
Browse files Browse the repository at this point in the history
Deploy to production
  • Loading branch information
jefflau authored Apr 29, 2019
2 parents 168dac0 + d932abd commit 82a9d9a
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 59 deletions.
6 changes: 3 additions & 3 deletions src/api/rootResolver.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getWeb3, { getAccounts, getNetworkId } from './web3'
import getWeb3, { getAccounts, getNetworkId, isReadOnly } from './web3'
import { getAddr } from './registry'
import merge from 'lodash/merge'
import fifsResolvers, {
Expand Down Expand Up @@ -55,10 +55,11 @@ const resolvers = {
}
},
Query: {
web3: async (_, variables, context) => {
web3: async () => {
try {
return {
...(await getWeb3()),
isReadOnly: isReadOnly(),
__typename: 'Web3'
}
} catch (e) {
Expand Down Expand Up @@ -88,7 +89,6 @@ const resolvers = {
const data = {
error: errorObj
}
console.log(data)
cache.writeData({ data })
return errorObj
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export async function getNetworkId() {

export async function getBlock() {
const web3 = await getWeb3()
let block = await web3.eth.getBlock('latest');
let block = await web3.eth.getBlock('latest')
return {
number: block.number,
timestamp: block.timestamp
Expand Down
1 change: 0 additions & 1 deletion src/components/Forms/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ const Button = props => {
className={className}
type={type}
onClick={onClick}
disabled={type === 'disabled'}
{...props}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/components/NetworkInformation/NetworkInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class NetworkInformation extends Component {
<Account data-testid="account" className="account">
<ReverseRecord address={accounts[0]} />
</Account>
<NetworkStatus>{network}</NetworkStatus>
<NetworkStatus>{network} Network</NetworkStatus>
</AccountContainer>
) : (
<NoAccountsModal colour={'#F5A623'} />
Expand Down
74 changes: 37 additions & 37 deletions src/components/SingleName/DetailsItemEditable.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,46 +380,45 @@ const Editable = ({
)
}

class DetailsEditable extends Component {
_renderViewOnly() {
let { value, keyName, type, deedOwner, isDeedOwner, domain } = this.props
if (parseInt(value, 16) === 0) {
let [newValue, newType] = getDefaultMessage(keyName)
value = newValue
type = newType
if (
keyName === 'Owner' &&
domain.parent === 'eth' &&
parseInt(deedOwner, 16) !== 0
) {
value = 'Pending'
if (isDeedOwner) {
value += '(You have not finalised)'
}
function ViewOnly({ value, keyName, type, deedOwner, isDeedOwner, domain }) {
if (parseInt(value, 16) === 0) {
let [newValue, newType] = getDefaultMessage(keyName)
value = newValue
type = newType
if (
keyName === 'Owner' &&
domain.parent === 'eth' &&
parseInt(deedOwner, 16) !== 0
) {
value = 'Pending'
if (isDeedOwner) {
value += '(You have not finalised)'
}
}
return (
<DetailsEditableContainer>
<DetailsContent>
<DetailsKey>{keyName}</DetailsKey>
<DetailsValue data-testid={`details-value-${keyName.toLowerCase()}`}>
{type === 'address' ? (
<EtherScanLink address={value}>
<SingleNameBlockies address={value} imageSize={24} />
{value}
</EtherScanLink>
) : (
value
)}
</DetailsValue>
</DetailsContent>
</DetailsEditableContainer>
)
}
render() {
const { isOwner } = this.props
return isOwner ? <Editable {...this.props} /> : this._renderViewOnly()
}
return (
<DetailsEditableContainer>
<DetailsContent>
<DetailsKey>{keyName}</DetailsKey>
<DetailsValue data-testid={`details-value-${keyName.toLowerCase()}`}>
{type === 'address' ? (
<EtherScanLink address={value}>
<SingleNameBlockies address={value} imageSize={24} />
{value}
</EtherScanLink>
) : type === 'date' ? (
formatDate(value)
) : (
value
)}
</DetailsValue>
</DetailsContent>
</DetailsEditableContainer>
)
}

function DetailsEditable(props) {
return props.canEdit ? <Editable {...props} /> : <ViewOnly {...props} />
}

DetailsEditable.propTypes = {
Expand All @@ -429,6 +428,7 @@ DetailsEditable.propTypes = {
mutation: PropTypes.object.isRequired, //graphql mutation string for making tx
mutationButton: PropTypes.string, // Mutation button text
editButton: PropTypes.string, //Edit button text
canEdit: PropTypes.bool,
domain: PropTypes.object.isRequired,
variableName: PropTypes.string, //can change the variable name for mutation
refetch: PropTypes.func.isRequired
Expand Down
15 changes: 11 additions & 4 deletions src/components/SingleName/Name.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,23 @@ function isRegistrationOpen(domain, isDeedOwner) {
return parent === 'eth' && !isDeedOwner && available
}

function isOwnerOfDomain(domain, account) {
if (domain.owner !== EMPTY_ADDRESS) {
return domain.owner.toLowerCase() === account.toLowerCase()
}
return false
}

function Name({ details: domain, name, pathname, refetch }) {
const smallBP = useMediaMin('small')
const percentDone = 0

return (
<QueryAccount>
{({ account }) => {
let isOwner = false
if (domain.owner !== EMPTY_ADDRESS) {
isOwner = domain.owner.toLowerCase() === account.toLowerCase()
}
const isOwner = isOwnerOfDomain(domain, account)
const isDeedOwner = domain.deedOwner === account

return (
<NameContainer state={isOwner ? 'Yours' : domain.state}>
<TopBar percentDone={percentDone}>
Expand All @@ -116,6 +122,7 @@ function Name({ details: domain, name, pathname, refetch }) {
domain={domain}
pathname={pathname}
refetch={refetch}
readOnly={account === EMPTY_ADDRESS}
/>
) : (
<NameDetails
Expand Down
12 changes: 6 additions & 6 deletions src/components/SingleName/NameDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class NameDetails extends Component {
domain={domain}
keyName="Registrant"
value={domain.registrant}
isOwner={isRegistrant}
canEdit={isRegistrant}
type="address"
editButton="Transfer"
mutationButton="Transfer"
Expand All @@ -165,7 +165,7 @@ class NameDetails extends Component {
domain={domain}
keyName="Controller"
value={domain.owner}
isOwner={isOwner || isRegistrant}
canEdit={isOwner || isRegistrant}
deedOwner={domain.deedOwner}
isDeedOwner={isDeedOwner}
type="address"
Expand All @@ -181,7 +181,7 @@ class NameDetails extends Component {
domain={domain}
keyName="Controller"
value={domain.owner}
isOwner={isOwner}
canEdit={isOwner}
deedOwner={domain.deedOwner}
isDeedOwner={isDeedOwner}
type="address"
Expand All @@ -204,12 +204,12 @@ class NameDetails extends Component {
''
)}
{domain.expiryTime ? (
domain.isNewRegistrar && isOwner ? (
domain.isNewRegistrar ? (
<DetailsItemEditable
domain={domain}
keyName="Expiration Date"
value={domain.expiryTime}
isOwner={isOwner}
canEdit={parseInt(account, 16) !== 0}
type="date"
editButton="Renew"
mutationButton="Renew"
Expand Down Expand Up @@ -248,7 +248,7 @@ class NameDetails extends Component {
keyName="Resolver"
type="address"
value={domain.resolver}
isOwner={isOwner}
canEdit={isOwner}
domain={domain}
editButton="Set"
mutationButton="Save"
Expand Down
38 changes: 33 additions & 5 deletions src/components/SingleName/NameRegister/CTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Mutation } from 'react-apollo'

import { COMMIT, REGISTER } from '../../../graphql/mutations'

import Tooltip from 'components/Tooltip/Tooltip'
import PendingTx from '../../PendingTx'
import Button from '../../Forms/Button'
import { ReactComponent as DefaultPencil } from '../../Icons/SmallPencil.svg'
Expand Down Expand Up @@ -37,7 +38,8 @@ function getCTA({
setTxHash,
setTimerRunning,
isAboveMinDuration,
refetch
refetch,
readOnly
}) {
const CTAs = {
PRICE_DECISION: (
Expand All @@ -50,10 +52,35 @@ function getCTA({
}}
>
{mutate =>
isAboveMinDuration ? (
isAboveMinDuration && !readOnly ? (
<Button data-testid="request-register-button" onClick={mutate}>
Request to register
</Button>
) : readOnly ? (
<Tooltip
text="<p>You are not connected to a web3 browser. Please connect to a web3 browser and try again</p>"
position="top"
border={true}
offset={{ left: -30, top: 10 }}
>
{({ tooltipElement, showTooltip, hideTooltip }) => {
return (
<Button
data-testid="request-register-button"
type="disabled"
onMouseOver={() => {
showTooltip()
}}
onMouseLeave={() => {
hideTooltip()
}}
>
Request to register
{tooltipElement}
</Button>
)
}}
</Tooltip>
) : (
<Button data-testid="request-register-button" type="disabled">
Request to register
Expand Down Expand Up @@ -119,12 +146,12 @@ function getCTA({
const CTA = ({
step,
incrementStep,
decrementStep,
duration,
label,
setTimerRunning,
isAboveMinDuration,
refetch
refetch,
readOnly
}) => {
const [txHash, setTxHash] = useState(undefined)
return (
Expand All @@ -138,7 +165,8 @@ const CTA = ({
setTxHash,
setTimerRunning,
isAboveMinDuration,
refetch
refetch,
readOnly
})}
</CTAContainer>
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/SingleName/NameRegister/NameRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const NameRegisterContainer = styled('div')`
padding: 20px 40px;
`

const NameRegister = ({ domain, waitTime, refetch }) => {
const NameRegister = ({ domain, waitTime, refetch, readOnly }) => {
const [step, dispatch] = useReducer(
registerReducer,
registerMachine.initialState
Expand Down Expand Up @@ -80,6 +80,7 @@ const NameRegister = ({ domain, waitTime, refetch }) => {
setTimerRunning={setTimerRunning}
refetch={refetch}
isAboveMinDuration={isAboveMinDuration}
readOnly={readOnly}
/>
</NameRegisterContainer>
)
Expand Down
1 change: 1 addition & 0 deletions src/graphql/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const GET_WEB3 = gql`
query web3 {
web3 @client {
accounts
isReadOnly
}
}
`
Expand Down

0 comments on commit 82a9d9a

Please sign in to comment.