-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7441173
commit ee05b95
Showing
15 changed files
with
19,803 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script> | ||
<script src="https://unpkg.com/moralis/dist/moralis.js"></script> | ||
|
||
<link href="src/style.css" rel="stylesheet"> | ||
<link href="style.css" rel="stylesheet"> | ||
|
||
<title>Itheum Data Dex</title> | ||
</head> | ||
|
@@ -77,7 +77,7 @@ | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script> | ||
--> | ||
|
||
<script src="src/app.js" type="module"></script> | ||
<script src="lib.js" type="module"></script> | ||
</body> | ||
</html> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
// import secrets (these are exported as like "export const appId = 'xxx';") | ||
import {appId, serverURL} from './secrets.js'; | ||
|
||
const templates = { | ||
dataOrder: { | ||
state: 1, | ||
sellerEthAddress: null, | ||
data: null | ||
} | ||
} | ||
|
||
const btnRefs = { | ||
metamaskLogin: null, | ||
fullmenu: null | ||
}; | ||
|
||
window.state = { | ||
loggedIn: false, | ||
user: null, | ||
currBuyObjectId: '' | ||
}; | ||
|
||
window.requestToBuy = (objectId) => { | ||
console.log(objectId); | ||
|
||
window.state.currBuyObjectId = objectId; | ||
|
||
btnRefs.buyPanelReason.style.display = 'block'; | ||
} | ||
|
||
const sendBuyOffer = () => { | ||
if (btnRefs.reasonToBuy.value.trim() === '') { | ||
alert('You need to provide a reason to buy this'); | ||
} else { | ||
console.log('lets buy ', window.state.currBuyObjectId); | ||
console.log('reason ', btnRefs.reasonToBuy.value); | ||
} | ||
} | ||
|
||
const onPageLoad = () => { | ||
// elem refs | ||
btnRefs.alerts = document.getElementById('alerts'); | ||
btnRefs.metamaskLogin = document.getElementById('metamask-login'); | ||
btnRefs.logout = document.getElementById('metamask-logout'); | ||
btnRefs.metamaskUser = document.getElementById('metamask-user'); | ||
btnRefs.fullmenu = document.getElementById('full-menu'); | ||
btnRefs.sellData = document.getElementById('sell-data'); | ||
btnRefs.buyData = document.getElementById('buy-data'); | ||
btnRefs.buyPanelReason = document.getElementById('buy-panel-reason'); | ||
btnRefs.reasonToBuy = document.getElementById('reasonToBuy'); | ||
btnRefs.sendBuyOffer = document.getElementById('sendBuyOffer'); | ||
btnRefs.sellPanel = document.getElementById('sell-panel'); | ||
btnRefs.buyPanel = document.getElementById('buy-panel'); | ||
btnRefs.dataOrdersView = document.getElementById('dataOrdersView'); | ||
|
||
// listeners | ||
btnRefs.metamaskLogin.addEventListener('click', login); | ||
btnRefs.logout.addEventListener('click', logout); | ||
btnRefs.sellData.addEventListener('click', sellView); | ||
btnRefs.buyData.addEventListener('click', buyView); | ||
btnRefs.sendBuyOffer.addEventListener('click', sendBuyOffer); | ||
|
||
document.getElementById('sellerOrder').addEventListener('click', sellOrderSubmit); | ||
|
||
initMoralis(); | ||
} | ||
|
||
const initMoralis = async () => { | ||
Moralis.initialize(appId); | ||
Moralis.serverURL = serverURL; | ||
|
||
window.web3 = await Moralis.Web3.enable(); | ||
|
||
// is user already logged in? | ||
const user = await Moralis.User.current(); | ||
|
||
if (user) { | ||
console.log('🚀 ~ user in session'); | ||
|
||
showUser(user); | ||
} | ||
} | ||
|
||
const login = async () => { | ||
try { | ||
const user = await Moralis.Web3.authenticate(); | ||
console.log('🚀 ~ login done'); | ||
|
||
showUser(user); | ||
} catch (error) { | ||
const code = error.code; | ||
const message = error.message; | ||
|
||
console.log('🚀 ~ login err= ~ code', code); | ||
console.log('🚀 ~ login err= ~ message', message); | ||
} | ||
} | ||
|
||
const logout = async () => { | ||
await Moralis.User.logOut(); | ||
console.log('🚀 ~ logout done'); | ||
|
||
showUser(); | ||
} | ||
|
||
const showUser = user => { | ||
console.log('user = ', user); | ||
|
||
btnRefs.metamaskUser.innerHTML = user && user.get('ethAddress') || ''; | ||
btnRefs.fullmenu.style.display = user && 'block' || 'none'; | ||
btnRefs.logout.style.display = user && 'block' || 'none'; | ||
btnRefs.metamaskLogin.style.display = user && 'none' || 'block'; | ||
|
||
window.state.loggedIn = !!user; | ||
window.state.user = user; | ||
} | ||
|
||
const buyView = async() => { | ||
setAlert(''); | ||
|
||
btnRefs.buyPanel.style.display = 'block'; | ||
btnRefs.sellPanel.style.display = 'none'; | ||
|
||
const DataOrder = Moralis.Object.extend("DataOrder"); | ||
const query = new Moralis.Query(DataOrder); | ||
|
||
query.equalTo("state", '1'); | ||
|
||
const results = await query.find(); | ||
|
||
setAlert('Successfully retrieved ' + results.length + ' data orders available for sale'); | ||
|
||
let dataorders = ''; | ||
|
||
for (let i = 0; i < results.length; i++) { | ||
const object = results[i]; | ||
dataorders += object.id + ' - ' + object.get('sellerEthAddress') + ' - ' + object.get('data'); | ||
|
||
// if curr user address is not seller's then show a 'buy' button | ||
if (object.get('sellerEthAddress') !== window.state.user.get('ethAddress')) { | ||
dataorders += '<button type="button" class="btn btn-secondary" onclick="window.requestToBuy(\''+object.id+'\')">Request to buy</button>'; | ||
} | ||
|
||
dataorders += '<br /><br />'; | ||
} | ||
|
||
btnRefs.dataOrdersView.innerHTML = dataorders; | ||
} | ||
|
||
const sellView = () => { | ||
setAlert(''); | ||
|
||
btnRefs.buyPanel.style.display = 'none'; | ||
btnRefs.sellPanel.style.display = 'block'; | ||
|
||
document.getElementById('sellerEthAddress').value = window.state.user.get('ethAddress'); | ||
} | ||
|
||
const sellOrderSubmit = async () => { | ||
// grab the data | ||
const sellerData = document.getElementById('sellerData').value.trim(); | ||
|
||
if (sellerData === '') { | ||
alert('You need to provide some data!') | ||
} else { | ||
// create the object | ||
const newDataOrder = {...templates.dataOrder, | ||
data: sellerData, | ||
sellerEthAddress: window.state.user.get('ethAddress') | ||
}; | ||
|
||
console.log('🚀 ~ sellOrderSubmit ~ newDataOrder', newDataOrder); | ||
// encrypt | ||
|
||
// store in moralis object storage (in future - store in IPFS) | ||
const DataOrder = Moralis.Object.extend("DataOrder"); | ||
const dataOrder = new DataOrder(); | ||
|
||
let savedSataOrder = null; | ||
|
||
try { | ||
savedSataOrder = dataOrder.save(newDataOrder); | ||
|
||
alert('Data Saved!'); | ||
} catch(error) { | ||
const code = error.code; | ||
const message = error.message; | ||
|
||
console.log('🚀 ~ sellOrderSubmit err= ~ code', code); | ||
console.log('🚀 ~ sellOrderSubmit err= ~ message', message); | ||
} | ||
} | ||
} | ||
|
||
const setAlert = msg => { | ||
btnRefs.alerts.innerHTML = msg; | ||
} | ||
|
||
window.addEventListener('load', onPageLoad); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
name="description" | ||
content="Web site created using create-react-app" | ||
/> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>React App</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
}, | ||
{ | ||
"src": "logo192.png", | ||
"type": "image/png", | ||
"sizes": "192x192" | ||
}, | ||
{ | ||
"src": "logo512.png", | ||
"type": "image/png", | ||
"sizes": "512x512" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: |
Oops, something went wrong.