mirror of
https://github.com/tornadocash/trusted-setup-server.git
synced 2024-11-21 17:36:54 +01:00
check contribution
This commit is contained in:
parent
a979220830
commit
36cf7d6c6e
@ -66,8 +66,7 @@ export default {
|
||||
if (!this.token) {
|
||||
window.location.replace(window.location.origin)
|
||||
} else {
|
||||
// TODO try to load contribution data. May be it's already authorized
|
||||
// also set `contributionIndex`
|
||||
await this.check()
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.$root.$emit('disableLoading')
|
||||
@ -103,6 +102,33 @@ export default {
|
||||
this.status.msg = 'Something went wrong. Please contact support'
|
||||
this.status.type = 'is-danger'
|
||||
}
|
||||
},
|
||||
async check() {
|
||||
const body = {
|
||||
token: this.token
|
||||
}
|
||||
try {
|
||||
const response = await fetch('/api/check_contribution', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
if (response.ok) {
|
||||
const { id } = await response.json()
|
||||
this.contributionIndex = id
|
||||
} else {
|
||||
const error = await response.text()
|
||||
this.status.msg = error
|
||||
this.status.type = 'is-danger'
|
||||
this.hideSaveBtn = true
|
||||
}
|
||||
} catch (e) {
|
||||
this.status.msg = 'Something went wrong. Please contact support'
|
||||
this.status.type = 'is-danger'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,4 +146,23 @@ router.post('/authorize_contribution', async (req, res) => {
|
||||
res.send('OK')
|
||||
})
|
||||
|
||||
router.post('/check_contribution', async (req, res) => {
|
||||
if (!req.body || !req.body.token) {
|
||||
res.status(404).send('Wrong request params')
|
||||
}
|
||||
|
||||
const contribution = await Contribution.findOne({ where: { token: req.body.token } })
|
||||
if (!contribution) {
|
||||
res.status(404).send('There is no such contribution')
|
||||
return
|
||||
}
|
||||
|
||||
if (contribution.dataValues.socialType !== 'anonymous') {
|
||||
res.status(404).send('The contribution is already authorized')
|
||||
return
|
||||
}
|
||||
|
||||
return res.json({ id: contribution.dataValues.id }).send()
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
|
Loading…
Reference in New Issue
Block a user