Skip to content

Commit

Permalink
feat(suite): allow lower fees for eth l2 networks and testnets
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive committed Dec 22, 2024
1 parent fcdb8b1 commit c22ce2f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/connect/src/data/coinInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const parseEthereumNetworksJson = (json: any) => {

ethereumNetworks.push({
...ethereumNetworkInfoBase,
...getEthereumFeeLevels(),
...getEthereumFeeLevels(network.chain),
blockchainLink: network.blockchain_link,
chainId: network.chain_id,
label: network.label,
Expand Down
40 changes: 26 additions & 14 deletions packages/connect/src/data/defaultFeeLevels.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BigNumber } from '@trezor/utils';

import { FeeLevel, FeeInfo } from '../types';

// this is workaround for the lack of information from 'trezor-common'
Expand Down Expand Up @@ -58,20 +60,30 @@ export const getBitcoinFeeLevels = (coin: CoinsJsonData): FeeInfoWithLevels => {
};
};

export const getEthereumFeeLevels = (): FeeInfoWithLevels => ({
blockTime: -1, // unknown
defaultFees: [
{
label: 'normal' as const,
feePerUnit: '5000000000',
feeLimit: '21000', // unlike the other networks ethereum have additional value "feeLimit" (Gas limit)
blocks: -1, // unknown
},
],
minFee: 1,
maxFee: 10000,
dustLimit: -1, // unknown/unused
});
export const getEthereumFeeLevels = (chain: string): FeeInfoWithLevels => {
const DEFAULT_FEE_PER_UNIT = '5'; // in wei
const GWEI = 1;
const GWEI_IN_WEI = 1000000000;

const GWeiChains = ['eth', 'pol', 'bsc'];
const divider = GWeiChains.includes(chain) ? GWEI : GWEI_IN_WEI;
const minFee = new BigNumber(GWEI).div(divider);

return {
blockTime: -1, // unknown
defaultFees: [
{
label: 'normal' as const,
feePerUnit: DEFAULT_FEE_PER_UNIT,
feeLimit: '21000', // unlike the other networks ethereum have additional value "feeLimit" (Gas limit)
blocks: -1, // unknown
},
],
minFee: minFee.toNumber(),
maxFee: 10000,
dustLimit: -1, // unknown/unused
};
};

const RIPPLE_FEE_INFO: FeeInfoWithLevels = {
blockTime: -1, // unknown
Expand Down
9 changes: 7 additions & 2 deletions packages/suite/src/components/wallet/Fees/CustomFee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ export const CustomFee = <TFieldValues extends FormState>({
except: networkType !== 'ethereum',
}),
range: (value: string) => {
const minFeeLocal = new BigNumber(minFee);
const feeBig = new BigNumber(value);
if (feeBig.isGreaterThan(maxFee) || feeBig.isLessThan(minFee)) {
return translationString('CUSTOM_FEE_NOT_IN_RANGE', { minFee, maxFee });

if (feeBig.isGreaterThan(maxFee) || feeBig.isLessThan(minFeeLocal)) {
return translationString('CUSTOM_FEE_NOT_IN_RANGE', {
minFee: minFeeLocal.toString(),
maxFee,
});
}
},
},
Expand Down

0 comments on commit c22ce2f

Please sign in to comment.