Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hiveuprss committed May 2, 2021
1 parent 57868c6 commit d2921f9
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

# ignore everything in the root except the "wp-content" directory.
!wp-content/

Expand Down
3 changes: 3 additions & 0 deletions axios.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions css/hep.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* hep.css */

div.hep_widget_container {
text-align: center;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
border: 1px solid #969696;
/*background-color: #EBEBEB;*/
}

div.hep_widget_container h4 {
margin: 0px;
}

div.hep_widget_container h5 {
margin-top: 20px;
margin-bottom: 20px;
}

div.hep_widget_container h6 {
margin: 0px;
}

div.hep_widget_header {
/*background-color: #277da1ff;*/
}

div.hep_widget_content {
/*background-color: #EBEBEB;*/

padding-left: 10px;
padding-right: 10px;
}

div.hep_widget_exchanges {
display:inline-block;
width: 100%;
border-top: 1px solid #969696;
min-width: 127px;
/*background-color: #EBEBEB;*/
}

div.hep_widget_exchanges > a {
padding: 10px;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
66 changes: 66 additions & 0 deletions hive-engine-price.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// hive-engine-price.js

const rpc = 'https://api.hive-engine.com/rpc/contracts';

function getSellBook(token) {
return new Promise((resolve, reject) => {
const query = {'id': 1,
jsonrpc: '2.0',
method: 'find',
params: {
contract: 'market',
table: 'sellBook',
query: {
symbol: token
}
}}
let nextBlock = false
axios.post(rpc, query).then((result) => {
return resolve(result.data.result)
}).catch((err) => {
console.log(err)
return reject(err)
})
})
}

function getHivePrice() {
return new Promise((resolve, reject) => {
const coingecko_api = 'https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=USD'
axios.get(coingecko_api).then((result) => {
return resolve(result.data.hive.usd)
}).catch((err) => {
console.log(err)
return reject(err)
})
})
}

function getTokenPrice(token, content_div_id) {
var hivePrice = getHivePrice()
var sellBook = getSellBook(token)

Promise.all([hivePrice,sellBook]).then((result) => {
let hivePrice = result[0]

let sellBook = result[1]
sellBook = sellBook.sort( (a,b) => Number(a.price) - Number(b.price) )

var targetDiv = document.querySelector('div#' + content_div_id)

let sellOrder = sellBook[0]

let quantity = sellOrder.quantity
let symbol = sellOrder.symbol
let price = sellOrder.price
targetDiv.innerHTML = (`${Number(price).toFixed(3)} HIVE <br> ${(price * hivePrice).toFixed(3)} USD`)
})
}

Array.from(document.querySelectorAll('div.hep_widget_content')).forEach( (div) => {
let token_name = div.getAttribute('data-token-name')
let div_id = div.getAttribute('id')
getTokenPrice(token_name.toUpperCase(), div_id)
})


Loading

0 comments on commit d2921f9

Please sign in to comment.