1
0
mirror of https://github.com/dap-ps/discover.git synced 2025-03-03 18:30:32 +00:00
This commit is contained in:
Kamen Stoykov 2019-06-04 13:52:57 +03:00
parent 00690070de
commit 273fcae191
4 changed files with 25 additions and 11 deletions
src
common
blockchain/services/discover-service
data
modules/Withdraw

@ -197,6 +197,12 @@ class DiscoverService extends BlockchainService {
throw new Error(`Uploading metadata failed. Details: ${error.message}`)
}
}
async withdrawMax(dappId) {
return DiscoverContract.methods.withdrawMax(dappId).call({
from: this.sharedContext.account,
})
}
}
export default DiscoverService

@ -2,6 +2,7 @@ const withdraw = {
visible: false,
dapp: null,
sntValue: '0',
withdrawMax: Number.MAX_SAFE_INTEGER,
}
export default withdraw

@ -27,28 +27,27 @@ class Withdraw extends React.Component {
}
handleSNTChange(e) {
const { dapp } = this.props
const { dapp, withdrawMax } = this.props
const { value } = e.target
if (value !== '' && /^[1-9][0-9]*$/.test(value) === false) return
const intValue = value === '' ? 0 : parseInt(value, 10)
if (intValue > 1571296) return
if (intValue > dapp.sntValue) return
if (intValue > withdrawMax) return
const { onInputSntValue } = this.props
onInputSntValue(value)
}
render() {
const { dappState, dapp, visible, onClickClose, sntValue } = this.props
const { dappState, dapp, visible, onClickClose, sntValue, withdrawMax } = this.props
if (dapp === null)
return <Modal visible={false} onClickClose={onClickClose} />
const currentSNTamount = dapp.sntValue
const dappsByCategory = dappState.getDappsByCategory(dapp.category)
const afterVoteRating =
dapp.sntValue - (sntValue !== '' ? parseInt(sntValue, 10) : 0)
const afterVoteRating = (sntValue !== '' ? parseInt(sntValue, 10) : 0)
let catPosition = dappsByCategory.length
for (let i = 0; i < dappsByCategory.length; ++i) {
@ -90,7 +89,7 @@ class Withdraw extends React.Component {
{currentSNTamount.toLocaleString()}
</span>
{afterVoteRating !== null &&
afterVoteRating !== currentSNTamount && (
afterVoteRating !== 0 && (
<span className={styles.redBadge}>
{`${afterVoteRating.toLocaleString()}`}
</span>
@ -149,6 +148,7 @@ Withdraw.propTypes = {
visible: PropTypes.bool.isRequired,
dapp: PropTypes.instanceOf(DappModel),
sntValue: PropTypes.string.isRequired,
withdrawMax: PropTypes.number.isRequired,
onClickClose: PropTypes.func.isRequired,
onWithdraw: PropTypes.func.isRequired,
onInputSntValue: PropTypes.func.isRequired,

@ -15,16 +15,16 @@ const SHOW_WITHDRAW_AFTER_CHECK = 'WITHDRAW_SHOW_WITHDRAW_AFTER_CHECK'
const CLOSE_WITHDRAW = 'WITHDRAW_CLOSE_WITHDRAW'
const ON_INPUT_SNT_VALUE = 'WITHDRAW_ON_INPUT_SNT_VALUE'
export const showWithdrawAfterCheckAction = dapp => {
export const showWithdrawAfterCheckAction = (dapp, withdrawMax) => {
window.location.hash = 'withdraw'
return {
type: SHOW_WITHDRAW_AFTER_CHECK,
payload: dapp,
payload: { dapp, withdrawMax },
}
}
export const showWithdrawAction = dapp => {
return (dispatch, getState) => {
return async (dispatch, getState) => {
const state = getState()
if (
state.transactionStatus.progress &&
@ -35,7 +35,11 @@ export const showWithdrawAction = dapp => {
'There is an active transaction. Please wait for it to finish and then you could be able to create your Ðapp',
),
)
} else dispatch(showWithdrawAfterCheckAction(dapp))
} else {
const blockchain = await BlockchainSDK.getInstance()
const withdrawMax = await blockchain.DiscoverService.withdrawMax(dapp.id)
dispatch(showWithdrawAfterCheckAction(dapp, parseInt(withdrawMax, 10)))
}
}
}
@ -75,10 +79,12 @@ export const onInputSntValueAction = sntValue => ({
payload: sntValue,
})
const showWithdrawAfterCheck = (state, dapp) => {
const showWithdrawAfterCheck = (state, payload) => {
const { dapp, withdrawMax } = payload
return Object.assign({}, state, {
visible: true,
dapp,
withdrawMax,
sntValue: dapp.sntValue.toString(),
})
}
@ -87,6 +93,7 @@ const closeWithdraw = state => {
return Object.assign({}, state, {
visible: false,
dapp: null,
withdrawMax: Number.MAX_SAFE_INTEGER,
})
}