Skip to content

Commit

Permalink
Merge pull request #135 from helium/mbthiery/updated-api
Browse files Browse the repository at this point in the history
Updated api
  • Loading branch information
mbthiery authored Aug 29, 2024
2 parents d6d6dea + bc26c43 commit b2a677a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 86 deletions.
37 changes: 16 additions & 21 deletions src/components/Header/HotspotSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { isValidCell } from "h3-js"
import { useRouter } from "next/navigation"
import { Fragment, useCallback, useState } from "react"
import { useDebouncedCallback } from "use-debounce"
import { Hotspot } from "../HotspotsMap/HexHotspots"
import { HeliumIotIcon } from "../icons/HeliumIotIcon"
import { HeliumMobileIcon } from "../icons/HeliumMobileIcon"
import { LoadingIcon } from "../icons/LoadingIcon"
Expand All @@ -16,20 +17,11 @@ let controller: AbortController | null = null

const RESULTS_LIMIT = 20

export interface HotspotResult {
hotspot_id: string
location_res8: string
location_res12: string
name: string
owner: string
cell_count: number
}

export function HotspotSearch() {
const router = useRouter()
const [query, setQuery] = useState("")
const [open, setOpen] = useState(false)
const [searchResults, setSearchResults] = useState<HotspotResult[]>([])
const [searchResults, setSearchResults] = useState<Hotspot[]>([])
const [isLoading, setIsLoading] = useState(false)

const searchItemByQuery = useCallback(async (query: string) => {
Expand All @@ -46,17 +38,18 @@ export function HotspotSearch() {

try {
const searchUrl = new URL(
`${process.env.NEXT_PUBLIC_HOTSPOTTY_EXPLORER_API_URL}/search`
`${process.env.NEXT_PUBLIC_HELIUMGEEK_EXPLORER_API_URL}`
)
searchUrl.searchParams.append("name", query.trim().replaceAll(" ", "-"))
searchUrl.searchParams.append("name", query.trim())

const results = (await fetch(searchUrl, {
signal,
next: { revalidate: 10 },
headers: {
Authorization: `bearer ${process.env.NEXT_PUBLIC_HOTSPOTTY_EXPLORER_API_TOKEN}`,
"x-api-key": `${process.env.NEXT_PUBLIC_HELIUMGEEK_EXPLORER_API_TOKEN}`,
"Content-Type": "application/json",
},
}).then((res) => res.json())) as HotspotResult[]
}).then((res) => res.json())) as Hotspot[]

setSearchResults(results)
setIsLoading(false)
Expand All @@ -82,8 +75,8 @@ export function HotspotSearch() {
}, [])

const handleHotspotSelection = useCallback(
(hotspot: HotspotResult) => {
router.push(`/hex/${hotspot.location_res8}`)
(hotspot: Hotspot) => {
router.push(`/hex/${hotspot.location.hex}`)
setOpen(false)
},
[router]
Expand Down Expand Up @@ -163,13 +156,15 @@ export function HotspotSearch() {
{searchResults
.slice(0, RESULTS_LIMIT)
.map((hotspot) => {
const Avatar =
hotspot.cell_count > 0
? HeliumMobileIcon
: HeliumIotIcon
const { cbrs, wifi, mobile } =
hotspot.capabilities
const isMobile = cbrs || wifi || mobile
const Avatar = isMobile
? HeliumMobileIcon
: HeliumIotIcon
return (
<Combobox.Option
key={hotspot.hotspot_id}
key={hotspot.address}
value={hotspot}
className={({ active }) =>
clsx(
Expand Down
21 changes: 0 additions & 21 deletions src/components/HotspotsMap/Attribution.tsx

This file was deleted.

21 changes: 8 additions & 13 deletions src/components/HotspotsMap/HexHotspotItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client"

import { usePreferences } from "@/context/usePreferences"
import animalHash from "angry-purple-tiger"
import Link from "next/link"
import { gaEvent } from "../GATracker"
import { HeliumIotIcon } from "../icons/HeliumIotIcon"
Expand All @@ -15,23 +14,19 @@ type HexHotSpotItemProps = {
export const HexHotSpotItem = ({ hotspot }: HexHotSpotItemProps) => {
const { provider } = usePreferences()

const hotspotName = animalHash(hotspot.hotspot_id)
const hasSmallCells = hotspot.cells.length > 0
const Avatar = hasSmallCells ? HeliumMobileIcon : HeliumIotIcon
const subtitle = hasSmallCells
? `${hotspot.cells.length} small cell${
hotspot.cells.length === 1 ? "" : "s"
}`
: "IoT Hotspot"
const { cbrs, wifi, mobile } = hotspot.capabilities
const isMobile = cbrs || wifi || mobile
const Avatar = isMobile ? HeliumMobileIcon : HeliumIotIcon
const subtitle = isMobile ? `Mobile Hotspot` : "IoT Hotspot"

return (
<li key={hotspot.hotspot_id}>
<li key={hotspot.address}>
<div className="group relative flex items-center px-2 py-3">
<Link
href={
!provider
? `/preferences?redirect=${hotspot.hotspot_id}`
: provider.getUrl(hotspot.hotspot_id)
? `/preferences?redirect=${hotspot.address}`
: provider.getUrl(hotspot.address)
}
className="-m-1 block flex-1 p-1"
target={!!provider ? "_" : "_self"}
Expand All @@ -54,7 +49,7 @@ export const HexHotSpotItem = ({ hotspot }: HexHotSpotItemProps) => {
<Avatar className="inline-block h-8 w-8 flex-shrink-0" />
<div className="truncate">
<p className="truncate text-sm font-medium leading-5 text-gray-900 dark:text-zinc-100">
{hotspotName}
{hotspot.name}
</p>
<p className="truncate text-xs text-gray-600 dark:text-zinc-300">
{subtitle}
Expand Down
46 changes: 23 additions & 23 deletions src/components/HotspotsMap/HexHotspots.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
"use client"

import { Tooltip } from "@/app/stats/components/Tooltip"
import { PreferencesProvider } from "@/context/usePreferences"
import clsx from "clsx"
import { HexHotSpotItem } from "./HexHotspotItem"

interface SmallCell {
cell_id: string
}

export interface Hotspot {
hotspot_id: string
active: boolean
cells: SmallCell[]
}

interface HexData {
hex: string
resolution: number
hotspots: Hotspot[]
export type Hotspot = {
address: string
name: string
status: number
statusString: "active" | "inactive"
capabilities: {
mobile: boolean
iot: boolean
cbrs: boolean
wifi: boolean
}
location: {
hex: string
}
}

const RECENT = "recently rewarded"
Expand All @@ -38,22 +40,23 @@ function getGroupedHotspots(hotspots: Hotspot[]) {
}

hotspots.forEach((hotspot) => {
const group = hotspot.active ? RECENT : NOT_RECENT
const group = hotspot.status === 0 ? RECENT : NOT_RECENT
groupedHotspots[group].push(hotspot)
})

return groupedHotspots
}

export async function HexHotspots({ hexId }: { hexId: string }) {
const { hotspots } = (await fetch(
`${process.env.NEXT_PUBLIC_HOTSPOTTY_EXPLORER_API_URL}/hex/${hexId}`,
const hotspots = (await fetch(
`${process.env.NEXT_PUBLIC_HELIUMGEEK_EXPLORER_API_URL}/hex/${hexId}`,
{
headers: {
Authorization: `bearer ${process.env.NEXT_PUBLIC_HOTSPOTTY_EXPLORER_API_TOKEN}`,
"x-api-key": `${process.env.NEXT_PUBLIC_HELIUMGEEK_EXPLORER_API_TOKEN}`,
"Content-Type": "application/json",
},
}
).then((res) => res.json())) as HexData
).then((res) => res.json())) as Hotspot[]

const groupedList = getGroupedHotspots(hotspots)

Expand Down Expand Up @@ -97,10 +100,7 @@ export async function HexHotspots({ hexId }: { hexId: string }) {
className="z-0 flex-1 divide-y divide-gray-200 overflow-y-auto dark:divide-white/10"
>
{groupedList[group].map((hotspot) => (
<HexHotSpotItem
key={hotspot.hotspot_id}
hotspot={hotspot}
/>
<HexHotSpotItem key={hotspot.address} hotspot={hotspot} />
))}
</ul>
</PreferencesProvider>
Expand Down
3 changes: 0 additions & 3 deletions src/components/HotspotsMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Map, {
Source,
} from "react-map-gl"
import { gaEvent } from "../GATracker"
import { Attribution } from "./Attribution"
import { NetworkCoverageLayer } from "./NetworkCoverageLayer"
import { mapLayersDark } from "./mapLayersDark"
import { mapLayersLight } from "./mapLayersLight"
Expand Down Expand Up @@ -159,8 +158,6 @@ export function HotspotsMap({ children }: { children: React.ReactNode }) {
<NavigationControl position="bottom-left" showCompass={false} />
{children}

{segment !== "stats" && <Attribution />}

{segment !== "mobile" && (
<NetworkCoverageLayer layer={networkLayers.iot} />
)}
Expand Down
10 changes: 5 additions & 5 deletions src/components/HotspotsMap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ export const networkLayers: { [network: string]: NetworkCoverageLayerOption } =
name: "IOT",
icon: HeliumIotIcon,
color: HELIUM_IOT_COLOR,
sourceDomain: process.env.NEXT_PUBLIC_HOTSPOTTY_TILESERVER_URL!,
sourceDomain: process.env.NEXT_PUBLIC_HELIUMGEEK_TILESERVER_URL!,
points: {
sourcePath: "public.helium_iot_points.json",
sourceLayer: "public.helium_iot_points",
sourcePath: "hg.gateways-rewarded-r8.points.json",
sourceLayer: "hg.gateways-rewarded-r8.points",
},
hexes: {
sourcePath: "public.helium_iot_hexes.json",
sourceLayer: "public.helium_iot_hexes",
sourcePath: "hg.gateways-rewarded-r8.hexes.json",
sourceLayer: "hg.gateways-rewarded-r8.hexes",
},
},
}
3 changes: 3 additions & 0 deletions src/knex/supplyLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export class SupplyLimit {
const hasBurnIncrease =
record.hnt_burned > (latestBurn?.hnt_burned || BigInt(0))

// HEROKU_PR_NUMBER injected to env vars when review app.
if (!!process.env.HEROKU_PR_NUMBER) return latest || latestBurn || record

if (
// first time app is run
(!latest && !latestBurn) ||
Expand Down

0 comments on commit b2a677a

Please sign in to comment.