Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Feb 28, 2025
1 parent 7ee2aba commit ecf33d0
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 31 deletions.
1 change: 1 addition & 0 deletions packages/connect/src/api/ethereum/EthereumFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class EthereumFeeLevels extends MiscFeeLevels {
async load(blockchain: Blockchain) {
try {
const [response] = await blockchain.estimateFee({ blocks: [1] });
console.log('response', response);

Check warning on line 23 in packages/connect/src/api/ethereum/EthereumFees.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
if (response.eip1559) {
const eip1559ResponseLevelKeys = [
'low',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const TransactionReviewSummary = ({
const baseFee = fees[symbol].levels[0].baseFeePerGas;
const hasEip1559Feature = getNetworkFeatures(symbol).includes('eip1559');
const shouldUsePriorityFees = !!tx.fee && hasEip1559Feature && !!baseFee;
console.log('shouldUsePriorityFees', shouldUsePriorityFees, tx, hasEip1559Feature, baseFee);
const fee = getFee({ account, tx, shouldUsePriorityFees });

const estimateTime = getEstimatedTime(networkType, fees[account.symbol], tx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ export const CustomFeeEthereum = <TFieldValues extends FormState>({
const estimatedFeeLimit = getValues('estimatedFeeLimit');
const feePerUnitError = errors.feePerUnit;
const feeLimitError = errors.feeLimit;
const customMaxBaseFeePerGasError = undefined; // prepared for when priority fee is implemented
const customMaxPriorityFeePerGasError = undefined; // prepared for when priority fee is implemented
// const customMaxBaseFeePerGasError = errors.customMaxBaseFeePerGas;
// const customMaxPriorityFeePerGasError = errors.customMaxPriorityFeePerGas;

const customMaxBaseFeePerGasError = errors.customMaxBaseFeePerGas;
const customMaxPriorityFeePerGasError = errors.customMaxPriorityFeePerGas;

const feeLimitRules = {
required: translationString('GAS_LIMIT_IS_NOT_SET'),
Expand Down Expand Up @@ -111,18 +110,19 @@ export const CustomFeeEthereum = <TFieldValues extends FormState>({
const feeLimitValidationButtonProps =
feeLimitError?.type === 'feeLimit' ? feeLimitValidationProps : undefined;

// const customMaxBaseFeeValidationProps = {
// onClick: () =>
// estimatedFeeLimit &&
// setValue(CUSTOM_MAX_BASE_FEE_PER_GAS, currentBaseFee, {
// shouldValidate: true,
// }),
// text: translationString('TR_CUSTOM_MAX_BASE_FEE_USE_NETWORK_BASE_FEE'),
// };
const customMaxBaseFeeValidationProps = {
onClick: () =>
estimatedFeeLimit &&
setValue(CUSTOM_MAX_BASE_FEE_PER_GAS, currentBaseFee, {
shouldValidate: true,
}),
text: translationString('TR_CUSTOM_MAX_BASE_FEE_USE_NETWORK_BASE_FEE'),
};

// const customMaxBaseFeeValidationButtonProps = customMaxBaseFeePerGasError?.type === 'customMaxBaseFeePerGas'
// ? customMaxBaseFeeValidationProps
// : undefined;
const customMaxBaseFeeValidationButtonProps =
customMaxBaseFeePerGasError?.type === 'customMaxBaseFeePerGas'
? customMaxBaseFeeValidationProps
: undefined;

const gasLimitInput = (
<NumberInput
Expand Down Expand Up @@ -161,13 +161,12 @@ export const CustomFeeEthereum = <TFieldValues extends FormState>({
data-testid={CUSTOM_MAX_BASE_FEE_PER_GAS}
rules={customMaxBaseFeePerGasRules}
bottomText={
// customMaxBaseFeePerGasError?.message ? (
// <InputError
// message={customMaxBaseFeePerGasError?.message}
// buttonProps={customMaxBaseFeeValidationButtonProps}
// />
// ) :
null
customMaxBaseFeePerGasError?.message ? (
<InputError
message={customMaxBaseFeePerGasError?.message}
buttonProps={customMaxBaseFeeValidationButtonProps}
/>
) : null
}
/>
<NumberInput
Expand All @@ -183,10 +182,7 @@ export const CustomFeeEthereum = <TFieldValues extends FormState>({
name={CUSTOM_MAX_PRIORITY_FEE_PER_GAS}
data-testid={CUSTOM_MAX_PRIORITY_FEE_PER_GAS}
rules={customMaxPriorityFeePerGasRules}
bottomText={
// customMaxPriorityFeePerGasError?.message ||
null
}
bottomText={customMaxPriorityFeePerGasError?.message || null}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ export const useTradingExchangeForm = ({
setMaxOutputId: values.setMaxOutputId,
});

console.log('result', result);

// in case of not success, recomposeAndSign shows notification
if (result?.success) {
const { txid } = result.payload;
Expand Down
9 changes: 9 additions & 0 deletions packages/suite/src/hooks/wallet/useTradingRecomposeAndSign.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useCallback } from 'react';

import { toWei } from 'web3-utils';

Check failure on line 3 in packages/suite/src/hooks/wallet/useTradingRecomposeAndSign.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

'toWei' is defined but never used. Allowed unused vars must match /^_/u

import { notificationsActions } from '@suite-common/toast-notifications';
import { networks } from '@suite-common/wallet-config';
import { DEFAULT_PAYMENT, DEFAULT_VALUES } from '@suite-common/wallet-constants';
Expand Down Expand Up @@ -55,6 +57,7 @@ export const useTradingRecomposeAndSign = () => {

return;
}
console.log('composed', composed);
// prepare the fee levels, set custom values from composed
// WORKAROUND: sendFormEthereumActions and sendFormRippleActions use form outputs instead of composed transaction data
const formState: FormState = {
Expand All @@ -72,6 +75,8 @@ export const useTradingRecomposeAndSign = () => {
feePerUnit: composed.feePerByte,
maxFeePerGas: composed.maxFeePerGas,
maxPriorityFeePerGas: composed.maxPriorityFeePerGas,
customMaxBaseFeePerGas: composed.maxFeePerGas,
customMaxPriorityFeePerGas: composed.maxPriorityFeePerGas,
feeLimit: composed.feeLimit || '',
estimatedFeeLimit: composed.estimatedFeeLimit,
options,
Expand All @@ -86,7 +91,11 @@ export const useTradingRecomposeAndSign = () => {
const feeInfo = getFeeInfo({
networkType: account.networkType,
feeInfo: fees[account.symbol],
customMaxFeePerGas: formState.customMaxBaseFeePerGas,
customMaxPriorityFeePerGas: formState.customMaxPriorityFeePerGas,
});

console.log('feeInfo', feeInfo, formState);
const composeContext = { account, network, feeInfo };

// recalcCustomLimit is used in case of custom fee level, when we want to keep the feePerUnit defined by the user
Expand Down
1 change: 1 addition & 0 deletions packages/suite/src/reducers/wallet/tradingReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface ComposedTransactionInfo {
| 'fee'
| 'maxFeePerGas'
| 'maxPriorityFeePerGas'
| 'effectiveGasPrice'
>;
selectedFee?: FeeLevel['label'];
}
Expand Down
2 changes: 2 additions & 0 deletions suite-common/wallet-core/src/send/sendFormEthereumThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const composeEthereumTransactionFeeLevelsThunk = createThunk<
});

const { output, tokenInfo, decimals } = composedOutput;
console.log('composedOutput', composedOutput);

Check failure on line 64 in suite-common/wallet-core/src/send/sendFormEthereumThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
const { availableBalance } = account;
const { address, amount } = formState.outputs[0];

Expand All @@ -70,6 +71,7 @@ export const composeEthereumTransactionFeeLevelsThunk = createThunk<
coin: account.symbol,
identity: getAccountIdentity(account),
request: {
feeLevels: 'smart',
blocks: [2],
specific: {
from: account.descriptor,
Expand Down
18 changes: 18 additions & 0 deletions suite-common/wallet-core/src/send/sendFormEthereumUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const calculateEvmTxWithFees = ({
let amount: string;
let max: string | undefined;

console.log('feeLevel', feeLevel);

Check failure on line 29 in suite-common/wallet-core/src/send/sendFormEthereumUtils.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error

const eip1559 = feeLevel.maxPriorityFeePerGas
? {
maxPriorityFeePerGas: feeLevel.maxPriorityFeePerGas,
Expand All @@ -41,6 +43,7 @@ export const calculateEvmTxWithFees = ({
const availableTokenBalance = token
? amountToSmallestUnit(token.balance!, token.decimals)
: undefined;

if (output.type === 'send-max' || output.type === 'send-max-noaddress') {
max = availableTokenBalance || calculateMax(availableBalance, feeInWei);
amount = max;
Expand All @@ -51,6 +54,19 @@ export const calculateEvmTxWithFees = ({
// total ETH spent (amount + fee), in ERC20 only fee
const totalSpent = new BigNumber(calculateTotal(token ? '0' : amount, feeInWei));

console.log(

Check failure on line 57 in suite-common/wallet-core/src/send/sendFormEthereumUtils.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
'totalSpent',
eip1559,
feeInWei,
availableTokenBalance,
amount,
output,
availableBalance,
token,
totalSpent.toString(),
totalSpent.isGreaterThan(availableBalance),
);

if (totalSpent.isGreaterThan(availableBalance)) {
if (token) {
return {
Expand All @@ -77,6 +93,8 @@ export const calculateEvmTxWithFees = ({
availableTokenBalance &&
(availableTokenBalance === '0' || new BigNumber(amount).gt(availableTokenBalance))
) {
console.log('availableTokenBalance error', availableTokenBalance, amount);

Check failure on line 96 in suite-common/wallet-core/src/send/sendFormEthereumUtils.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error

return {
type: 'error',
error: 'AMOUNT_IS_NOT_ENOUGH',
Expand Down
31 changes: 28 additions & 3 deletions suite-common/wallet-utils/src/sendFormUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,21 @@ export const prepareEthereumTransaction = (
interface GetFeeInfoProps {
feeInfo: FeeInfo;
networkType: NetworkType;
customMaxFeePerGas?: string;
customMaxPriorityFeePerGas?: string;
}

const getFeeLevels = ({ feeInfo, networkType }: GetFeeInfoProps) => {
const getFeeLevels = ({
feeInfo,
networkType,
customMaxFeePerGas,
customMaxPriorityFeePerGas,
}: GetFeeInfoProps) => {
const levels = feeInfo.levels.concat({
label: 'custom',
feePerUnit: '0',
// maxFeePerGas: customMaxFeePerGas,
// maxPriorityFeePerGas: customMaxPriorityFeePerGas,
blocks: -1,
});

Expand All @@ -215,6 +224,7 @@ const getFeeLevels = ({ feeInfo, networkType }: GetFeeInfoProps) => {
feePerUnit: level.feePerUnit,
maxFeePerGas: level.maxFeePerGas,
maxPriorityFeePerGas: level.maxPriorityFeePerGas,
effectiveGasPrice: level.effectiveGasPrice,
feeLimit: level.feeLimit,
}));
}
Expand All @@ -228,20 +238,35 @@ const getFeeLevels = ({ feeInfo, networkType }: GetFeeInfoProps) => {
? feeInfo.minFee.toString()
: gwei.toString();

const calculatedMaxFeePerGas = BigNumber.minimum(
new BigNumber(level?.maxFeePerGas || '0'),
new BigNumber(feeInfo.levels[0].baseFeePerGas || '0').plus(
level?.maxPriorityFeePerGas || '0',
),
).toFixed();

return {
...level,
feePerUnit,
feeLimit: level.feeLimit,
maxFeePerGas: customMaxFeePerGas,
maxPriorityFeePerGas: customMaxPriorityFeePerGas,
effectiveGasPrice: calculatedMaxFeePerGas,
};
});
}

return levels;
};

export const getFeeInfo = ({ networkType, feeInfo }: GetFeeInfoProps): FeeInfo => ({
export const getFeeInfo = ({
networkType,
feeInfo,
customMaxFeePerGas,
customMaxPriorityFeePerGas,
}: GetFeeInfoProps): FeeInfo => ({
...feeInfo,
levels: getFeeLevels({ networkType, feeInfo }),
levels: getFeeLevels({ networkType, feeInfo, customMaxFeePerGas, customMaxPriorityFeePerGas }),
});

export const getInputState = (
Expand Down

0 comments on commit ecf33d0

Please sign in to comment.