From e87f6122790d0b82edeb7ce713b4b503082ce8f2 Mon Sep 17 00:00:00 2001 From: mischief Date: Thu, 25 Apr 2024 00:48:59 -0500 Subject: [PATCH] working --- ui/src/app.tsx | 52 ++++++++++++++++++---------------- ui/src/contexts/ApiContext.tsx | 23 ++++++++++++++- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/ui/src/app.tsx b/ui/src/app.tsx index 59ba1d1..5e4c5fd 100644 --- a/ui/src/app.tsx +++ b/ui/src/app.tsx @@ -10,36 +10,40 @@ import ChannelDisplay from './components/status/ChannelDisplay'; import { VoltProviderContextProvider } from './contexts/VoltProviderContext'; import { HotWalletContextProvider } from './contexts/HotWalletContext'; import { PaymentUpdateContextProvider } from './contexts/PaymentUpdateContext'; +import { ApiProvider } from './contexts/ApiContext'; export function App() { return ( - - - - - -
-
-
- -
-
-
- -
-
- - + + + + + + +
+
+
+ +
+
+
+ +
+
+ + +
-
-
-
-
-
-
-
+ + + + + + +
+ ); } diff --git a/ui/src/contexts/ApiContext.tsx b/ui/src/contexts/ApiContext.tsx index ad1c75e..654efb7 100644 --- a/ui/src/contexts/ApiContext.tsx +++ b/ui/src/contexts/ApiContext.tsx @@ -1,4 +1,4 @@ -import React, { createContext } from 'react'; +import React, { createContext, useEffect } from 'react'; import Urbit from '@urbit/http-api'; type ApiContextValue = Urbit; @@ -9,6 +9,27 @@ api.ship = process.env.VITE_SHIP_NAME || window.ship; export const ApiContext = createContext(api); export const ApiProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { + + useEffect(() => { + const redirectToAuthIfNotLoggedIn = async () => { + try { + await api.scry({ + app: "volt", + path: "/hot-wallet-fee", + }); + } catch (e: any) { + if (e?.status === 403) { + document.location = `${document.location.protocol}//${document.location.host}`; + } + } + } + // Redirect to the auth page happens automatically if this is running from a glob + // So this is only useful for local development + if (process.env.VITE_SHIP_NAME) { + redirectToAuthIfNotLoggedIn(); + } + }, []); + return ( {children}