Fix: Don't remove fields in JSON mode if empty.
This commit is contained in:
		@@ -43,7 +43,6 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
 | 
			
		||||
    (state: Partial<TransactionState> = txState) => {
 | 
			
		||||
      const {
 | 
			
		||||
        selectedTransaction,
 | 
			
		||||
        selectedDestAccount,
 | 
			
		||||
        selectedAccount,
 | 
			
		||||
        txFields,
 | 
			
		||||
        selectedFlags,
 | 
			
		||||
@@ -126,6 +125,12 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
 | 
			
		||||
        throw Error('Account must be selected from imported accounts!')
 | 
			
		||||
      }
 | 
			
		||||
      const options = prepareOptions(st)
 | 
			
		||||
      // delete unnecessary fields
 | 
			
		||||
      Object.keys(options).forEach(field => {
 | 
			
		||||
        if (!options[field]) {
 | 
			
		||||
          delete options[field]
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      await sendTransaction(account, options, { logPrefix })
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
import { FC, ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
 | 
			
		||||
import { FC, ReactNode, useCallback, useEffect, useState } from 'react'
 | 
			
		||||
import Container from '../Container'
 | 
			
		||||
import Flex from '../Flex'
 | 
			
		||||
import Input from '../Input'
 | 
			
		||||
@@ -9,7 +9,6 @@ import {
 | 
			
		||||
  TransactionState,
 | 
			
		||||
  transactionsOptions,
 | 
			
		||||
  TxFields,
 | 
			
		||||
  getTxFields,
 | 
			
		||||
  defaultTransactionType
 | 
			
		||||
} from '../../state/transactions'
 | 
			
		||||
import { useSnapshot } from 'valtio'
 | 
			
		||||
@@ -295,6 +294,7 @@ export const TxUI: FC<UIProps> = ({
 | 
			
		||||
            return (
 | 
			
		||||
              <TxField key={field} label={field}>
 | 
			
		||||
                <Select
 | 
			
		||||
                  isClearable
 | 
			
		||||
                  instanceId={field}
 | 
			
		||||
                  placeholder={`Select ${field} account`}
 | 
			
		||||
                  options={accountOptions}
 | 
			
		||||
@@ -302,7 +302,7 @@ export const TxUI: FC<UIProps> = ({
 | 
			
		||||
                    value,
 | 
			
		||||
                    label
 | 
			
		||||
                  }}
 | 
			
		||||
                  onChange={(acc: any) => handleSetField(field, acc.value)}
 | 
			
		||||
                  onChange={(acc: any) => handleSetField(field, acc?.value)}
 | 
			
		||||
                />
 | 
			
		||||
              </TxField>
 | 
			
		||||
            )
 | 
			
		||||
 
 | 
			
		||||
@@ -141,7 +141,7 @@ export const prepareTransaction = (data: any) => {
 | 
			
		||||
      if (_value.$value) {
 | 
			
		||||
        options[field] = (+(_value as any).$value * 1000000 + '')
 | 
			
		||||
      } else {
 | 
			
		||||
        options[field] = undefined
 | 
			
		||||
        options[field] = ""
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    // amount.token
 | 
			
		||||
@@ -156,7 +156,7 @@ export const prepareTransaction = (data: any) => {
 | 
			
		||||
    }
 | 
			
		||||
    // account
 | 
			
		||||
    if (_value.$type === 'account') {
 | 
			
		||||
      options[field] = _value.$value?.toString();
 | 
			
		||||
      options[field] = _value.$value?.toString() || ""
 | 
			
		||||
    }
 | 
			
		||||
    // json
 | 
			
		||||
    if (_value.$type === 'json') {
 | 
			
		||||
@@ -172,13 +172,6 @@ export const prepareTransaction = (data: any) => {
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  // delete unnecessary fields
 | 
			
		||||
  Object.keys(options).forEach(field => {
 | 
			
		||||
    if (!options[field]) {
 | 
			
		||||
      delete options[field]
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  return options
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -269,7 +262,7 @@ export const prepareState = (value: string, transactionType?: string) => {
 | 
			
		||||
    } else if (isAccount) {
 | 
			
		||||
      rest[field] = {
 | 
			
		||||
        $type: "account",
 | 
			
		||||
        $value: value?.toString()
 | 
			
		||||
        $value: value?.toString() || ""
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else if (typeof value === 'object') {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user