Skip to content

Commit

Permalink
feat(settings): add setting for always clear transaction data after s…
Browse files Browse the repository at this point in the history
…ending

Closes #117
  • Loading branch information
No-Cash-7970 committed Jan 6, 2024
1 parent 52dd1ee commit 5fac2a3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 26 deletions.
15 changes: 15 additions & 0 deletions src/app/[lang]/components/NavBar/Settings/SettingsDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('Settings Dialog', () => {
await userEvent.click(screen.getByLabelText('settings.default_apar_c_use_snd'));
await userEvent.click(screen.getByLabelText('settings.default_apar_r_use_snd'));
await userEvent.click(screen.getByLabelText('settings.default_auto_send'));
await userEvent.click(screen.getByLabelText('settings.always_clear_after_send'));
// XXX: Add more settings here

// Click reset button
Expand All @@ -96,6 +97,7 @@ describe('Settings Dialog', () => {
expect(screen.getByLabelText('settings.default_apar_c_use_snd')).toBeChecked();
expect(screen.getByLabelText('settings.default_apar_r_use_snd')).toBeChecked();
expect(screen.getByLabelText('settings.default_auto_send')).toBeChecked();
expect(screen.getByLabelText('settings.always_clear_after_send')).toBeChecked();
// XXX: Add more settings here
});

Expand Down Expand Up @@ -328,6 +330,19 @@ describe('Settings Dialog', () => {
expect(screen.getByText('settings.saved_message')).toBeInTheDocument();
});

it('notifies when "always clear after sending transaction" setting is changed',
async () => {
render(
<ToastProvider>
<SettingsDialog open={true} />
<ToastViewport />
</ToastProvider>
);
// Change setting from checked (true) --> unchecked (false)
await userEvent.click(screen.getByLabelText('settings.always_clear_after_send'));
expect(screen.getByText('settings.saved_message')).toBeInTheDocument();
});

it('has "clear transaction data" button', () => {
render(
<ToastProvider>
Expand Down
12 changes: 12 additions & 0 deletions src/app/[lang]/components/NavBar/Settings/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function SettingsForm(props: Props) {
const [defaultApar_cUseSnd, setDefaultApar_cUseSnd] = useAtom(Settings.defaultApar_cUseSnd);
const [defaultApar_rUseSnd, setDefaultApar_rUseSnd] = useAtom(Settings.defaultApar_rUseSnd);
const [defaultAutoSend, setDefaultAutoSend] = useAtom(Settings.defaultAutoSend);
const [alwaysClearAfterSend, setAlwaysClearAfterSend] = useAtom(Settings.alwaysClearAfterSend);
const setStoredTxnData = useSetAtom(storedTxnDataAtom);
const setSignedTxn = useSetAtom(storedSignedTxnAtom);
// XXX: Add more settings here
Expand Down Expand Up @@ -82,6 +83,7 @@ export default function SettingsForm(props: Props) {
setDefaultApar_cUseSnd(Settings.defaults.defaultApar_cUseSnd);
setDefaultApar_rUseSnd(Settings.defaults.defaultApar_rUseSnd);
setDefaultAutoSend(Settings.defaults.defaultAutoSend);
setAlwaysClearAfterSend(Settings.defaults.alwaysClearAfterSend);
// XXX: Add more settings here

// Notify user of reset
Expand Down Expand Up @@ -162,6 +164,16 @@ export default function SettingsForm(props: Props) {
onChange={(e) => {setDefaultAutoSend(e.target.checked); notifySave();}}
/>

{/* Setting: Always clear transaction data after sending */}
<ToggleField
name='always_clear_after_send'
label={t('settings.always_clear_after_send')}
inputClass='toggle-primary'
containerClass='mt-4'
value={alwaysClearAfterSend}
onChange={(e) => {setAlwaysClearAfterSend(e.target.checked); notifySave();}}
/>

<h3>{t('settings.asset_create_title')}</h3>

{/* Setting: Set manager address to the sender address by default */}
Expand Down
11 changes: 8 additions & 3 deletions src/app/[lang]/txn/send/components/SendTxn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useDebouncedCallback } from 'use-debounce';
import { dataUrlToBytes } from '@/app/lib/utils';
import { storedSignedTxnAtom, storedTxnDataAtom } from '@/app/lib/txn-data';
import { nodeConfigAtom } from '@/app/lib/node-config';
import { alwaysClearAfterSend as alwaysClearAfterSendAtom } from '@/app/lib/app-settings';

type Props = {
/** Language */
Expand Down Expand Up @@ -47,6 +48,7 @@ const WAIT_ROUNDS_TO_CONFIRM = 10;
export default function SendTxn({ lng }: Props) {
const { t } = useTranslation(lng || '', ['send_txn']);
const currentURLParams = useSearchParams();
const alwaysClearAfterSend = useAtomValue(alwaysClearAfterSendAtom);

const [waiting, setWaiting] = useState(false);
const [pendingTxId, setPendingTxId] = useState('');
Expand Down Expand Up @@ -118,9 +120,12 @@ export default function SendTxn({ lng }: Props) {
try {
const response = await algokit.waitForConfirmation(txId, wait, algod);
setSuccessMsg({txId, response});
// Remove stored transaction data because it is not needed anymore
setStoredTxnData(RESET);
setStoredSignedTxn(RESET);

// Remove stored transaction data because it is not needed anymore, if allowed by the settings
if (alwaysClearAfterSend) {
setStoredTxnData(RESET);
setStoredSignedTxn(RESET);
}
} catch (e) {
setFailMsg(getFailMessage(e));
} finally {
Expand Down
1 change: 1 addition & 0 deletions src/app/i18n/locales/en/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ settings:
default_apar_c_use_snd: Set the clawback address to the sender address by default
default_apar_r_use_snd: Set the reserve address to the sender address by default
default_auto_send: Automatically send transaction after signing by default
always_clear_after_send: Always clear saved transaction data after sending
clear_data_title: Clear Stored Data
clear_txn_data_btn: Clear saved transaction data
clear_all_data_btn: Clear ALL data
Expand Down
1 change: 1 addition & 0 deletions src/app/i18n/locales/es/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ settings:
default_apar_r_use_snd: >
Establecer la dirección de reserva en la dirección del remitente por defecto
default_auto_send: Enviar automáticamente la transacción después de firmar por defecto
always_clear_after_send: Borrar siempre los datos de transacción guardados tras el envío
clear_data_title: Borrar datos almacenados
clear_txn_data_btn: Borrar datos de transacciones guardados
clear_all_data_btn: Borrar TODOS los datos
Expand Down
37 changes: 14 additions & 23 deletions src/app/lib/app-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,25 @@ export const defaults = {
* (default: `false` - Do not ignore)
*/
ignoreFormErrors: false,
/** Use the suggested fee by default? (default: `true` - Use suggested fee by default) */
/** Use the suggested fee by default? */
defaultUseSugFee: true,
/** Use the suggested first & last valid round by default?
* (default: `true` - Use suggested rounds by default)
*/
/** Use the suggested first & last valid round by default? */
defaultUseSugRounds: true,
/** Set manager address to the sender address by default?
* (default: `true` - Set manager address to the sender address by default)
*/
/** Set manager address to the sender address by default? */
defaultApar_mUseSnd: true,
/** Set freeze address to the sender address by default?
* (default: `true` - Set freeze address to the sender address by default)
*/
/** Set freeze address to the sender address by default? */
defaultApar_fUseSnd: true,
/** Set clawback address to the sender address by default?
* (default: `true` - Set clawback address to the sender address by default)
*/
/** Set clawback address to the sender address by default? */
defaultApar_cUseSnd: true,
/** Set reserve address to the sender address by default?
* (default: `true` - Set reserve address to the sender address by default)
*/
/** Set reserve address to the sender address by default? */
defaultApar_rUseSnd: true,
/** Retrieve asset information when asset ID is entered?
* (default: `true` - Get asset information when ID is entered)
*/
/** Retrieve asset information when asset ID is entered? */
assetInfoGet: true,
/** Automatically send after signing by default?
* (default: `true` - Automatically send after signing by default)
*/
/** Automatically send after signing by default? */
defaultAutoSend: true,
};
/** Always clear transaction data after sending? */
alwaysClearAfterSend: true,
} as const;

/** Theme mode */
export const themeAtom = atomWithStorage<Themes>('theme', defaults.theme, storage);
Expand Down Expand Up @@ -84,3 +72,6 @@ export const assetInfoGet =
/** Automatically send after signing by default? */
export const defaultAutoSend =
atomWithStorage<boolean>('defaultAutoSend', defaults.defaultAutoSend, storage);
/** Always clear transaction data after sending? */
export const alwaysClearAfterSend =
atomWithStorage<boolean>('alwaysClearAfterSend', defaults.alwaysClearAfterSend, storage);

0 comments on commit 5fac2a3

Please sign in to comment.