') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - ConsenSysMesh/kittybrowser: Coding challenge for front-end dev candidates · GitHub
Skip to content

Latest commit

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Kitty Browser

CryptoKitties is one of the most popular distributed apps on the Ethereum Network. It's a game that allows players to purchase, collect, breed and sell various types of virtual cats.

To be able to run CryptoKitties on your browser you'll need to install Metamask or use a dedicated Ethereum browser like Mist or Parity.

For this challenge you will create a simple UI that will be able to interact with the Ethereum Blockchain, using web3.js and the drizzle library. This UI will allow the user to type in a CryptoKitty's ID, and will display information about that Kitty.

Requirements to complete this challenge

  • Use the code provided in this repo as a starting point to build your solution
  • Given the address for the CryptoKitties Smart Contract: 0x06012c8cf97bead5deae237070f9587f8e7a266d Find its ABI (You will need it to complete the challenge)
  • Build a simple UI where the user can type in an ID and display the following information about a Kitty:
    • Genes
    • Birth time
    • Generation
  • Write a unit test that you consider relevant, using the unit test framework of your preference. It should run using npm run test
  • You will get extra points if you use react-testing-library 🏅
  • You will get extra points if you also display the Kitty's picture. 🏅
  • You will get extra points if you create a "Fetch random Kitty" button. 🏅
  • You will get extra points if you use TypeScript 🏅
  • Feel free to customize the styles as you wish or use any extra libraries that you need

The result should look somethig like this:

kitty browser

Hints

  • You will need to use the drizzle instance available on React's context (See components/Browser.js)
  • You will need to explore the smart contract methods to find out which one will get you the kitty's info (This operation won't require spending any ether)

Setting up your dev environment

  • Install and setup Metamask in your browser
  • Clone this repo, to be used as a starting point for your solution
  • Install the dependencies and run the development server

Code Overview

This repo contains a few components that will be useful for you to complete this project. These components are based on the drizzle-react examples

containers/Loading.js

Shows a Loading message while drizzle is being initialized or an error message if the browser is not web3 enabled

if(window.web3===undefined||this.props.web3.status==='failed'){return(// Display a web3 warning.<divclassName="warning"><p>This browser has no connection to the Ethereum network. </p><p>Please use the Chrome/FireFox extension MetaMask, or dedicated Ethereum browsers Mist or Parity.</p></div>);}if(this.props.drizzleStatus.initialized){// Load the dapp.returnChildren.only(this.props.children);}return(// Display a loading indicator.<divclassName="loading"><h1>Loading dapp...</h1><imgsrc="https://www.cryptokitties.co/images/loader.gif"width="120"alt="loading"/></div>);

App.js

Initializes the DrizzleProvider and wraps your app with the Loading component.

classAppextendsComponent{render(){constdrizzleOptions={contracts: []};return(<DrizzleProvideroptions={drizzleOptions}><Loading><Browser/></Loading></DrizzleProvider>);}}

components/Browser.js

Once you have the Smart Contract's ABI, uncomment the lines you need to add the contract to the drizzle store, and start building your solution.

Questions or comments

For any questions or comments please contact Dragos Rizescu <dragos.rizescu@consensys.net> or Ruben Torres <ruben.torres@consensys.net>

About

Coding challenge for front-end dev candidates

Resources

Stars

13 stars

Watchers

12 watching

Forks

Releases

Packages

Used by

Contributors

Languages