mirror of
https://github.com/dap-ps/discover.git
synced 2025-03-04 02:40:38 +00:00
withdraw
This commit is contained in:
parent
00690070de
commit
273fcae191
@ -197,6 +197,12 @@ class DiscoverService extends BlockchainService {
|
|||||||
throw new Error(`Uploading metadata failed. Details: ${error.message}`)
|
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
|
export default DiscoverService
|
||||||
|
@ -2,6 +2,7 @@ const withdraw = {
|
|||||||
visible: false,
|
visible: false,
|
||||||
dapp: null,
|
dapp: null,
|
||||||
sntValue: '0',
|
sntValue: '0',
|
||||||
|
withdrawMax: Number.MAX_SAFE_INTEGER,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withdraw
|
export default withdraw
|
||||||
|
@ -27,28 +27,27 @@ class Withdraw extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleSNTChange(e) {
|
handleSNTChange(e) {
|
||||||
const { dapp } = this.props
|
const { dapp, withdrawMax } = this.props
|
||||||
const { value } = e.target
|
const { value } = e.target
|
||||||
if (value !== '' && /^[1-9][0-9]*$/.test(value) === false) return
|
if (value !== '' && /^[1-9][0-9]*$/.test(value) === false) return
|
||||||
|
|
||||||
const intValue = value === '' ? 0 : parseInt(value, 10)
|
const intValue = value === '' ? 0 : parseInt(value, 10)
|
||||||
if (intValue > 1571296) return
|
if (intValue > 1571296) return
|
||||||
if (intValue > dapp.sntValue) return
|
if (intValue > withdrawMax) return
|
||||||
|
|
||||||
const { onInputSntValue } = this.props
|
const { onInputSntValue } = this.props
|
||||||
onInputSntValue(value)
|
onInputSntValue(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { dappState, dapp, visible, onClickClose, sntValue } = this.props
|
const { dappState, dapp, visible, onClickClose, sntValue, withdrawMax } = this.props
|
||||||
|
|
||||||
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 =
|
const afterVoteRating = (sntValue !== '' ? parseInt(sntValue, 10) : 0)
|
||||||
dapp.sntValue - (sntValue !== '' ? parseInt(sntValue, 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) {
|
||||||
@ -90,7 +89,7 @@ class Withdraw extends React.Component {
|
|||||||
{currentSNTamount.toLocaleString()}
|
{currentSNTamount.toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
{afterVoteRating !== null &&
|
{afterVoteRating !== null &&
|
||||||
afterVoteRating !== currentSNTamount && (
|
afterVoteRating !== 0 && (
|
||||||
<span className={styles.redBadge}>
|
<span className={styles.redBadge}>
|
||||||
{`${afterVoteRating.toLocaleString()} ↓`}
|
{`${afterVoteRating.toLocaleString()} ↓`}
|
||||||
</span>
|
</span>
|
||||||
@ -149,6 +148,7 @@ Withdraw.propTypes = {
|
|||||||
visible: PropTypes.bool.isRequired,
|
visible: PropTypes.bool.isRequired,
|
||||||
dapp: PropTypes.instanceOf(DappModel),
|
dapp: PropTypes.instanceOf(DappModel),
|
||||||
sntValue: PropTypes.string.isRequired,
|
sntValue: PropTypes.string.isRequired,
|
||||||
|
withdrawMax: PropTypes.number.isRequired,
|
||||||
onClickClose: PropTypes.func.isRequired,
|
onClickClose: PropTypes.func.isRequired,
|
||||||
onWithdraw: PropTypes.func.isRequired,
|
onWithdraw: PropTypes.func.isRequired,
|
||||||
onInputSntValue: 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 CLOSE_WITHDRAW = 'WITHDRAW_CLOSE_WITHDRAW'
|
||||||
const ON_INPUT_SNT_VALUE = 'WITHDRAW_ON_INPUT_SNT_VALUE'
|
const ON_INPUT_SNT_VALUE = 'WITHDRAW_ON_INPUT_SNT_VALUE'
|
||||||
|
|
||||||
export const showWithdrawAfterCheckAction = dapp => {
|
export const showWithdrawAfterCheckAction = (dapp, withdrawMax) => {
|
||||||
window.location.hash = 'withdraw'
|
window.location.hash = 'withdraw'
|
||||||
return {
|
return {
|
||||||
type: SHOW_WITHDRAW_AFTER_CHECK,
|
type: SHOW_WITHDRAW_AFTER_CHECK,
|
||||||
payload: dapp,
|
payload: { dapp, withdrawMax },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const showWithdrawAction = dapp => {
|
export const showWithdrawAction = dapp => {
|
||||||
return (dispatch, getState) => {
|
return async (dispatch, getState) => {
|
||||||
const state = getState()
|
const state = getState()
|
||||||
if (
|
if (
|
||||||
state.transactionStatus.progress &&
|
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',
|
'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,
|
payload: sntValue,
|
||||||
})
|
})
|
||||||
|
|
||||||
const showWithdrawAfterCheck = (state, dapp) => {
|
const showWithdrawAfterCheck = (state, payload) => {
|
||||||
|
const { dapp, withdrawMax } = payload
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
visible: true,
|
visible: true,
|
||||||
dapp,
|
dapp,
|
||||||
|
withdrawMax,
|
||||||
sntValue: dapp.sntValue.toString(),
|
sntValue: dapp.sntValue.toString(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -87,6 +93,7 @@ const closeWithdraw = state => {
|
|||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
visible: false,
|
visible: false,
|
||||||
dapp: null,
|
dapp: null,
|
||||||
|
withdrawMax: Number.MAX_SAFE_INTEGER,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user