Skip to content
Merged
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
52 changes: 28 additions & 24 deletions ui/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<FeedbackContextProvider>
<HotWalletContextProvider>
<ChannelContextProvider>
<PaymentUpdateContextProvider>
<VoltProviderContextProvider>
<InvoiceContextProvider>
<main className="bg-slate-200 h-screen">
<div className="flex h-full overflow-y-hidden">
<div className="bg-zinc-100 w-1/2 pt-20">
<Commands />
</div>
<div className='flex flex-col h-full w-1/2'>
<div className='h-1/3 bg-zinc-800 overflow-scroll rounded-b-sm'>
<CommandFeedback />
</div>
<div className='h-2/3 bg-zinc-300 text-gray-500 rounded-sm'>
<LiquidityDisplay/>
<ChannelDisplay />
<ApiProvider>
<HotWalletContextProvider>
<ChannelContextProvider>
<PaymentUpdateContextProvider>
<VoltProviderContextProvider>
<InvoiceContextProvider>
<main className="bg-slate-200 h-screen">
<div className="flex h-full overflow-y-hidden">
<div className="bg-zinc-100 w-1/2 pt-20">
<Commands />
</div>
<div className='flex flex-col h-full w-1/2'>
<div className='h-1/3 bg-zinc-800 overflow-scroll rounded-b-sm'>
<CommandFeedback />
</div>
<div className='h-2/3 bg-zinc-300 text-gray-500 rounded-sm'>
<LiquidityDisplay/>
<ChannelDisplay />
</div>
</div>
</div>
</div>
</main>
</InvoiceContextProvider>
</VoltProviderContextProvider>
</PaymentUpdateContextProvider>
</ChannelContextProvider>
</HotWalletContextProvider>
</main>
</InvoiceContextProvider>
</VoltProviderContextProvider>
</PaymentUpdateContextProvider>
</ChannelContextProvider>
</HotWalletContextProvider>
</ApiProvider>
</FeedbackContextProvider>

);
}
23 changes: 22 additions & 1 deletion ui/src/contexts/ApiContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext } from 'react';
import React, { createContext, useEffect } from 'react';
import Urbit from '@urbit/http-api';

type ApiContextValue = Urbit;
Expand All @@ -9,6 +9,27 @@ api.ship = process.env.VITE_SHIP_NAME || window.ship;
export const ApiContext = createContext<ApiContextValue>(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 (
<ApiContext.Provider value={api}>
{children}
Expand Down