Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-7616 set api call for config json needed for dynamic setting of m… #10

Merged
merged 2 commits into from Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/App.tsx
Expand Up @@ -7,7 +7,11 @@ import ToastMessage from './ToastMessage';
import MarloweSDK from '../services/MarloweSDK';


const App: React.FC = () => {
type AppProps = {
runtimeURL: string;
}

const App: React.FC<AppProps> = ({runtimeURL}) => {
const [sdk, setSdk] = useState(new MarloweSDK());
const [toasts, setToasts] = useState<any[]>([]);

Expand All @@ -24,7 +28,7 @@ const App: React.FC = () => {
<Router>
<Routes>
<Route path="/" element={<Landing sdk={sdk} setAndShowToast={setAndShowToast} />} />
<Route path="/vesting-schedules" element={<VestingSchedule sdk={sdk} setAndShowToast={setAndShowToast} />} />
<Route path="/vesting-schedules" element={<VestingSchedule sdk={sdk} setAndShowToast={setAndShowToast} runtimeURL={runtimeURL} />} />
</Routes>
<div className="toast-container position-fixed bottom-0 end-0 p-3">
{toasts.map(toast => (
Expand Down
7 changes: 3 additions & 4 deletions src/components/VestingSchedule.tsx
Expand Up @@ -16,11 +16,10 @@ import CancelVestingScheduleModal from './modals/CancelVestingScheduleModal';
import ClaimsModal from './modals/ClaimsModal';
import ProgressMeter from './widgets/ProgressMeter';

const runtimeURL = `${process.env.MARLOWE_RUNTIME_WEB_URL}`;

type VestingScheduleProps = {
sdk: MarloweSDK,
setAndShowToast: (title:string, message:any, isDanger: boolean) => void
setAndShowToast: (title:string, message:any, isDanger: boolean) => void,
runtimeURL: string
};

enum VestingScheduleModal {
Expand All @@ -30,7 +29,7 @@ enum VestingScheduleModal {
DEPOSIT = 'deposit',
}

const VestingSchedule: React.FC<VestingScheduleProps> = ({sdk, setAndShowToast}) => {
const VestingSchedule: React.FC<VestingScheduleProps> = ({sdk, setAndShowToast, runtimeURL}) => {
const navigate = useNavigate();
const selectedAWalletExtension = localStorage.getItem('walletProvider');
if (!selectedAWalletExtension) { navigate('/'); }
Expand Down
17 changes: 16 additions & 1 deletion src/index.tsx
Expand Up @@ -7,6 +7,17 @@ import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js';
import './styles/main.scss';

let runtimeURL = process.env.MARLOWE_RUNTIME_WEB_URL;
await fetch('/config.json').then(async(res) => {
if (res.status === 200) {
const {marloweWebServerUrl} = await res.json();
if (!!marloweWebServerUrl) {
runtimeURL = marloweWebServerUrl;
}
}
});

const hasValidRuntimeInstance = runtimeURL !== undefined && runtimeURL !== null && runtimeURL !== '' && runtimeURL.startsWith('http');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a healthcheck endpoint available in the sdk, you should call it instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not good enough

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's something along these lines if I'm not mistaken:

import { mkRestClient } from "@marlowe.io/runtime-rest-client";

const restClient = mkRestClient(runtimeURL)

const hasValidRuntimeInstance = await restClient.healthcheck()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this.


// 2) Get a reference to the div with ID root
const el = document.getElementById('root');
Expand All @@ -19,4 +30,8 @@ if (!el) {
const root = ReactDOM.createRoot(el);

// 4) Show the component on the screen
root.render(<App />);
if (hasValidRuntimeInstance && runtimeURL) {
root.render(<App runtimeURL={runtimeURL} />);
} else {
alert("Missing valid config.json file with marloweWebServerUrl OR env keys are not set")
}