From 4217813fd7e81dc6c0e411fd375698ab6707f2dc Mon Sep 17 00:00:00 2001 From: Vaclav Barta Date: Mon, 13 Jun 2022 08:22:55 +0200 Subject: [PATCH] take default header names from /api/header-files JSON (#210) This is a client-side upgrade for the server-side XRPLF/xrpl-hooks-compiler#17 - not hard-coding expected header names but taking them from the compilation backend. --- state/actions/fetchFiles.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/state/actions/fetchFiles.ts b/state/actions/fetchFiles.ts index d330fb9..4e1f3f1 100644 --- a/state/actions/fetchFiles.ts +++ b/state/actions/fetchFiles.ts @@ -23,16 +23,18 @@ export const fetchFiles = (gistId: string) => { return res } // in case of templates, fetch header file(s) and append to res - let resHeaderJson; try { const resHeader = await fetch(`${process.env.NEXT_PUBLIC_COMPILE_API_BASE_URL}/api/header-files`); if (resHeader.ok) { - resHeaderJson = await resHeader.json(); + const resHeaderJson = await resHeader.json() + const headerFiles: Record = {}; + Object.entries(resHeaderJson).forEach(([key, value]) => { + const fname = `${key}.h`; + headerFiles[fname] = { filename: fname, content: value as string, language: 'C' } + }) const files = { ...res.data.files, - 'hookapi.h': res.data.files?.['hookapi.h'] || { filename: 'hookapi.h', content: resHeaderJson.hookapi, language: 'C' }, - 'hookmacro.h': res.data.files?.['hookmacro.h'] || { filename: 'hookmacro.h', content: resHeaderJson.hookmacro, language: 'C' }, - 'sfcodes.h': res.data.files?.['sfcodes.h'] || { filename: 'sfcodes.h', content: resHeaderJson.sfcodes, language: 'C' }, + ...headerFiles }; res.data.files = files; } @@ -112,4 +114,4 @@ export const fetchFiles = (gistId: string) => { return; } state.loading = false; -}; \ No newline at end of file +};