FIx json mode schema

This commit is contained in:
muzam1l
2022-05-30 23:32:53 +05:30
parent ae038f17ff
commit 377c963c7a
4 changed files with 28 additions and 13 deletions

View File

@@ -158,9 +158,11 @@ const Transaction: FC<TransactionProps> = ({
ptx.Sequence = account.sequence; ptx.Sequence = account.sequence;
const res = await _estimateFee(ptx, account, { silent: true }); const res = await _estimateFee(ptx, account, { silent: true });
return res?.base_fee; const fee = res?.base_fee;
setState({ estimatedFee: fee });
return fee;
}, },
[accounts, prepareOptions, txState] [accounts, prepareOptions, setState, txState]
); );
return ( return (

View File

@@ -37,18 +37,30 @@ export const TxJson: FC<JsonProps> = ({
state: txState, state: txState,
header, header,
setState, setState,
estimateFee,
}) => { }) => {
const { editorSettings, accounts } = useSnapshot(state); const { editorSettings, accounts } = useSnapshot(state);
const { editorValue = value, selectedTransaction } = txState; const { editorValue = value, estimatedFee } = txState;
const { theme } = useTheme(); const { theme } = useTheme();
const [hasUnsaved, setHasUnsaved] = useState(false); const [hasUnsaved, setHasUnsaved] = useState(false);
const [currTxType, setCurrTxType] = useState<string>();
useEffect(() => { useEffect(() => {
setState({ editorValue: value }); setState({ editorValue: value });
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]); }, [value]);
useEffect(() => {
const parsed = parseJSON(editorValue);
if (!parsed) return;
const tt = parsed.TransactionType;
const tx = transactionsData.find(t => t.TransactionType === tt);
if (tx) setCurrTxType(tx.TransactionType);
else {
setCurrTxType(undefined);
}
}, [editorValue]);
useEffect(() => { useEffect(() => {
if (editorValue === value) setHasUnsaved(false); if (editorValue === value) setHasUnsaved(false);
else setHasUnsaved(true); else setHasUnsaved(true);
@@ -85,8 +97,9 @@ export const TxJson: FC<JsonProps> = ({
const monaco = useMonaco(); const monaco = useMonaco();
const getSchemas = useCallback(async (): Promise<any[]> => { const getSchemas = useCallback(async (): Promise<any[]> => {
const tt = selectedTransaction?.value; const txObj = transactionsData.find(
const txObj = transactionsData.find(td => td.TransactionType === tt); td => td.TransactionType === currTxType
);
let genericSchemaProps: any; let genericSchemaProps: any;
if (txObj) { if (txObj) {
@@ -100,7 +113,6 @@ export const TxJson: FC<JsonProps> = ({
{} {}
); );
} }
const estimatedFee = await estimateFee?.();
return [ return [
{ {
uri: "file:///main-schema.json", // id of the first schema uri: "file:///main-schema.json", // id of the first schema
@@ -152,19 +164,21 @@ export const TxJson: FC<JsonProps> = ({
type: "string", type: "string",
title: "Fee type", title: "Fee type",
const: estimatedFee, const: estimatedFee,
description: "Above mentioned value is recommended base fee", description: estimatedFee
? "Above mentioned value is recommended base fee"
: undefined,
}, },
}, },
{ {
...amountSchema, ...amountSchema,
}, },
]; ];
}, [accounts, header, selectedTransaction?.value]); }, [accounts, currTxType, estimatedFee, header]);
useEffect(() => { useEffect(() => {
if (!monaco) return; if (!monaco) return;
getSchemas().then(schemas => { getSchemas().then(schemas => {
console.log('seeung schmea') console.log("seeung schmea");
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true, validate: true,
schemas, schemas,

View File

@@ -110,8 +110,6 @@ export const TxUI: FC<UIProps> = ({
k => !specialFields.includes(k) k => !specialFields.includes(k)
) as [keyof TxFields]; ) as [keyof TxFields];
console.log("render ui");
return ( return (
<Container <Container
css={{ css={{

View File

@@ -19,7 +19,8 @@ export interface TransactionState {
txFields: TxFields; txFields: TxFields;
viewType: 'json' | 'ui', viewType: 'json' | 'ui',
editorSavedValue: null | string, editorSavedValue: null | string,
editorValue?: string editorValue?: string,
estimatedFee?: string
} }