Allow owner to update content url (#3083)
This commit is contained in:
parent
5336f65cf5
commit
d47c6db713
@ -108,14 +108,19 @@
|
|||||||
background: #fcc;
|
background: #fcc;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hashError {
|
.hashError, .hashWarning, .hashOk {
|
||||||
padding-top: 0.5em;
|
padding-top: 0.5em;
|
||||||
color: #f66;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hashOk {
|
.hashError {
|
||||||
padding-top: 0.5em;
|
color: #f66;
|
||||||
opacity: 0.5;
|
}
|
||||||
text-align: center;
|
|
||||||
|
.hashWarning {
|
||||||
|
color: #f80;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hashOk {
|
||||||
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,13 @@ const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|||||||
|
|
||||||
export default class Application extends Component {
|
export default class Application extends Component {
|
||||||
state = {
|
state = {
|
||||||
|
fromAddress: null,
|
||||||
loading: true,
|
loading: true,
|
||||||
url: '',
|
url: '',
|
||||||
urlError: null,
|
urlError: null,
|
||||||
contentHash: '',
|
contentHash: '',
|
||||||
contentHashError: null,
|
contentHashError: null,
|
||||||
|
contentHashOwner: null,
|
||||||
registerBusy: false,
|
registerBusy: false,
|
||||||
registerError: null,
|
registerError: null,
|
||||||
registerState: ''
|
registerState: ''
|
||||||
@ -63,7 +65,14 @@ export default class Application extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderPage () {
|
renderPage () {
|
||||||
const { registerBusy, url, urlError, contentHash, contentHashError } = this.state;
|
const { fromAddress, registerBusy, url, urlError, contentHash, contentHashError, contentHashOwner } = this.state;
|
||||||
|
|
||||||
|
let hashClass = null;
|
||||||
|
if (contentHashError) {
|
||||||
|
hashClass = contentHashOwner !== fromAddress ? styles.hashError : styles.hashWarning;
|
||||||
|
} else {
|
||||||
|
hashClass = styles.hashOk;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={ styles.container }>
|
<div className={ styles.container }>
|
||||||
@ -81,7 +90,7 @@ export default class Application extends Component {
|
|||||||
className={ urlError ? styles.error : null }
|
className={ urlError ? styles.error : null }
|
||||||
onChange={ this.onChangeUrl } />
|
onChange={ this.onChangeUrl } />
|
||||||
</div>
|
</div>
|
||||||
<div className={ contentHashError ? styles.hashError : styles.hashOk }>
|
<div className={ hashClass }>
|
||||||
{ contentHashError || contentHash }
|
{ contentHashError || contentHash }
|
||||||
</div>
|
</div>
|
||||||
{ registerBusy ? this.renderProgress() : this.renderButtons() }
|
{ registerBusy ? this.renderProgress() : this.renderButtons() }
|
||||||
@ -92,7 +101,7 @@ export default class Application extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderButtons () {
|
renderButtons () {
|
||||||
const { accounts, fromAddress, url, urlError, contentHashError } = this.state;
|
const { accounts, fromAddress, url, urlError, contentHashError, contentHashOwner } = this.state;
|
||||||
const account = accounts[fromAddress];
|
const account = accounts[fromAddress];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -105,7 +114,7 @@ export default class Application extends Component {
|
|||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
onClick={ this.onClickRegister }
|
onClick={ this.onClickRegister }
|
||||||
disabled={ !!contentHashError || !!urlError || url.length === 0 }>register url</Button>
|
disabled={ (!!contentHashError && contentHashOwner !== fromAddress) || !!urlError || url.length === 0 }>register url</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -163,9 +172,9 @@ export default class Application extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClickRegister = () => {
|
onClickRegister = () => {
|
||||||
const { url, urlError, contentHash, contentHashError, fromAddress, instance } = this.state;
|
const { url, urlError, contentHash, contentHashError, contentHashOwner, fromAddress, instance } = this.state;
|
||||||
|
|
||||||
if (!!contentHashError || !!urlError || url.length === 0) {
|
if ((!!contentHashError && contentHashOwner !== fromAddress) || !!urlError || url.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,13 +252,17 @@ export default class Application extends Component {
|
|||||||
|
|
||||||
instance.entries
|
instance.entries
|
||||||
.call({}, [contentHash])
|
.call({}, [contentHash])
|
||||||
.then(([accountSlashRepo, commit, owner]) => {
|
.then(([accountSlashRepo, commit, contentHashOwner]) => {
|
||||||
console.log('lookupHash', accountSlashRepo, api.util.bytesToHex(commit), owner);
|
console.log('lookupHash', accountSlashRepo, api.util.bytesToHex(commit), contentHashOwner);
|
||||||
|
|
||||||
if (owner !== ZERO_ADDRESS) {
|
if (contentHashOwner !== ZERO_ADDRESS) {
|
||||||
this.setState({ contentHashError: contentHash, contentHash: null });
|
this.setState({
|
||||||
|
contentHashError: contentHash,
|
||||||
|
contentHashOwner,
|
||||||
|
contentHash
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setState({ contentHashError: null, contentHash });
|
this.setState({ contentHashError: null, contentHashOwner, contentHash });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user