mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2026-09-27 15:15:48 +00:00
make functions more pure
This commit is contained in:
@@ -15,7 +15,9 @@ export function createFilters (item: ParsedItem): ItemFilters {
|
||||
trade: {
|
||||
offline: false,
|
||||
listed: undefined,
|
||||
league: league.value!
|
||||
league: league.value!,
|
||||
chaosPriceThreshold: cfg.chaosPriceThreshold,
|
||||
collapseListings: cfg.collapseListings
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ export interface ItemFilters {
|
||||
offline: boolean
|
||||
listed: string | undefined
|
||||
league: string
|
||||
chaosPriceThreshold: number
|
||||
collapseListings: 'api' | 'app'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ function useBulkApi () {
|
||||
;(async function () {
|
||||
try {
|
||||
requested = true
|
||||
items.value = await requestResults(query.queryId, query.listedIds.slice(0, 20))
|
||||
items.value = await requestResults(query.queryId, query.listedIds.slice(0, 20), { accountName: Config.store.accountName })
|
||||
} catch (err) {
|
||||
error.value = (err as Error).message
|
||||
}
|
||||
|
||||
@@ -185,11 +185,11 @@ function useTradeApi () {
|
||||
// first two req are parallel, then sequential on demand
|
||||
{
|
||||
const r1 = (_searchResult.result.length > 0)
|
||||
? requestResults(_searchResult.id, _searchResult.result.slice(0, 10))
|
||||
? requestResults(_searchResult.id, _searchResult.result.slice(0, 10), { accountName: Config.store.accountName })
|
||||
.then(results => { _fetchResults.push(...results) })
|
||||
: Promise.resolve()
|
||||
const r2 = (_searchResult.result.length > 10)
|
||||
? requestResults(_searchResult.id, _searchResult.result.slice(10, 20))
|
||||
? requestResults(_searchResult.id, _searchResult.result.slice(10, 20), { accountName: Config.store.accountName })
|
||||
.then(results => r1
|
||||
.then(() => { _fetchResults.push(...results) }))
|
||||
: Promise.resolve()
|
||||
@@ -207,7 +207,7 @@ function useTradeApi () {
|
||||
fetched < _searchResult.total &&
|
||||
fetched < API_FETCH_LIMIT
|
||||
) {
|
||||
await requestResults(_searchResult.id, _searchResult.result.slice(fetched, fetched + 10))
|
||||
await requestResults(_searchResult.id, _searchResult.result.slice(fetched, fetched + 10), { accountName: Config.store.accountName })
|
||||
.then(results => { _fetchResults.push(...results) })
|
||||
fetched += 10
|
||||
return fetchMore()
|
||||
|
||||
@@ -5,7 +5,6 @@ import { RateLimiter } from './RateLimiter'
|
||||
import { ItemFilters } from '../filters/interfaces'
|
||||
import { ParsedItem } from '@/parser'
|
||||
import { Cache } from './Cache'
|
||||
import { Config } from '@/web/Config'
|
||||
|
||||
interface TradeRequest { /* eslint-disable camelcase */
|
||||
exchange: {
|
||||
@@ -80,7 +79,11 @@ async function requestTradeResultList (body: TradeRequest): Promise<SearchResult
|
||||
return data
|
||||
}
|
||||
|
||||
export async function requestResults (queryId: string, resultIds: string[]): Promise<PricingResult[]> {
|
||||
export async function requestResults (
|
||||
queryId: string,
|
||||
resultIds: string[],
|
||||
opts: { accountName: string }
|
||||
): Promise<PricingResult[]> {
|
||||
interface ResponseT { result: FetchResult[], error: SearchResult['error'] }
|
||||
let data = cache.get<ResponseT>(resultIds)
|
||||
|
||||
@@ -107,7 +110,7 @@ export async function requestResults (queryId: string, resultIds: string[]): Pro
|
||||
exchangeAmount: result.listing.price.exchange.amount,
|
||||
itemAmount: result.listing.price.item.amount,
|
||||
stock: result.listing.price.item.stock,
|
||||
isMine: (result.listing.account.name === Config.store.accountName),
|
||||
isMine: (result.listing.account.name === opts.accountName),
|
||||
ign: result.listing.account.lastCharacterName,
|
||||
accountName: result.listing.account.name,
|
||||
accountStatus: result.listing.account.online
|
||||
|
||||
@@ -5,8 +5,6 @@ import { MainProcess } from '@/ipc/main-process-bindings'
|
||||
import { SearchResult, Account, getTradeEndpoint, adjustRateLimits, RATE_LIMIT_RULES, preventQueueCreation } from './common'
|
||||
import { STAT_BY_REF, TRANSLATED_ITEM_NAME_BY_REF } from '@/assets/data'
|
||||
import { RateLimiter } from './RateLimiter'
|
||||
import { Config } from '@/web/Config'
|
||||
import { PriceCheckWidget } from '@/web/overlay/interfaces'
|
||||
import { ModifierType } from '@/parser/modifiers'
|
||||
import { Cache } from './Cache'
|
||||
|
||||
@@ -236,14 +234,12 @@ export function createTradeRequest (filters: ItemFilters, stats: StatFilter[], i
|
||||
}
|
||||
const { query } = body
|
||||
|
||||
{
|
||||
const cfg = Config.store.widgets.find(w => w.wmType === 'price-check') as PriceCheckWidget
|
||||
if (cfg.chaosPriceThreshold !== 0) {
|
||||
prop.set(query.filters, 'trade_filters.filters.price.min', cfg.chaosPriceThreshold)
|
||||
}
|
||||
if (cfg.collapseListings === 'api') {
|
||||
prop.set(query.filters, 'trade_filters.filters.collapse.option', String(true))
|
||||
}
|
||||
if (filters.trade.chaosPriceThreshold !== 0) {
|
||||
prop.set(query.filters, 'trade_filters.filters.price.min', filters.trade.chaosPriceThreshold)
|
||||
}
|
||||
|
||||
if (filters.trade.collapseListings === 'api') {
|
||||
prop.set(query.filters, 'trade_filters.filters.collapse.option', String(true))
|
||||
}
|
||||
|
||||
if (filters.trade.listed) {
|
||||
@@ -541,7 +537,11 @@ export async function requestTradeResultList (body: TradeRequest, leagueId: stri
|
||||
return data
|
||||
}
|
||||
|
||||
export async function requestResults (queryId: string, resultIds: string[]): Promise<PricingResult[]> {
|
||||
export async function requestResults (
|
||||
queryId: string,
|
||||
resultIds: string[],
|
||||
opts: { accountName: string }
|
||||
): Promise<PricingResult[]> {
|
||||
interface ResponseT { result: FetchResult[], error: SearchResult['error'] }
|
||||
let data = cache.get<ResponseT>(resultIds)
|
||||
|
||||
@@ -572,7 +572,7 @@ export async function requestResults (queryId: string, resultIds: string[]): Pro
|
||||
listedAt: result.listing.indexed,
|
||||
priceAmount: result.listing.price?.amount ?? 0,
|
||||
priceCurrency: result.listing.price?.currency ?? 'no price',
|
||||
isMine: (result.listing.account.name === Config.store.accountName),
|
||||
isMine: (result.listing.account.name === opts.accountName),
|
||||
ign: result.listing.account.lastCharacterName,
|
||||
accountName: result.listing.account.name,
|
||||
accountStatus: result.listing.account.online
|
||||
|
||||
Reference in New Issue
Block a user