mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-22 12:45:50 +00:00
Move Build a Desktop Wallet code samples
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
const xrpl = require("xrpl");
|
||||
|
||||
// The rippled server and its APIs represent time as an unsigned integer.
|
||||
// This number measures the number of seconds since the "Ripple Epoch" of
|
||||
// January 1, 2000 (00:00 UTC). This is like the way the Unix epoch works,
|
||||
// Reference: https://xrpl.org/basic-data-types.html
|
||||
const RIPPLE_EPOCH = 946684800;
|
||||
|
||||
const prepareAccountData = (rawAccountData) => {
|
||||
return {
|
||||
classicAddress: rawAccountData.Account,
|
||||
xAddress: xrpl.classicAddressToXAddress(rawAccountData.Account, false, true),
|
||||
xrpBalance: xrpl.dropsToXrp(rawAccountData.Balance)
|
||||
}
|
||||
}
|
||||
|
||||
const prepareLedgerData = (rawLedgerData) => {
|
||||
const timestamp = RIPPLE_EPOCH + (rawLedgerData.ledger_time ?? rawLedgerData.close_time)
|
||||
const dateTime = new Date(timestamp * 1000)
|
||||
const dateTimeString = dateTime.toLocaleDateString() + ' ' + dateTime.toLocaleTimeString()
|
||||
|
||||
return {
|
||||
ledgerIndex: rawLedgerData.ledger_index,
|
||||
ledgerHash: rawLedgerData.ledger_hash,
|
||||
ledgerCloseTime: dateTimeString
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { prepareAccountData, prepareLedgerData }
|
||||
Reference in New Issue
Block a user