From 6dc3d892ae4afc74c08b59b3ea7155c4257dafe7 Mon Sep 17 00:00:00 2001 From: Grishon Date: Sat, 7 May 2022 09:26:02 +0300 Subject: [PATCH] Add final changes before talk --- __pycache__/blockchain.cpython-38.pyc | Bin 1461 -> 10251 bytes app.py | 68 +++- blockchain.py | 547 ++++++++++++++++++++++++-- frontend/package-lock.json | 17 + frontend/package.json | 1 + frontend/src/App.js | 38 +- frontend/src/api/endpoints.js | 19 + frontend/src/components/navbar.js | 6 +- frontend/src/components/wallet.js | 250 +++++++++--- generated_nfts.json | 4 +- requirements.txt | 50 +++ 11 files changed, 901 insertions(+), 99 deletions(-) diff --git a/__pycache__/blockchain.cpython-38.pyc b/__pycache__/blockchain.cpython-38.pyc index 86b73bcceccfdca17880094b15a0725eb3082e11..63d449229ecd2779d0fd5be8412a26c995563596 100644 GIT binary patch literal 10251 zcmeHNTW=f36`on{@+RtH*^bi|0UQAhz#y<>*^)0Xj4Hk$LSk94WZ2olAeK8rX{qHd zGdq+-mues6B1M5b^gSq~qA&hS``V}cgSO~H&za>&BqhqC%GhpN3fjx;nVB=+`OY~r zv-@;(G*967uiwk^x1SL5H@xZmnQ-$f_>cYw2Syn6iH&E&r!~ViC}Al(#SL!knLM>m zcd1R8XTNuMePxmWBFIaF0c_+fb%FDWn*w2 zW8-WB&g1MHn}qWOJI^k_`5e30zNagsc&0BbHB;wa#Kza2F+U7h^B5|t~h?gKf_Wls5c}QfmlunszS!MIfGIu8cI$T zN-hG&Uv1VoJehJB6FiEhuo-w9I5kxqZUtQELfIpWqC2Vrs`MZBu_>(|-{gUu$}1p#nwAOcTsSg3 z3k?pKc?{#qVVFSKLAQP+P_idm&3gjA_2$lwFj`fK*1h_w zaDu49g=qWVJ7;%Agf;E7+S7E1Qal(|*pcCIyU`(}9mRC)I8(sUR(V6f=@ax%72gLM zes_z*9BJF{lYxc}sk2xTfFtQh{-`0HvgdoUiRlWmU)^asWuJG0Q)vXQ^unMsARpq> z9nS?1LJ;Q%Uhrd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#}0*vrW5uEGdQt2t(T58u-4D4A-$I?_tD43_%N*fCYDLd&d5nO&j>SDz!-93BQO3;$xeonmlqh3=USOvh&^eL_?rAh#h{(cZ!^!~E-;=eQWdQw zfoMU{u;3M-%VTTP@f+OEt~t>%q7KX+K>=gc&a5MqiS&qQf4u0qkT(Wy%LqyooHR02SwCyZ9{I`In;o&5?p5F zwvw=OZ~@=-G<+FT-b>a(y&)h(MjX9!63K#`BGjO>bQ0XCfRT|-Q1LO8cF`A!gwYMp z(N}PgKn|(W4Y-rJPj-#_Dcl^hedYb z@Il#2Qdw3PC8}f6RGCR74;6Toe<;lqaXMJ1BBnwwd#4t%hR^S!p`$4{WN9H~8e@iO U=6^@*>ci~s-t delta 878 zcmZ8fzi$&U6teotsk)UR8QEB1U}0cq=l+9k>?}NovS7*I`~1%D^Yi(8zxO$td%3V+AsFMI;eJs) z&n@Gp=Nos|nBr>jY@dIzWm5{+00=8M zhYhR|8;cyQJ(4tUEuDS=8leMxKo~Bd36Xr7iOCGdke@0sW@JWKMslVw6}a|6oxmDu z)TtI{m_8#D<>danQjZnc-UM0&9Wz#eYq2JdVvQLE#LPn?j$R>VwGd#owF1GfDk!oJ zE%6DXiH_09BC}(iEfi4l>sIMB*A(*CxGIl&T=d_ZT}KyHnNYf8-Y=`E>Ic5ZQxXNK zdPHB3xSQ$H&@}+|MBn4?Lr$FjnUp+ab~UxRvHF!G}?8LgFW>N1rN`(3{s3F?Q`i~51@E{5D^Z9&KF zDEYqToTlcJV~-Ezx3b|{QP93rNi{l$Fn^; z3=2.0.0 || >=3.0.0 || >=3.0.0-alpha.1" + } + }, "node_modules/@testing-library/dom": { "version": "8.13.0", "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.13.0.tgz", @@ -18391,6 +18401,13 @@ "loader-utils": "^2.0.0" } }, + "@tailwindcss/line-clamp": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@tailwindcss/line-clamp/-/line-clamp-0.4.0.tgz", + "integrity": "sha512-HQZo6gfx1D0+DU3nWlNLD5iA6Ef4JAXh0LeD8lOGrJwEDBwwJNKQza6WoXhhY1uQrxOuU8ROxV7CqiQV4CoiLw==", + "dev": true, + "requires": {} + }, "@testing-library/dom": { "version": "8.13.0", "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.13.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 25565b1..0102350 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -38,6 +38,7 @@ ] }, "devDependencies": { + "@tailwindcss/line-clamp": "^0.4.0", "autoprefixer": "^10.4.7", "postcss": "^8.4.13", "tailwindcss": "^3.0.24" diff --git a/frontend/src/App.js b/frontend/src/App.js index ec051df..a7e57e9 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -7,17 +7,17 @@ import { Navbar } from './components/navbar' function App() { const [loading, setLoading] = useState(false) const [user, setUser] = useState(null) + const [nfts, setNfts] = useState([]) const [showWallet, setShowWallet] = useState(false) + const [showPayment, setShowPayment] = useState(false) - useEffect(() => { - console.log(user) - }, [user]) useEffect(() => { const fetchNewToken = () => { refreshToken().then((response) => { console.log(response) if (response && response.status === 200) { setUser(response.data.user) + setNfts(response.data.nfts) } }) } @@ -25,27 +25,30 @@ function App() { refreshToken().then((response) => { if (response && response.status === 200) { setUser(response.data.user) + setNfts(response.data.nfts) setTimeout(fetchNewToken, 1.8e+6) } }) } else { setTimeout(fetchNewToken, 1.8e+6) } - }, [user, setUser]) + }, [user, setUser, nfts, setNfts]) + const generateNft = () => { if (user) { - setLoading(true); - }else{ + setShowPayment(true) + + } else { setShowWallet(true) } } return (
- +
-
+
@@ -73,6 +76,25 @@ function App() { }
+ { + user && nfts.length > 0 && + nfts.map((nft, idx) => { + return ( +
+
+
+ +
+
+
+
+ Collection #{nft["id"]} +
+
+
+ ) + }) + }
diff --git a/frontend/src/api/endpoints.js b/frontend/src/api/endpoints.js index 1423141..7596f67 100644 --- a/frontend/src/api/endpoints.js +++ b/frontend/src/api/endpoints.js @@ -21,3 +21,22 @@ export const refreshToken = async () => { return error.response }) } + +export const getUserBalance = async () => { + return await api.get('/get_user_balance').then((response) => response).catch((error) => { + return error.response + }) +} + +export const generateNFT = async (keyDetails) => { + return await api.post('/generate_nft', keyDetails).then((response) => response).catch((error) => { + return error.response + }) +} + +export const getNFTPrice = async () => { + return await api.get('/get_nft_price').then((response) => response).catch((error) => { + return error.response + }) +} + diff --git a/frontend/src/components/navbar.js b/frontend/src/components/navbar.js index d80ba1b..1666156 100644 --- a/frontend/src/components/navbar.js +++ b/frontend/src/components/navbar.js @@ -1,7 +1,7 @@ import { BiWalletAlt } from 'react-icons/bi'; import { FaUserSecret } from 'react-icons/fa' import { Wallet } from './wallet' -export const Navbar = ({ user, setUser, showWallet, setShowWallet }) => { +export const Navbar = ({ user, setUser, showWallet, setShowWallet, showPayment, setShowPayment, setLoading }) => { return (
@@ -17,8 +17,8 @@ export const Navbar = ({ user, setUser, showWallet, setShowWallet }) => { {setShowWallet(prevState=>(!prevState))}}/> } { - showWallet && - + (showWallet || showPayment) && + }
diff --git a/frontend/src/components/wallet.js b/frontend/src/components/wallet.js index 849b553..4da60fe 100644 --- a/frontend/src/components/wallet.js +++ b/frontend/src/components/wallet.js @@ -1,91 +1,181 @@ -import { useState } from 'react' +import { useState, useEffect } from 'react' import bg from '../assets/bg.jpg' import eth from '../assets/eth.png' import crypto from '../assets/crypto.svg' import loader from '../assets/round_loader.gif' -import { auth } from '../api/endpoints' +import { auth, getUserBalance, getNFTPrice, generateNFT } from '../api/endpoints' -export const Wallet = ({ user, setUser }) => { +export const Wallet = ({ user, setUser, showPayment, setShowPayment, setLoading }) => { return (
{ user && - + || - + }
) } -const UserWallet = ({ user }) => { +const UserWallet = ({ user, showPayment, setShowPayment, setStartGenerating, setLoading }) => { + const [balance, setBalance] = useState(0) + const [price, setPrice] = useState(0) + const [privateKey, setPrivateKey] = useState("") + const [paymentError, setPaymentError] = useState(false) + + useEffect(() => { + if (!showPayment) { + getUserBalance().then(response => { + if (response && response.status === 200) { + setBalance(response.data.balance) + } + }) + } else { + getNFTPrice().then(response => { + if (response && response.status === 200) { + setPrice(response.data.price) + } + }) + } + }, []) function copy() { navigator.clipboard.writeText(user) } + const handleChange = (input) => { + setPrivateKey(input.target.value) + } + + const makePaymentAndGenerateNFT = () => { + setLoading(true) + generateNFT({ private_key: privateKey }).then(response => { + setLoading(false) + if (response && response.status === 200) { + setStartGenerating(true) + } else { + setPaymentError(response.data.message) + } + + }) + } + + const closePayment = () => { + setShowPayment(false) + } return ( -
-
-
- pY +
{ + + showPayment && +
+
+ Authorize Transaction +
+
+
+ PyConKE NFTs is charging {price} ether to generate your NFT +
+
+ { + paymentError && +
+ {paymentError} +
+ } +
+ Enter your Private Key
-
-
-
+
+
+ +
+
+
+
+
+
-
- Ethereum Local +
+
+
+
+
-
- -
-
-
{ copy() }}> -
-
- Account -
-
- - - + || +
+
+
+ pY +
+
+
+
+ +
+
+ Ethereum Local +
-
- {user.substring(0,5)}...{user.substring(user.length-4, user.length)} +
+
-
-
-
- -
-
-
-
- 0 ETH +
+
{ copy() }}> +
+
+ Account +
+
+ + + +
+
+
+ {user?.substring(0, 5)}...{user?.substring(user?.length - 4, user?.length)} +
+
-
- KES 0.00 +
+
+ +
-
-
-
- - - +
+
+ {balance} ETH +
+
+ KES 0.00 +
-
- Buy +
+
+ + + +
+
+ Buy +
+ }
+ ) } @@ -93,16 +183,15 @@ const CreateAccount = ({ setUser }) => { const [creatingAccount, setCreatingAccount] = useState("") const [createLoading, setCreateLoading] = useState(false) const [createError, setCreateError] = useState(false) - const [importLoading, setImportLoading] = useState(false) const [importError, setImportError] = useState(false) const [user, setCreatedUser] = useState(null) + const [privateKey, setPrivateKey] = useState("") const createAccount = () => { setCreatingAccount("create") setCreateLoading(true) auth().then(response => { setCreateLoading(false) - console.log(response) if (response && response.status === 200) { setCreatedUser(response.data.key) } else { @@ -111,10 +200,31 @@ const CreateAccount = ({ setUser }) => { }) } + const handleChange = (input) => { + setPrivateKey(input.target.value) + } + + const importAccount = () => { + auth({ private_key: privateKey }).then(response => { + console.log(response) + if (response && response.status === 200) { + setCreatingAccount(false) + setUser(response.data.key) + } else { + setImportError("Something wrong happened") + } + }) + } + + const closeImport = () => { + setCreatingAccount("") + } + const finishCreatingAccount = () => { setCreatingAccount(false) - setUser(user) + setUser(user.public) } + return (
{ @@ -133,7 +243,7 @@ const CreateAccount = ({ setUser }) => {
-
@@ -145,8 +255,38 @@ const CreateAccount = ({ setUser }) => {
Import Account
-
+ { + importError && +
+ {importError} +
+ } +
+ Enter your Private Key +
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+ +
|| @@ -177,7 +317,7 @@ const CreateAccount = ({ setUser }) => {
-
diff --git a/generated_nfts.json b/generated_nfts.json index e350710..544b7b4 100644 --- a/generated_nfts.json +++ b/generated_nfts.json @@ -1 +1,3 @@ -{"bg_5outer_1inner_1python_2.png": {"bg": ["bg_5.png"], "outer": ["outer_1.png"], "inner": ["inner_1.png"], "python": ["python_2.png"]}} \ No newline at end of file +{ + +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index db89eb4..88d6d67 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,51 @@ +aiohttp==3.8.1 +aiosignal==1.2.0 +async-timeout==4.0.2 +attrs==21.4.0 +base58==2.1.1 +bitarray==1.2.2 +certifi==2021.10.8 +charset-normalizer==2.0.12 +click==8.1.3 +cytoolz==0.11.2 +eth-abi==2.1.1 +eth-account==0.5.7 +eth-hash==0.3.2 +eth-keyfile==0.5.1 +eth-keys==0.3.4 +eth-rlp==0.3.0 +eth-typing==2.3.0 +eth-utils==1.10.0 +Flask==2.1.2 +Flask-Cors==3.0.10 +frozenlist==1.3.0 +hexbytes==0.2.2 +idna==3.3 +importlib-metadata==4.11.3 +importlib-resources==5.7.1 +ipfshttpclient==0.8.0a2 +itsdangerous==2.1.2 +Jinja2==3.1.2 +jsonschema==4.4.0 +lru-dict==1.1.7 +MarkupSafe==2.1.1 +multiaddr==0.0.9 +multidict==6.0.2 +netaddr==0.8.0 +parsimonious==0.8.1 Pillow==9.1.0 +protobuf==3.20.1 +pycryptodome==3.14.1 +PyJWT==2.3.0 +pyrsistent==0.18.1 +requests==2.27.1 +rlp==2.0.1 +six==1.16.0 +toolz==0.11.2 +urllib3==1.26.9 +varint==1.0.2 +web3==5.29.0 +websockets==9.1 +Werkzeug==2.1.2 +yarl==1.7.2 +zipp==3.8.0