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';
|
2021-12-01 01:31:21 +01:00
|
|
|
import Button from '../../../ui/button';
|
|
|
|
import I18nValue from '../../../ui/i18n-value';
|
|
|
|
|
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();
|
|
|
|
const {
|
2021-12-03 16:59:48 +01:00
|
|
|
gasLimit,
|
2021-12-08 23:56:10 +01:00
|
|
|
hasErrors,
|
2021-12-01 01:31:21 +01:00
|
|
|
maxFeePerGas,
|
|
|
|
maxPriorityFeePerGas,
|
2021-12-06 19:47:26 +01:00
|
|
|
} = 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}>
|
2021-12-01 01:31:21 +01:00
|
|
|
<I18nValue messageKey="save" />
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AdvancedGasFeeSaveButton;
|