Skip to content

Commit a02ee59

Browse files
committed
feat(suite): wip frontend
1 parent a56ae2b commit a02ee59

File tree

13 files changed

+491
-217
lines changed

13 files changed

+491
-217
lines changed

packages/connect/src/api/bitcoin/Fees.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class FeeLevels {
8686
if (response.eip1559) {
8787
const eip1559LevelKeys = ['low', 'medium', 'high'] as const;
8888

89-
const { eip1559, ...baseLevel } = response;
89+
const { eip1559 } = response;
9090
const eip1559Levels = eip1559LevelKeys.map(levelKey => {
9191
const level = eip1559[levelKey];
9292

@@ -104,10 +104,7 @@ export class FeeLevels {
104104
};
105105
});
106106

107-
this.levels = [
108-
{ ...baseLevel, label: 'normal' as const, blocks: -1, ethFeeType: 'legacy' },
109-
...eip1559Levels,
110-
];
107+
this.levels = [...eip1559Levels];
111108
} else {
112109
this.levels[0] = {
113110
...this.levels[0],

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/ClaimModal/ClaimModal.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const ClaimModal = ({ onCancel }: ClaimModalModalProps) => {
2626

2727
const {
2828
account,
29+
network,
2930
formState: { errors, isSubmitting },
3031
register,
3132
control,
@@ -113,6 +114,7 @@ export const ClaimModal = ({ onCancel }: ClaimModalModalProps) => {
113114

114115
<Card paddingType="small" margin={{ vertical: spacings.xs }}>
115116
<Fees
117+
network={network}
116118
control={control}
117119
errors={errors}
118120
register={register}

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeModal/StakeEthForm/StakeEthForm.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { AvailableBalance } from './AvailableBalance';
1212
export const StakeEthForm = () => {
1313
const {
1414
account,
15+
network,
1516
isConfirmModalOpen,
1617
closeConfirmModal,
1718
signTx,
@@ -45,6 +46,7 @@ export const StakeEthForm = () => {
4546

4647
<Card paddingType="small" margin={{ top: spacings.xs }}>
4748
<Fees
49+
network={network}
4850
control={control}
4951
errors={errors}
5052
register={register}

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/TxDetailModal/ChangeFee/RbfFees.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export const RbfFees = () => {
1313
account,
1414
feeInfo,
1515
composedLevels,
16+
network,
1617
} = useRbfContext();
1718

1819
return (
1920
<Fees
21+
network={network}
2022
control={control}
2123
errors={errors}
2224
register={register}

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/UnstakeModal/UnstakeEthForm/Fees.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ const UnstakeFees = () => {
2222
changeFeeLevel,
2323
feeInfo,
2424
composedLevels,
25+
network,
2526
} = useUnstakeEthFormContext();
2627

2728
return (
2829
<StyledCard>
2930
<Fees
31+
network={network}
3032
control={control}
3133
errors={errors}
3234
register={register}

packages/suite/src/components/wallet/Fees/CustomFee.tsx

+64-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from 'react-hook-form';
1010

1111
import { BigNumber } from '@trezor/utils/src/bigNumber';
12-
import { Note, Banner, variables, Grid, Column, useMediaQuery, Text } from '@trezor/components';
12+
import { Note, Banner, Grid, Column, Text, variables, useMediaQuery } from '@trezor/components';
1313
import { getInputState, getFeeUnits, isInteger } from '@suite-common/wallet-utils';
1414
import { FeeInfo, FormState } from '@suite-common/wallet-types';
1515
import { NetworkType } from '@suite-common/wallet-config';
@@ -28,6 +28,9 @@ import { InputError } from '../InputError';
2828
const FEE_PER_UNIT = 'feePerUnit';
2929
const FEE_LIMIT = 'feeLimit';
3030

31+
const MAX_FEE_PER_GAS = 'maxFeePerGas';
32+
const MAX_PRIORITY_FEE_PER_GAS = 'maxPriorityFeePerGas';
33+
3134
interface CustomFeeProps<TFieldValues extends FormState> {
3235
networkType: NetworkType;
3336
feeInfo: FeeInfo;
@@ -36,24 +39,26 @@ interface CustomFeeProps<TFieldValues extends FormState> {
3639
control: Control;
3740
setValue: UseFormSetValue<TFieldValues>;
3841
getValues: UseFormGetValues<TFieldValues>;
39-
changeFeeLimit?: (value: string) => void;
4042
composedFeePerByte: string;
43+
shouldUsePriorityFees: boolean;
4144
}
4245

4346
export const CustomFee = <TFieldValues extends FormState>({
4447
networkType,
4548
feeInfo,
4649
register,
4750
control,
48-
changeFeeLimit,
4951
composedFeePerByte,
52+
shouldUsePriorityFees = false,
5053
...props
5154
}: CustomFeeProps<TFieldValues>) => {
5255
const { translationString } = useTranslation();
5356
const isBelowLaptop = useMediaQuery(`(max-width: ${variables.SCREEN_SIZE.LG})`);
5457

5558
const locale = useSelector(selectLanguage);
5659

60+
console.log('feeInfo', feeInfo);
61+
5762
// Type assertion allowing to make the component reusable, see https://stackoverflow.com/a/73624072.
5863
const { getValues, setValue } = props as unknown as UseFormReturn<FormState>;
5964
const errors = props.errors as unknown as FieldErrors<FormState>;
@@ -64,6 +69,11 @@ export const CustomFee = <TFieldValues extends FormState>({
6469
const feeUnits = getFeeUnits(networkType);
6570
const estimatedFeeLimit = getValues('estimatedFeeLimit');
6671

72+
// const maxFeePerGas = shouldUsePriorityFees ? getValues(MAX_FEE_PER_GAS) : undefined; //only for priority fees on evms
73+
// const maxPriorityFeePerGas = shouldUsePriorityFees
74+
// ? getValues(MAX_PRIORITY_FEE_PER_GAS)
75+
// : undefined;
76+
6777
const feePerUnitError = errors.feePerUnit;
6878
const feeLimitError = errors.feeLimit;
6979

@@ -169,7 +179,6 @@ export const CustomFee = <TFieldValues extends FormState>({
169179
inputState={getInputState(feeLimitError)}
170180
name={FEE_LIMIT}
171181
data-testid={FEE_LIMIT}
172-
onChange={changeFeeLimit}
173182
bottomText={
174183
feeLimitError?.message ? (
175184
<InputError
@@ -183,21 +192,57 @@ export const CustomFee = <TFieldValues extends FormState>({
183192
) : (
184193
<input type="hidden" {...register(FEE_LIMIT as FieldPath<TFieldValues>)} />
185194
)}
186-
<NumberInput
187-
label={useFeeLimit ? <Translation id="TR_GAS_PRICE" /> : undefined}
188-
locale={locale}
189-
control={control}
190-
inputState={getInputState(feePerUnitError)}
191-
innerAddon={
192-
<Text variant="tertiary" typographyStyle="label">
193-
{feeUnits}
194-
</Text>
195-
}
196-
name={FEE_PER_UNIT}
197-
data-testid={FEE_PER_UNIT}
198-
rules={feeRules}
199-
bottomText={feePerUnitError?.message || null}
200-
/>
195+
196+
{shouldUsePriorityFees && feeInfo.levels[0].ethFeeType === 'eip1559' ? (
197+
<>
198+
<NumberInput
199+
label={<Translation id="TR_MAX_PRIORITY_FEE_PER_GAS" />}
200+
locale={locale}
201+
control={control}
202+
inputState={getInputState(feePerUnitError)}
203+
innerAddon={
204+
<Text variant="tertiary" typographyStyle="label">
205+
{feeUnits}
206+
</Text>
207+
}
208+
name={MAX_PRIORITY_FEE_PER_GAS}
209+
data-testid={MAX_PRIORITY_FEE_PER_GAS}
210+
rules={feeRules}
211+
bottomText={feePerUnitError?.message || null}
212+
/>
213+
<NumberInput
214+
label={<Translation id="TR_MAX_FEE_PER_GAS" />}
215+
locale={locale}
216+
control={control}
217+
inputState={getInputState(feePerUnitError)}
218+
innerAddon={
219+
<Text variant="tertiary" typographyStyle="label">
220+
{feeUnits}
221+
</Text>
222+
}
223+
name={MAX_FEE_PER_GAS}
224+
data-testid={MAX_FEE_PER_GAS}
225+
rules={feeRules}
226+
bottomText={feePerUnitError?.message || null}
227+
/>
228+
</>
229+
) : (
230+
<NumberInput
231+
label={useFeeLimit ? <Translation id="TR_GAS_PRICE" /> : undefined}
232+
locale={locale}
233+
control={control}
234+
inputState={getInputState(feePerUnitError)}
235+
innerAddon={
236+
<Text variant="tertiary" typographyStyle="label">
237+
{feeUnits}
238+
</Text>
239+
}
240+
name={FEE_PER_UNIT}
241+
data-testid={FEE_PER_UNIT}
242+
rules={feeRules}
243+
bottomText={feePerUnitError?.message || null}
244+
/>
245+
)}
201246
</Grid>
202247
{feeDifferenceWarning && <Note>{feeDifferenceWarning}</Note>}
203248
</Column>

0 commit comments

Comments
 (0)