{"componentChunkName":"component---src-templates-page-js","path":"/projects/2021/open-source","result":{"data":{"markdownRemark":{"frontmatter":{"title":"Open source","path":"/projects/2021/open-source","excerpt":null,"tags":null,"liveUrl":null,"sampleCode":"true","sourceCode":"https://github.com/smaniotto/secret-hangman","coverImage":{"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAMABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAQACBf/EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhADEAAAAeK5QiP/xAAXEAADAQAAAAAAAAAAAAAAAAAAARAR/9oACAEBAAEFAjK3P//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8BP//EABYQAAMAAAAAAAAAAAAAAAAAAAAgQf/aAAgBAQAGPwIq/wD/xAAZEAEAAgMAAAAAAAAAAAAAAAABACEQETH/2gAIAQEAAT8hLq9xQbQYK5Eeq4//2gAMAwEAAgADAAAAEBDP/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPxA//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPxA//8QAGxABAAICAwAAAAAAAAAAAAAAAQARQVEQITH/2gAIAQEAAT8QCwCWu5XkbSW7YlCkTJAwMPLxx//Z","aspectRatio":1.7094017094017093,"src":"/static/b8fd52e4d6be93350d0185878c2b0c88/14b42/open-source.jpg","srcSet":"/static/b8fd52e4d6be93350d0185878c2b0c88/f836f/open-source.jpg 200w,\n/static/b8fd52e4d6be93350d0185878c2b0c88/2244e/open-source.jpg 400w,\n/static/b8fd52e4d6be93350d0185878c2b0c88/14b42/open-source.jpg 800w,\n/static/b8fd52e4d6be93350d0185878c2b0c88/47498/open-source.jpg 1200w,\n/static/b8fd52e4d6be93350d0185878c2b0c88/ec6c5/open-source.jpg 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"id":"8f3d2604-049b-564d-b638-a47d472053c4","html":"<blockquote>\n<p>Joined an interesting open-source project that emulates a simple hangman game, with an added twist: the secret word must be public though it still must be kept secret.\nThe technology behind the scenes is Secret Network, a blockchain-based, open-source protocol that lets anyone perform computations on encrypted data, bringing privacy to smart contracts and public blockchains.</p>\n</blockquote>\n<blockquote>\n<p>Stack: React.js, Storybook, Jest, Rust*, Secret Network* > *Did not contribute on the server-side</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">main-page/index.js\n\nimport React, { useState, useContext, useEffect } from &quot;react&quot;;\n\nimport Gibbet from &quot;components/molecules/gibbet&quot;;\nimport WordReveal from &quot;components/molecules/word-reveal&quot;;\nimport Keyboard from &quot;components/organisms/keyboard&quot;;\nimport Navbar from &quot;components/organisms/navbar&quot;;\nimport Footer from &quot;components/organisms/footer&quot;;\nimport Loading from &quot;components/atoms/loading&quot;;\nimport GameEnd from &quot;components/molecules/game-end&quot;;\nimport { WalletContext } from &quot;context/wallet&quot;;\nimport useSmartContract from &quot;hooks/smart-contract&quot;;\n\nimport styles from &quot;./styles.module.scss&quot;;\n\nconst MainPage = () =&gt; {\n  const { client } = useContext(WalletContext);\n\n  const [\n    contractAddress,\n    mistakes,\n    wordLength,\n    wordReveal,\n    gameResult,\n    isLoading,\n    queryStatus,\n    guessLetter,\n    restart,\n  ] = useSmartContract(client);\n\n  const [usedLetters, setUsedLetters] = useState([]);\n  const [isWaitingForWord, setIsWaitingForWord] = useState(false);\n\n  useEffect(() =&gt; {\n    const updateGameStatus = async () =&gt; {\n      if (contractAddress) {\n        setTimeout(async () =&gt; {\n          await queryStatus();\n        }, 5000);\n      }\n    };\n    updateGameStatus();\n  }, [contractAddress]);\n\n  useEffect(() =&gt; {\n    if (!client) {\n      return;\n    }\n    !wordLength &amp;&amp; setIsWaitingForWord(true);\n    wordLength &amp;&amp; setIsWaitingForWord(false);\n  }, [client, wordLength]);\n\n  const handleGuess = async (letter) =&gt; {\n    try {\n      await guessLetter(letter);\n      setUsedLetters([...usedLetters, letter]);\n    } catch (error) {\n      console.log(error);\n    }\n  };\n\n  const handleRestart = async () =&gt; {\n    try {\n      setUsedLetters([]);\n      await restart();\n    } catch (error) {\n      console.log(error);\n    }\n  };\n\n  const loading = isLoading || isWaitingForWord;\n\n  return (\n    &lt;div className={styles.container}&gt;\n      {loading &amp;&amp; &lt;Loading /&gt;}\n      {gameResult &amp;&amp; &lt;GameEnd result={gameResult} restart={handleRestart} /&gt;}\n      &lt;Navbar /&gt;\n      &lt;div className={styles.mainSection}&gt;\n        &lt;div className={styles.upper}&gt;\n          &lt;div className={styles.gibbet}&gt;\n            &lt;Gibbet mistakes={mistakes} /&gt;\n          &lt;/div&gt;\n          &lt;div className={styles.wordReveal}&gt;\n            &lt;WordReveal letters={wordReveal} /&gt;\n          &lt;/div&gt;\n        &lt;/div&gt;\n        &lt;div className={styles.lower}&gt;\n          &lt;Keyboard usedLetters={usedLetters} onClick={handleGuess} /&gt;\n        &lt;/div&gt;\n      &lt;/div&gt;\n      &lt;Footer /&gt;\n    &lt;/div&gt;\n  );\n};\n\nexport default MainPage;</code></pre></div>","excerpt":"Joined an interesting open-source project that emulates a simple hangman game, with an added twist: the secret word must be public though it…"}},"pageContext":{"type":"posts","next":{"frontmatter":{"path":"/projects","title":"Projects","tags":null},"fileAbsolutePath":"/Users/felipesmaniotto/my-real-portfolio/src/posts/projects.md"},"previous":{"frontmatter":{"path":"/projects/2017/self-employed","title":"Self-employed","tags":null},"fileAbsolutePath":"/Users/felipesmaniotto/my-real-portfolio/src/posts/self-employed.md"}}},"staticQueryHashes":["1425477374","3128451518"]}