fix handling Destination field
This commit is contained in:
@@ -52,9 +52,11 @@ const Transaction: FC<TransactionProps> = ({
|
|||||||
txFields,
|
txFields,
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
const TransactionType = selectedTransaction?.value;
|
const TransactionType = selectedTransaction?.value || null;
|
||||||
const Destination = selectedDestAccount?.value;
|
const Destination =
|
||||||
const Account = selectedAccount?.value;
|
selectedDestAccount?.value ||
|
||||||
|
("Destination" in txFields ? null : undefined);
|
||||||
|
const Account = selectedAccount?.value || null;
|
||||||
|
|
||||||
return prepareTransaction({
|
return prepareTransaction({
|
||||||
...txFields,
|
...txFields,
|
||||||
@@ -99,6 +101,10 @@ const Transaction: FC<TransactionProps> = ({
|
|||||||
}
|
}
|
||||||
const options = prepareOptions(st);
|
const options = prepareOptions(st);
|
||||||
|
|
||||||
|
if (options.Destination === null) {
|
||||||
|
throw Error("Destination account cannot be null")
|
||||||
|
}
|
||||||
|
|
||||||
await sendTransaction(account, options, { logPrefix });
|
await sendTransaction(account, options, { logPrefix });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -105,11 +105,10 @@ export const modifyTransaction = (
|
|||||||
export const prepareTransaction = (data: any) => {
|
export const prepareTransaction = (data: any) => {
|
||||||
let options = { ...data };
|
let options = { ...data };
|
||||||
|
|
||||||
// options.Destination = selectedDestAccount?.value;
|
|
||||||
(Object.keys(options)).forEach(field => {
|
(Object.keys(options)).forEach(field => {
|
||||||
let _value = options[field];
|
let _value = options[field];
|
||||||
// convert currency
|
// convert currency
|
||||||
if (typeof _value === "object" && _value.type === "currency") {
|
if (_value && typeof _value === "object" && _value.type === "currency") {
|
||||||
if (+_value.value) {
|
if (+_value.value) {
|
||||||
options[field] = (+_value.value * 1000000 + "") as any;
|
options[field] = (+_value.value * 1000000 + "") as any;
|
||||||
} else {
|
} else {
|
||||||
@@ -117,7 +116,7 @@ export const prepareTransaction = (data: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// handle type: `json`
|
// handle type: `json`
|
||||||
if (typeof _value === "object" && _value.type === "json") {
|
if (_value && typeof _value === "object" && _value.type === "json") {
|
||||||
if (typeof _value.value === "object") {
|
if (typeof _value.value === "object") {
|
||||||
options[field] = _value.value as any;
|
options[field] = _value.value as any;
|
||||||
} else {
|
} else {
|
||||||
@@ -133,7 +132,7 @@ export const prepareTransaction = (data: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// delete unneccesary fields
|
// delete unneccesary fields
|
||||||
if (!options[field]) {
|
if (options[field] === undefined) {
|
||||||
delete options[field];
|
delete options[field];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -180,24 +179,28 @@ export const prepareState = (value?: string) => {
|
|||||||
tx.selectedTransaction = null;
|
tx.selectedTransaction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Destination) {
|
if (Destination !== undefined) {
|
||||||
const dest = state.accounts.find(acc => acc.address === Destination);
|
const dest = state.accounts.find(acc => acc.address === Destination);
|
||||||
|
rest.Destination = null
|
||||||
if (dest) {
|
if (dest) {
|
||||||
tx.selectedDestAccount = {
|
tx.selectedDestAccount = {
|
||||||
label: dest.name,
|
label: dest.name,
|
||||||
value: dest.address,
|
value: dest.address,
|
||||||
};
|
};
|
||||||
} else {
|
}
|
||||||
|
else if (Destination) {
|
||||||
tx.selectedDestAccount = {
|
tx.selectedDestAccount = {
|
||||||
label: Destination,
|
label: Destination,
|
||||||
value: Destination,
|
value: Destination,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
tx.selectedDestAccount = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(rest).forEach(field => {
|
Object.keys(rest).forEach(field => {
|
||||||
const value = rest[field];
|
const value = rest[field];
|
||||||
console.log({ field, value });
|
|
||||||
if (field === "Amount") {
|
if (field === "Amount") {
|
||||||
rest[field] = {
|
rest[field] = {
|
||||||
type: "currency",
|
type: "currency",
|
||||||
|
|||||||
Reference in New Issue
Block a user