Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(suite): do not remember selected fee #13145

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const SET_LOCAL_CURRENCY = '@wallet-settings/set-local-currency';
export const SET_HIDE_BALANCE = '@wallet-settings/hide-balance';
export const CHANGE_NETWORKS = '@wallet-settings/change-networks';
export const SET_LAST_USED_FEE_LEVEL = '@wallet-settings/set-last-used-fee-level';
export const FROM_STORAGE = '@wallet-settings/from-storage';
export const SET_BITCOIN_AMOUNT_UNITS = '@suite/set-bitcoin-amount-units';
18 changes: 0 additions & 18 deletions packages/suite/src/actions/settings/walletSettingsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,6 @@ export const changeCoinVisibility =
});
};

export const setLastUsedFeeLevel =
(feeLevel?: FeeLevel) => (dispatch: Dispatch, getState: GetState) => {
const { selectedAccount } = getState().wallet;
if (selectedAccount.status !== 'loaded') return;
dispatch({
type: WALLET_SETTINGS.SET_LAST_USED_FEE_LEVEL,
symbol: selectedAccount.account.symbol,
feeLevel,
});
};

export const getLastUsedFeeLevel = () => (_: Dispatch, getState: GetState) => {
const { selectedAccount, settings } = getState().wallet;
if (selectedAccount.status !== 'loaded') return;

return settings.lastUsedFeeLevel[selectedAccount.account.symbol];
};

