Compare commits
2 Commits
feat/fetch
...
feat/strea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04e2274dbf | ||
|
|
842b8a5226 |
@@ -2,7 +2,6 @@ NEXTAUTH_URL=https://example.com
|
|||||||
GITHUB_SECRET=""
|
GITHUB_SECRET=""
|
||||||
GITHUB_ID=""
|
GITHUB_ID=""
|
||||||
NEXT_PUBLIC_COMPILE_API_ENDPOINT="http://localhost:9000/api/build"
|
NEXT_PUBLIC_COMPILE_API_ENDPOINT="http://localhost:9000/api/build"
|
||||||
NEXT_PUBLIC_COMPILE_API_BASE_URL="http://localhost:9000"
|
|
||||||
NEXT_PUBLIC_LANGUAGE_SERVER_API_ENDPOINT="ws://localhost:9000/language-server/c"
|
NEXT_PUBLIC_LANGUAGE_SERVER_API_ENDPOINT="ws://localhost:9000/language-server/c"
|
||||||
NEXT_PUBLIC_TESTNET_URL="hooks-testnet-v2.xrpl-labs.com"
|
NEXT_PUBLIC_TESTNET_URL="hooks-testnet-v2.xrpl-labs.com"
|
||||||
NEXT_PUBLIC_DEBUG_STREAM_URL="hooks-testnet-v2-debugstream.xrpl-labs.com"
|
NEXT_PUBLIC_DEBUG_STREAM_URL="hooks-testnet-v2-debugstream.xrpl-labs.com"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ interface ISelect<T = string> {
|
|||||||
value: T;
|
value: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
const streamState = proxy({
|
export const streamState = proxy({
|
||||||
selectedAccount: null as ISelect | null,
|
selectedAccount: null as ISelect | null,
|
||||||
logs: [] as ILog[],
|
logs: [] as ILog[],
|
||||||
socket: undefined as WebSocket | undefined,
|
socket: undefined as WebSocket | undefined,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import transactionsData from "../../content/transactions.json";
|
|||||||
import state from "../../state";
|
import state from "../../state";
|
||||||
import { sendTransaction } from "../../state/actions";
|
import { sendTransaction } from "../../state/actions";
|
||||||
import { getSplit, saveSplit } from "../../state/actions/persistSplits";
|
import { getSplit, saveSplit } from "../../state/actions/persistSplits";
|
||||||
|
import { streamState } from "../../components/DebugStream";
|
||||||
|
|
||||||
const DebugStream = dynamic(() => import("../../components/DebugStream"), {
|
const DebugStream = dynamic(() => import("../../components/DebugStream"), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@@ -37,6 +38,11 @@ type TxFields = Omit<
|
|||||||
>;
|
>;
|
||||||
type OtherFields = (keyof Omit<TxFields, "Destination">)[];
|
type OtherFields = (keyof Omit<TxFields, "Destination">)[];
|
||||||
|
|
||||||
|
interface AccountOption {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
header?: string;
|
header?: string;
|
||||||
}
|
}
|
||||||
@@ -44,7 +50,7 @@ interface Props {
|
|||||||
const Transaction: FC<Props> = ({ header, ...props }) => {
|
const Transaction: FC<Props> = ({ header, ...props }) => {
|
||||||
const snap = useSnapshot(state);
|
const snap = useSnapshot(state);
|
||||||
|
|
||||||
const transactionsOptions = transactionsData.map((tx) => ({
|
const transactionsOptions = transactionsData.map(tx => ({
|
||||||
value: tx.TransactionType,
|
value: tx.TransactionType,
|
||||||
label: tx.TransactionType,
|
label: tx.TransactionType,
|
||||||
}));
|
}));
|
||||||
@@ -52,23 +58,24 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
typeof transactionsOptions[0] | null
|
typeof transactionsOptions[0] | null
|
||||||
>(null);
|
>(null);
|
||||||
|
|
||||||
const accountOptions = snap.accounts.map((acc) => ({
|
const accountOptions: AccountOption[] = snap.accounts.map(acc => ({
|
||||||
label: acc.name,
|
label: acc.name,
|
||||||
value: acc.address,
|
value: acc.address,
|
||||||
}));
|
}));
|
||||||
const [selectedAccount, setSelectedAccount] = useState<
|
|
||||||
typeof accountOptions[0] | null
|
|
||||||
>(null);
|
|
||||||
|
|
||||||
const destAccountOptions = snap.accounts
|
const [selectedAccount, setSelectedAccount] = useState<AccountOption | null>(
|
||||||
.map((acc) => ({
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
const destAccountOptions: AccountOption[] = snap.accounts
|
||||||
|
.map(acc => ({
|
||||||
label: acc.name,
|
label: acc.name,
|
||||||
value: acc.address,
|
value: acc.address,
|
||||||
}))
|
}))
|
||||||
.filter((acc) => acc.value !== selectedAccount?.value);
|
.filter(acc => acc.value !== selectedAccount?.value);
|
||||||
const [selectedDestAccount, setSelectedDestAccount] = useState<
|
|
||||||
typeof destAccountOptions[0] | null
|
const [selectedDestAccount, setSelectedDestAccount] =
|
||||||
>(null);
|
useState<AccountOption | null>(null);
|
||||||
|
|
||||||
const [txIsLoading, setTxIsLoading] = useState(false);
|
const [txIsLoading, setTxIsLoading] = useState(false);
|
||||||
const [txIsDisabled, setTxIsDisabled] = useState(false);
|
const [txIsDisabled, setTxIsDisabled] = useState(false);
|
||||||
@@ -77,7 +84,7 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const transactionType = selectedTransaction?.value;
|
const transactionType = selectedTransaction?.value;
|
||||||
const account = snap.accounts.find(
|
const account = snap.accounts.find(
|
||||||
(acc) => acc.address === selectedAccount?.value
|
acc => acc.address === selectedAccount?.value
|
||||||
);
|
);
|
||||||
if (!account || !transactionType || txIsLoading) {
|
if (!account || !transactionType || txIsLoading) {
|
||||||
setTxIsDisabled(true);
|
setTxIsDisabled(true);
|
||||||
@@ -88,7 +95,7 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let _txFields: TxFields | undefined = transactionsData.find(
|
let _txFields: TxFields | undefined = transactionsData.find(
|
||||||
(tx) => tx.TransactionType === selectedTransaction?.value
|
tx => tx.TransactionType === selectedTransaction?.value
|
||||||
);
|
);
|
||||||
if (!_txFields) return setTxFields({});
|
if (!_txFields) return setTxFields({});
|
||||||
_txFields = { ..._txFields } as TxFields;
|
_txFields = { ..._txFields } as TxFields;
|
||||||
@@ -105,7 +112,7 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
|
|
||||||
const submitTest = useCallback(async () => {
|
const submitTest = useCallback(async () => {
|
||||||
const account = snap.accounts.find(
|
const account = snap.accounts.find(
|
||||||
(acc) => acc.address === selectedAccount?.value
|
acc => acc.address === selectedAccount?.value
|
||||||
);
|
);
|
||||||
const TransactionType = selectedTransaction?.value;
|
const TransactionType = selectedTransaction?.value;
|
||||||
if (!account || !TransactionType || txIsDisabled) return;
|
if (!account || !TransactionType || txIsDisabled) return;
|
||||||
@@ -116,7 +123,7 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
let options = { ...txFields };
|
let options = { ...txFields };
|
||||||
|
|
||||||
options.Destination = selectedDestAccount?.value;
|
options.Destination = selectedDestAccount?.value;
|
||||||
(Object.keys(options) as (keyof TxFields)[]).forEach((field) => {
|
(Object.keys(options) as (keyof TxFields)[]).forEach(field => {
|
||||||
let _value = options[field];
|
let _value = options[field];
|
||||||
// convert currency
|
// convert currency
|
||||||
if (typeof _value === "object" && _value.type === "currency") {
|
if (typeof _value === "object" && _value.type === "currency") {
|
||||||
@@ -182,9 +189,14 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
setTxIsLoading(false);
|
setTxIsLoading(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleSetAccount = (acc: AccountOption) => {
|
||||||
|
setSelectedAccount(acc);
|
||||||
|
streamState.selectedAccount = acc;
|
||||||
|
};
|
||||||
|
|
||||||
const usualFields = ["TransactionType", "Amount", "Account", "Destination"];
|
const usualFields = ["TransactionType", "Amount", "Account", "Destination"];
|
||||||
const otherFields = Object.keys(txFields).filter(
|
const otherFields = Object.keys(txFields).filter(
|
||||||
(k) => !usualFields.includes(k)
|
k => !usualFields.includes(k)
|
||||||
) as OtherFields;
|
) as OtherFields;
|
||||||
return (
|
return (
|
||||||
<Box css={{ position: "relative", height: "calc(100% - 28px)" }} {...props}>
|
<Box css={{ position: "relative", height: "calc(100% - 28px)" }} {...props}>
|
||||||
@@ -217,7 +229,7 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
hideSelectedOptions
|
hideSelectedOptions
|
||||||
css={{ width: "70%" }}
|
css={{ width: "70%" }}
|
||||||
value={selectedTransaction}
|
value={selectedTransaction}
|
||||||
onChange={(tt) => setSelectedTransaction(tt as any)}
|
onChange={(tt: any) => setSelectedTransaction(tt)}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex
|
<Flex
|
||||||
@@ -239,7 +251,7 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
css={{ width: "70%" }}
|
css={{ width: "70%" }}
|
||||||
options={accountOptions}
|
options={accountOptions}
|
||||||
value={selectedAccount}
|
value={selectedAccount}
|
||||||
onChange={(acc) => setSelectedAccount(acc as any)}
|
onChange={(acc: any) => handleSetAccount(acc)} // TODO make react-select have correct types for acc
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
{txFields.Amount !== undefined && (
|
{txFields.Amount !== undefined && (
|
||||||
@@ -258,7 +270,7 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
</Text>
|
</Text>
|
||||||
<Input
|
<Input
|
||||||
value={txFields.Amount.value}
|
value={txFields.Amount.value}
|
||||||
onChange={(e) =>
|
onChange={e =>
|
||||||
setTxFields({
|
setTxFields({
|
||||||
...txFields,
|
...txFields,
|
||||||
Amount: { type: "currency", value: e.target.value },
|
Amount: { type: "currency", value: e.target.value },
|
||||||
@@ -289,11 +301,11 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
options={destAccountOptions}
|
options={destAccountOptions}
|
||||||
value={selectedDestAccount}
|
value={selectedDestAccount}
|
||||||
isClearable
|
isClearable
|
||||||
onChange={(acc) => setSelectedDestAccount(acc as any)}
|
onChange={(acc: any) => setSelectedDestAccount(acc)}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
{otherFields.map((field) => {
|
{otherFields.map(field => {
|
||||||
let _value = txFields[field];
|
let _value = txFields[field];
|
||||||
let value = typeof _value === "object" ? _value.value : _value;
|
let value = typeof _value === "object" ? _value.value : _value;
|
||||||
value =
|
value =
|
||||||
@@ -319,7 +331,7 @@ const Transaction: FC<Props> = ({ header, ...props }) => {
|
|||||||
</Text>
|
</Text>
|
||||||
<Input
|
<Input
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(e) =>
|
onChange={e =>
|
||||||
setTxFields({
|
setTxFields({
|
||||||
...txFields,
|
...txFields,
|
||||||
[field]:
|
[field]:
|
||||||
@@ -376,7 +388,7 @@ const Test = () => {
|
|||||||
gutterSize={4}
|
gutterSize={4}
|
||||||
gutterAlign="center"
|
gutterAlign="center"
|
||||||
style={{ height: "calc(100vh - 60px)" }}
|
style={{ height: "calc(100vh - 60px)" }}
|
||||||
onDragEnd={(e) => saveSplit("testVertical", e)}
|
onDragEnd={e => saveSplit("testVertical", e)}
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex
|
||||||
row
|
row
|
||||||
@@ -398,21 +410,19 @@ const Test = () => {
|
|||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
}}
|
}}
|
||||||
onDragEnd={(e) => saveSplit("testHorizontal", e)}
|
onDragEnd={e => saveSplit("testHorizontal", e)}
|
||||||
>
|
>
|
||||||
<Box css={{ width: "55%", px: "$2" }}>
|
<Box css={{ width: "55%", px: "$2" }}>
|
||||||
<Tabs
|
<Tabs
|
||||||
keepAllAlive
|
keepAllAlive
|
||||||
forceDefaultExtension
|
forceDefaultExtension
|
||||||
defaultExtension=".json"
|
defaultExtension=".json"
|
||||||
onCreateNewTab={(name) =>
|
onCreateNewTab={name => setTabHeaders(tabHeaders.concat(name))}
|
||||||
setTabHeaders(tabHeaders.concat(name))
|
onCloseTab={index =>
|
||||||
}
|
|
||||||
onCloseTab={(index) =>
|
|
||||||
setTabHeaders(tabHeaders.filter((_, idx) => idx !== index))
|
setTabHeaders(tabHeaders.filter((_, idx) => idx !== index))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{tabHeaders.map((header) => (
|
{tabHeaders.map(header => (
|
||||||
<Tab key={header} header={header}>
|
<Tab key={header} header={header}>
|
||||||
<Transaction header={header} />
|
<Transaction header={header} />
|
||||||
</Tab>
|
</Tab>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { Octokit } from "@octokit/core";
|
|||||||
import Router from "next/router";
|
import Router from "next/router";
|
||||||
import state from '../index';
|
import state from '../index';
|
||||||
import { templateFileIds } from '../constants';
|
import { templateFileIds } from '../constants';
|
||||||
|
import { hookapiH, hookmacroH, sfcodesH } from '../constants/headerTemplates';
|
||||||
|
|
||||||
|
|
||||||
const octokit = new Octokit();
|
const octokit = new Octokit();
|
||||||
|
|
||||||
@@ -18,29 +20,18 @@ export const fetchFiles = (gistId: string) => {
|
|||||||
|
|
||||||
octokit
|
octokit
|
||||||
.request("GET /gists/{gist_id}", { gist_id: gistId })
|
.request("GET /gists/{gist_id}", { gist_id: gistId })
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
if (!Object.values(templateFileIds).includes(gistId)) {
|
if (!Object.values(templateFileIds).includes(gistId)) {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
// in case of templates, fetch header file(s) and append to 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();
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = {
|
const files = {
|
||||||
...res.data.files,
|
...res.data.files,
|
||||||
'hookapi.h': res.data.files?.['hookapi.h'] || { filename: 'hookapi.h', content: resHeaderJson.hookapi, language: 'C' },
|
'hookapi.h': res.data.files?.['hookapi.h'] || { filename: 'hookapi.h', content: hookapiH, language: 'C' },
|
||||||
'hookmacro.h': res.data.files?.['hookmacro.h'] || { filename: 'hookmacro.h', content: resHeaderJson.hookmacro, language: 'C' },
|
'hookmacro.h': res.data.files?.['hookmacro.h'] || { filename: 'hookmacro.h', content: hookmacroH, language: 'C' },
|
||||||
'sfcodes.h': res.data.files?.['sfcodes.h'] || { filename: 'sfcodes.h', content: resHeaderJson.sfcodes, language: 'C' },
|
'sfcodes.h': res.data.files?.['sfcodes.h'] || { filename: 'sfcodes.h', content: sfcodesH, language: 'C' },
|
||||||
};
|
};
|
||||||
res.data.files = files;
|
res.data.files = files;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
// If you want to load templates from GIST instad, uncomment the code below and comment the code above.
|
// If you want to load templates from GIST instad, uncomment the code below and comment the code above.
|
||||||
// return octokit.request("GET /gists/{gist_id}", { gist_id: templateFileIds.headers }).then(({ data: { files: headerFiles } }) => {
|
// return octokit.request("GET /gists/{gist_id}", { gist_id: templateFileIds.headers }).then(({ data: { files: headerFiles } }) => {
|
||||||
|
|||||||
1383
state/constants/headerTemplates.ts
Normal file
1383
state/constants/headerTemplates.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user