diff --git a/nuxt.config.js b/nuxt.config.js index 01a06a5..139b2e8 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -99,12 +99,7 @@ module.exports = { ** Axios module configuration ** See https://axios.nuxtjs.org/options */ - axios: { - baseURL: - process.env.NODE_ENV === 'production' - ? 'http://ceremony.tornado.cash/' - : `http://localhost:3000/` - }, + axios: {}, /* ** Build configuration */ diff --git a/pages/index.vue b/pages/index.vue index 8e59dc4..8114c22 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -42,7 +42,7 @@ {{ props.row.account }} - + @@ -80,7 +80,7 @@ Hello, @{{ user.handle }} -

Lorem ipsum dolor sit amet, consectetur?

-

- If you don’t trust binaries, we encorage you to follow this instruction to - contribute by compiling from source code. It is very easy! -

- +

+ What way do you want to contribute to the Tornado.cash Trusted Setup Ceremony? +

-
-
Lorem ipsum
+
+
Anonymously
-
Lorem ipsum
+
Using a social account
@@ -29,7 +30,10 @@
- Sign In + SignIn via Twitter + + + SignIn via Github
@@ -43,24 +47,29 @@
Make the contribution Tweet about your contribution
+

+ If you don’t trust binaries, we encorage you to follow this instruction to + contribute by compiling from source code. It is very easy! +

@@ -75,7 +84,9 @@ export default { }, data() { return { - isContributeBtnDisabled: false, + contributionType: null, + contributionIndex: null, + isContributeBtnSnown: false, status: { type: '', msg: '' @@ -86,24 +97,57 @@ export default { computed: { isLoggedIn() { return !!this.user.name && this.user.name !== 'Anonymous' + }, + isContributeBtnDisabled() { + return !this.contributionType } }, async mounted() { try { - const data = await this.$axios.$get('/api/user_data') + const response = await fetch('/api/user_data') + const data = await response.json() console.log('data', data) if (data.name !== 'Anonymous') { this.user.handle = data.handle this.user.name = data.name + // TODO check whether it's github or twitter + this.contributionType = 'twitter' } } catch (e) { console.error('user_data fail', e) } }, methods: { + makeTweet() { + const tweetText = `Just make the contribution %23${this.contributionIndex} to Tornado.cash trusted setup ceremony! 🚀` + const popUpWindowWidth = 600 + const popUpWindowHeight = 250 + const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX + const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY + + const width = window.innerWidth + ? window.innerWidth + : document.documentElement.clientWidth + ? document.documentElement.clientWidth + : screen.width + const height = window.innerHeight + ? window.innerHeight + : document.documentElement.clientHeight + ? document.documentElement.clientHeight + : screen.height + + const systemZoom = width / window.screen.availWidth + const left = (width - popUpWindowWidth) / 2 / systemZoom + dualScreenLeft + const top = (height - popUpWindowHeight) / 2 / systemZoom + dualScreenTop + window.open( + `https://twitter.com/intent/tweet?text=${tweetText}`, + '', + `menubar=no,toolbar=no,resizable=yes,scrollbars=no,height=${popUpWindowHeight},width=${popUpWindowWidth},top=${top},left=${left}` + ) + }, async makeContribution({ retry = 0 } = {}) { try { - this.isContributeBtnDisabled = true + this.isContributeBtnSnown = true this.status.msg = 'Downloading last contribution' this.status.type = '' @@ -121,16 +165,19 @@ export default { console.log('this.user.name', this.user) const formData = new FormData() formData.append('response', new Blob([result], { type: 'application/octet-stream' })) - formData.append('name', this.user.name) - formData.append('company', this.user.company) + if (this.contributionType !== 'anonymous') { + formData.append('name', this.user.name) + formData.append('company', this.user.company) + } const resp = await fetch('api/response', { method: 'POST', body: formData }) - + const responseData = await resp.json() if (resp.ok) { this.status.msg = 'Your contribution is verified and recorded. THX BYE.' this.status.type = 'is-success' + this.contributionIndex = responseData.contributionIndex } else if (resp.status === 422) { if (retry < 3) { console.log(`Looks like someone else uploaded contribution ahead of us, retrying`) @@ -138,22 +185,27 @@ export default { } else { this.status.msg = `Failed to upload your contribution after ${retry} attempts` this.status.type = 'is-danger' - this.isContributeBtnDisabled = false + this.isContributeBtnSnown = false } } else { this.status.msg = 'Error uploading your contribution' this.status.type = 'is-danger' - this.isContributeBtnDisabled = false + this.isContributeBtnSnown = false } } catch (e) { console.error(e.message) this.status.msg = e.message this.status.type = 'is-danger' - this.isContributeBtnDisabled = false + this.isContributeBtnSnown = false } }, logIn() { + this.contributionType = 'twitter' window.location.replace('/api/connect') + }, + onAnonymousHandler() { + this.contributionType = 'anonymous' + this.user = { name: '', handle: 'Anonymous', company: '' } } } } diff --git a/server/controllers/contributions.js b/server/controllers/contributions.js index 0c2f0c2..ae64ae8 100644 --- a/server/controllers/contributions.js +++ b/server/controllers/contributions.js @@ -78,7 +78,7 @@ router.post('/response', upload.single('response'), async (req, res) => { req.body ? req.body.company || null : null ) console.log('Finished') - res.send() + res.json({ contributionIndex: currentContributionIndex }) } catch (e) { console.error('Error', e) res.status(503).send(e.toString()) diff --git a/server/controllers/sessions.js b/server/controllers/sessions.js index ff24316..56f4529 100644 --- a/server/controllers/sessions.js +++ b/server/controllers/sessions.js @@ -58,7 +58,7 @@ router.get('/twitter_callback', (req, res) => { } else { req.session.oauthAccessToken = oauthAccessToken req.session.oauthAccessTokenSecret = oauthAccessTokenSecret - res.redirect('/') + res.redirect('/make-contribution') } } ) diff --git a/server/snark_files/current.params b/server/snark_files/current.params index 050fbc6..8d69909 100644 Binary files a/server/snark_files/current.params and b/server/snark_files/current.params differ