2021-12-01 01:31:21 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { PRIORITY_LEVELS } from '../../../../../shared/constants/gas';
|
2022-02-01 18:53:03 +01:00
|
|
|
import { decGWEIToHexWEI } from '../../../../../shared/modules/conversion.utils';
|
2021-12-01 01:31:21 +01:00
|
|
|
import { useTransactionModalContext } from '../../../../contexts/transaction-modal';
|
|
|
|
import { useGasFeeContext } from '../../../../contexts/gasFee';
|
2022-02-01 18:53:03 +01:00
|
|
|
import { useTransactionEventFragment } from '../../../../hooks/useTransactionEventFragment';
|
2022-07-12 15:59:38 +02:00
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
2021-12-01 01:31:21 +01:00
|
|
|
import Button from '../../../ui/button';
|
|
|
|
|
2021-12-06 19:47:26 +01:00
|
|
|
import { useAdvancedGasFeePopoverContext } from '../context';
|
2021-12-01 01:31:21 +01:00
|
|
|
|
|
|
|
const AdvancedGasFeeSaveButton = () => {
|
2022-03-22 17:05:46 +01:00
|
|
|
const { closeModal } = useTransactionModalContext();
|
2022-02-01 18:53:03 +01:00
|
|
|
const { updateTransactionEventFragment } = useTransactionEventFragment();
|
2021-12-01 01:31:21 +01:00
|
|
|
const { updateTransaction } = useGasFeeContext();
|
2022-07-12 15:59:38 +02:00
|
|
|
const t = useI18nContext();
|
2022-07-31 20:26:40 +02:00
|
|
|
const { gasLimit, hasErrors, maxFeePerGas, maxPriorityFeePerGas } =
|
|
|
|
useAdvancedGasFeePopoverContext();
|
2021-12-01 01:31:21 +01:00
|
|
|
|
|
|
|
const onSave = () => {
|
2021-12-03 16:59:48 +01:00
|
|
|
updateTransaction({
|
|
|
|
estimateUsed: PRIORITY_LEVELS.CUSTOM,
|
|
|
|
maxFeePerGas: decGWEIToHexWEI(maxFeePerGas),
|
|
|
|
maxPriorityFeePerGas: decGWEIToHexWEI(maxPriorityFeePerGas),
|
|
|
|
gasLimit,
|
|
|
|
});
|
2022-02-01 18:53:03 +01:00
|
|
|
updateTransactionEventFragment({
|
|
|
|
properties: {
|
|
|
|
gas_edit_type: 'advanced',
|
|
|
|
},
|
|
|
|
});
|
2022-03-22 17:05:46 +01:00
|
|
|
closeModal(['advancedGasFee', 'editGasFee']);
|
2021-12-01 01:31:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2021-12-08 23:56:10 +01:00
|
|
|
<Button type="primary" disabled={hasErrors} onClick={onSave}>
|
2022-07-12 15:59:38 +02:00
|
|
|
{t('save')}
|
2021-12-01 01:31:21 +01:00
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AdvancedGasFeeSaveButton;
|