From 3a064f307b00543d1e44286766cf805cd4db61f0 Mon Sep 17 00:00:00 2001 From: muzam1l Date: Fri, 28 Oct 2022 14:21:22 +0530 Subject: [PATCH] Add global flags. --- components/Transaction/ui.tsx | 8 +++----- state/constants/flags.ts | 23 ++++++++++++++++++----- state/transactions.ts | 4 ++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/components/Transaction/ui.tsx b/components/Transaction/ui.tsx index 87543ae..9313ad9 100644 --- a/components/Transaction/ui.tsx +++ b/components/Transaction/ui.tsx @@ -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 | undefined) => TransactionState | undefined @@ -44,7 +44,7 @@ export const TxUI: FC = ({ 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 = ({ 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 ( { + 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]) => { diff --git a/state/transactions.ts b/state/transactions.ts index 4eca896..f7b0f31 100644 --- a/state/transactions.ts +++ b/state/transactions.ts @@ -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