diff --git a/components/Transaction/index.tsx b/components/Transaction/index.tsx index f5b2cb3..ef75aa2 100644 --- a/components/Transaction/index.tsx +++ b/components/Transaction/index.tsx @@ -3,10 +3,12 @@ import { FC, useCallback, useEffect } from "react"; import { useSnapshot } from "valtio"; import state from "../../state"; import { + defaultTransactionType, getTxFields, modifyTransaction, prepareState, prepareTransaction, + SelectOption, TransactionState, } from "../../state/transactions"; import { sendTransaction } from "../../state/actions"; @@ -135,10 +137,6 @@ const Transaction: FC = ({ prepareOptions, ]); - const resetState = useCallback(() => { - modifyTransaction(header, { viewType }, { replaceState: true }); - }, [header, viewType]); - const getJsonString = useCallback( (state?: Partial) => JSON.stringify( @@ -149,6 +147,30 @@ const Transaction: FC = ({ [editorSettings.tabSize, prepareOptions] ); + const resetState = useCallback( + (transactionType: SelectOption | undefined = defaultTransactionType) => { + const fields = getTxFields(transactionType?.value); + + const nwState: Partial = { + viewType, + selectedTransaction: transactionType, + }; + + if (fields.Destination !== undefined) { + nwState.selectedDestAccount = null; + fields.Destination = ""; + } else { + fields.Destination = undefined; + } + nwState.txFields = fields; + + const state = modifyTransaction(header, nwState, { replaceState: true }); + const editorValue = getJsonString(state); + return setState({ editorValue }); + }, + [getJsonString, header, setState, viewType] + ); + const estimateFee = useCallback( async (st?: TransactionState, opts?: { silent?: boolean }) => { const state = st || txState; @@ -209,7 +231,7 @@ const Transaction: FC = ({ {viewType === "ui" ? "EDIT AS JSON" : "EXIT JSON MODE"} -