From 204073eb61ed7ea15607d2bbdb349a4fb49e9687 Mon Sep 17 00:00:00 2001 From: Alexander Drozdov Date: Sun, 11 Sep 2022 23:46:26 +0300 Subject: [PATCH] poeprices dev decided to leave it as is for now, #730 --- renderer/src/web/background/Prices.ts | 28 ++++++++----------- renderer/src/web/overlay/WidgetItemSearch.vue | 2 +- .../filters/FilterModifierAnointment.vue | 2 +- .../price-check/price-prediction/poeprices.ts | 16 +++++++++-- .../related-items/RelatedItems.vue | 2 +- .../price-check/stack-value/StackValue.vue | 2 +- .../src/web/price-check/trends/PriceTrend.vue | 2 +- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/renderer/src/web/background/Prices.ts b/renderer/src/web/background/Prices.ts index c60adab6..0f6378bf 100644 --- a/renderer/src/web/background/Prices.ts +++ b/renderer/src/web/background/Prices.ts @@ -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' diff --git a/renderer/src/web/overlay/WidgetItemSearch.vue b/renderer/src/web/overlay/WidgetItemSearch.vue index 0a77998c..b852780d 100644 --- a/renderer/src/web/overlay/WidgetItemSearch.vue +++ b/renderer/src/web/overlay/WidgetItemSearch.vue @@ -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 = '' } diff --git a/renderer/src/web/price-check/filters/FilterModifierAnointment.vue b/renderer/src/web/price-check/filters/FilterModifierAnointment.vue index be75bdb9..ea8c9518 100644 --- a/renderer/src/web/price-check/filters/FilterModifierAnointment.vue +++ b/renderer/src/web/price-check/filters/FilterModifierAnointment.vue @@ -48,7 +48,7 @@ export default defineComponent({ return { icons: oils.map(item => item!.icon), price: (totalChaos != null) - ? autoCurrency(totalChaos, 'chaos') + ? autoCurrency(totalChaos) : undefined } }) diff --git a/renderer/src/web/price-check/price-prediction/poeprices.ts b/renderer/src/web/price-check/price-prediction/poeprices.ts index 7b8dc6c3..1ded4c68 100644 --- a/renderer/src/web/price-check/price-prediction/poeprices.ts +++ b/renderer/src/web/price-check/price-prediction/poeprices.ts @@ -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(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 { diff --git a/renderer/src/web/price-check/related-items/RelatedItems.vue b/renderer/src/web/price-check/related-items/RelatedItems.vue index ccbd4920..901cb908 100644 --- a/renderer/src/web/price-check/related-items/RelatedItems.vue +++ b/renderer/src/web/price-check/related-items/RelatedItems.vue @@ -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) } } diff --git a/renderer/src/web/price-check/stack-value/StackValue.vue b/renderer/src/web/price-check/stack-value/StackValue.vue index 759d6a0a..ac474fd6 100644 --- a/renderer/src/web/price-check/stack-value/StackValue.vue +++ b/renderer/src/web/price-check/stack-value/StackValue.vue @@ -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}` } diff --git a/renderer/src/web/price-check/trends/PriceTrend.vue b/renderer/src/web/price-check/trends/PriceTrend.vue index f867770a..e0b0d1f0 100644 --- a/renderer/src/web/price-check/trends/PriceTrend.vue +++ b/renderer/src/web/price-check/trends/PriceTrend.vue @@ -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,