export const setBitcoinAmountUnits = (units: PROTO.AmountUnit): WalletSettingsAction => {
analytics.report({
type: EventType.SettingsGeneralChangeBitcoinUnit,
Expand Down
2 changes: 0 additions & 2 deletions packages/suite/src/components/wallet/Fees/CustomFee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ interface CustomFeeProps<TFieldValues extends FormState> {
control: Control;
setValue: UseFormSetValue<TFieldValues>;
getValues: UseFormGetValues<TFieldValues>;
changeFeeLimit?: (value: string) => void;
composedFeePerByte: string;
}

Expand All @@ -64,7 +63,6 @@ export const CustomFee = <TFieldValues extends FormState>({
feeInfo,
register,
control,
changeFeeLimit,
composedFeePerByte,
...props
}: CustomFeeProps<TFieldValues>) => {
Expand Down
3 changes: 0 additions & 3 deletions packages/suite/src/components/wallet/Fees/Fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export interface FeesProps<TFieldValues extends FormState> {
getValues: UseFormGetValues<TFieldValues>;
errors: FieldErrors<TFieldValues>;
changeFeeLevel: (level: FeeLevel['label']) => void;
changeFeeLimit?: (value: string) => void;
composedLevels?: PrecomposedLevels | PrecomposedLevelsCardano;
label?: ExtendedMessageDescriptor['id'];
rbfForm?: boolean;
Expand All @@ -120,7 +119,6 @@ export const Fees = <TFieldValues extends FormState>({
feeInfo,
control,
changeFeeLevel,
changeFeeLimit,
composedLevels,
label,
rbfForm,
Expand Down Expand Up @@ -220,7 +218,6 @@ export const Fees = <TFieldValues extends FormState>({
register={register}
getValues={getValues}
setValue={setValue}
changeFeeLimit={changeFeeLimit}
composedFeePerByte={
(transactionInfo as PrecomposedTransactionFinal)?.feePerByte
}
Expand Down
24 changes: 2 additions & 22 deletions packages/suite/src/hooks/wallet/form/useFees.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useRef } from 'react';
import { FieldPath, UseFormReturn } from 'react-hook-form';
import { FeeLevel } from '@trezor/connect';
import { setLastUsedFeeLevel } from 'src/actions/settings/walletSettingsActions';
import { useDispatch } from 'src/hooks/suite';
import {
FeeInfo,
Expand Down Expand Up @@ -80,21 +79,8 @@ export const useFees = <TFieldValues extends FormState>({
}

// compose
if (updateField) {
if (composeRequest) {
composeRequest(updateField);
}
// save last used fee
if (
saveLastUsedFeeRef.current &&
feePerUnit &&
!errors.feePerUnit &&
!errors.feeLimit
) {
dispatch(
setLastUsedFeeLevel({ label: 'custom', feePerUnit, feeLimit, blocks: -1 }),
);
}
if (updateField && composeRequest) {
composeRequest(updateField);
}
}, [dispatch, feePerUnit, feeLimit, errors.feePerUnit, errors.feeLimit, composeRequest]);

Expand Down Expand Up @@ -152,12 +138,6 @@ export const useFees = <TFieldValues extends FormState>({
// on change callback
if (onChange) onChange(selectedFeeRef.current, level);

// save last used fee
if (level !== 'custom' && saveLastUsedFeeRef.current) {
const nextLevel = feeInfo.levels.find(l => l.label === (level || 'normal'))!;
dispatch(setLastUsedFeeLevel(nextLevel));
}

selectedFeeRef.current = selectedFee;
};

Expand Down
29 changes: 9 additions & 20 deletions packages/suite/src/hooks/wallet/useSendForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
saveSendFormDraftThunk,
signAndPushSendFormTransactionThunk,
} from 'src/actions/wallet/send/sendFormThunks';
import {
getLastUsedFeeLevel,
setLastUsedFeeLevel,
} from 'src/actions/settings/walletSettingsActions';
import { goto } from 'src/actions/suite/routerActions';
import { fillSendForm } from 'src/actions/suite/protocolActions';
import { AppState } from 'src/types/suite';
Expand Down Expand Up @@ -114,25 +110,12 @@
// used in "loadDraft" useEffect and "importTransaction" callback
const getLoadedValues = useCallback(
(loadedState?: Partial<FormState>) => {
const feeEnhancement: Partial<FormState> = {};
if (!loadedState || !loadedState.selectedFee) {
const lastUsedFee = dispatch(getLastUsedFeeLevel());
if (lastUsedFee) {
feeEnhancement.selectedFee = lastUsedFee.label;
if (lastUsedFee.label === 'custom') {
feeEnhancement.feePerUnit = lastUsedFee.feePerUnit;
feeEnhancement.feeLimit = lastUsedFee.feeLimit;
}
}
}

return {
...getDefaultValues(localCurrencyOption),
...loadedState,
...feeEnhancement,
};
},
[dispatch, localCurrencyOption],
[localCurrencyOption, state.network, localCurrencyOption],

Check failure on line 118 in packages/suite/src/hooks/wallet/useSendForm.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

React Hook useCallback has an unnecessary dependency: 'state.network'. Either exclude it or remove the dependency array
);

// update custom values
Expand Down Expand Up @@ -211,7 +194,6 @@
const resetContext = useCallback(() => {
setComposedLevels(undefined);
dispatch(removeSendFormDraftThunk()); // reset draft;
dispatch(setLastUsedFeeLevel()); // reset last known FeeLevel
setState(getStateFromProps(props)); // resetting state will trigger "loadDraft" useEffect block, which will reset FormState to default
}, [dispatch, props, setComposedLevels]);

Expand Down Expand Up @@ -346,7 +328,14 @@
useEffect(() => {
if (!draftSaveRequest) return;
if (Object.keys(formState.errors).length === 0) {
dispatch(saveSendFormDraftThunk({ formState: getValues() }));
dispatch(
saveSendFormDraftThunk({
formState: {
...getValues(),
selectedFee: undefined,
},
}),
);
}
setDraftSaveRequest(false);
}, [dispatch, draftSaveRequest, setDraftSaveRequest, getValues, formState.errors]);
Expand Down
1 change: 0 additions & 1 deletion packages/suite/src/middlewares/wallet/storageMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ const storageMiddleware = (api: MiddlewareAPI<Dispatch, AppState>) => {
case WALLET_SETTINGS.SET_HIDE_BALANCE:
case walletSettingsActions.setLocalCurrency.type:
case WALLET_SETTINGS.SET_BITCOIN_AMOUNT_UNITS:
case WALLET_SETTINGS.SET_LAST_USED_FEE_LEVEL:
api.dispatch(storageActions.saveWalletSettings());
break;

Expand Down
19 changes: 9 additions & 10 deletions packages/suite/src/storage/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,16 +812,6 @@ export const migrate: OnUpgradeFunc<SuiteDBSchema> = async (
return tx;
});

await updateAll(transaction, 'walletSettings', walletSettings => {
Object.keys(walletSettings.lastUsedFeeLevel).forEach(coin => {
if (walletSettings.lastUsedFeeLevel[coin].label === 'low') {
delete walletSettings.lastUsedFeeLevel[coin];
}
});

return walletSettings;
});

await updateAll(transaction, 'suiteSettings', suiteSettings => {
// @ts-expect-error
delete suiteSettings.flags.showDashboardT2B1PromoBanner;
Expand Down Expand Up @@ -885,4 +875,13 @@ export const migrate: OnUpgradeFunc<SuiteDBSchema> = async (

await updateAll(transaction, 'suiteSettings', suiteSettings => suiteSettings);
}

if (oldVersion < 47) {
await updateAll(transaction, 'walletSettings', walletSettings => {
// @ts-expect-error
delete walletSettings.lastUsedFeeLevel;

return walletSettings;
});
}
};
3 changes: 0 additions & 3 deletions suite-common/wallet-types/src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Network } from '@suite-common/wallet-config';
import { FeeLevel, PROTO } from '@trezor/connect';

Check failure on line 2 in suite-common/wallet-types/src/settings.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

'FeeLevel' is defined but never used. Allowed unused vars must match /^_/u
import { FiatCurrencyCode } from '@suite-common/suite-config';

export const AddressDisplayOptions = {
Expand All @@ -22,7 +22,4 @@
discreetMode: boolean;
enabledNetworks: Network['symbol'][];
bitcoinAmountUnit: PROTO.AmountUnit;
lastUsedFeeLevel: {
[key: string]: Omit<FeeLevel, 'blocks'>; // Key: Network['symbol']
};
}
Loading