1
0
mirror of https://github.com/bigchaindb/site.git synced 2024-11-02 00:05:37 +01:00
site/_src/_assets/javascripts/page-getstarted.js

117 lines
3.4 KiB
JavaScript
Raw Normal View History

2017-06-26 22:38:25 +02:00
//=require gumshoe/dist/js/gumshoe.js
2017-06-15 19:16:45 +02:00
//=include bigchain/smoothscroll.js
//=include bigchain/newsletter.js
2016-02-10 01:04:57 +01:00
jQuery(function($) {
2017-06-15 19:16:45 +02:00
//
// init modules
//
Newsletter.init()
2017-06-26 22:38:25 +02:00
2017-06-15 19:16:45 +02:00
})
2017-06-22 17:03:05 +02:00
2017-06-26 22:38:25 +02:00
//
// Sticky nav
//
const menu = document.getElementsByClassName('menu--sub')[0]
if ( window.innerWidth >= 768 ) {
const offset = menu.offsetTop
window.addEventListener('scroll', function() {
if (offset < window.pageYOffset) {
menu.classList.add('sticky')
} else {
menu.classList.remove('sticky')
}
}, false)
}
//
// Scrollspy
//
gumshoe.init()
//
// BigchainDB transaction tool
//
2017-06-23 12:47:58 +02:00
//=include bigchaindb-driver/dist/browser/bigchaindb-driver.window.min.js
2017-06-22 17:23:48 +02:00
2017-06-26 22:38:25 +02:00
window.addEventListener('DOMContentLoaded', function domload(event) {
2017-06-22 17:23:48 +02:00
window.removeEventListener('DOMContentLoaded', domload, false)
2017-06-22 17:03:05 +02:00
const driver = window.BigchainDB
const API_PATH = 'https://test.ipdb.io/api/v1/'
const APP_ID = 'b563bf22'
const APP_KEY = 'fd639614dcf8ee90a8c51a013ac11fb0'
2017-06-22 17:23:48 +02:00
const form = document.getElementById('form-transaction')
2017-06-22 17:03:05 +02:00
const postButton = document.getElementById('post')
2017-06-23 12:47:58 +02:00
const messageInput = document.getElementById('message')
// quick form validation
messageInput.addEventListener('input', function() {
if (messageInput.value === '') {
postButton.setAttribute('disabled', '')
2017-06-23 12:47:58 +02:00
} else {
postButton.removeAttribute('disabled')
2017-06-23 12:47:58 +02:00
}
})
2017-06-22 17:03:05 +02:00
postButton.addEventListener('click', function(e) {
e.preventDefault()
2017-06-23 12:47:58 +02:00
const message = messageInput.value
2017-06-22 17:03:05 +02:00
2017-06-22 17:23:48 +02:00
const alice = new driver.Ed25519Keypair()
2017-06-26 22:38:25 +02:00
const tx = driver.Transaction.makeCreateTransaction({
assetMessage: message
}, {
metaDataMessage: message
}, [driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey))], alice.publicKey)
2017-06-22 17:03:05 +02:00
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey)
const conn = new driver.Connection(API_PATH, {
app_id: APP_ID,
app_key: APP_KEY
})
2017-06-22 18:12:56 +02:00
const waiting = document.getElementsByClassName('waiting')[0]
2017-06-23 12:47:58 +02:00
const responseArea = document.getElementsByClassName('response')[0]
2017-06-22 18:12:56 +02:00
const output = document.getElementsByClassName('output')[0]
2017-06-22 18:23:47 +02:00
const messageSuccess = document.getElementsByClassName('message--success')[0]
const messageFail = document.getElementsByClassName('message--fail')[0]
const transactionLink = document.getElementsByClassName('transaction-link')[0]
2017-06-22 18:12:56 +02:00
2017-06-26 22:38:25 +02:00
conn.postTransaction(txSigned).then((response) => {
waiting.classList.add('hide')
responseArea.classList.remove('hide')
messageSuccess.classList.remove('hide')
2017-06-22 18:12:56 +02:00
2017-06-26 22:38:25 +02:00
console.log(response)
2017-06-23 12:47:58 +02:00
2017-06-26 22:38:25 +02:00
const outputContent = JSON.stringify(response, null, 4) // indented with 4 spaces
output.textContent = outputContent
2017-06-23 12:47:58 +02:00
2017-06-26 22:38:25 +02:00
transactionLink.href = 'https://test.ipdb.io/api/v1/transactions/' + response.id
2017-06-26 22:38:25 +02:00
}, reason => { // Error!
console.log(reason)
2017-06-22 18:12:56 +02:00
2017-06-26 22:38:25 +02:00
waiting.classList.add('hide')
responseArea.classList.remove('hide')
messageFail.classList.remove('hide')
2017-06-22 17:03:05 +02:00
2017-06-26 22:38:25 +02:00
const outputContent = reason.status + ' ' + reason.statusText
output.textContent = outputContent
}).then((res) => console.log('Transaction status:', res.status))
2017-06-22 17:03:05 +02:00
}, false)
}, false)