Skip to content
Open
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
32 changes: 32 additions & 0 deletions api/resolvers/price.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,42 @@ const getPrice = cachedFetcher(async function fetchPrice (fiat = 'USD') {
keyGenerator: (fiat = 'USD') => fiat
})

const getBigMacPrice = cachedFetcher(async function fetchBigMacPrice () {
const csvUrl = 'https://raw.githubusercontent.com/TheEconomist/big-mac-data/master/output-data/big-mac-raw-index.csv'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good enough for the first version, but I think it would be a lot cooler if the data would update more frequently. It seems to update every 6 months but for some reason, the last update is 2025-01-01, not 2025-07-01 🤔

They documented here how they calculated it.

I think it would be really funny if we would have the most up-to-date big mac prices just to show them in sats, could be good for marketing haha

But as mentioned, more something for a follow-up PR, #2502 is only labeled as good-first-issue anyway.

Copy link
Member

@ekzyis ekzyis Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I forgot the number we display is going to update frequently because we calculate it in sats anyway. I thought we would just be staring at the same number for a long time.

And I assume Big Mac prices in USD don't update that often, that's why The Economist is also not issuing updates very often.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to find a more frequently updated price source but Big Macs are as stable as gold ahah

try {
const res = await fetch(csvUrl)
const csvText = await res.text()
const lines = csvText.split('\n')
const usaEntries = lines
.filter(line => line.includes(',USA,USD,'))
.map(line => {
const cols = line.split(',')
return {
date: cols[0],
price: parseFloat(cols[4])
}
})
.filter(entry => !isNaN(entry.price))
.sort((a, b) => new Date(b.date) - new Date(a.date))
return usaEntries[0]?.price || 5.79
} catch (err) {
console.error('Big Mac price fetch error:', err)
return 5.79
}
}, {
maxSize: 1,
cacheExpiry: 24 * 60 * 60 * 1000,
forceRefreshThreshold: 0,
keyGenerator: () => 'bigmac-usd'
})

export default {
Query: {
price: async (parent, { fiatCurrency }, ctx) => {
return await getPrice(fiatCurrency) || -1
},
bigMacPrice: async () => {
return await getBigMacPrice() || 5.79
}
}
}
1 change: 1 addition & 0 deletions api/typeDefs/price.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { gql } from 'graphql-tag'
export default gql`
extend type Query {
price(fiatCurrency: String): Float
bigMacPrice: Float
}
`
3 changes: 2 additions & 1 deletion components/nav/price-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const carousel = [
'1btc',
'blockHeight',
'chainFee',
'halving'
'halving',
'bigmac'
]

export const PriceCarouselContext = createContext({
Expand Down
19 changes: 15 additions & 4 deletions components/price.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { usePriceCarousel } from './nav/price-carousel'

export const PriceContext = React.createContext({
price: null,
fiatSymbol: null
fiatSymbol: null,
bigMacPrice: null
})

export function usePrice () {
Expand All @@ -34,8 +35,9 @@ export function PriceProvider ({ price, children }) {

const contextValue = useMemo(() => ({
price: data?.price || price,
fiatSymbol: CURRENCY_SYMBOLS[fiatCurrency] || '$'
}), [data?.price, price, me?.privates?.fiatCurrency])
fiatSymbol: CURRENCY_SYMBOLS[fiatCurrency] || '$',
bigMacPrice: data?.bigMacPrice || 5.79
}), [data?.price, data?.bigMacPrice, price, me?.privates?.fiatCurrency])

return (
<PriceContext.Provider value={contextValue}>
Expand All @@ -56,7 +58,7 @@ function AccessibleButton ({ id, description, children, ...props }) {
export default function Price ({ className }) {
const [selection, handleClick] = usePriceCarousel()

const { price, fiatSymbol } = usePrice()
const { price, fiatSymbol, bigMacPrice } = usePrice()
const { height: blockHeight, halving } = useBlockHeight()
const { fee: chainFee } = useChainFee()

Expand Down Expand Up @@ -106,6 +108,15 @@ export default function Price ({ className }) {
)
}

if (selection === 'bigmac') {
if (!price || price < 0 || !bigMacPrice) return null
return (
<AccessibleButton id='bigmac-hint' description='Show satoshis per Big Mac' className={compClassName} onClick={handleClick} variant='link'>
{fixedDecimal(Math.round((bigMacPrice / price) * 100000000), 0)} sats/Big Mac
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe sats/🍔 is better

Copy link
Member

@Soxasora Soxasora Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's a Whopper instead? 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can put the whole MC menu :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, I like sats/Big Mac more than sats/🍔 😅

</AccessibleButton>
)
}

if (selection === 'fiat') {
if (!price || price < 0) return null
return (
Expand Down
1 change: 1 addition & 0 deletions fragments/price.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { gql } from '@apollo/client'
export const PRICE = gql`
query price($fiatCurrency: String) {
price(fiatCurrency: $fiatCurrency)
bigMacPrice
}`