diff --git a/components/Select.tsx b/components/Select.tsx index 8c5e975..3822e18 100644 --- a/components/Select.tsx +++ b/components/Select.tsx @@ -38,7 +38,8 @@ const Select = forwardRef((props, ref) => { container: provided => { return { ...provided, - position: 'relative' + position: 'relative', + width: '100%' } }, singleValue: provided => ({ diff --git a/components/Transaction/index.tsx b/components/Transaction/index.tsx index 22a2ccc..0e73b04 100644 --- a/components/Transaction/index.tsx +++ b/components/Transaction/index.tsx @@ -20,6 +20,7 @@ import { TxUI } from './ui' import { default as _estimateFee } from '../../utils/estimateFee' import toast from 'react-hot-toast' import { combineFlags, extractFlags, transactionFlags } from '../../state/constants/flags' +import { SetHookData, toHex } from '../../utils/setHook' export interface TransactionProps { header: string @@ -40,16 +41,30 @@ const Transaction: FC = ({ header, state: txState, ...props }) const prepareOptions = useCallback( (state: Partial = txState) => { - const { selectedTransaction, selectedDestAccount, selectedAccount, txFields, selectedFlags } = - state + const { + selectedTransaction, + selectedDestAccount, + selectedAccount, + txFields, + selectedFlags, + hookParameters + } = state const TransactionType = selectedTransaction?.value || null const Destination = selectedDestAccount?.value || txFields?.Destination const Account = selectedAccount?.value || null const Flags = combineFlags(selectedFlags?.map(flag => flag.value)) || txFields?.Flags + const HookParameters = Object.entries(hookParameters || {}).reduce< + SetHookData['HookParameters'] + >((acc, [_, { label, value }]) => { + return acc.concat({ + HookParameter: { HookParameterName: toHex(label), HookParameterValue: toHex(value) } + }) + }, []) return prepareTransaction({ ...txFields, + HookParameters, Flags, TransactionType, Destination, diff --git a/components/Transaction/ui.tsx b/components/Transaction/ui.tsx index 59e2d64..df7ba33 100644 --- a/components/Transaction/ui.tsx +++ b/components/Transaction/ui.tsx @@ -1,4 +1,4 @@ -import { FC, useCallback, useEffect, useMemo, useState } from 'react' +import { FC, ReactNode, useCallback, useEffect, useMemo, useState } from 'react' import Container from '../Container' import Flex from '../Flex' import Input from '../Input' @@ -18,6 +18,7 @@ import { streamState } from '../DebugStream' import { Button } from '..' import Textarea from '../Textarea' import { getFlags } from '../../state/constants/flags' +import { Plus, Trash } from 'phosphor-react' interface UIProps { setState: (pTx?: Partial | undefined) => TransactionState | undefined @@ -28,8 +29,14 @@ interface UIProps { export const TxUI: FC = ({ state: txState, setState, resetState, estimateFee }) => { const { accounts } = useSnapshot(state) - const { selectedAccount, selectedDestAccount, selectedTransaction, txFields, selectedFlags } = - txState + const { + selectedAccount, + selectedDestAccount, + selectedTransaction, + txFields, + selectedFlags, + hookParameters + } = txState const accountOptions: SelectOption[] = accounts.map(acc => ({ label: acc.name, @@ -110,7 +117,7 @@ export const TxUI: FC = ({ state: txState, setState, resetState, estima [selectedTransaction?.value] ) - const richFields = ['TransactionType', 'Account'] + const richFields = ['TransactionType', 'Account', 'HookParameters'] if (fields.Destination !== undefined) { richFields.push('Destination') } @@ -120,7 +127,6 @@ export const TxUI: FC = ({ state: txState, setState, resetState, estima } const otherFields = Object.keys(txFields).filter(k => !richFields.includes(k)) as [keyof TxFields] - return ( = ({ state: txState, setState, resetState, estima }} > - - - Transaction type:{' '} - + handleSetAccount(acc)} // TODO make react-select have correct types for acc /> - + {richFields.includes('Destination') && ( - - - Destination account:{' '} - + = ({ state: txState, setState, resetState, estima selectedFlags ? selectedFlags.length >= flagsOptions.length - 1 : false } /> - + )} {otherFields.map(field => { let _value = txFields[field] @@ -251,93 +204,162 @@ export const TxUI: FC = ({ state: txState, setState, resetState, estima let rows = isJson ? (value?.match(/\n/gm)?.length || 0) + 1 : undefined if (rows && rows > 5) rows = 5 return ( - - - - {field + (isXrp ? ' (XRP)' : '')}:{' '} - - {isJson ? ( -