mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-06-07 02:36:41 +00:00
refactor: move hasNextPage from Client to utils (#1715)
* add hasNextPage * remove unused util * add tests * remove hasNextPage from client
This commit is contained in:
@@ -276,22 +276,6 @@ class Client extends EventEmitter {
|
||||
return this.connection.getUrl()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more pages of data.
|
||||
*
|
||||
* When there are more results than contained in the response, the response
|
||||
* includes a `marker` field.
|
||||
*
|
||||
* See https://ripple.com/build/rippled-apis/#markers-and-pagination.
|
||||
*
|
||||
* @param response - Response to check for more pages on.
|
||||
* @returns Whether the response has more pages of data.
|
||||
* @category Network
|
||||
*/
|
||||
public static hasNextPage(response: MarkerResponse): boolean {
|
||||
return Boolean(response.result.marker)
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Network
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
xAddressToClassicAddress,
|
||||
} from 'ripple-address-codec'
|
||||
|
||||
import { Response } from '../models/methods'
|
||||
|
||||
import getBalanceChanges from './balanceChanges'
|
||||
import { deriveKeypair, deriveXAddress } from './derive'
|
||||
import { generateXAddress } from './generateAddress'
|
||||
@@ -69,25 +71,6 @@ function isValidAddress(address: string): boolean {
|
||||
return isValidXAddress(address) || isValidClassicAddress(address)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes undefined values from an object.
|
||||
*
|
||||
* @param obj - Object to remove undefined values from.
|
||||
* @returns The same object, but without undefined values.
|
||||
*/
|
||||
function removeUndefined<T extends Record<string, unknown>>(obj: T): T {
|
||||
const newObj = { ...obj }
|
||||
|
||||
Object.entries(obj).forEach(([key, value]) => {
|
||||
if (value == null) {
|
||||
/* eslint-disable-next-line @typescript-eslint/no-dynamic-delete -- Deletes undefined values. */
|
||||
delete newObj[key]
|
||||
}
|
||||
})
|
||||
|
||||
return newObj
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string to its hex equivalent. Useful for Memos.
|
||||
*
|
||||
@@ -98,6 +81,22 @@ function convertStringToHex(string: string): string {
|
||||
return Buffer.from(string, 'utf8').toString('hex').toUpperCase()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more pages of data.
|
||||
*
|
||||
* When there are more results than contained in the response, the response
|
||||
* includes a `marker` field.
|
||||
*
|
||||
* See https://ripple.com/build/rippled-apis/#markers-and-pagination.
|
||||
*
|
||||
* @param response - Response to check for more pages on.
|
||||
* @returns Whether the response has more pages of data.
|
||||
*/
|
||||
function hasNextPage(response: Response): boolean {
|
||||
// eslint-disable-next-line @typescript-eslint/dot-notation -- only checking if it exists
|
||||
return Boolean(response.result['marker'])
|
||||
}
|
||||
|
||||
const hashes = {
|
||||
hashSignedTx,
|
||||
hashTx,
|
||||
@@ -117,7 +116,7 @@ export {
|
||||
getBalanceChanges,
|
||||
dropsToXrp,
|
||||
xrpToDrops,
|
||||
removeUndefined,
|
||||
hasNextPage,
|
||||
rippleTimeToISOTime,
|
||||
ISOTimeToRippleTime,
|
||||
rippleTimeToUnixTime,
|
||||
|
||||
Reference in New Issue
Block a user