poa-dapps-keys-generation/src/helpers.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

import { constants } from './constants'
import { messages } from './messages'
import swal from 'sweetalert'
2018-01-29 10:03:32 -08:00
var toAscii = function(hex) {
var str = '',
2018-10-15 07:52:03 -07:00
i = 0,
l = hex.length
if (hex.substring(0, 2) === '0x') {
i = 2
2018-01-29 10:03:32 -08:00
}
2018-10-15 07:52:03 -07:00
for (; i < l; i += 2) {
var code = parseInt(hex.substr(i, 2), 16)
if (code === 0) continue // this is added
str += String.fromCharCode(code)
2018-01-29 10:03:32 -08:00
}
return str
}
2018-01-29 10:03:32 -08:00
function addressesURL(branch) {
const URL = `https://raw.githubusercontent.com/${constants.organization}/${constants.repoName}/${branch}/${
constants.addressesSourceFile
}`
return URL
2018-01-29 10:03:32 -08:00
}
function ABIURL(branch, contract) {
const URL = `https://raw.githubusercontent.com/${constants.organization}/${constants.repoName}/${branch}/abis/${
constants.ABIsSources[contract]
}`
return URL
2018-01-29 10:03:32 -08:00
}
function getABI(branch, contract) {
let addr = ABIURL(branch, contract)
2018-10-15 07:52:03 -07:00
return fetch(addr).then(function(response) {
return response.json()
})
2018-01-29 10:03:32 -08:00
}
function wrongRepoAlert(addr) {
var content = document.createElement('div')
2018-10-15 07:52:03 -07:00
content.innerHTML = `<div>
Something went wrong!<br/><br/>
${messages.wrongRepo(addr)}
</div>`
2018-10-15 07:52:03 -07:00
swal({
icon: 'error',
title: 'Error',
2018-10-15 07:52:03 -07:00
content: content
})
2018-01-29 10:03:32 -08:00
}
let helpers = {
toAscii,
addressesURL,
ABIURL,
getABI,
wrongRepoAlert
}
2018-01-29 10:03:32 -08:00
export default helpers