Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLASK] Transaction Insights V2 Integration #20554

Merged
merged 127 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
92688c9
added warning logic for tx insight v2 integration
hmalik88 Aug 22, 2023
db6977a
spelling fix
hmalik88 Aug 22, 2023
c07bcca
create tx insight warning component
hmalik88 Aug 22, 2023
1d3dedc
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Aug 22, 2023
80d5326
finish warnings modal
hmalik88 Aug 28, 2023
7603363
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Aug 28, 2023
35d8b9b
fixed some errors
hmalik88 Aug 28, 2023
54ec61a
copy & styling updates, moved warning modal appearance
hmalik88 Aug 31, 2023
d78bccc
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Aug 31, 2023
0d32590
Fix a few issues during testing
FrederikBolding Aug 31, 2023
1be1920
fix some errors
hmalik88 Aug 31, 2023
b1ff7cb
fix warning onClick function & state
hmalik88 Aug 31, 2023
b8c8370
make adjustments to allow for single insight fetching in stable
hmalik88 Sep 1, 2023
a654f81
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 1, 2023
ddc8fbb
add some more fencing
hmalik88 Sep 1, 2023
126e046
remove empty css file
hmalik88 Sep 1, 2023
9d77641
lint fix
hmalik88 Sep 1, 2023
c7bfaeb
remove comment
hmalik88 Sep 1, 2023
78c5cbd
add more fencing
hmalik88 Sep 1, 2023
fbf8c98
fix fencing
hmalik88 Sep 1, 2023
41c60f8
another fencing fix
hmalik88 Sep 1, 2023
ac83df0
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 13, 2023
2c3f772
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 18, 2023
25bf04d
handling analytics differently for v2 in flask
hmalik88 Sep 18, 2023
897a52e
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 18, 2023
28775fb
fix fencing
hmalik88 Sep 18, 2023
5f59aba
simplify fencing
hmalik88 Sep 18, 2023
b49e378
fix fencing (again)
hmalik88 Sep 18, 2023
ebfa26a
remove unused import
hmalik88 Sep 18, 2023
63cbe75
more fencing adjustment
hmalik88 Sep 18, 2023
b2ce4a9
add fencing for handler type import
hmalik88 Sep 18, 2023
d2703d6
fix fencing for track insight action
hmalik88 Sep 18, 2023
5ffe262
Revert "fix fencing for track insight action"
hmalik88 Sep 18, 2023
ae66d42
add missing directive
hmalik88 Sep 18, 2023
b1330ed
fencing change
hmalik88 Sep 18, 2023
38091a3
remove nested fencing in favor of different check for flask
hmalik88 Sep 18, 2023
ecfe72d
change fencing for import
hmalik88 Sep 18, 2023
a72da98
change header color for better contrast
hmalik88 Sep 19, 2023
5e6d764
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 19, 2023
c115ac2
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 21, 2023
3c77685
addressed PR comments
hmalik88 Sep 21, 2023
7e685fd
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 21, 2023
547f28b
add newline to scss file
hmalik88 Sep 21, 2023
324cab4
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 21, 2023
d514a17
rebuilt policy
hmalik88 Sep 21, 2023
176b506
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 27, 2023
94f0d8d
update import
hmalik88 Sep 27, 2023
d246c99
updated policy
hmalik88 Sep 27, 2023
9c059ad
fixed logic to only fetch once for v2
hmalik88 Sep 27, 2023
6f2b7fe
fix fetching logic
hmalik88 Sep 28, 2023
27f2489
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 28, 2023
b488a18
add default prop
hmalik88 Sep 28, 2023
b6bbb78
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 28, 2023
5451c93
remove fence
hmalik88 Sep 28, 2023
c320b23
fix fence
hmalik88 Sep 28, 2023
abc1f77
remove dep array
hmalik88 Sep 29, 2023
10dc59e
add condition
hmalik88 Sep 29, 2023
69e87b2
Revert "remove dep array"
hmalik88 Sep 29, 2023
ddc7762
update build-types in fencing
hmalik88 Sep 29, 2023
429b1e8
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 29, 2023
4f6aa40
some more fencing updates
hmalik88 Sep 29, 2023
37cc03c
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Sep 29, 2023
138d711
removed erroneous setState
hmalik88 Sep 29, 2023
40614da
lint fix
hmalik88 Sep 29, 2023
5f1ec3c
simplify & fix
hmalik88 Oct 3, 2023
5b7f543
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 3, 2023
1553a4f
add missing fence
hmalik88 Oct 3, 2023
0f7f5de
update policies
hmalik88 Oct 3, 2023
1c70c14
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 3, 2023
2d49867
update policies again
hmalik88 Oct 3, 2023
8b41bad
more fixes
hmalik88 Oct 3, 2023
61c824d
add more fencing
hmalik88 Oct 4, 2023
c2cbd3b
Fix fencing
FrederikBolding Oct 4, 2023
40b2aa4
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 4, 2023
6625ff6
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 5, 2023
b501e79
addressed comments
hmalik88 Oct 6, 2023
e670c4b
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 6, 2023
711196a
add component for insight tab(s)
hmalik88 Oct 6, 2023
703349b
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 6, 2023
0576d3f
fix
hmalik88 Oct 6, 2023
23bd317
fix condition
hmalik88 Oct 6, 2023
ea4972f
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 6, 2023
2b4298c
fixes per comments
hmalik88 Oct 9, 2023
71fdcb7
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 9, 2023
625f525
Revert "add component for insight tab(s)"
hmalik88 Oct 9, 2023
1b2d0a4
removed file, left comment for future work
hmalik88 Oct 9, 2023
fdf2f3a
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 9, 2023
42a08af
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 9, 2023
9faebdf
addressed some comments
hmalik88 Oct 17, 2023
e125026
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 17, 2023
e424859
memoize permission subjects
hmalik88 Oct 19, 2023
e0417c6
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 19, 2023
ed299e5
fix selector
hmalik88 Oct 19, 2023
0fbd413
add new event for tracking insight views in flask
hmalik88 Oct 19, 2023
1223354
lint fix:
hmalik88 Oct 19, 2023
5524ad8
fix fencing
hmalik88 Oct 19, 2023
6850a46
update snapshot
hmalik88 Oct 19, 2023
588b1e8
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 19, 2023
1952098
use already defined createDeepEqualSelector
hmalik88 Oct 19, 2023
f419f54
remove nested selector
hmalik88 Oct 19, 2023
07c9bc9
lint fix
hmalik88 Oct 19, 2023
4154b98
update create snap redirect snapshot
hmalik88 Oct 19, 2023
46809cb
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 19, 2023
41eb299
lint fix
hmalik88 Oct 19, 2023
1e7f992
addressed comments
hmalik88 Oct 19, 2023
06f9bb8
adjustments per comments
hmalik88 Oct 20, 2023
4483aa8
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 20, 2023
6bee2be
move var assignment outside of fence
hmalik88 Oct 21, 2023
7b8c629
add fencing
hmalik88 Oct 23, 2023
745eb15
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 23, 2023
a714020
fencing fix
hmalik88 Oct 23, 2023
b3a9716
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 23, 2023
1ccc4a6
more fencing
hmalik88 Oct 23, 2023
f28daf1
more & more fencing
hmalik88 Oct 23, 2023
6d084c6
update hook
hmalik88 Oct 23, 2023
8111abd
var assignment fix
hmalik88 Oct 23, 2023
d409435
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 27, 2023
c3ae276
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 31, 2023
5a3398c
center div =^.^=
hmalik88 Oct 31, 2023
2468d61
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Oct 31, 2023
3ed9d85
Fix some state management issues
FrederikBolding Nov 1, 2023
221c2ca
Fix lint
FrederikBolding Nov 1, 2023
8abb832
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Nov 1, 2023
e9e754e
styling adjustments
hmalik88 Nov 1, 2023
c81601c
update snapshot
hmalik88 Nov 1, 2023
eee827f
Merge branch 'develop' into hm/tx-insight-v2
hmalik88 Nov 1, 2023
35b2df2
update another snapshot
hmalik88 Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ import {
} from '@metamask/controller-utils';
import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';

