From 55fb69cadc142a613762e1b8717cbbe95daf0b0a Mon Sep 17 00:00:00 2001 From: Ray Jacobson Date: Tue, 30 Dec 2025 14:00:38 -0800 Subject: [PATCH] Revert "Fix react-hono example (#13389)" This reverts commit 9fc6ff2d5ac78a32a1c4cab9a77e6670b06cbed9. --- .../examples/react-hono/src/client/App.tsx | 29 ++++++++++--------- .../react-hono/src/client/hooks/useSdk.ts | 25 +--------------- .../tests/e2e/react-hono/react-hono.test.ts | 18 +++++++----- 3 files changed, 28 insertions(+), 44 deletions(-) diff --git a/packages/create-audius-app/examples/react-hono/src/client/App.tsx b/packages/create-audius-app/examples/react-hono/src/client/App.tsx index 4ccbf4cd666..11b885ca9f9 100644 --- a/packages/create-audius-app/examples/react-hono/src/client/App.tsx +++ b/packages/create-audius-app/examples/react-hono/src/client/App.tsx @@ -17,11 +17,10 @@ import { hc } from 'hono/client' import { css } from '@emotion/react' import { useSdk } from './hooks/useSdk' import { useAuth } from './contexts/AuthProvider' -import type { AppType } from '..' +import { AppType } from '..' import { Status } from './contexts/types' -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const client = hc('/') as any +const client = hc('/') export default function App() { const { sdk } = useSdk() @@ -83,12 +82,12 @@ export default function App() { const { data: tracks } = await res.json() setTracks(tracks ?? []) - const trackFavorites = (tracks ?? []).reduce( - (result: Record, track: FullSdk.TrackFull) => ({ + const trackFavorites = (tracks ?? []).reduce>( + (result, track) => ({ ...result, [track.id]: track.hasCurrentUserSaved }), - {} as Record + {} ) setFavorites(trackFavorites) @@ -110,7 +109,7 @@ export default function App() { /** * Favorite or unfavorite a track. This requires a user to be authenticated and granted - * write permissions to the app. Uses the client-side SDK with hedgehog wallet for signing. + * write permissions to the app */ const favoriteTrack = (trackId: string, favorite = true): MouseEventHandler => @@ -120,14 +119,18 @@ export default function App() { setFavorites((prev) => ({ ...prev, [trackId]: favorite })) try { if (favorite) { - await sdk.tracks.favoriteTrack({ - userId: user.id, - trackId + await client.favorite.$post({ + json: { + userId: user.id, + trackId + } }) } else { - await sdk.tracks.unfavoriteTrack({ - userId: user.id, - trackId + await client.unfavorite.$post({ + json: { + userId: user.id, + trackId + } }) } } catch (e) { diff --git a/packages/create-audius-app/examples/react-hono/src/client/hooks/useSdk.ts b/packages/create-audius-app/examples/react-hono/src/client/hooks/useSdk.ts index 05ca15c83aa..42b274b27be 100644 --- a/packages/create-audius-app/examples/react-hono/src/client/hooks/useSdk.ts +++ b/packages/create-audius-app/examples/react-hono/src/client/hooks/useSdk.ts @@ -1,32 +1,9 @@ import { sdk } from '@audius/sdk' -import { Hedgehog } from '@audius/hedgehog' -import { createHedgehogWalletClient } from '@audius/sdk' const apiKey = import.meta.env.VITE_AUDIUS_API_KEY as string -// Initialize Hedgehog for write operations -// For OAuth apps, hedgehog reads the wallet from localStorage set by OAuth flow -// We use no-op functions since OAuth handles authentication -const getFn = async () => ({ iv: '', cipherText: '' }) -const setAuthFn = async () => ({ iv: '', cipherText: '' }) -const setUserFn = async () => ({}) - -const hedgehog = new Hedgehog( - getFn, - setAuthFn, - setUserFn, - true, // useLocalStorage - window.localStorage -) - -// Create SDK instance with hedgehog wallet for write operations -const audiusWalletClient = createHedgehogWalletClient(hedgehog) - const instance = sdk({ - apiKey, - services: { - audiusWalletClient - } + apiKey }) export const useSdk = () => ({ sdk: instance }) diff --git a/packages/create-audius-app/tests/e2e/react-hono/react-hono.test.ts b/packages/create-audius-app/tests/e2e/react-hono/react-hono.test.ts index bc342b29087..d07955af9d5 100644 --- a/packages/create-audius-app/tests/e2e/react-hono/react-hono.test.ts +++ b/packages/create-audius-app/tests/e2e/react-hono/react-hono.test.ts @@ -9,8 +9,9 @@ test('auths, fetches tracks, and favorites a track', async ({ // Set entropy so we don't need to do OTP const entropy = process.env.CREATE_AUDIUS_APP_TEST_ENTROPY ?? '' await context.addInitScript((entropy) => { - // Set entropy for both audius.co (OAuth) and localhost (app) - window.localStorage.setItem('hedgehog-entropy-key', entropy) + if (window.location.hostname === 'audius.co') { + window.localStorage.setItem('hedgehog-entropy-key', entropy) + } }, entropy) await page.goto('localhost:4173') @@ -32,11 +33,14 @@ test('auths, fetches tracks, and favorites a track', async ({ await page.getByRole('button', { name: 'Get Tracks' }).click() // Set up block_confirmation response listener - // The SDK makes requests to relay and then polls block_confirmation - const responsePromise = page.waitForResponse((response) => { - return ( - response.url().includes('block_confirmation') && response.status() === 200 - ) + const responsePromise = page.waitForResponse(async (response) => { + if ( + response.url().includes('favorite') || + response.url().includes('unfavorite') + ) { + const json = await response.json() + return json.trackId + } }) const favoriteButton = page