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

Conversation

edsonayllon
Copy link

@edsonayllon edsonayllon commented Dec 10, 2019

Issue number

#209

Description

@julien51 The Kickback team wants to provide paid benefits for people willing to deploy their own kickback contract. In order to do that, the kickback will deploy one or more locks (one for each level of benefits).

The front-end form will then ensure that the user owns a key to any of the kickback locks in order to deploy their kickback contract. If the user does not have a key, they are offered the ability to purchase a key to any of the lock (either thru crypto or credit card) thru Unlock.
[...]

See issue #209 linked.

In this PR, unlock displays page, as seen in the image below, requesting membership to view requested content. Once verified, form to deploy kickback contract is displayed to the user with membership status.

List of features added/changed

  • Adds membership tiers paywall for /create

How Has This Been Tested?

Testing done in Rinkeby. If account does not have membership token, form is not displayed. Purchase of membership token tested. Form displays after purchase. Switching to an account with no membership token shows restricted page again, as expected.

React-Router has also been updated to include history as a hook. Browsing other pages show routing is still working as expected.

Screenshots (if appropriate):

Screen Shot 2019-12-09 at 9 06 30 PM

Checklist:

  • My code follows the code style of this project.
  • My code implements all the required features.

@makoto
Copy link
Contributor

makoto commented Dec 10, 2019

Hi, @edsonayllon . Thank you for the submission. When I tested locally, Clicking the "Unlock membership? didn't do anything.

I can also see "An error occurred on client" message (highlighted in red).

Screenshot 2019-12-10 at 21 25 29

I can also see some error messages on console when I first load the /create page cc @julien51

Screenshot 2019-12-10 at 21 29 55

@edsonayllon
Copy link
Author

edsonayllon commented Dec 10, 2019

@makoto Yes, currently this PR isn't ready for review (marked as Work in Progress).

I ran into this issue yesterday. I talked to @julien51 and it seems Unlock's paywall app is only deployed on Rinkeby testnet, however, the addresses provided were for Kovan. Julien's provided me keys for Rinkeby which I'll test soon.

The Readme for the app includes instructions for Kovan, but package.json shows Rinkeby is available. Is there any documentation available for using Kickback on Rinkeby?

@edsonayllon edsonayllon reopened this Dec 10, 2019
@edsonayllon
Copy link
Author

edsonayllon commented Dec 11, 2019

Sorry, closed the PR by accident.

In 292b7b0 when using Rinkeby.

Screen Shot 2019-12-10 at 10 14 37 PM

Screen Shot 2019-12-10 at 10 16 53 PM

Remaining is having Unlock load depending on either Rinkeby or Mainnet.

@julien51 stated in #209 src/config/env.json can somehow be used.

@edsonayllon
Copy link
Author

edsonayllon commented Dec 11, 2019

Build is passing, but tests are failing from needing credentials.

Screen Shot 2019-12-11 at 12 21 50 AM

@edsonayllon edsonayllon changed the title [WIP] Unlock Membership Tiers for Kickback Unlock Membership Tiers for Kickback Dec 11, 2019
@edsonayllon
Copy link
Author

edsonayllon commented Dec 11, 2019

@makoto This PR should be ready for review.

682d830 Network for Unlock is selected based on NODE_ENV which can be development, staging, or deployment depending on build or start scripts.

Dynamically selecting the network for Unlock was a bit tricky. Unlock is configured in public/index.html, as seen through the docs and their React example on the Unlock Github. I didn't see a way to access env.json from the public folder. Discovering the current network by importing the dist of web3.js would increase load times of the app, so I avoided that as well.

To work around these, seeing the testnet version of Unlock would only be accessed during development or staging, and the mainnet verion of Unlock would be accessed in deployment, I set dynamically choosing the network based on the Environment Variable NODE_ENV.

Again, currently Unlock Paywall is only compatible with Rinkeby and Mainnet, so testing should be done on Rinkeby. I've left the unlock keys for Mainnet empty, so make sure to enter those when your team creates them.

@edsonayllon edsonayllon mentioned this pull request Dec 11, 2019
// 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.

@makoto
Copy link
Contributor

makoto commented Dec 11, 2019

Hi,

Can you write an instruction on how to test on my local machine? I just did NODE_ENV=development yarn start and opened my browser pointing network to Rinkeby but it shows "Wrong network", and pointing to mainnet does not seem to load locks.

