Skip to content

Commit

Permalink
Fix onboarding bugs and add locations to hotspots
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Oct 5, 2023
1 parent ac4c8da commit eea1d99
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/hooks/useHotspotAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useMemo } from 'react'
import { HotspotWithPendingRewards } from '../types/solana'

function withOptComma(value: string | undefined) {
if (value) {
return `${value}, `
}

return ''
}

export function useHotspotAddress(
hotspot: HotspotWithPendingRewards | undefined,
): string | undefined {
const { metadata } = hotspot?.content || {}
const attributes = useMemo(() => {
return metadata?.attributes?.reduce((acc, att) => {
if (att && att.trait_type && typeof att.value !== 'undefined') {
acc[att.trait_type] = att.value
}
return acc
}, {} as Record<string, string>)
}, [metadata])
return useMemo(() => {
if (attributes) {
const street = attributes.iot_street || attributes.mobile_street || ''
const city = attributes.iot_city || attributes.mobile_city || ''
const state = attributes.iot_state || attributes.mobile_state || ''

return `${withOptComma(street)}${withOptComma(city)}${withOptComma(
state,
)}`
}
}, [attributes])
}

0 comments on commit eea1d99

Please sign in to comment.