///: BEGIN:ONLY_INCLUDE_IN(snaps)
import { HandlerType } from '@metamask/snaps-utils';
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(petnames)
import {
NameController,
Expand Down Expand Up @@ -1916,7 +1919,6 @@ export default class MetamaskController extends EventEmitter {
///: END:ONLY_INCLUDE_IN

///: BEGIN:ONLY_INCLUDE_IN(snaps)

/**
* Tracks snaps export usage. Note: This function is throttled to 1 call per 60 seconds.
*
Expand Down Expand Up @@ -1947,7 +1949,13 @@ export default class MetamaskController extends EventEmitter {
* @returns The result of the JSON-RPC request.
*/
handleSnapRequest(args) {
this._trackSnapExportUsage(args.snapId, args.handler);
// we're not tracking at this point in flask because we eagerly fetch insights in v2
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
if (
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
args.handler !== HandlerType.OnTransaction &&
!process.env.ALLOW_LOCAL_SNAPS
) {
this._trackSnapExportUsage(args.snapId, args.handler);
}

return this.controllerMessenger.call('SnapController:handleRequest', args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import { useI18nContext } from '../../../hooks/useI18nContext';
///: BEGIN:ONLY_INCLUDE_IN(snaps)
import useTransactionInsights from '../../../hooks/useTransactionInsights';
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
import TxInsightWarnings from '../snaps/tx-insight-warnings/tx-insight-warnings';
///: END:ONLY_INCLUDE_IN
import {
getAccountName,
getAddressBookEntry,
Expand All @@ -59,6 +62,7 @@ import {
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
///: END:ONLY_INCLUDE_IN

import {
ConfirmPageContainerHeader,
ConfirmPageContainerContent,
Expand Down Expand Up @@ -118,7 +122,10 @@ const ConfirmPageContainer = (props) => {
const trackEvent = useContext(MetaMetricsContext);
///: END:ONLY_INCLUDE_IN
const [collectionBalance, setCollectionBalance] = useState('0');

///: BEGIN:ONLY_INCLUDE_IN(build-flask)
const [isShowingTxInsightWarnings, setIsShowingTxInsightWarnings] =
useState(false);
///: END:ONLY_INCLUDE_IN
const isBuyableChain = useSelector(getIsBuyableChain);
const contact = useSelector((state) => getAddressBookEntry(state, toAddress));
const networkIdentifier = useSelector(getNetworkIdentifier);
Expand Down Expand Up @@ -159,11 +166,30 @@ const ConfirmPageContainer = (props) => {
///: BEGIN:ONLY_INCLUDE_IN(snaps)
// As confirm-transction-base is converted to functional component
// this code can bemoved to it.
const insightComponent = useTransactionInsights({
const insightObject = useTransactionInsights({
txData,
});
const insightComponent = insightObject?.insightComponent;
///: END:ONLY_INCLUDE_IN

const handleSubmit = () => {
if (isSetApproveForAll && isApprovalOrRejection) {
onSetApprovalForAll();
} else {
onSubmit();
}
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
};

// TODO: Better name
const topLevelHandleSubmit = () => {
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
if (insightObject?.warnings?.length > 0) {
return setIsShowingTxInsightWarnings(true);
}
///: END:ONLY_INCLUDE_IN
return handleSubmit();
};

useEffect(() => {
if (isSetApproveForAll && assetStandard === TokenStandard.ERC721) {
fetchCollectionBalance();
Expand Down Expand Up @@ -231,7 +257,7 @@ const ConfirmPageContainer = (props) => {
onCancelAll={onCancelAll}
onCancel={onCancel}
cancelText={t('reject')}
onSubmit={onSubmit}
onSubmit={topLevelHandleSubmit}
submitText={t('confirm')}
disabled={disabled}
unapprovedTxCount={unapprovedTxCount}
Expand Down Expand Up @@ -326,11 +352,7 @@ const ConfirmPageContainer = (props) => {
<PageContainerFooter
onCancel={onCancel}
cancelText={t('reject')}
onSubmit={
isSetApproveForAll && isApprovalOrRejection
? onSetApprovalForAll
: onSubmit
}
onSubmit={topLevelHandleSubmit}
submitText={t('confirm')}
submitButtonType={
isSetApproveForAll && isApprovalOrRejection
Expand Down Expand Up @@ -359,6 +381,23 @@ const ConfirmPageContainer = (props) => {
<AdvancedGasFeePopover />
</>
)}
{
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
}
{insightObject?.warnings?.length > 0 && isShowingTxInsightWarnings && (
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
<TxInsightWarnings
warnings={insightObject.warnings}
origin={origin}
onCancel={() => setIsShowingTxInsightWarnings(false)}
onSubmit={() => {
handleSubmit();
setIsShowingTxInsightWarnings(false);
}}
/>
)}
{
///: END:ONLY_INCLUDE_IN
}
</div>
</GasFeeContextProvider>
);
Expand Down
70 changes: 39 additions & 31 deletions ui/components/app/confirm-page-container/snaps/snap-insight.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React from 'react';
import React, {
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
useEffect,
///: END:ONLY_INCLUDE_IN
} from 'react';

import PropTypes from 'prop-types';

import { useSelector } from 'react-redux';
import {
useSelector,
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
useDispatch,
///: END:ONLY_INCLUDE_IN
} from 'react-redux';
import Preloader from '../../../ui/icon/preloader/preloader-icon.component';
import { Text } from '../../../component-library';
import {
Expand All @@ -13,38 +23,44 @@ import {
TextVariant,
} from '../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { useTransactionInsightSnap } from '../../../../hooks/snaps/useTransactionInsightSnap';
import Box from '../../../ui/box/box';
import { SnapUIRenderer } from '../../snaps/snap-ui-renderer';
import { SnapDelineator } from '../../snaps/snap-delineator';
import { DelineatorType } from '../../../../helpers/constants/snaps';
import { getSnapName } from '../../../../helpers/utils/util';
import { Copyable } from '../../snaps/copyable';
import { getTargetSubjectMetadata } from '../../../../selectors';
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
import { trackInsightSnapUsage } from '../../../../store/actions';
///: END:ONLY_INCLUDE_IN

export const SnapInsight = ({ transaction, origin, chainId, selectedSnap }) => {
export const SnapInsight = ({ data, loading }) => {
const t = useI18nContext();
const {
data: response,
error,
loading,
} = useTransactionInsightSnap({
transaction,
chainId,
origin,
snapId: selectedSnap.id,
});
snapId,
response: { content },
} = data;
FrederikBolding marked this conversation as resolved.
Show resolved Hide resolved
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
const dispatch = useDispatch();

useEffect(() => {
const trackInsightUsage = async () => {
await dispatch(trackInsightSnapUsage(snapId));
};
trackInsightUsage();
}, [snapId, dispatch]);
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
///: END:ONLY_INCLUDE_IN

const targetSubjectMetadata = useSelector((state) =>
getTargetSubjectMetadata(state, selectedSnap.id),
getTargetSubjectMetadata(state, snapId),
);

const snapName = getSnapName(selectedSnap.id, targetSubjectMetadata);

const data = response?.content;
const snapName = getSnapName(snapId, targetSubjectMetadata);

const hasNoData =
!error && (loading || !data || (data && Object.keys(data).length === 0));
!error &&
(loading || !content || (content && Object.keys(content).length === 0));
return (
<Box
flexDirection={FLEX_DIRECTION.COLUMN}
Expand All @@ -64,8 +80,8 @@ export const SnapInsight = ({ transaction, origin, chainId, selectedSnap }) => {
>
{data && Object.keys(data).length > 0 ? (
<SnapUIRenderer
snapId={selectedSnap.id}
data={data}
snapId={snapId}
data={content}
delineatorType={DelineatorType.Insights}
/>
) : (
Expand Down Expand Up @@ -110,19 +126,11 @@ export const SnapInsight = ({ transaction, origin, chainId, selectedSnap }) => {

SnapInsight.propTypes = {
/*
* The transaction data object
*/
transaction: PropTypes.object,
/*
* CAIP2 Chain ID
*/
chainId: PropTypes.string,
/*
* The origin of the transaction
* The insight object
*/
origin: PropTypes.string,
data: PropTypes.object,
/*
* The insight snap selected
* Boolean as to whether or not the insights are loading
*/
selectedSnap: PropTypes.object,
loading: PropTypes.bool,
};
4 changes: 4 additions & 0 deletions ui/components/app/snaps/snap-delineator/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
overflow: hidden;
}
}

&__expansion-icon {
cursor: pointer;
}
}
Loading
Loading