mirror of
https://github.com/dap-ps/discover.git
synced 2025-02-28 08:50:34 +00:00
fixes #31: dynamic withdraw amount
This commit is contained in:
parent
c479cb4501
commit
5e13d419a7
@ -1,3 +1,5 @@
|
|||||||
|
/* eslint-disable react/destructuring-assignment */
|
||||||
|
/* eslint-disable react/no-did-update-set-state */
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import ReactImageFallback from 'react-image-fallback'
|
import ReactImageFallback from 'react-image-fallback'
|
||||||
@ -19,6 +21,20 @@ class Withdraw extends React.Component {
|
|||||||
super(props)
|
super(props)
|
||||||
this.onWithdraw = this.onWithdraw.bind(this)
|
this.onWithdraw = this.onWithdraw.bind(this)
|
||||||
this.handleSNTChange = this.handleSNTChange.bind(this)
|
this.handleSNTChange = this.handleSNTChange.bind(this)
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
withdrawAmount: props.withdrawMax || 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
if (
|
||||||
|
(!prevProps.withdrawMax && this.props.withdrawMax) ||
|
||||||
|
(this.props.withdrawMax &&
|
||||||
|
prevProps.withdrawMax != this.props.withdrawMax)
|
||||||
|
) {
|
||||||
|
this.setState({ withdrawAmount: this.props.withdrawMax })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onWithdraw() {
|
onWithdraw() {
|
||||||
@ -35,6 +51,8 @@ class Withdraw extends React.Component {
|
|||||||
if (intValue > 1571296) return
|
if (intValue > 1571296) return
|
||||||
if (intValue > withdrawMax) return
|
if (intValue > withdrawMax) return
|
||||||
|
|
||||||
|
this.setState({ withdrawAmount: value })
|
||||||
|
|
||||||
const { onInputSntValue } = this.props
|
const { onInputSntValue } = this.props
|
||||||
onInputSntValue(value)
|
onInputSntValue(value)
|
||||||
}
|
}
|
||||||
@ -49,12 +67,14 @@ class Withdraw extends React.Component {
|
|||||||
withdrawMax,
|
withdrawMax,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
|
const { withdrawAmount } = this.state
|
||||||
|
|
||||||
if (dapp === null)
|
if (dapp === null)
|
||||||
return <Modal visible={false} onClickClose={onClickClose} />
|
return <Modal visible={false} onClickClose={onClickClose} />
|
||||||
|
|
||||||
const currentSNTamount = dapp.sntValue
|
const currentSNTamount = dapp.sntValue
|
||||||
const dappsByCategory = dappState.getDappsByCategory(dapp.category)
|
const dappsByCategory = dappState.getDappsByCategory(dapp.category)
|
||||||
const afterVoteRating = withdrawMax // TODO: make this dynamic
|
const afterVoteRating = withdrawMax - (parseInt(withdrawAmount, 10) || 0)
|
||||||
|
|
||||||
let catPosition = dappsByCategory.length
|
let catPosition = dappsByCategory.length
|
||||||
for (let i = 0; i < dappsByCategory.length; ++i) {
|
for (let i = 0; i < dappsByCategory.length; ++i) {
|
||||||
@ -95,7 +115,7 @@ class Withdraw extends React.Component {
|
|||||||
<img src={sntIcon} alt="SNT" width="24" height="24" />
|
<img src={sntIcon} alt="SNT" width="24" height="24" />
|
||||||
{currentSNTamount.toLocaleString()}
|
{currentSNTamount.toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
{afterVoteRating !== null && afterVoteRating !== 0 && (
|
{afterVoteRating !== null && afterVoteRating >= 0 && (
|
||||||
<span className={styles.redBadge}>
|
<span className={styles.redBadge}>
|
||||||
{`${afterVoteRating.toLocaleString()} ↓`}
|
{`${afterVoteRating.toLocaleString()} ↓`}
|
||||||
</span>
|
</span>
|
||||||
@ -122,7 +142,7 @@ class Withdraw extends React.Component {
|
|||||||
<div className={`${styles.inputArea} ${styles.inputAreaBorder}`}>
|
<div className={`${styles.inputArea} ${styles.inputAreaBorder}`}>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={withdrawMax}
|
value={withdrawAmount}
|
||||||
onChange={this.handleSNTChange}
|
onChange={this.handleSNTChange}
|
||||||
style={{ width: `${21 * Math.max(1, sntValue.length)}px` }}
|
style={{ width: `${21 * Math.max(1, sntValue.length)}px` }}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user