mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-22 12:45:50 +00:00
Re-added code to clean branch
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
const async = require('async')
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
const path = require('path')
|
||||
const xrpl = require("xrpl")
|
||||
|
||||
const TESTNET_URL = "wss://s.altnet.rippletest.net:51233"
|
||||
|
||||
/**
|
||||
* This function sends a ledger-request and returns the response
|
||||
*
|
||||
* @param client
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
const getValidatedLedgerData = async (client) => {
|
||||
// Reference: https://xrpl.org/ledger.html#ledger
|
||||
const ledgerRequest = {
|
||||
"command": "ledger",
|
||||
"ledger_index": "validated"
|
||||
}
|
||||
const ledgerResponse = await client.request(ledgerRequest)
|
||||
|
||||
return ledgerResponse.result
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates our application window
|
||||
*
|
||||
* @returns {Electron.CrossProcessExports.BrowserWindow}
|
||||
*/
|
||||
const createWindow = () => {
|
||||
|
||||
const appWindow = new BrowserWindow({
|
||||
width: 1024,
|
||||
height: 768,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'view', '2_preload.js'),
|
||||
},
|
||||
})
|
||||
|
||||
appWindow.loadFile(path.join(__dirname, 'view', '2_async.html'))
|
||||
|
||||
return appWindow
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a XRPL client, continuously polls the XRPL with a ledger-request and broadcasts
|
||||
* the result by dispatching the 'update-ledger-data' event which will be picked up by the frontend
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const main = async () => {
|
||||
const appWindow = createWindow()
|
||||
|
||||
const client = new xrpl.Client(TESTNET_URL)
|
||||
|
||||
await client.connect()
|
||||
|
||||
async.forever(
|
||||
function(next) {
|
||||
getValidatedLedgerData(client).then((value) => {
|
||||
appWindow.webContents.send('update-ledger-data', value)
|
||||
})
|
||||
|
||||
setTimeout(function() {
|
||||
next()
|
||||
}, 2500)
|
||||
},
|
||||
function(err) {
|
||||
// if next is called with a value in its first parameter, it will appear
|
||||
// in here as 'err', and execution will stop.
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
app.whenReady().then(main)
|
||||
Reference in New Issue
Block a user