Tx decoding accreditation (#12918)

* feature: adding support for truffle and etherscan accreditation

* Fix scss linting

* fix styling and classnames

* Switch font size to rem

* Update ui/components/app/transaction-decoding/components/ui/accreditation/accreditation.component.js

Co-authored-by: George Marshall <georgewrmarshall@gmail.com>

* Update ui/components/app/transaction-decoding/components/ui/accreditation/index.scss

Co-authored-by: George Marshall <georgewrmarshall@gmail.com>

* Update ui/components/app/transaction-decoding/components/ui/accreditation/accreditation.component.js

Co-authored-by: George Marshall <georgewrmarshall@gmail.com>

* Update ui/components/app/transaction-decoding/components/ui/accreditation/accreditation.component.js

Co-authored-by: George Marshall <georgewrmarshall@gmail.com>

* Fix linting

Co-authored-by: g. nicholas d'andrea <gnidan@trufflesuite.com>
Co-authored-by: Dan J Miller <danjm.com@gmail.com>
Co-authored-by: George Marshall <georgewrmarshall@gmail.com>
Co-authored-by: g. nicholas d'andrea <gnidan@users.noreply.github.com>
feature/default_network_editable
Alaa Hadad 3 years ago committed by GitHub
parent 9c5bc2ba6d
commit a858b85899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/_locales/en/messages.json
  2. 70
      ui/components/app/transaction-decoding/components/ui/accreditation/accreditation.component.js
  3. 1
      ui/components/app/transaction-decoding/components/ui/accreditation/index.js
  4. 23
      ui/components/app/transaction-decoding/components/ui/accreditation/index.scss
  5. 1
      ui/components/app/transaction-decoding/index.scss
  6. 23
      ui/components/app/transaction-decoding/transaction-decoding.component.js

@ -3096,6 +3096,12 @@
"transactionData": { "transactionData": {
"message": "Transaction data" "message": "Transaction data"
}, },
"transactionDecodingAccreditationDecoded": {
"message": "Decoded by Truffle"
},
"transactionDecodingAccreditationVerified": {
"message": "Verified contract on"
},
"transactionDecodingUnsupportedNetworkError": { "transactionDecodingUnsupportedNetworkError": {
"message": "Transaction decoding is not available for chainId $1" "message": "Transaction decoding is not available for chainId $1"
}, },

@ -0,0 +1,70 @@
import React, { useContext } from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { getAccountLink } from '@metamask/etherscan-link';
import {
getCurrentChainId,
getRpcPrefsForCurrentProvider,
} from '../../../../../../selectors';
import { I18nContext } from '../../../../../../contexts/i18n';
import { TYPOGRAPHY } from '../../../../../../helpers/constants/design-system';
import Button from '../../../../../ui/button';
import Typography from '../../../../../ui/typography';
const Accreditation = ({ fetchVia, address }) => {
const t = useContext(I18nContext);
const chainId = useSelector(getCurrentChainId);
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
const addressLink = getAccountLink(address, chainId, rpcPrefs);
const AccreditationLink = () => {
return (
<>
<Typography
variant={TYPOGRAPHY.H7}
className="accreditation__prefix"
boxProps={{ margin: 0 }}
>
{t('transactionDecodingAccreditationVerified')}
</Typography>
<Button
type="link"
className="accreditation__link"
onClick={() => {
global.platform.openTab({
url: addressLink,
});
}}
target="_blank"
rel="noopener noreferrer"
title={t('etherscanView')}
>
{fetchVia}
</Button>
<Typography variant={TYPOGRAPHY.H7} boxProps={{ margin: 0 }}>
{t('transactionDecodingAccreditationDecoded')}
</Typography>
</>
);
};
return (
<div className="accreditation">
<div className="accreditation__icon">
<i className="fa fa-info-circle" />
</div>
<div className="accreditation__info">
<AccreditationLink />
</div>
</div>
);
};
Accreditation.propTypes = {
fetchVia: PropTypes.string.isRequired,
address: PropTypes.string.isRequired,
};
export default Accreditation;

@ -0,0 +1 @@
export { default } from './accreditation.component';

@ -0,0 +1,23 @@
.accreditation {
display: flex;
align-items: center;
margin-top: 8px;
&__icon {
margin-right: 8px;
}
&__info {
color: $ui-black;
display: flex;
flex-wrap: wrap;
}
&__link.btn-link {
@include H7;
padding: 0 4px;
width: auto;
}
}

@ -1,5 +1,6 @@
//styling for ui components //styling for ui components
@import './components/ui/copy-raw-data/index'; @import './components/ui/copy-raw-data/index';
@import './components/ui/accreditation/index';
//styling for decoding components //styling for decoding components
@import './components/decoding/address/index'; @import './components/decoding/address/index';

@ -19,10 +19,14 @@ import {
import Address from './components/decoding/address'; import Address from './components/decoding/address';
import CopyRawData from './components/ui/copy-raw-data'; import CopyRawData from './components/ui/copy-raw-data';
import Accreditation from './components/ui/accreditation';
export default function TransactionDecoding({ to = '', inputData: data = '' }) { export default function TransactionDecoding({ to = '', inputData: data = '' }) {
const t = useContext(I18nContext); const t = useContext(I18nContext);
const [tx, setTx] = useState([]); const [tx, setTx] = useState([]);
const [sourceAddress, setSourceAddress] = useState('');
const [sourceFetchedVia, setSourceFetchedVia] = useState('');
const { address: from } = useSelector(getSelectedAccount); const { address: from } = useSelector(getSelectedAccount);
const network = hexToDecimal(useSelector(getCurrentChainId)); const network = hexToDecimal(useSelector(getCurrentChainId));
@ -55,7 +59,16 @@ export default function TransactionDecoding({ to = '', inputData: data = '' }) {
const response = await fetchWithCache(requestUrl, { method: 'GET' }); const response = await fetchWithCache(requestUrl, { method: 'GET' });
const { info: projectInfo } = response; const { info: projectInfo, fetchedVia, address } = response;
// update source information
if (address) {
setSourceAddress(address);
}
if (fetchedVia) {
setSourceFetchedVia(fetchedVia);
}
// creating instance of the truffle decoder // creating instance of the truffle decoder
const decoder = await forAddress(to, { const decoder = await forAddress(to, {
@ -210,6 +223,14 @@ export default function TransactionDecoding({ to = '', inputData: data = '' }) {
<div className="tx-insight-content__copy-raw-tx"> <div className="tx-insight-content__copy-raw-tx">
<CopyRawData data={data} /> <CopyRawData data={data} />
</div> </div>
{sourceFetchedVia && sourceAddress ? (
<div className="tx-insight-content__accreditation">
<Accreditation
address={sourceAddress}
fetchVia={sourceFetchedVia}
/>
</div>
) : null}
</div> </div>
); );
}; };

Loading…
Cancel
Save