@edsonayllon
Copy link
Author

edsonayllon commented Dec 11, 2019

@makoto NODE_ENV is defined automatically by create-react-app (CRA), seeing if either react-scripts start or react-scripts build is used. Starting with yarn start should have the environment default to "development". Anything running yarn build should change the environment to "production". I'm not entirely sure if NODE_ENV can be manually set in CRA.

The red message box indicating wrong network is configured by src/config/env.json. By default that's set to Kovan, and displays this error if Rinkeby is used. However, the Paywall only works in Rinkeby or Mainnet, as stated before. So switching to Rinkeby should load locks and allow purchasing, but will display "wrong network" on the Kickback app. Once a token is purchased in Rinkeby, switching to Kovan should still show the form, and remove the error message if configured to Kovan. Because Unlock is set to default to Rinkeby unless the app is built for production, which sets it to Mainnet, if the account owns the token in Rinkeby it will still display the field even if the account provider changes network.

@edsonayllon
Copy link
Author

Note: I changed the component Create to a functional component using hooks, as the Readme Contribution Style Guide said the app is transitioning in that direction anyway.

I can change it back to a class component, if your team prefers.

@makoto
Copy link
Contributor

makoto commented Dec 12, 2019

So is this the correct config?

$more src/config/env.json
{
  "API_URL": "https://kovan.api.kickback.events",
  "NUM_CONFIRMATIONS": 1,
  "ENV": "rinkeby"
}

I am still getting "Wrong network" on unlock.

Screenshot 2019-12-12 at 09 33 58

Also Is it possible to disable Unlock if ENV=local ? Otherwise we cannot test when we are testing against local server and ganache.

@edsonayllon
Copy link
Author

edsonayllon commented Dec 12, 2019

@makoto Can you verify that you pulled the latest commits? Also, what are the steps you are taking to run the app? And what browser and OS?

As for disabling Unlock, I can disable the paywall, and display the Create form by default if ENV=local in env.json. However, preventing the script from running in public/index.html would be more complicated. I'm guessing, however, you only need the form to show in ganache.

@edsonayllon
Copy link
Author

edsonayllon commented Dec 13, 2019

595316b Paywall is disabled if env.json sets ENV to local network, displaying "Create" form.


Is something wrong with https://kovan.api.kickback.events/graphql? It's throwing errors in the console.

@makoto
Copy link
Contributor

makoto commented Dec 13, 2019

Hi, @edsonayllon kovan was down but now up. You can also test with https://rinkeby.kickback.events/create . Still not fully up and running but at least you can test the account creation page.

@makoto
Copy link
Contributor

makoto commented Dec 13, 2019

umm, I deployed your branch to both rinkeby and kovan but both are showing spinning message.

Screenshot 2019-12-13 at 12 48 07

{
  "DEPLOYER_CONTRACT_ADDRESS": "0x8fE91259DC1F723d01b87Cf29534d8484F70e7Bc",
  "API_URL": "https://rinkeby.api.kickback.events",
  "NUM_CONFIRMATIONS": 1,
  "ENV": "rinkeby",
  "GIT_COMMIT": "595316b9f82d516e64ffda03cffe7b5e0a82a9d1",
  "ROLLBAR_TOKEN": "e676d64e462b48d098a12db8a173598a",
  "BLOCKNATIVE_DAPPID": "27b3eac2-e46c-428a-9a0c-56cce2725d42",
  "MIXPANEL_ID": "28243587317e7b2d8a669dcce23302cb"
}
{
  "DEPLOYER_CONTRACT_ADDRESS": "0x8fE91259DC1F723d01b87Cf29534d8484F70e7Bc",
  "API_URL": "https://kovan.api.kickback.events",
  "NUM_CONFIRMATIONS": 1,
  "ENV": "kovan",
  "GIT_COMMIT": "595316b9f82d516e64ffda03cffe7b5e0a82a9d1",
  "ROLLBAR_TOKEN": "",
  "BLOCKNATIVE_DAPPID": "",
  "MIXPANEL_ID": "28243587317e7b2d8a669dcce23302cb"
}

Can you think of what would cause this?

@makoto
Copy link
Contributor

makoto commented Dec 13, 2019

Actually I am seeing the same spinning on localhost if ENV=rinkeby (ENV=local will just render the event creation page as requested. Thanks!)

