diff --git a/public/locales/en.json b/public/locales/en.json index 9bcd195..ba1a837 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -416,6 +416,7 @@ "transactionsHighlightOwn": "Highlight own transactions in the transactions table", "transactionsHighlightVerified": "Highlight verified addresses in the transactions table", "transactionDefaultRaw": "Default to the 'Raw' tab instead of 'CommonMeta' on the transaction page", + "clearTransactionForm": "Clear the Send Transaction form after clicking 'Send'", "defaultPageSize": "Default page size for table listings", "tableHotkeys": "Enable table navigation hotkeys (left and right arrows)", diff --git a/src/pages/settings/SettingsPage.tsx b/src/pages/settings/SettingsPage.tsx index 3d32234..2d2de50 100644 --- a/src/pages/settings/SettingsPage.tsx +++ b/src/pages/settings/SettingsPage.tsx @@ -66,6 +66,8 @@ booleanSetting("transactionsHighlightOwn"), booleanSetting("transactionsHighlightVerified"), booleanSetting("transactionDefaultRaw"), + booleanSetting("clearTransactionForm"), + integerSetting("sendTransactionDelay"), integerSetting("defaultPageSize"), booleanSetting("tableHotkeys"), ]} diff --git a/src/pages/transactions/send/SendTransactionForm.tsx b/src/pages/transactions/send/SendTransactionForm.tsx index a315967..ac21700 100644 --- a/src/pages/transactions/send/SendTransactionForm.tsx +++ b/src/pages/transactions/send/SendTransactionForm.tsx @@ -15,6 +15,7 @@ import { useWallets, Wallet } from "@wallets"; import { useMountEffect } from "@utils"; +import { useBooleanSetting, useIntegerSetting } from "@utils/settings"; import { APIError } from "@api"; import { KristTransaction } from "@api/types"; @@ -194,6 +195,7 @@ to?: string; onError?: (err: Error) => void; onSuccess?: (transaction: KristTransaction) => void; + allowClearOnSend?: boolean; } interface TransactionFormHookResponse { @@ -208,7 +210,8 @@ from: initialFrom, to: initialTo, onError, - onSuccess + onSuccess, + allowClearOnSend }: TransactionFormHookProps = {}): TransactionFormHookResponse { const { t } = useTranslation(); @@ -224,6 +227,11 @@ // Modal used when auth fails const { showAuthFailed, authFailedContextHolder } = useAuthFailedModal(); + // If the form allows it, and the setting is enabled, clear the form when + // sending a transaction. + const clearOnSend = useBooleanSetting("clearTransactionForm"); + const sendDelay = useIntegerSetting("sendTransactionDelay"); + // Called when the modal is closed function onReset() { form.resetFields(); @@ -252,6 +260,15 @@ metadata ); + // Intentionally delay transaction submission, to prevent accidental double + // clicks on fast networks. + if (sendDelay > 0) + await (() => new Promise(resolve => setTimeout(resolve, sendDelay)))(); + + // Clear the form if the setting for it is enabled + if (allowClearOnSend && clearOnSend) + form.resetFields(); + onSuccess?.(tx); } diff --git a/src/pages/transactions/send/SendTransactionPage.tsx b/src/pages/transactions/send/SendTransactionPage.tsx index d8c135e..0120bdb 100644 --- a/src/pages/transactions/send/SendTransactionPage.tsx +++ b/src/pages/transactions/send/SendTransactionPage.tsx @@ -38,6 +38,12 @@ const { addressList } = useWallets(); const hasWallets = addressList?.length > 0; + function onSubmit() { + // Close the alert before submission, to forcibly move the form + setAlert(null); + triggerSubmit(); + } + return + diff --git a/src/utils/settings.ts b/src/utils/settings.ts index 7f52610..1489755 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -52,6 +52,10 @@ readonly transactionsHighlightVerified: boolean; /** Default to the 'Raw' tab instead of 'CommonMeta' on the transaction page. */ readonly transactionDefaultRaw: boolean; + /** Clear the Send Transaction form after clicking 'Send'. */ + readonly clearTransactionForm: boolean; + /** Time to wait, in milliseconds, before allowing another transaction to be sent. */ + readonly sendTransactionDelay: number; /** Default page size for table listings. */ readonly defaultPageSize: number; /** Enable table navigation hotkeys (left and right arrows). */ @@ -81,6 +85,8 @@ transactionsHighlightOwn: true, transactionsHighlightVerified: false, transactionDefaultRaw: false, + clearTransactionForm: false, + sendTransactionDelay: 300, defaultPageSize: 15, tableHotkeys: true, importOverwrite: true,