mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2026-09-19 19:25:53 +00:00
poeprices dev decided to leave it as is for now, #730
This commit is contained in:
@@ -143,31 +143,27 @@ export function findPriceByQuery (query: DbQuery) {
|
||||
return null
|
||||
}
|
||||
|
||||
export function autoCurrency (value: number, currency: 'chaos' | 'div'): { min: number, max: number, currency: 'chaos' | 'div' } {
|
||||
if (currency === 'chaos') {
|
||||
if (value > ((xchgRate.value || 9999) * 0.94)) {
|
||||
if (value < ((xchgRate.value || 9999) * 1.06)) {
|
||||
return { min: 1, max: 1, currency: 'div' }
|
||||
} else {
|
||||
return { min: chaosToStable(value), max: chaosToStable(value), currency: 'div' }
|
||||
}
|
||||
export function autoCurrency (value: number | [number, number]): { min: number, max: number, currency: 'chaos' | 'div' } {
|
||||
if (Array.isArray(value)) {
|
||||
if (value[1] > (xchgRate.value || 9999)) {
|
||||
return { min: chaosToStable(value[0]), max: chaosToStable(value[1]), currency: 'div' }
|
||||
}
|
||||
} else if (currency === 'div') {
|
||||
if (value < 1) {
|
||||
return { min: stableToChaos(value), max: stableToChaos(value), currency: 'chaos' }
|
||||
return { min: value[0], max: value[1], currency: 'chaos' }
|
||||
}
|
||||
if (value > ((xchgRate.value || 9999) * 0.94)) {
|
||||
if (value < ((xchgRate.value || 9999) * 1.06)) {
|
||||
return { min: 1, max: 1, currency: 'div' }
|
||||
} else {
|
||||
return { min: chaosToStable(value), max: chaosToStable(value), currency: 'div' }
|
||||
}
|
||||
}
|
||||
return { min: value, max: value, currency }
|
||||
return { min: value, max: value, currency: 'chaos' }
|
||||
}
|
||||
|
||||
function chaosToStable (count: number) {
|
||||
return count / (xchgRate.value || 9999)
|
||||
}
|
||||
|
||||
function stableToChaos (count: number) {
|
||||
return count * (xchgRate.value || 9999)
|
||||
}
|
||||
|
||||
export function displayRounding (value: number, fraction: boolean = false): string {
|
||||
if (fraction && Math.abs(value) < 1) {
|
||||
if (value === 0) return '0'
|
||||
|
||||
@@ -166,7 +166,7 @@ export default defineComponent({
|
||||
name: item.name,
|
||||
icon: item.icon,
|
||||
chaos: price?.chaos,
|
||||
price: (price != null) ? autoCurrency(price.chaos, 'chaos') : undefined
|
||||
price: (price != null) ? autoCurrency(price.chaos) : undefined
|
||||
})
|
||||
searchValue.value = ''
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export default defineComponent({
|
||||
return {
|
||||
icons: oils.map(item => item!.icon),
|
||||
price: (totalChaos != null)
|
||||
? autoCurrency(totalChaos, 'chaos')
|
||||
? autoCurrency(totalChaos)
|
||||
: undefined
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2,11 +2,12 @@ import { ParsedItem } from '@/parser'
|
||||
import { selected as league } from '@/web/background/Leagues'
|
||||
import { MainProcess } from '@/web/background/IPC'
|
||||
import { Cache } from '../trade/Cache'
|
||||
import { autoCurrency, findPriceByQuery } from '@/web/background/Prices'
|
||||
|
||||
const cache = new Cache()
|
||||
|
||||
interface PoepricesApiResponse { /* eslint-disable camelcase */
|
||||
currency: 'chaos' | 'divine'
|
||||
currency: 'chaos' | 'divine' | 'exalt'
|
||||
error: number
|
||||
error_msg: string
|
||||
warning_msg: string
|
||||
@@ -50,8 +51,17 @@ export async function requestPoeprices (item: ParsedItem): Promise<RareItemPrice
|
||||
cache.set<PoepricesApiResponse>(query, data, 300)
|
||||
}
|
||||
|
||||
if (data.currency !== 'divine' && data.currency !== 'chaos') {
|
||||
throw new Error('poeprices.info gave the price in Exalted Orbs.')
|
||||
if (data.currency === 'exalt') {
|
||||
const xchgExalted = findPriceByQuery({ ns: 'ITEM', name: 'Exalted Orb', variant: undefined })
|
||||
if (!xchgExalted) {
|
||||
throw new Error('poeprices.info gave the price in Exalted Orbs.')
|
||||
}
|
||||
const converted = autoCurrency([data.min * xchgExalted.chaos, data.max * xchgExalted.chaos])
|
||||
data.min = converted.min
|
||||
data.max = converted.max
|
||||
data.currency = (converted.currency === 'div') ? 'divine' : 'chaos'
|
||||
} else if (data.currency !== 'divine' && data.currency !== 'chaos') {
|
||||
throw new Error('poeprices.info gave the price in unknown currency.')
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -48,7 +48,7 @@ function findPriceByQueryId (queryId: string) {
|
||||
const [name, variant] = encodedName.split(' // ')
|
||||
const priceEntry = findPriceByQuery({ ns, name, variant })
|
||||
if (priceEntry) {
|
||||
return autoCurrency(priceEntry.chaos, 'chaos')
|
||||
return autoCurrency(priceEntry.chaos)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export default defineComponent({
|
||||
|
||||
const price = (props.item.info.refName === 'Divine Orb')
|
||||
? { min: n * one.chaos, max: n * one.chaos, currency: 'chaos' as const }
|
||||
: autoCurrency(n * one.chaos, 'chaos')
|
||||
: autoCurrency(n * one.chaos)
|
||||
|
||||
return `${displayRounding(price.min)} ${price.currency}`
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export default defineComponent({
|
||||
|
||||
const price = (props.item.info.refName === 'Divine Orb')
|
||||
? { min: trend.chaos, max: trend.chaos, currency: 'chaos' as const }
|
||||
: autoCurrency(trend.chaos, 'chaos')
|
||||
: autoCurrency(trend.chaos)
|
||||
|
||||
return {
|
||||
price: price,
|
||||
|
||||
Reference in New Issue
Block a user