Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlock Membership Tiers for Kickback #220

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
536ec70
Converted /create page to functional component, started unlock integr…
edsonayllon Dec 10, 2019
292b7b0
converted paywall to Rinkeby
edsonayllon Dec 11, 2019
682d830
Unlock network selected based on React environment NODE_ENV
edsonayllon Dec 11, 2019
a60f5f7
Changed logo displayed in unlock to Kickback
edsonayllon Dec 11, 2019
eda6bd5
Remove logo.svg from public folder
edsonayllon Dec 11, 2019
595316b
removes paywall in /create for local network set in env.json
edsonayllon Dec 13, 2019
c1f1908
updated unlock environment selection by package.json parameters, adde…
edsonayllon Dec 13, 2019
a1166a7
fix for build env variables, displays membership keys in /create
edsonayllon Dec 15, 2019
ca62713
edit comments
edsonayllon Dec 15, 2019
2170033
Clean up public/index.hmtl
edsonayllon Dec 15, 2019
dbc56b9
merge useEffects
edsonayllon Dec 16, 2019
f53d6be
Minor. Typo in comment
edsonayllon Dec 16, 2019
393de51
moved lock addresses to env.json
edsonayllon Dec 16, 2019
0c05ba2
Readme json fix
edsonayllon Dec 16, 2019
b76de81
Comment edits
edsonayllon Dec 16, 2019
54149f1
add to Readme
edsonayllon Dec 16, 2019
2eee09a
update setup.js for Rinkeby
edsonayllon Dec 16, 2019
c0eaed3
fix membership ownership to correct ownership
edsonayllon Dec 18, 2019
173d5c3
Minor change. Edit comment wording
edsonayllon Dec 18, 2019
c62e1e5
Merge branch 'dev' into dev
edsonayllon Dec 23, 2019
e5f3a30
Merge branch 'dev' into dev
edsonayllon Jan 17, 2020
ee72b5d
Merge branch 'dev' into dev
edsonayllon Jan 22, 2020
7e1fa4b
yarn.lock
edsonayllon Jan 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"react-dropzone": "^7.0.1",
"react-emotion": "^9.2.6",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-dom": "^5.1.2",
"react-router-hash-link": "^1.2.0",
"react-scripts": "2.1.5",
"react-select": "^2.1.0",
Expand Down
64 changes: 64 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,70 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Kickback</title>

<!--
Unlock snippet scripts modified from
https://github.com/unlock-protocol/react-example/blob/master/public/index.html
-->
<script> (function (d, s) {
// if production, set network to Mainnet, else set to Rinkeby for paywall
const environment = "%NODE_ENV%";
const networkId = environment === "production" ? 1 : 4;

// if Rinkeby set, use Rinkeby paywall, else use Mainnet
let testnetUrl = networkId === 4 ? 'staging-' : '';
let js = d.createElement(s);
let sc = d.getElementsByTagName(s)[0];
js.src = `https://${testnetUrl}paywall.unlock-protocol.com/static/unlock.1.0.min.js`;
sc.parentNode.insertBefore(js, sc);
}(document, "script"));
</script>

<script>
// if production, set network to Mainnet, else set to Rinkeby for paywall
const environment = "%NODE_ENV%";
const networkId = environment === "production" ? 1 : 4;

// Kovan is included, but currently only Rinkeby and Mainnet is unsupported with paywall
// tokens entered first to last are displayed right to left in paywall modal
// NOTE: Replace Mainnet keys with keys Kickback owns
const locks = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to abstract these into the main src directory. It's not very visible having the locks in the index.html.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I looked through Unlock's documentation, and looked at the React example in Unlock's Github. They had this config in public/index.html. I also don't think there's a way to import a file from src to public, else I'd be using env.json instead of passing environment variables through package.json. Unless @julien51 has any suggestions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... I think this just adds a variable to window. Let me test something

Copy link
Author

@edsonayllon edsonayllon Dec 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Locks moved to config/env.json in src. Readme updated as well with instructions. 393de51

1: {
"enter-key-address-here": {
name: "Kickback Gold Supporter"
},
"enter-key-address-here": {
name: "Kickback Bronze Supporter"
}
},
4: {
"0xb452A1BfE64036718aCeFC8B5F718E0c9d233cB8": {
name: "Kickback Gold Supporter"
},
"0x70456ebD53E19eaE05932C482FeF1b24251ABb18": {
name: "Kickback Bronze Supporter"
}
},
42: {
"0x2eD8aD6AA973BEA5D60FA70Eead10F113fb4Dc99": {
name: "Kickback Gold Supporter"
},
"0xe61607898287220586abE01b536714d8429f675C": {
name: "Kickback Bronze Supporter"
}
}
}[networkId]

