Compare commits

...

4 Commits

Author SHA1 Message Date
Mayukha Vadari
9fa3f73d5a import from lodash/ 2021-10-18 18:30:25 -04:00
Mayukha Vadari
9bf7df868e remove omitBy 2021-10-18 18:30:25 -04:00
Mayukha Vadari
3134dc112f remove flatmap 2021-10-18 18:30:25 -04:00
Mayukha Vadari
915118265f remove flatten 2021-10-18 18:30:25 -04:00
9 changed files with 62 additions and 50 deletions

View File

@@ -62,8 +62,7 @@ function getAgent(url: string, config: ConnectionOptions): Agent | undefined {
const parsedURL = new URL(url)
const parsedProxyURL = new URL(config.proxy)
const proxyOptions = _.omitBy(
{
const proxyOptions = {
secureEndpoint: parsedURL.protocol === 'wss:',
secureProxy: parsedProxyURL.protocol === 'https:',
auth: config.proxyAuthorization,
@@ -82,9 +81,7 @@ function getAgent(url: string, config: ConnectionOptions): Agent | undefined {
pathname: parsedProxyURL.pathname,
search: parsedProxyURL.search,
hash: parsedProxyURL.hash,
},
(value) => value == null,
)
}
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(
{
const optionsOverrides = {
ca: config.trustedCertificates,
key: config.key,
passphrase: config.passphrase,
cert: config.certificate,
},
(value) => value == null,
)
}
const websocketOptions = { ...options, ...optionsOverrides }
const websocket = new WebSocket(url, websocketOptions)
/*

View File

@@ -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), {})
)
}

View File

@@ -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 !== '') {

View File

@@ -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,
)

View File

@@ -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())
}

View 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 {}

View File

@@ -1,5 +1,4 @@
import { assert } from 'chai'
import _ from 'lodash'
import { ServerInfoResponse } from '../src'

View File

@@ -1,5 +1,4 @@
import { assert } from 'chai'
import _ from 'lodash'
import { Client } from 'xrpl-local'

View File

@@ -2,7 +2,6 @@
import net from 'net'
import { assert } from 'chai'
import _ from 'lodash'
import {
Client,