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