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

@@ -5,24 +5,37 @@ 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
const num = flags.reduce((cumm, curr) => cumm | BigInt(curr), BigInt(0))
const num = flags.reduce((cumm, curr) => cumm | BigInt(curr), BigInt(0))
return num.toString()
}
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