Add global flags.

This commit is contained in:
muzam1l
2022-10-28 14:21:22 +05:30
parent 6fca05f310
commit 3a064f307b
3 changed files with 23 additions and 12 deletions

View File

@@ -17,7 +17,7 @@ import state from '../../state'
import { streamState } from '../DebugStream'
import { Button } from '..'
import Textarea from '../Textarea'
import { transactionFlags } from '../../state/constants/flags'
import { getFlags } from '../../state/constants/flags'
interface UIProps {
setState: (pTx?: Partial<TransactionState> | undefined) => TransactionState | undefined
@@ -44,7 +44,7 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState, resetState, estima
.filter(acc => acc.value !== selectedAccount?.value)
const flagsOptions: SelectOption[] = Object.entries(
transactionFlags[selectedTransaction?.value || ''] || {}
getFlags(selectedTransaction?.value) || {}
).map(([label, value]) => ({
label,
value
@@ -119,9 +119,7 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState, resetState, estima
richFields.push('Flags')
}
const otherFields = Object.keys(txFields).filter(k => !richFields.includes(k)) as [
keyof TxFields
]
const otherFields = Object.keys(txFields).filter(k => !richFields.includes(k)) as [keyof TxFields]
return (
<Container

View File

@@ -5,14 +5,27 @@ interface Flags {
}
export const transactionFlags: { [key: /* TransactionType */ string]: Flags } = {
"*": {
tfFullyCanonicalSig: '0x80000000'
},
Payment: {
tfNoDirectRipple: "0x00010000",
tfPartialPayment: "0x00020000",
tfLimitQuality: "0x00040000",
tfNoDirectRipple: '0x00010000',
tfPartialPayment: '0x00020000',
tfLimitQuality: '0x00040000',
},
// TODO Add more here
}
export const getFlags = (tt?: string) => {
if (!tt) return
const flags = {
...transactionFlags['*'],
...transactionFlags[tt]
}
return flags
}
export function combineFlags(flags?: string[]): string | undefined {
if (!flags) return
@@ -22,7 +35,7 @@ export function combineFlags(flags?: string[]): string | undefined {
}
export function extractFlags(transactionType: string, flags?: string | number,): SelectOption[] {
const flagsObj = transactionFlags[transactionType]
const flagsObj = getFlags(transactionType)
if (!flags || !flagsObj) return []
const extracted = Object.entries(flagsObj).reduce((cumm, [label, value]) => {

View File

@@ -4,7 +4,7 @@ import transactionsData from '../content/transactions.json'
import state from '.'
import { showAlert } from '../state/actions/showAlert'
import { parseJSON } from '../utils/json'
import { extractFlags, transactionFlags } from './constants/flags'
import { extractFlags, getFlags } from './constants/flags'
export type SelectOption = {
value: string
@@ -207,7 +207,7 @@ export const prepareState = (value: string, transactionType?: string) => {
rest.Destination = Destination
}
if (transactionFlags[TransactionType] && rest.Flags) {
if (getFlags(TransactionType) && rest.Flags) {
const flags = extractFlags(TransactionType, rest.Flags)
rest.Flags = undefined