Skip to content

Commit

Permalink
add "custom" to show what profit is currently based on
Browse files Browse the repository at this point in the history
removed last client side profit calculation as this is now backend-side
  • Loading branch information
matthias-luger committed Feb 25, 2024
1 parent eca50d2 commit 654afd5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
6 changes: 3 additions & 3 deletions components/Flipper/Flipper.tsx
Expand Up @@ -14,7 +14,7 @@ import { FixedSizeList as List } from 'react-window'
import { v4 as generateUUID } from 'uuid'
import api from '../../api/ApiHelper'
import { CUSTOM_EVENTS } from '../../api/ApiTypes.d'
import { calculateProfit, DEFAULT_FLIP_SETTINGS, DEMO_FLIP, getFlipCustomizeSettings } from '../../utils/FlipUtils'
import { DEFAULT_FLIP_SETTINGS, DEMO_FLIP, getFlipCustomizeSettings } from '../../utils/FlipUtils'
import { useWasAlreadyLoggedIn } from '../../utils/Hooks'
import { getLoadingElement } from '../../utils/LoadingUtils'
import { getHighestPriorityPremiumProduct, getPremiumType, hasHighEnoughPremium, PREMIUM_RANK } from '../../utils/PremiumTypeUtils'
Expand Down Expand Up @@ -312,7 +312,7 @@ function Flipper(props: Props) {

missedInfo = {
estimatedProfitCopiedAuctions: missedInfo.estimatedProfitCopiedAuctions,
missedEstimatedProfit: newFlipAuction.sold ? missedInfo.missedEstimatedProfit + calculateProfit(newFlipAuction) : missedInfo.missedEstimatedProfit,
missedEstimatedProfit: newFlipAuction.sold ? missedInfo.missedEstimatedProfit + newFlipAuction.profit : missedInfo.missedEstimatedProfit,
missedFlipsCount: newFlipAuction.sold ? missedInfo.missedFlipsCount + 1 : missedInfo.missedFlipsCount,
totalFlips: missedInfo.totalFlips + 1
}
Expand Down Expand Up @@ -346,7 +346,7 @@ function Flipper(props: Props) {
function onCopyFlip(flip: FlipAuction) {
let settings = getFlipCustomizeSettings()
let currentMissedInfo = missedInfo
currentMissedInfo.estimatedProfitCopiedAuctions += calculateProfit(flip, settings)
currentMissedInfo.estimatedProfitCopiedAuctions += flip.profit
flip.isCopied = true
setFlips(flips)
}
Expand Down
18 changes: 12 additions & 6 deletions components/Flipper/FlipperFilter/FlipperFilter.tsx
Expand Up @@ -8,7 +8,7 @@ import { NumericFormat } from 'react-number-format'
import { v4 as generateUUID } from 'uuid'
import api from '../../../api/ApiHelper'
import { CUSTOM_EVENTS } from '../../../api/ApiTypes.d'
import { getFlipCustomizeSettings, isCurrentCalculationBasedOnLbin } from '../../../utils/FlipUtils'
import { getFlipCustomizeSettings, getCurrentProfitCalculationState } from '../../../utils/FlipUtils'
import { getDecimalSeparator, getThousandSeparator } from '../../../utils/Formatter'
import { FLIPPER_FILTER_KEY, FLIP_CUSTOMIZING_KEY, getSettingsObject, mapRestrictionsToApiFormat, setSetting } from '../../../utils/SettingsUtils'
import Tooltip from '../../Tooltip/Tooltip'
Expand Down Expand Up @@ -89,7 +89,9 @@ function FlipperFilter(props: Props) {
}

function onProfitCalculationButtonClick() {
if (isCurrentCalculationBasedOnLbin(flipCustomizeSettings)) {
let flipPriceCalculationState = getCurrentProfitCalculationState(flipCustomizeSettings)

if (flipPriceCalculationState === 'lbin' || flipPriceCalculationState === 'custom') {
flipCustomizeSettings.finders = [1, 4]
flipCustomizeSettings.useLowestBinForProfit = false
api.setFlipSetting('lbin', false)
Expand Down Expand Up @@ -168,6 +170,8 @@ function FlipperFilter(props: Props) {
</Modal>
)

let flipPriceCalculationState = getCurrentProfitCalculationState(flipCustomizeSettings)

return (
<div className={styles.flipperFilter}>
<div className={styles.flipperFilterGroup}>
Expand Down Expand Up @@ -258,22 +262,24 @@ function FlipperFilter(props: Props) {
type="hover"
content={<Form.Label className={`${styles.flipperFilterFormfieldLabel}`}>Profit based on</Form.Label>}
tooltipContent={
isCurrentCalculationBasedOnLbin(flipCustomizeSettings) ? (
flipPriceCalculationState === 'lbin' ? (
<span>
Profit is currently based off the lowest bin of similar items. Lbin Flips (also called snipes) will not show if there is no
similar auction on ah. Auctions shown are expected to sell quickly. There is very high competition for these types of
auctions.
</span>
) : (
) : flipPriceCalculationState === 'median' ? (
<span>
Profit is currently based off the weighted median sell value of similar items (so called references). This is the
recommended setting as it makes the most money over all and prices items based on daily and weekly price swings. But items
may only sell after days.
</span>
)
) : undefined
}
/>
<Button onClick={onProfitCalculationButtonClick}>{isCurrentCalculationBasedOnLbin(flipCustomizeSettings) ? 'Lowest BIN' : 'Median'}</Button>
<Button onClick={onProfitCalculationButtonClick}>
{flipPriceCalculationState === 'lbin' ? 'Lowest BIN' : flipPriceCalculationState === 'median' ? 'Median' : 'Custom'}
</Button>
</Form.Group>
<Form.Group
onClick={() => {
Expand Down
30 changes: 21 additions & 9 deletions utils/FlipUtils.tsx
Expand Up @@ -201,14 +201,26 @@ export const DEFAULT_FLIP_SETTINGS = {
} as FlipperFilter
}

export function isCurrentCalculationBasedOnLbin(flipCustomizeSettings: FlipCustomizeSettings) {
return (flipCustomizeSettings.finders?.length === 1 && flipCustomizeSettings.finders[0].toString() === '2') || flipCustomizeSettings.useLowestBinForProfit
}

export function calculateProfit(flip: FlipAuction, settings?: FlipCustomizeSettings) {
if (flip.finder === 2 || (settings && isCurrentCalculationBasedOnLbin(settings))) {
return flip.lowestBin - flip.cost
} else {
return flip.median - flip.cost
export function getCurrentProfitCalculationState(flipCustomizeSettings: FlipCustomizeSettings): 'lbin' | 'median' | 'custom' {
if (flipCustomizeSettings.useLowestBinForProfit) {
return 'lbin'
}
if (flipCustomizeSettings.finders?.length === 1 && flipCustomizeSettings.finders[0].toString() === '2') {
return 'lbin'
}
if (flipCustomizeSettings.finders?.length === 1 && flipCustomizeSettings.finders[0].toString() === '1') {
return 'median'
}
if (flipCustomizeSettings.finders?.length === 1 && flipCustomizeSettings.finders[0].toString() === '4') {
return 'median'
}
if (
flipCustomizeSettings.finders?.length === 2 &&
flipCustomizeSettings.finders.find(f => f.toString() === '1') &&
flipCustomizeSettings.finders.find(f => f.toString() === '4')
) {
return 'median'
}

return 'custom'
}

0 comments on commit 654afd5

Please sign in to comment.