2022-03-09 15:38:12 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import ConfirmTokenTransactionBase from '../confirm-token-transaction-base/confirm-token-transaction-base';
|
|
|
|
import { SEND_ROUTE } from '../../helpers/constants/routes';
|
2022-07-01 15:58:35 +02:00
|
|
|
import { editExistingTransaction } from '../../ducks/send';
|
2022-03-09 15:38:12 +01:00
|
|
|
import {
|
|
|
|
contractExchangeRateSelector,
|
|
|
|
getCurrentCurrency,
|
|
|
|
} from '../../selectors';
|
|
|
|
import {
|
|
|
|
getConversionRate,
|
|
|
|
getNativeCurrency,
|
|
|
|
} from '../../ducks/metamask/metamask';
|
|
|
|
import { clearConfirmTransaction } from '../../ducks/confirm-transaction/confirm-transaction.duck';
|
|
|
|
import { showSendTokenPage } from '../../store/actions';
|
2022-07-19 18:07:13 +02:00
|
|
|
import {
|
2023-01-18 15:47:29 +01:00
|
|
|
AssetType,
|
|
|
|
TokenStandard,
|
2022-07-19 18:07:13 +02:00
|
|
|
} from '../../../shared/constants/transaction';
|
2022-03-09 15:38:12 +01:00
|
|
|
|
|
|
|
export default function ConfirmSendToken({
|
|
|
|
assetStandard,
|
|
|
|
toAddress,
|
|
|
|
tokenAddress,
|
|
|
|
assetName,
|
|
|
|
tokenSymbol,
|
|
|
|
tokenAmount,
|
|
|
|
tokenId,
|
|
|
|
transaction,
|
|
|
|
image,
|
|
|
|
ethTransactionTotal,
|
|
|
|
fiatTransactionTotal,
|
|
|
|
hexMaximumTransactionFee,
|
|
|
|
}) {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const history = useHistory();
|
|
|
|
|
2022-07-01 15:58:35 +02:00
|
|
|
const handleEditTransaction = async ({ txData }) => {
|
2022-03-09 15:38:12 +01:00
|
|
|
const { id } = txData;
|
2023-01-18 15:47:29 +01:00
|
|
|
await dispatch(editExistingTransaction(AssetType.token, id.toString()));
|
2022-03-09 15:38:12 +01:00
|
|
|
dispatch(clearConfirmTransaction());
|
|
|
|
dispatch(showSendTokenPage());
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleEdit = (confirmTransactionData) => {
|
2022-07-01 15:58:35 +02:00
|
|
|
handleEditTransaction(confirmTransactionData).then(() => {
|
|
|
|
history.push(SEND_ROUTE);
|
|
|
|
});
|
2022-03-09 15:38:12 +01:00
|
|
|
};
|
|
|
|
const conversionRate = useSelector(getConversionRate);
|
|
|
|
const nativeCurrency = useSelector(getNativeCurrency);
|
|
|
|
const currentCurrency = useSelector(getCurrentCurrency);
|
|
|
|
const contractExchangeRate = useSelector(contractExchangeRateSelector);
|
|
|
|
|
|
|
|
let title, subtitle;
|
|
|
|
|
2023-01-18 15:47:29 +01:00
|
|
|
if (assetStandard === TokenStandard.ERC721) {
|
2022-03-09 15:38:12 +01:00
|
|
|
title = assetName;
|
|
|
|
subtitle = `#${tokenId}`;
|
2023-01-18 15:47:29 +01:00
|
|
|
} else if (assetStandard === TokenStandard.ERC20) {
|
2022-03-09 15:38:12 +01:00
|
|
|
title = `${tokenAmount} ${tokenSymbol}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConfirmTokenTransactionBase
|
|
|
|
onEdit={handleEdit}
|
|
|
|
conversionRate={conversionRate}
|
|
|
|
currentCurrency={currentCurrency}
|
|
|
|
nativeCurrency={nativeCurrency}
|
|
|
|
contractExchangeRate={contractExchangeRate}
|
|
|
|
title={title}
|
|
|
|
subtitle={subtitle}
|
|
|
|
assetStandard={assetStandard}
|
|
|
|
assetName={assetName}
|
|
|
|
tokenSymbol={tokenSymbol}
|
|
|
|
tokenAmount={tokenAmount}
|
|
|
|
tokenId={tokenId}
|
|
|
|
transaction={transaction}
|
|
|
|
image={image}
|
|
|
|
toAddress={toAddress}
|
|
|
|
tokenAddress={tokenAddress}
|
|
|
|
ethTransactionTotal={ethTransactionTotal}
|
|
|
|
fiatTransactionTotal={fiatTransactionTotal}
|
|
|
|
hexMaximumTransactionFee={hexMaximumTransactionFee}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.propTypes = {
|
|
|
|
tokenAmount: PropTypes.string,
|
|
|
|
assetStandard: PropTypes.string,
|
|
|
|
assetName: PropTypes.string,
|
|
|
|
tokenSymbol: PropTypes.string,
|
|
|
|
image: PropTypes.string,
|
|
|
|
tokenId: PropTypes.string,
|
|
|
|
toAddress: PropTypes.string,
|
|
|
|
tokenAddress: PropTypes.string,
|
|
|
|
transaction: PropTypes.shape({
|
|
|
|
origin: PropTypes.string,
|
|
|
|
txParams: PropTypes.shape({
|
|
|
|
data: PropTypes.string,
|
|
|
|
to: PropTypes.string,
|
|
|
|
from: PropTypes.string,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ethTransactionTotal: PropTypes.string,
|
|
|
|
fiatTransactionTotal: PropTypes.string,
|
|
|
|
hexMaximumTransactionFee: PropTypes.string,
|
|
|
|
};
|