2020-02-06 16:41:43 +01:00
const state = ( ) => {
return {
name : null ,
handle : 'Anonymous' ,
company : '' ,
contributionType : null ,
contributionIndex : null
}
}
const mutations = {
SET _NAME ( state , name ) {
state . name = name
} ,
SET _HANDLE ( state , handle ) {
state . handle = handle
} ,
SET _COMPANY ( state , company ) {
state . company = company
} ,
SET _CONTRIBUTION _TYPE ( state , contributionType ) {
state . contributionType = contributionType
} ,
SET _CONTRIBUTION _INDEX ( state , contributionIndex ) {
state . contributionIndex = contributionIndex
}
}
const getters = {
isLoggedIn : ( state ) => {
return state . name !== null && state . name !== 'Anonymous'
} ,
hasErrorName : ( state ) => {
const name = state . name
if ( name === null ) {
return { invalid : false , msg : '' }
}
if ( name === '' ) {
return { invalid : true , msg : 'Name is empty' }
}
if ( name . length < 4 ) {
return { invalid : true , msg : 'Name is too short' }
}
if ( name . length > 35 ) {
return { invalid : true , msg : 'Name is too long' }
}
return { invalid : false , msg : '' }
}
}
const actions = {
2020-02-07 16:21:34 +01:00
logInVia ( { state } , provider ) {
window . location . replace ( ` /api/connect/ ${ provider } ` )
2020-02-06 16:41:43 +01:00
} ,
makeTweet ( { state } ) {
2020-02-29 10:17:53 +01:00
const tweetText = ` Just made the contribution %23 ${ state . contributionIndex } to @TornadoCash Trusted Setup Ceremony! 🚀 %23 ${ process . env . NUXT _ENV _TWITTER _HASHTAG } `
2020-02-06 16:41:43 +01:00
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 } `
)
} ,
2020-02-08 15:41:27 +01:00
async logOut ( { commit } ) {
commit ( 'SET_HANDLE' , 'Anonymous' )
commit ( 'SET_CONTRIBUTION_TYPE' , null )
commit ( 'SET_NAME' , null )
commit ( 'SET_COMPANY' , '' )
2020-02-06 16:41:43 +01:00
await fetch ( '/api/logout' )
2020-02-06 17:16:38 +01:00
} ,
async getUserData ( { commit } ) {
try {
const response = await fetch ( '/api/user_data' )
const data = await response . json ( )
console . log ( 'data' , data )
if ( data . name !== 'Anonymous' ) {
commit ( 'SET_HANDLE' , data . handle )
commit ( 'SET_NAME' , data . name )
2020-02-07 16:21:34 +01:00
commit ( 'SET_CONTRIBUTION_TYPE' , data . socialType )
2020-02-06 17:16:38 +01:00
}
} catch ( e ) {
console . error ( 'user_data fail' , e )
}
2020-02-06 16:41:43 +01:00
}
}
export default {
namespaced : true ,
state ,
getters ,
mutations ,
actions
}