Remove Destination as special field.

This commit is contained in:
muzam1l
2023-03-23 15:49:17 +05:30
parent 80f58e903c
commit 7aafca21df
4 changed files with 34 additions and 63 deletions

View File

@@ -52,7 +52,6 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
} = state } = state
const TransactionType = selectedTransaction?.value || null const TransactionType = selectedTransaction?.value || null
const Destination = selectedDestAccount?.value || txFields?.Destination
const Account = selectedAccount?.value || null const Account = selectedAccount?.value || null
const Flags = combineFlags(selectedFlags?.map(flag => flag.value)) || txFields?.Flags const Flags = combineFlags(selectedFlags?.map(flag => flag.value)) || txFields?.Flags
const HookParameters = Object.entries(hookParameters || {}).reduce< const HookParameters = Object.entries(hookParameters || {}).reduce<
@@ -75,7 +74,6 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
HookParameters, HookParameters,
Flags, Flags,
TransactionType, TransactionType,
Destination,
Account, Account,
Memos Memos
}) })
@@ -129,11 +127,6 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
} }
const options = prepareOptions(st) 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 }) await sendTransaction(account, options, { logPrefix })
} catch (error) { } catch (error) {
console.error(error) console.error(error)
@@ -167,13 +160,6 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
selectedTransaction: transactionType selectedTransaction: transactionType
} }
if (fields.Destination !== undefined) {
nwState.selectedDestAccount = null
fields.Destination = ''
} else {
fields.Destination = undefined
}
if (transactionType?.value && transactionFlags[transactionType?.value] && fields.Flags) { if (transactionType?.value && transactionFlags[transactionType?.value] && fields.Flags) {
nwState.selectedFlags = extractFlags(transactionType.value, fields.Flags) nwState.selectedFlags = extractFlags(transactionType.value, fields.Flags)
fields.Flags = undefined fields.Flags = undefined

View File

@@ -136,15 +136,7 @@ export const TxUI: FC<UIProps> = ({
} }
}, [handleChangeTxType, selectedTransaction?.value]) }, [handleChangeTxType, selectedTransaction?.value])
const fields = useMemo(
() => getTxFields(selectedTransaction?.value),
[selectedTransaction?.value]
)
const richFields = ['TransactionType', 'Account', 'HookParameters', 'Memos'] const richFields = ['TransactionType', 'Account', 'HookParameters', 'Memos']
if (fields.Destination !== undefined) {
richFields.push('Destination')
}
if (flagsOptions.length) { if (flagsOptions.length) {
richFields.push('Flags') richFields.push('Flags')
@@ -192,18 +184,6 @@ export const TxUI: FC<UIProps> = ({
<TxField label="Sequence"> <TxField label="Sequence">
<AccountSequence address={selectedAccount?.value} /> <AccountSequence address={selectedAccount?.value} />
</TxField> </TxField>
{richFields.includes('Destination') && (
<TxField label="Destination account">
<Select
instanceId="to-account"
placeholder="Select the destination account"
options={destAccountOptions}
value={selectedDestAccount}
isClearable
onChange={(acc: any) => setState({ selectedDestAccount: acc })}
/>
</TxField>
)}
{richFields.includes('Flags') && ( {richFields.includes('Flags') && (
<TxField label="Flags"> <TxField label="Flags">
<Select <Select

View File

@@ -2,7 +2,10 @@
{ {
"TransactionType": "AccountDelete", "TransactionType": "AccountDelete",
"Account": "rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm", "Account": "rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm",
"Destination": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe", "Destination": {
"$type": "account",
"$value": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
},
"DestinationTag": 13, "DestinationTag": 13,
"Fee": "2000000", "Fee": "2000000",
"Sequence": 2470665, "Sequence": 2470665,
@@ -40,7 +43,10 @@
{ {
"TransactionType": "CheckCreate", "TransactionType": "CheckCreate",
"Account": "rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo", "Account": "rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo",
"Destination": "rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy", "Destination": {
"$type": "account",
"$value": "rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy"
},
"SendMax": "100000000", "SendMax": "100000000",
"Expiration": 570113521, "Expiration": 570113521,
"InvoiceID": "6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B", "InvoiceID": "6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B",
@@ -58,7 +64,10 @@
{ {
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"TransactionType": "EscrowCancel", "TransactionType": "EscrowCancel",
"Owner": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "Owner": {
"$type": "account",
"$value": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"
},
"OfferSequence": 7, "OfferSequence": 7,
"Fee": "10" "Fee": "10"
}, },
@@ -69,7 +78,10 @@
"$value": "100", "$value": "100",
"$type": "amount.xrp" "$type": "amount.xrp"
}, },
"Destination": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW", "Destination": {
"$type": "account",
"$value": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW"
},
"CancelAfter": 533257958, "CancelAfter": 533257958,
"FinishAfter": 533171558, "FinishAfter": 533171558,
"Condition": "A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100", "Condition": "A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100",
@@ -80,7 +92,10 @@
{ {
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"TransactionType": "EscrowFinish", "TransactionType": "EscrowFinish",
"Owner": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "Owner": {
"$type": "account",
"$value": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"
},
"OfferSequence": 7, "OfferSequence": 7,
"Condition": "A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100", "Condition": "A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100",
"Fulfillment": "A0028000", "Fulfillment": "A0028000",
@@ -127,7 +142,10 @@
"$type": "amount.xrp" "$type": "amount.xrp"
}, },
"Flags": "1", "Flags": "1",
"Destination": "", "Destination": {
"$type": "account",
"$value": ""
},
"Fee": "10" "Fee": "10"
}, },
{ {
@@ -162,7 +180,10 @@
{ {
"TransactionType": "Payment", "TransactionType": "Payment",
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"Destination": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", "Destination": {
"$type": "account",
"$value": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX"
},
"Amount": { "Amount": {
"$value": "100", "$value": "100",
"$type": "amount.xrp" "$type": "amount.xrp"
@@ -178,7 +199,10 @@
"$value": "100", "$value": "100",
"$type": "amount.xrp" "$type": "amount.xrp"
}, },
"Destination": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW", "Destination": {
"$type": "account",
"$value": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW"
},
"SettleDelay": 86400, "SettleDelay": 86400,
"PublicKey": "32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A", "PublicKey": "32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A",
"CancelAfter": 533171558, "CancelAfter": 533171558,

View File

@@ -28,7 +28,6 @@ export type Memos = {
export interface TransactionState { export interface TransactionState {
selectedTransaction: SelectOption | null selectedTransaction: SelectOption | null
selectedAccount: SelectOption | null selectedAccount: SelectOption | null
selectedDestAccount: SelectOption | null
selectedFlags: SelectOption[] | null selectedFlags: SelectOption[] | null
hookParameters: HookParameters hookParameters: HookParameters
memos: Memos memos: Memos
@@ -192,7 +191,7 @@ export const prepareState = (value: string, transactionType?: string) => {
return return
} }
const { Account, TransactionType, Destination, HookParameters, Memos, ...rest } = options const { Account, TransactionType, HookParameters, Memos, ...rest } = options
let tx: Partial<TransactionState> = {} let tx: Partial<TransactionState> = {}
const schema = getTxFields(transactionType) 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) { if (getFlags(TransactionType) && rest.Flags) {
const flags = extractFlags(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)) { if (isAmount && ["number", "string"].includes(typeof value)) {
rest[field] = { rest[field] = {
$type: 'amount.xrp', // Maybe have $type map or something $type: 'amount.xrp', // TODO narrow typed $type.
$value: +value / 1000000 // ! maybe use bigint? $value: +value / 1000000 // ! maybe use bigint?
} }
} }