Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add net price tooltip to GE records #475

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/routes/account/grand-exchange.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h, Fragment } from 'preact'
import ago from 's-ago'
import { numberWithCommas } from '../../util'
import { numberWithCommas, determineTax } from '../../util'
import { connect } from 'react-redux'
import {
fetchGe,
Expand Down Expand Up @@ -42,8 +42,11 @@ const buildRecord = record => (
<p class="mb-0">
<img src={`/img/ge_${record.buy ? 'bought' : 'sold'}.png`} alt="" />
<span>{record.buy ? 'Bought' : 'Sold'}</span> for{' '}
<span>{numberWithCommas(record.price * record.quantity)}</span> gp (
<span>{numberWithCommas(record.price)}</span> gp/ea)
<span title={determineTax(record)}>
{' '}
{numberWithCommas(record.price * record.quantity)}
</span>{' '}
gp (<span>{numberWithCommas(record.price)}</span> gp/ea)
</p>
</div>
<div class="ge-record-timestamp ml-auto">
Expand Down
38 changes: 37 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const flattenMap = map => {
export const toMMSS = s => {
const minutes = Math.floor(s / 60)
// Weird arithmetic is needed here to prevent rounding errors due to JS's floating point math
const seconds = Math.round(s % 60 * 10) / 10
const seconds = Math.round((s % 60) * 10) / 10
const minutesStr = String(minutes).padStart(2, '0')
const secondsStr = String(seconds).padStart(2, '0')
return minutesStr + ':' + secondsStr
Expand Down Expand Up @@ -124,3 +124,39 @@ export const digest = (data, callback) => {
})
}
}

export const determineTax = item => {
if (item.buy) return ''

const exemptMessage = 'Item is exempt from tax'

const exemptItems = [
1755, // chisel
5343, // dibber
5325, // gardening trowel
1785, // glassblowing pipe
2347, // hammer
1733, // needle
233, // pestle and mortar
5341, // rake
8794, // saw
5329, // secateurs
1735, // shears
952, // spade
5331 // watering can (0)
]
const foundExemptItem = exemptItems.includes(item.itemId)
if (foundExemptItem) return exemptMessage

if (item.price < 100) return exemptMessage
if (item.price > 499999999) return numberWithCommas(5000000)

const tax = Math.floor(item.price * 0.01) * item.quantity
const gross = item.price * item.quantity
const net = gross - tax
const netEach = Math.floor(net / item.quantity)

return `Net of ${numberWithCommas(net)} gp = ${numberWithCommas(
gross
)} - ${numberWithCommas(tax)} (${numberWithCommas(netEach)} gp/ea)`
}