// Copyright 2015, 2016 Ethcore (UK) Ltd. // This file is part of Parity. // Parity is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // Parity is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Parity. If not, see . import React, { Component } from 'react'; import { observer } from 'mobx-react'; import { api } from '../parity'; import DappsStore from '../dappsStore'; import Input from '../Input'; import SelectAccount from '../SelectAccount'; import styles from './dapp.css'; @observer export default class Dapp extends Component { dappsStore = DappsStore.instance(); render () { const app = this.dappsStore.isNew || this.dappsStore.isEditing ? this.dappsStore.wipApp : this.dappsStore.currentApp; if (!app) { return null; } return (
{ this.dappsStore.isNew ? this.renderOwnerSelect(app) : this.renderOwnerStatic(app) } { this.renderInputs(app) }
); } renderInputs (app) { if (this.dappsStore.isNew) { return null; } return [ this.renderHashInput(app, 'image', 'Image hash, as generated by Githubhint', true), this.renderHashInput(app, 'manifest', 'Manifest hash, as generated by Githubhint'), this.renderHashInput(app, 'content', 'Content hash, as generated by Githubhint') ]; } renderOwnerSelect (app) { const overlayImage = ( ); return ( ); } renderOwnerStatic (app) { const overlayImage = ( ); return ( ); } renderHashInput (app, type, label, withImage = false) { const onChange = (event) => this.onChangeHash(event, type); const hash = app[`${type}Hash`]; let overlayImage = null; if (withImage && hash) { overlayImage = ( ); } return ( ); } onChangeHash (event, type) { if (!this.dappsStore.isNew && !this.dappsStore.isEditing) { return; } const hash = event.target.value; let changed = false; let url = null; if (this.dappsStore.isNew) { if (hash && hash.length) { changed = true; } } else { if (this.dappsStore.currentApp[`${type}Hash`] !== hash) { changed = true; } else { url = this.dappsStore.currentApp[`${type}Url`]; } } this.dappsStore.editWip({ [`${type}Changed`]: changed, [`${type}Error`]: null, [`${type}Hash`]: hash, [`${type}Url`]: changed ? 'Resolving url from hash' : url }); if (changed) { if (hash.length) { this.dappsStore .lookupHash(hash) .then((url) => { this.dappsStore.editWip({ [`${type}Error`]: url ? null : 'Unable to resolve url', [`${type}Url`]: url }); }); } else { this.dappsStore.editWip({ [`${type}Url`]: null }); } } } }