@edsonayllon
Copy link
Author

edsonayllon commented Dec 13, 2019

@makoto umm, I deployed your branch to both rinkeby and kovan but both are showing spinning message. Can you think of what would cause this?

Yup. "deploy:rinkeby" or "deploy:kovan" actually configures unlock for mainnet. Currently, there are placeholders for mainnet keys, and not real addresses, which would cause an error in the configuration. When there's an error in the config, the state never updates from loading to locked or unlocked.

I can think of a simple workaround to address that. Will do so after work.

@makoto
Copy link
Contributor

makoto commented Dec 13, 2019

Ah ok. Would you mind adding the description of how to set things up in our README so that I can just follow that?

@edsonayllon
Copy link
Author

edsonayllon commented Dec 13, 2019

@makoto Ah ok. Would you mind adding the description of how to set things up in our README so that I can just follow that?

Added instructions in Readme. Deploy scripts now chooses appropriate Unlock network, limited to Rinkeby or Mainnet (all test networks default to Rinkeby for Unlock). c1f1908

@makoto
Copy link
Contributor

makoto commented Dec 15, 2019

Hi.
I was able to test the purchase flow.
Once purchased and the create page is shown, would it be possible to display what lock has been purchased?

For the deployed environment, I again deployed to https://rinkeby.kickback.events/create but getting the spinning image when connecting to either rinkeby or mainnet.
Here is the config when deploying to rinkeby.

$yarn deploy:rinkeby
yarn run v1.15.2
$ 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
$ REACT_APP_ENV=rinkeby yarn setup --rinkeby && yarn build
$ scripts/setup.js --rinkeby
{
  "DEPLOYER_CONTRACT_ADDRESS": "0x8fE91259DC1F723d01b87Cf29534d8484F70e7Bc",
  "API_URL": "https://rinkeby.api.kickback.events",
  "NUM_CONFIRMATIONS": 1,
  "ENV": "rinkeby",
  "GIT_COMMIT": "c1f1908d7da54ccdb89da409eeb4dd0a1ea5b283",
  "ROLLBAR_TOKEN": "e676d64e462b48d098a12db8a173598a",
  "BLOCKNATIVE_DAPPID": "27b3eac2-e46c-428a-9a0c-56cce2725d42",
  "MIXPANEL_ID": "28243587317e7b2d8a669dcce23302cb"
}

Can you check https://rinkeby.kickback.events/create and see if you are seeing the same spinning image?

@edsonayllon
Copy link
Author

edsonayllon commented Dec 15, 2019

@makoto Once purchased and the create page is shown, would it be possible to display what lock has been purchased?

Something like this?

Screen Shot 2019-12-15 at 3 02 39 PM

Added a1166a7.

@makoto For the deployed environment, I again deployed to https://rinkeby.kickback.events/create but getting the spinning image when connecting to either rinkeby or mainnet.

I tested and got the same thing building locally. The environment variable was written to pass with yarn setup which should have instead been with && yarn build. I corrected the placement, and added cross-env for compatibility with Windows.

Fixed a1166a7.

I added temporary keys for Mainnet, please replace these with your keys in public/index.html.


