From 7aafca21df61e3e0b7415a326d9ec1a2c5f6e9f1 Mon Sep 17 00:00:00 2001 From: muzam1l Date: Thu, 23 Mar 2023 15:49:17 +0530 Subject: [PATCH] Remove Destination as special field. --- components/Transaction/index.tsx | 14 ----------- components/Transaction/ui.tsx | 20 ---------------- content/transactions.json | 40 +++++++++++++++++++++++++------- state/transactions.ts | 23 ++---------------- 4 files changed, 34 insertions(+), 63 deletions(-) diff --git a/components/Transaction/index.tsx b/components/Transaction/index.tsx index da10c1e..1d48349 100644 --- a/components/Transaction/index.tsx +++ b/components/Transaction/index.tsx @@ -52,7 +52,6 @@ const Transaction: FC = ({ header, state: txState, ...props }) } = state const TransactionType = selectedTransaction?.value || null - const Destination = selectedDestAccount?.value || txFields?.Destination const Account = selectedAccount?.value || null const Flags = combineFlags(selectedFlags?.map(flag => flag.value)) || txFields?.Flags const HookParameters = Object.entries(hookParameters || {}).reduce< @@ -75,7 +74,6 @@ const Transaction: FC = ({ header, state: txState, ...props }) HookParameters, Flags, TransactionType, - Destination, Account, Memos }) @@ -129,11 +127,6 @@ const Transaction: FC = ({ header, state: txState, ...props }) } const options = prepareOptions(st) - const fields = getTxFields(options.TransactionType) - if (fields.Destination && !options.Destination) { - throw Error('Destination account is required!') - } - await sendTransaction(account, options, { logPrefix }) } catch (error) { console.error(error) @@ -167,13 +160,6 @@ const Transaction: FC = ({ header, state: txState, ...props }) selectedTransaction: transactionType } - if (fields.Destination !== undefined) { - nwState.selectedDestAccount = null - fields.Destination = '' - } else { - fields.Destination = undefined - } - if (transactionType?.value && transactionFlags[transactionType?.value] && fields.Flags) { nwState.selectedFlags = extractFlags(transactionType.value, fields.Flags) fields.Flags = undefined diff --git a/components/Transaction/ui.tsx b/components/Transaction/ui.tsx index eec1d62..9cddf97 100644 --- a/components/Transaction/ui.tsx +++ b/components/Transaction/ui.tsx @@ -136,15 +136,7 @@ export const TxUI: FC = ({ } }, [handleChangeTxType, selectedTransaction?.value]) - const fields = useMemo( - () => getTxFields(selectedTransaction?.value), - [selectedTransaction?.value] - ) - const richFields = ['TransactionType', 'Account', 'HookParameters', 'Memos'] - if (fields.Destination !== undefined) { - richFields.push('Destination') - } if (flagsOptions.length) { richFields.push('Flags') @@ -192,18 +184,6 @@ export const TxUI: FC = ({ - {richFields.includes('Destination') && ( - - { return } - const { Account, TransactionType, Destination, HookParameters, Memos, ...rest } = options + const { Account, TransactionType, HookParameters, Memos, ...rest } = options let tx: Partial = {} const schema = getTxFields(transactionType) @@ -238,24 +237,6 @@ export const prepareState = (value: string, transactionType?: string) => { }, {}) } - if (schema.Destination !== undefined) { - const dest = state.accounts.find(acc => acc.address === Destination) - if (dest) { - tx.selectedDestAccount = { - label: dest.name, - value: dest.address - } - } else if (Destination) { - tx.selectedDestAccount = { - label: Destination, - value: Destination - } - } else { - tx.selectedDestAccount = null - } - } else if (Destination) { - rest.Destination = Destination - } if (getFlags(TransactionType) && rest.Flags) { const flags = extractFlags(TransactionType, rest.Flags) @@ -274,7 +255,7 @@ export const prepareState = (value: string, transactionType?: string) => { if (isAmount && ["number", "string"].includes(typeof value)) { rest[field] = { - $type: 'amount.xrp', // Maybe have $type map or something + $type: 'amount.xrp', // TODO narrow typed $type. $value: +value / 1000000 // ! maybe use bigint? } }