Merge branch 'develop' of https://github.com/status-im/discover-dapps into develop

This commit is contained in:
Lyubomir Kiprov 2019-05-09 16:03:03 +03:00
commit 46b5524a5f
9 changed files with 175 additions and 13 deletions

View File

@ -1,8 +1,25 @@
const transactionStatus = { import {
dappName: 'slow.Trade', getTransactionData,
dappUrl: '/images/dapps/slowtrade.png', setTransactionData,
progress: false, } from '../../modules/TransactionStatus/TransactionStatus.utilities'
published: true,
let transactionStatus
const transactionData = getTransactionData()
if (transactionData !== '') {
transactionStatus = JSON.parse(transactionData)
if (transactionStatus.dappTransactionHash === '') {
transactionStatus.dappName = ''
transactionStatus.dappImg = ''
}
} else {
transactionStatus = {
dappTransactionHash: '',
dappName: '',
dappImg: '',
progress: false,
published: false,
}
} }
export default transactionStatus export default transactionStatus

View File

@ -13,7 +13,9 @@ import {
onImgMoveAction, onImgMoveAction,
onImgDoneAction, onImgDoneAction,
onImgCancelAction, onImgCancelAction,
submitAction,
} from './Submit.reducer' } from './Submit.reducer'
import { onStartProgressAction } from '../TransactionStatus/TransactionStatus.recuder'
const mapStateToProps = state => state.submit const mapStateToProps = state => state.submit
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
@ -27,6 +29,10 @@ const mapDispatchToProps = dispatch => ({
onImgMove: (x, y) => dispatch(onImgMoveAction(x, y)), onImgMove: (x, y) => dispatch(onImgMoveAction(x, y)),
onImgCancel: () => dispatch(onImgCancelAction()), onImgCancel: () => dispatch(onImgCancelAction()),
onImgDone: imgBase64 => dispatch(onImgDoneAction(imgBase64)), onImgDone: imgBase64 => dispatch(onImgDoneAction(imgBase64)),
onSubmit: dapp => {
dispatch(onStartProgressAction(dapp))
dispatch(submitAction(dapp))
},
}) })
export default withRouter( export default withRouter(

View File

@ -23,6 +23,7 @@ class Submit extends React.Component {
this.onTouchMove = this.onTouchMove.bind(this) this.onTouchMove = this.onTouchMove.bind(this)
this.onEndMove = this.onEndMove.bind(this) this.onEndMove = this.onEndMove.bind(this)
this.onImgDone = this.onImgDone.bind(this) this.onImgDone = this.onImgDone.bind(this)
this.onSubmit = this.onSubmit.bind(this)
} }
componentDidUpdate() { componentDidUpdate() {
@ -139,6 +140,19 @@ class Submit extends React.Component {
onImgDone(imgBase64) onImgDone(imgBase64)
} }
onSubmit() {
const { onSubmit, name, desc, url, img, category } = this.props
const dapp = {
name,
url,
img,
category,
desc,
}
onSubmit(dapp)
}
render() { render() {
const { const {
visible, visible,
@ -153,6 +167,9 @@ class Submit extends React.Component {
onImgCancel, onImgCancel,
} = this.props } = this.props
const canSubmit =
name !== '' && desc !== '' && url !== '' && img !== '' && category !== ''
return ( return (
<Modal <Modal
visible={visible && window.location.hash === '#submit'} visible={visible && window.location.hash === '#submit'}
@ -240,7 +257,8 @@ class Submit extends React.Component {
<button <button
className={styles.submitButton} className={styles.submitButton}
type="submit" type="submit"
disabled={true} disabled={!canSubmit}
onClick={this.onSubmit}
> >
Continue Continue
</button> </button>
@ -322,6 +340,7 @@ Submit.propTypes = {
onImgMove: PropTypes.func.isRequired, onImgMove: PropTypes.func.isRequired,
onImgCancel: PropTypes.func.isRequired, onImgCancel: PropTypes.func.isRequired,
onImgDone: PropTypes.func.isRequired, onImgDone: PropTypes.func.isRequired,
onSubmit: PropTypes.func.isRequired,
} }
export default Submit export default Submit

View File

@ -172,6 +172,7 @@
font-family: $font; font-family: $font;
padding: calculateRem(11) calculateRem(38); padding: calculateRem(11) calculateRem(38);
font-size: calculateRem(15); font-size: calculateRem(15);
cursor: pointer;
} }
.submitButton:disabled, .submitButton:disabled,

View File

@ -1,5 +1,21 @@
import submitInitialState from '../../common/data/submit' import submitInitialState from '../../common/data/submit'
import reducerUtil from '../../common/utils/reducer' import reducerUtil from '../../common/utils/reducer'
import {
onPublishedSuccessAction,
onReceiveTransactionHashAction,
} from '../TransactionStatus/TransactionStatus.recuder'
//TODO: create here. You can completely delete the following two functions. They must be imported.
const createDapp = async (name, url, desc, category, img) => {
return '0x3513rewrsdfsdf'
}
const checkTransactionStatus = async hash => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, 5000)
})
}
const SHOW_SUBMIT = 'SHOW_SUBMIT' const SHOW_SUBMIT = 'SHOW_SUBMIT'
const CLOSE_SUBMIT = 'CLOSE_SUBMIT' const CLOSE_SUBMIT = 'CLOSE_SUBMIT'
@ -80,6 +96,30 @@ export const onImgDoneAction = imgBase64 => ({
payload: imgBase64, payload: imgBase64,
}) })
export const submitAction = dapp => {
return async dispatch => {
dispatch(closeSubmitAction())
const hash = await createDapp(
dapp.name,
dapp.url,
dapp.desc,
dapp.category,
dapp.img,
)
dispatch(onReceiveTransactionHashAction(hash))
await checkTransactionStatus(hash)
dispatch(onPublishedSuccessAction())
}
}
export const statusCheckAction = hash => {
return async dispatch => {
await checkTransactionStatus(hash)
dispatch(onPublishedSuccessAction())
}
}
const showSubmit = state => { const showSubmit = state => {
return Object.assign({}, state, { return Object.assign({}, state, {
visible: true, visible: true,

View File

@ -1,10 +1,12 @@
import { connect } from 'react-redux' import { connect } from 'react-redux'
import TransactionStatus from './TransactionStatus' import TransactionStatus from './TransactionStatus'
import { hideAction } from './TransactionStatus.recuder' import { hideAction } from './TransactionStatus.recuder'
import { statusCheckAction } from '../Submit/Submit.reducer'
const mapStateToProps = state => state.transactionStatus const mapStateToProps = state => state.transactionStatus
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
hide: () => dispatch(hideAction()), hide: () => dispatch(hideAction()),
statusCheck: hash => dispatch(statusCheckAction(hash)),
}) })
export default connect( export default connect(

View File

@ -8,6 +8,7 @@ import loadingSpinner from '../../common/assets/images/loading-spinner.svg'
class TransactionStatus extends React.Component { class TransactionStatus extends React.Component {
componentDidMount() { componentDidMount() {
this.checkPublished() this.checkPublished()
this.checkTransactionHash()
} }
componentDidUpdate() { componentDidUpdate() {
@ -23,14 +24,20 @@ class TransactionStatus extends React.Component {
} }
} }
checkTransactionHash() {
const { dappTransactionHash, statusCheck } = this.props
if (dappTransactionHash === '') return
statusCheck(dappTransactionHash)
}
render() { render() {
const { dappName, dappUrl, published, progress } = this.props const { dappName, dappImg, published, progress } = this.props
return ( return (
<div className={`${styles.cnt} ${dappName !== '' ? styles.active : ''}`}> <div className={`${styles.cnt} ${dappName !== '' ? styles.active : ''}`}>
<ReactImageFallback <ReactImageFallback
className={styles.image} className={styles.image}
src={dappUrl} src={dappImg}
fallbackImage={icon} fallbackImage={icon}
alt="App icon" alt="App icon"
/> />
@ -53,16 +60,14 @@ class TransactionStatus extends React.Component {
} }
} }
TransactionStatus.defaultProps = {
dapp: null,
}
TransactionStatus.propTypes = { TransactionStatus.propTypes = {
dappTransactionHash: PropTypes.string.isRequired,
dappName: PropTypes.string.isRequired, dappName: PropTypes.string.isRequired,
dappUrl: PropTypes.string.isRequired, dappImg: PropTypes.string.isRequired,
progress: PropTypes.bool.isRequired, progress: PropTypes.bool.isRequired,
published: PropTypes.bool.isRequired, published: PropTypes.bool.isRequired,
hide: PropTypes.func.isRequired, hide: PropTypes.func.isRequired,
statusCheck: PropTypes.func.isRequired,
} }
export default TransactionStatus export default TransactionStatus

View File

@ -1,21 +1,83 @@
import transactionStatusInitialState from '../../common/data/transaction-status' import transactionStatusInitialState from '../../common/data/transaction-status'
import reducerUtil from '../../common/utils/reducer' import reducerUtil from '../../common/utils/reducer'
import {
setTransactionData,
getTransactionData,
} from './TransactionStatus.utilities'
const HIDE = 'HIDE' const HIDE = 'HIDE'
const ON_START_PROGRESS = 'ON_START_PROGRESS'
const ON_RECEIVE_TRANSACTION_HASH = 'ON_RECEIVE_TRANSACTION_HASH'
const ON_PUBLISHED_SUCCESS = 'ON_PUBLISHED_SUCCESS'
export const hideAction = () => ({ export const hideAction = () => ({
type: HIDE, type: HIDE,
payload: null, payload: null,
}) })
export const onStartProgressAction = dapp => ({
type: ON_START_PROGRESS,
payload: dapp,
})
export const onReceiveTransactionHashAction = hash => ({
type: ON_RECEIVE_TRANSACTION_HASH,
payload: hash,
})
export const onPublishedSuccessAction = () => ({
type: ON_PUBLISHED_SUCCESS,
payload: null,
})
const hide = state => { const hide = state => {
return Object.assign({}, state, { return Object.assign({}, state, {
dappName: '', dappName: '',
}) })
} }
const onStartProgress = (state, dapp) => {
const dappState = {
dappTransactionHash: '',
dappName: dapp.name,
dappImg: dapp.img,
progress: true,
published: false,
}
setTransactionData(JSON.stringify(dappState))
return Object.assign({}, state, dappState)
}
const onReceiveTransactionHash = (state, hash) => {
const transactionData = getTransactionData()
if (transactionData !== '') {
const dappState = JSON.parse(transactionData)
dappState.dappTransactionHash = hash
setTransactionData(JSON.stringify(dappState))
}
return Object.assign({}, state, {
dappTransactionHash: hash,
})
}
const onPublishedSuccess = state => {
const transactionData = getTransactionData()
if (transactionData !== '') {
const dappState = JSON.parse(transactionData)
dappState.dappTransactionHash = ''
setTransactionData(JSON.stringify(dappState))
}
return Object.assign({}, state, {
progress: false,
published: true,
})
}
const map = { const map = {
[HIDE]: hide, [HIDE]: hide,
[ON_START_PROGRESS]: onStartProgress,
[ON_RECEIVE_TRANSACTION_HASH]: onReceiveTransactionHash,
[ON_PUBLISHED_SUCCESS]: onPublishedSuccess,
} }
export default reducerUtil(map, transactionStatusInitialState) export default reducerUtil(map, transactionStatusInitialState)

View File

@ -0,0 +1,10 @@
export const COOKIE_NAME = 'TRANSACTION_STATUS_COOKIE'
export const setTransactionData = value => {
localStorage.setItem(COOKIE_NAME, value)
}
export const getTransactionData = () => {
const value = localStorage.getItem(COOKIE_NAME)
return value === null ? '' : value
}