mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-05 21:35:49 +00:00
Compare commits
4 Commits
ripple-bin
...
mv/lodash-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fa3f73d5a | ||
|
|
9bf7df868e | ||
|
|
3134dc112f | ||
|
|
915118265f |
@@ -62,29 +62,26 @@ function getAgent(url: string, config: ConnectionOptions): Agent | undefined {
|
||||
const parsedURL = new URL(url)
|
||||
const parsedProxyURL = new URL(config.proxy)
|
||||
|
||||
const proxyOptions = _.omitBy(
|
||||
{
|
||||
secureEndpoint: parsedURL.protocol === 'wss:',
|
||||
secureProxy: parsedProxyURL.protocol === 'https:',
|
||||
auth: config.proxyAuthorization,
|
||||
ca: config.trustedCertificates,
|
||||
key: config.key,
|
||||
passphrase: config.passphrase,
|
||||
cert: config.certificate,
|
||||
href: parsedProxyURL.href,
|
||||
origin: parsedProxyURL.origin,
|
||||
protocol: parsedProxyURL.protocol,
|
||||
username: parsedProxyURL.username,
|
||||
password: parsedProxyURL.password,
|
||||
host: parsedProxyURL.host,
|
||||
hostname: parsedProxyURL.hostname,
|
||||
port: parsedProxyURL.port,
|
||||
pathname: parsedProxyURL.pathname,
|
||||
search: parsedProxyURL.search,
|
||||
hash: parsedProxyURL.hash,
|
||||
},
|
||||
(value) => value == null,
|
||||
)
|
||||
const proxyOptions = {
|
||||
secureEndpoint: parsedURL.protocol === 'wss:',
|
||||
secureProxy: parsedProxyURL.protocol === 'https:',
|
||||
auth: config.proxyAuthorization,
|
||||
ca: config.trustedCertificates,
|
||||
key: config.key,
|
||||
passphrase: config.passphrase,
|
||||
cert: config.certificate,
|
||||
href: parsedProxyURL.href,
|
||||
origin: parsedProxyURL.origin,
|
||||
protocol: parsedProxyURL.protocol,
|
||||
username: parsedProxyURL.username,
|
||||
password: parsedProxyURL.password,
|
||||
host: parsedProxyURL.host,
|
||||
hostname: parsedProxyURL.hostname,
|
||||
port: parsedProxyURL.port,
|
||||
pathname: parsedProxyURL.pathname,
|
||||
search: parsedProxyURL.search,
|
||||
hash: parsedProxyURL.hash,
|
||||
}
|
||||
|
||||
let HttpsProxyAgent: new (opt: typeof proxyOptions) => Agent
|
||||
try {
|
||||
@@ -118,15 +115,12 @@ function createWebSocket(
|
||||
const base64 = Buffer.from(config.authorization).toString('base64')
|
||||
options.headers = { Authorization: `Basic ${base64}` }
|
||||
}
|
||||
const optionsOverrides = _.omitBy(
|
||||
{
|
||||
ca: config.trustedCertificates,
|
||||
key: config.key,
|
||||
passphrase: config.passphrase,
|
||||
cert: config.certificate,
|
||||
},
|
||||
(value) => value == null,
|
||||
)
|
||||
const optionsOverrides = {
|
||||
ca: config.trustedCertificates,
|
||||
key: config.key,
|
||||
passphrase: config.passphrase,
|
||||
cert: config.certificate,
|
||||
}
|
||||
const websocketOptions = { ...options, ...optionsOverrides }
|
||||
const websocket = new WebSocket(url, websocketOptions)
|
||||
/*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable complexity -- verifies 19 tx types hence a lot of checks needed */
|
||||
/* eslint-disable max-lines-per-function -- need to work with a lot of Tx verifications */
|
||||
|
||||
import _ from 'lodash'
|
||||
import isEqual from 'lodash/isEqual'
|
||||
import { encode, decode } from 'ripple-binary-codec'
|
||||
|
||||
import { ValidationError } from '../../errors'
|
||||
@@ -164,11 +164,23 @@ export function validate(transaction: Record<string, unknown>): void {
|
||||
}
|
||||
|
||||
if (
|
||||
!_.isEqual(
|
||||
!isEqual(
|
||||
decode(encode(tx)),
|
||||
_.omitBy(tx, (value) => value == null),
|
||||
omitBy(tx, (value) => value == null),
|
||||
)
|
||||
) {
|
||||
throw new ValidationError(`Invalid Transaction: ${tx.TransactionType}`)
|
||||
}
|
||||
}
|
||||
|
||||
function omitBy(
|
||||
obj: Record<string, unknown>,
|
||||
fn: (value: unknown) => unknown,
|
||||
): Record<string, unknown> {
|
||||
return (
|
||||
Object.keys(obj)
|
||||
.filter((key) => !fn(obj[key]))
|
||||
// eslint-disable-next-line no-return-assign -- it's fine
|
||||
.reduce((acc, key) => ((acc[key] = obj[key]), acc), {})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import _ from 'lodash'
|
||||
|
||||
import type { Client } from '..'
|
||||
import { LedgerIndex } from '../models/common'
|
||||
import { AccountInfoRequest } from '../models/methods'
|
||||
@@ -95,7 +93,7 @@ async function getBalances(
|
||||
// combine results
|
||||
await Promise.all([xrpPromise, linesPromise]).then(
|
||||
([xrpBalance, linesResponses]) => {
|
||||
const accountLinesBalance = _.flatMap(linesResponses, (response) =>
|
||||
const accountLinesBalance = linesResponses.flatMap((response) =>
|
||||
formatBalances(response.result.lines),
|
||||
)
|
||||
if (xrpBalance !== '') {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
/* eslint-disable max-lines-per-function -- Needs to process orderbooks. */
|
||||
import BigNumber from 'bignumber.js'
|
||||
import _ from 'lodash'
|
||||
|
||||
import type { Client } from '../client'
|
||||
import { LedgerIndex } from '../models/common'
|
||||
@@ -65,12 +63,10 @@ async function getOrderbook(
|
||||
request.taker_pays = takerGets
|
||||
const reverseOfferResults = await this.requestAll(request)
|
||||
// 3. Return Formatted Response
|
||||
const directOffers = _.flatMap(
|
||||
directOfferResults,
|
||||
const directOffers = directOfferResults.flatMap(
|
||||
(directOfferResult) => directOfferResult.result.offers,
|
||||
)
|
||||
const reverseOffers = _.flatMap(
|
||||
reverseOfferResults,
|
||||
const reverseOffers = reverseOfferResults.flatMap(
|
||||
(reverseOfferResult) => reverseOfferResult.result.offers,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import BigNumber from 'bignumber.js'
|
||||
import _ from 'lodash'
|
||||
import groupBy from 'lodash/groupBy'
|
||||
|
||||
import { Amount, IssuedCurrencyAmount } from '../models/common'
|
||||
import TransactionMetadata, { Node } from '../models/transactions/metadata'
|
||||
@@ -66,7 +66,7 @@ function normalizeNodes(metadata: TransactionMetadata): NormalizedNode[] {
|
||||
}
|
||||
|
||||
function groupByAccount(balanceChanges: BalanceChange[]): BalanceChanges[] {
|
||||
const grouped = _.groupBy(balanceChanges, (node) => node.account)
|
||||
const grouped = groupBy(balanceChanges, (node) => node.account)
|
||||
return Object.entries(grouped).map(([account, items]) => {
|
||||
return { account, balances: items.map((item) => item.balance) }
|
||||
})
|
||||
@@ -181,5 +181,5 @@ export default function getBalanceChanges(
|
||||
}
|
||||
return []
|
||||
})
|
||||
return groupByAccount(_.flatten(quantities))
|
||||
return groupByAccount(quantities.flat())
|
||||
}
|
||||
|
||||
15
src/utils/internalUtils.ts
Normal file
15
src/utils/internalUtils.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// NOTE: This should not be exported at the top level
|
||||
|
||||
export function omitBy(
|
||||
obj: Record<string, unknown>,
|
||||
fn: (unknown, string) => unknown,
|
||||
): Record<string, unknown> {
|
||||
return (
|
||||
Object.keys(obj)
|
||||
.filter((key) => !fn(obj[key], key))
|
||||
// eslint-disable-next-line no-return-assign -- it's fine
|
||||
.reduce((acc, key) => ((acc[key] = obj[key]), acc), {})
|
||||
)
|
||||
}
|
||||
|
||||
export function groupBy(): void {}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { assert } from 'chai'
|
||||
import _ from 'lodash'
|
||||
|
||||
import { ServerInfoResponse } from '../src'
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { assert } from 'chai'
|
||||
import _ from 'lodash'
|
||||
|
||||
import { Client } from 'xrpl-local'
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import net from 'net'
|
||||
|
||||
import { assert } from 'chai'
|
||||
import _ from 'lodash'
|
||||
|
||||
import {
|
||||
Client,
|
||||
|
||||
Reference in New Issue
Block a user