diff --git a/content/transactions.json b/content/transactions.json index 213f57e..f2bb3ac 100644 --- a/content/transactions.json +++ b/content/transactions.json @@ -172,7 +172,7 @@ "Fee": "12", "SignerQuorum": 3, "SignerEntries": { - "type": "list", + "type": "json", "value": [ { "SignerEntry": { diff --git a/pages/test/[[...slug]].tsx b/pages/test/[[...slug]].tsx index f199b91..79416d8 100644 --- a/pages/test/[[...slug]].tsx +++ b/pages/test/[[...slug]].tsx @@ -83,31 +83,52 @@ const Transaction = () => { setTxIsLoading(true); // setTxIsError(null) - let options = { ...txFields }; + try { + let options = { ...txFields }; - options.Destination = selectedDestAccount?.value; - (Object.keys(options) as (keyof TxFields)[]).forEach(field => { - let _value = options[field]; - // convert currency - if (typeof _value === "object" && _value.type === "currency") { - if (+_value.value) { - options[field] = (+_value.value * 1000000 + "") as any; - } else { - options[field] = undefined; // 👇 💀 + options.Destination = selectedDestAccount?.value; + (Object.keys(options) as (keyof TxFields)[]).forEach(field => { + let _value = options[field]; + // convert currency + if (typeof _value === "object" && _value.type === "currency") { + if (+_value.value) { + options[field] = (+_value.value * 1000000 + "") as any; + } else { + options[field] = undefined; // 👇 💀 + } + } + // handle type: `json` + if (typeof _value === "object" && _value.type === "json") { + if (typeof _value.value === "object") { + options[field] = _value.value as any; + } else { + try { + options[field] = JSON.parse(_value.value); + } catch (error) { + const message = `Input error for json field '${field}': ${ + error instanceof Error ? error.message : "" + }`; + throw Error(message); + } + } } - } - // delete unneccesary fields - if (!options[field]) { - delete options[field]; - } - }); - await sendTransaction(account, { - TransactionType, - ...options, - }); + // delete unneccesary fields + if (!options[field]) { + delete options[field]; + } + }); + await sendTransaction(account, { + TransactionType, + ...options, + }); + } catch (error) { + console.error(error); + if (error instanceof Error) { + state.transactionLogs.push({ type: "error", message: error.message }); + } + } setTxIsLoading(false); - // TODO catch error for UI to show }, [ selectedAccount, selectedDestAccount, @@ -196,6 +217,7 @@ const Transaction = () => { {otherFields.map(field => { let _value = txFields[field]; let value = typeof _value === "object" ? _value.value : _value; + value = typeof value === "object" ? JSON.stringify(value) : value?.toLocaleString(); let isCurrency = typeof _value === "object" && _value.type === "currency"; return ( { {field + (isCurrency ? " (XRP)" : "")}:{" "} setTxFields({ ...txFields, diff --git a/state/actions/sendTransaction.ts b/state/actions/sendTransaction.ts index 7c405d1..55d9d40 100644 --- a/state/actions/sendTransaction.ts +++ b/state/actions/sendTransaction.ts @@ -41,10 +41,10 @@ export const sendTransaction = async (account: IAccount, txOptions: TransactionO }); } } catch (err) { - console.log(err); + console.error(err); state.transactionLogs.push({ type: "error", - message: "Something went wrong, try again later.", + message: err instanceof Error ? `Error: ${err.message}` : 'Something went wrong, try again later', }); } }; \ No newline at end of file