// unlock config must use var
var unlockProtocolConfig = {
locks,
icon: 'https://unlock-protocol.com/static/images/svg/unlock-word-mark.svg',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be changed to a Kickback logo ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Changed in a60f5f7. It looks like only public urls are compatible with Unlock, so I used https://kickback.events/card.png.

callToAction: {
default:
'Select a membership to access page',
},
}
</script>
</head>

<body>
Expand Down
137 changes: 107 additions & 30 deletions src/routes/CreateEvent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { Component } from 'react'
import React, { useState, useEffect } from 'react'
import styled from 'react-emotion'
import { withRouter } from 'react-router-dom'
import { useHistory } from 'react-router-dom'
import DefaultTextInput from '../components/Forms/TextInput'
import Label from '../components/Forms/Label'
import DefaultButton from '../components/Forms/Button'
import Loader from '../components/Loader'

import PartyForm from '../components/SingleEvent/Admin/PartyForm'
import { CREATE_PENDING_PARTY } from '../graphql/mutations'
Expand All @@ -13,42 +15,117 @@ const CreateContainer = styled('div')`
flex-direction: column;
`

const LockedContainer = styled('div')`
display: flex;
flex-direction: column;
`

const TextInput = styled(DefaultTextInput)`
margin-bottom: 20px;
`

class Create extends Component {
state = {
password: ''
}
const Button = styled(DefaultButton)`
margin: 60px auto 0px auto;
`

render() {
const { password } = this.state

return (
<CreateContainer>
<PartyForm
onCompleted={this._onCreated}
mutation={CREATE_PENDING_PARTY}
variables={{ password }}
type="create"
>
<Label>SECRET PASSWORD:</Label>
<TextInput
value={password}
onChangeText={val => this.setState({ password: val })}
type="password"
/>
</PartyForm>
</CreateContainer>
)
}
const UnlockCredit = styled('div')`
margin: 40px auto 140px auto;
font-size: 14px;
`

_onCreated = ({ id }, deposit, limitOfParticipants, coolingPeriod) => {
this.props.history.push(
const UnlockedLogo = styled('a')`
color: #ff6771;
font-weight: 800;
`

function Create() {
const [password, setPassword] = useState('')
const [locked, setLocked] = useState('pending')
let history = useHistory()

const _onCreated = ({ id }, deposit, limitOfParticipants, coolingPeriod) => {
history.push(
`/deploy?id=${id}&deposit=${deposit}&limitOfParticipants=${limitOfParticipants}&coolingPeriod=${coolingPeriod}`
)
}

const unlockHandler = e => {
setLocked(e.detail)
/*
Status can either be 'unlocked' or 'locked'...
If state is 'unlocked': implement code here which will be triggered when
the current visitor has a valid lock key
If state is 'locked': implement code here which will be
triggered when the current visitor does not have a valid lock key
*/
}

const checkout = () => {
window.ethereum.enable()
window.unlockProtocol && window.unlockProtocol.loadCheckoutModal()
}

useEffect(() => {
window.addEventListener('unlockProtocol', unlockHandler)
}, [])

useEffect(() => {
return () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not be bundled with the other useEffect's return statement?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. dbc56b9

window.removeEventListener('unlockProtocol', unlockHandler)
}
}, [])

return (
<CreateContainer>
{
{
unlocked: (
<PartyForm
onCompleted={_onCreated}
mutation={CREATE_PENDING_PARTY}
variables={{ password }}
type="create"
>
<Label>SECRET PASSWORD:</Label>
<TextInput
value={password}
onChangeText={val => setPassword(val)}
type="password"
/>
</PartyForm>
),
locked: (
<LockedContainer>
<h1>Deploy your Kickback contract with us</h1>
<p>
Kickback offers paid benefits for event organizers publishing
their own kickback contract. Membership comes in two tiers.
</p>
<Button
data-testid="unlock-button"
analyticsId="Unlock Membership"
onClick={checkout}
>
Unlock Membership
</Button>
<UnlockCredit>
Powered by{' '}
<UnlockedLogo href="https://unlock-protocol.com/">
Unlock
</UnlockedLogo>
</UnlockCredit>
</LockedContainer>
),
pending: (
<div>
<Loader />
</div>
),
default: <div>Please enable Javascript</div>
}[locked || locked['default']]
}
</CreateContainer>
)
}

export default withRouter(Create)
export default Create
Loading