HookParameters UI for transactions.

This commit is contained in:
muzam1l
2023-03-03 18:32:03 +05:30
parent b50b300307
commit 39699a1cb9
6 changed files with 125 additions and 20 deletions

View File

@@ -5,17 +5,23 @@ import state from '.'
import { showAlert } from '../state/actions/showAlert'
import { parseJSON } from '../utils/json'
import { extractFlags, getFlags } from './constants/flags'
import { fromHex } from '../utils/setHook'
export type SelectOption = {
value: string
label: string
}
export type HookParameters = {
[key: string]: SelectOption
}
export interface TransactionState {
selectedTransaction: SelectOption | null
selectedAccount: SelectOption | null
selectedDestAccount: SelectOption | null
selectedFlags: SelectOption[] | null
hookParameters: HookParameters
txIsLoading: boolean
txIsDisabled: boolean
txFields: TxFields
@@ -36,6 +42,7 @@ export const defaultTransaction: TransactionState = {
selectedAccount: null,
selectedDestAccount: null,
selectedFlags: null,
hookParameters: {},
txIsLoading: false,
txIsDisabled: false,
txFields: {},
@@ -160,7 +167,7 @@ export const prepareState = (value: string, transactionType?: string) => {
return
}
const { Account, TransactionType, Destination, ...rest } = options
const { Account, TransactionType, Destination, HookParameters, ...rest } = options
let tx: Partial<TransactionState> = {}
const schema = getTxFields(transactionType)
@@ -190,6 +197,14 @@ export const prepareState = (value: string, transactionType?: string) => {
tx.selectedTransaction = null
}
if (HookParameters && HookParameters instanceof Array) {
tx.hookParameters = HookParameters.reduce<TransactionState["hookParameters"]>((acc, cur, idx) => {
const param = { label: fromHex(cur.HookParameter?.HookParameterName || ""), value: fromHex(cur.HookParameter?.HookParameterValue || "") }
acc[idx] = param;
return acc;
}, {})
}
if (schema.Destination !== undefined) {
const dest = state.accounts.find(acc => acc.address === Destination)
if (dest) {