Skip to content

Commit

Permalink
fix for build env variables, displays membership keys in /create
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonayllon committed Dec 15, 2019
1 parent c1f1908 commit a1166a7
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 23 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
"seedParty": "node scripts/seedParty.js",
"start": "react-scripts start",
"build": "react-scripts build",
"build:release:kovan": "REACT_APP_ENV=kovan yarn setup --kovan && yarn build",
"build:release:ropsten": "REACT_APP_ENV=ropsten yarn setup --ropsten && yarn build",
"build:release:rinkeby": "REACT_APP_ENV=rinkeby yarn setup --rinkeby && yarn build",
"build:release:alpha": "REACT_APP_ENV=alpha yarn setup --alpha && yarn build",
"build:release:live": "REACT_APP_ENV=live yarn setup --live && yarn build",
"build:release:kovan": "yarn setup --kovan && cross-env REACT_APP_ENV=kovan yarn build",
"build:release:ropsten": "yarn setup --ropsten && cross-env REACT_APP_ENV=ropsten yarn build",
"build:release:rinkeby": "yarn setup --rinkeby && cross-env REACT_APP_ENV=rinkeby yarn build",
"build:release:alpha": "yarn setup --alpha && cross-env REACT_APP_ENV=alpha yarn build",
"build:release:live": "yarn setup --live && cross-env REACT_APP_ENV=live yarn build",
"deploy:ropsten": "yarn build:release:ropsten && yarn now -f --local-config .deploy/now.ropsten.json --public && yarn now alias --local-config .deploy/now.ropsten.json && yarn now rm kickback-app-ropsten --safe --yes",
"deploy:rinkeby": "yarn build:release:rinkeby && yarn now -f --local-config .deploy/now.rinkeby.json --public && yarn now alias --local-config .deploy/now.rinkeby.json && yarn now rm kickback-app-rinkeby --safe --yes",
"deploy:kovan": "yarn build:release:kovan && yarn now -f --local-config .deploy/now.kovan.json --public && yarn now alias --local-config .deploy/now.kovan.json && yarn now rm kickback-app-kovan --safe --yes",
Expand All @@ -84,6 +84,7 @@
"@storybook/addon-links": "^3.4.11",
"@storybook/react": "^3.4.11",
"babel-plugin-macros": "^2.4.2",
"cross-env": "^6.0.3",
"cypress": "^3.1.2",
"cypress-testing-library": "^2.3.3",
"ganache-cli": "^6.1.8",
Expand Down
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@
*/
const locks = {
1: {
"enter-key-address-here": {
"0xa5bA2f45aFc9864bFA97CBb7D92BF8390744d529": {
name: "Kickback Gold Supporter"
},
"enter-key-address-here": {
"0xa5bA2f45aFc9864bFA97CBb7D92BF8390744d529": {
name: "Kickback Bronze Supporter"
}
},
Expand Down
85 changes: 69 additions & 16 deletions src/routes/CreateEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,27 @@ const UnlockedLogo = styled('a')`
font-weight: 800;
`

const AddrDisplay = styled('span')`
background-color: #6e76ff;
color: #fff;
border-radius: 2px;
padding: 4px;
font-size: 10px;
margin-right: 10px;
`

const UnlockUserDetails = styled('div')`
display: flex;
flex-direction: row;
margin-bottom: 30px;
transition: transform 300ms ease-in-out;
`

export default function Create() {
const [password, setPassword] = useState('')
const [locked, setLocked] = useState('pending')
const [membership, setMembership] = useState('')
const [membershipAddr, setMembershipAddr] = useState('')
let history = useHistory()

const _onCreated = ({ id }, deposit, limitOfParticipants, coolingPeriod) => {
Expand All @@ -49,15 +67,42 @@ export default function Create() {
)
}

const unlockHandler = e => {
setLocked(e.detail)
const updateUnlockUser = () => {
// sets membership lock and lock name to state
let unlock = window.unlockProtocol.blockchainData()
let locks = Object.keys(unlock.locks).map(i => unlock.locks[i])
let bronze = locks.find(o => o.name.includes('Kickback Bronze'))
let gold = locks.find(o => o.name.includes('Kickback Gold'))
if (gold) {
setMembership(gold.name)
setMembershipAddr(gold.address)
} else {
setMembership(bronze.name)
setMembershipAddr(bronze.address)
}
}

const unlockHandler = async e => {
/*
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
*/

setLocked(e.detail)

// run this loop only if unlocked
if (e.detail === 'unlocked') {
// blockchainData() will load empty first, check if loaded before updating state every, checks every 100 ms
let checkExist = setInterval(function() {
if (window.unlockProtocol.blockchainData()) {
updateUnlockUser()
clearInterval(checkExist)
}
}, 100)
}
}

const checkout = () => {
Expand All @@ -75,7 +120,7 @@ export default function Create() {

useEffect(() => {
return () => {
if (ENV !== 'local')
ENV !== 'local' &&
window.removeEventListener('unlockProtocol', unlockHandler)
}
}, [])
Expand All @@ -85,19 +130,27 @@ export default function Create() {
{
{
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>
<div>
{membershipAddr !== '' && (
<UnlockUserDetails>
<AddrDisplay>{membership}</AddrDisplay>
<AddrDisplay>{membershipAddr}</AddrDisplay>
</UnlockUserDetails>
)}
<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>
</div>
),
locked: (
<LockedContainer>
Expand Down
40 changes: 40 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4494,6 +4494,13 @@ create-react-class@^15.6.2:
loose-envify "^1.3.1"
object-assign "^4.1.1"

cross-env@^6.0.3:
version "6.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-6.0.3.tgz#4256b71e49b3a40637a0ce70768a6ef5c72ae941"
integrity sha512-+KqxF6LCvfhWvADcDPqo64yVIB31gv/jQulX2NGzKS/g3GEVz6/pt4wjHFtFWsHMddebWD/sDthJemzM4MaAag==
dependencies:
cross-spawn "^7.0.0"

cross-fetch@2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.2.tgz#a47ff4f7fc712daba8f6a695a11c948440d45723"
Expand All @@ -4519,6 +4526,15 @@ cross-spawn@6.0.5, cross-spawn@^6.0.0, cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0:
version "7.0.1"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
integrity sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==
dependencies:
path-key "^3.1.0"
shebang-command "^2.0.0"
which "^2.0.1"

cryptiles@3.x.x:
version "3.1.4"
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-3.1.4.tgz#769a68c95612b56faadfcebf57ac86479cbe8322"
Expand Down Expand Up @@ -10275,6 +10291,11 @@ path-key@^2.0.0, path-key@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"

path-key@^3.1.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==

path-parse@^1.0.5, path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
Expand Down Expand Up @@ -12846,10 +12867,22 @@ shebang-command@^1.2.0:
dependencies:
shebang-regex "^1.0.0"

shebang-command@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==
dependencies:
shebang-regex "^3.0.0"

shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"

shebang-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==

shell-quote@1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767"
Expand Down Expand Up @@ -14767,6 +14800,13 @@ which@^1.2.10, which@^1.2.12, which@^1.2.14, which@^1.2.9, which@^1.3.0, which@^
dependencies:
isexe "^2.0.0"

which@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
dependencies:
isexe "^2.0.0"

wide-align@^1.1.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"
Expand Down

0 comments on commit a1166a7

Please sign in to comment.