useEffect(() => {
// remove unlock in component unmount1
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

Kovan lock is included for when kovan is supported by Unlock paywall
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

@makoto
Copy link
Contributor

makoto commented Dec 16, 2019

Hi,I tried both local and https://rinkeby.kickback.events/ with the latest commit (b76de81) and still stack at spinning despite placing "LOCKS" in the src/config/env.json.

~/.../kickback/app (pr/220)$yarn deploy:rinkeby
yarn run v1.15.2
$ 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
$ yarn setup --rinkeby && cross-env REACT_APP_ENV=rinkeby yarn build
$ scripts/setup.js --rinkeby
{
  "DEPLOYER_CONTRACT_ADDRESS": "0x291CD2C3e7Cf7627Fd8caC837635b7d00e9c9700",
  "API_URL": "https://rinkeby.api.kickback.events",
  "NUM_CONFIRMATIONS": 1,
  "ENV": "rinkeby",
  "DAI_CONTRACT_ADDRESS": "0xc4375b7de8af5a38a93548eb8453a498222c4ff2",
  "GIT_COMMIT": "b76de810aad37b2ee082492505473b17e2329bff",
  "LOGROCKET_TOKEN": "",
  "ROLLBAR_TOKEN": "e676d64e462b48d098a12db8a173598a",
  "BLOCKNATIVE_DAPPID": "27b3eac2-e46c-428a-9a0c-56cce2725d42",
  "MIXPANEL_ID": "28243587317e7b2d8a669dcce23302cb",
  "LOCKS": "https://staging-app.unlock-protocol.com/dashboard/"
}

Screenshot 2019-12-16 at 20 39 02

@edsonayllon
Copy link
Author

@makoto Hi,I tried both local and https://rinkeby.kickback.events/ with the latest commit (b76de81) and still stack at spinning despite placing "LOCKS" in the src/config/env.json.

~/.../kickback/app (pr/220)$yarn deploy:rinkeby
yarn run v1.15.2
$ 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
$ yarn setup --rinkeby && cross-env REACT_APP_ENV=rinkeby yarn build
$ scripts/setup.js --rinkeby
{
  "DEPLOYER_CONTRACT_ADDRESS": "0x291CD2C3e7Cf7627Fd8caC837635b7d00e9c9700",
  "API_URL": "https://rinkeby.api.kickback.events",
  "NUM_CONFIRMATIONS": 1,
  "ENV": "rinkeby",
  "DAI_CONTRACT_ADDRESS": "0xc4375b7de8af5a38a93548eb8453a498222c4ff2",
  "GIT_COMMIT": "b76de810aad37b2ee082492505473b17e2329bff",
  "LOGROCKET_TOKEN": "",
  "ROLLBAR_TOKEN": "e676d64e462b48d098a12db8a173598a",
  "BLOCKNATIVE_DAPPID": "27b3eac2-e46c-428a-9a0c-56cce2725d42",
  "MIXPANEL_ID": "28243587317e7b2d8a669dcce23302cb",
  "LOCKS": "https://staging-app.unlock-protocol.com/dashboard/"
}

That locks config is wrong. Please follow the README.

https://github.com/wearekickback/app/blob/b76de810aad37b2ee082492505473b17e2329bff/README.md#setup

@edsonayllon
Copy link
Author

@makoto I've updated setup.js for Rinkeby so the correct lock is automatically added. 2eee09a

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'))
Copy link
Contributor

@makoto makoto Dec 17, 2019

Choose a reason for hiding this comment

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

Is this part used to determine which lock I became the member of?

Screenshot 2019-12-17 at 22 36 48

Does unlock.locks returns all the locks only purchased by the specific Ethereum account? I tested with 4 different metamask accounts where account 1~3 bought gold and account 4 bought bronze though it kept showing gold no matter which ETH account I switch into.

When I put console.log({locks}) under account 4 it had both bronze and gold hence looks like it picked gold regardless.

I wonder if unlock.locks just returns all the available locks, rather than the lock purchased by the purchaser (=event organiser). cc @julien51

Choose a reason for hiding this comment

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

So, it is undocumented, but the way to get the locks for which the user has a key is to do this:

const data = window.unlockProtocol.blockchainData()
          if (data.keys) {
            // They should be indexed by lock.
            // Let's assume there is only one valid.
            const lockAddress = Object.keys(data.keys)[0]
          }

Copy link
Author

Choose a reason for hiding this comment

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

@makoto I wonder if unlock.locks just returns all the available locks, rather than the lock purchased by the purchaser (=event organiser).

You're right.

@julien51 So, it is undocumented, but the way to get the locks for which the user has a key is to do this: [...]

data.keys returned all available locks as well for me. Tested by purchasing on a new account.

I used data.transaction instead to get the latest purchase. Then displayed the membership by the lock purchased. I left the full algorithm commented in updateUnlockUser().

Should display the correct membership owned now.

Screen Shot 2019-12-17 at 7 16 11 PM

c0eaed3

@makoto
Copy link
Contributor

makoto commented Dec 18, 2019

LGTM @edsonayllon @julien51 . Thank you so much for being super patient with my constant feedback!

Copy link

@julien51 julien51 left a comment

Choose a reason for hiding this comment

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

All good for me too!

@makoto Pleaase send me the lock addresses that you'd like to enable credit card for!

@julien51
Copy link

julien51 commented Jan 7, 2020

Let's merge this so we can release the bounty! ;)
Happy new year everyone!

@edsonayllon
Copy link
Author

@makoto @jefflau Any updates on this?

@makoto makoto mentioned this pull request Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants