Skip to content

Commit

Permalink
Merge branch 'main' into fix/fix-swaps-button-on-asset-detail-page
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri authored Dec 12, 2024
2 parents 3233475 + c1c2e79 commit 8543a56
Show file tree
Hide file tree
Showing 45 changed files with 1,231 additions and 1,523 deletions.
1 change: 0 additions & 1 deletion .js.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
export MM_PUBNUB_SUB_KEY=""
export MM_PUBNUB_PUB_KEY=""
export MM_OPENSEA_KEY=""
export MM_ETHERSCAN_KEY=""
export MM_FOX_CODE="EXAMPLE_FOX_CODE"

# NOTE: Non-MetaMask only, will need to create an account and generate
Expand Down
18 changes: 16 additions & 2 deletions app/components/Nav/Main/RootRPCMethodsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,34 @@ const RootRPCMethodsUI = (props) => {
);

const parameters = {
...analyticsParams,
time_to_mine: timeToMine,
estimated_vs_used_gasRatio: estimatedVsUsedGasRatio,
quote_vs_executionRatio: quoteVsExecutionRatio,
token_to_amount_received: tokenToAmountReceived.toString(),
is_smart_transaction: props.shouldUseSmartTransaction,
...smartTransactionMetricsProperties,
available_quotes: analyticsParams.available_quotes,
best_quote_source: analyticsParams.best_quote_source,
chain_id: analyticsParams.chain_id,
custom_slippage: analyticsParams.custom_slippage,
network_fees_USD: analyticsParams.network_fees_USD,
other_quote_selected: analyticsParams.other_quote_selected,
request_type: analyticsParams.request_type,
token_from: analyticsParams.token_from,
token_to: analyticsParams.token_to,
};
const sensitiveParameters = {
token_from_amount: analyticsParams.token_from_amount,
token_to_amount: analyticsParams.token_to_amount,
network_fees_ETH: analyticsParams.network_fees_ETH,
};

Logger.log('Swaps', 'Sending metrics event', event);

trackEvent(
createEventBuilder(event)
.addSensitiveProperties({ ...parameters })
.addProperties({ ...parameters })
.addSensitiveProperties({ ...sensitiveParameters })
.build(),
);
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const Main = (props) => {
stopIncomingTransactionPolling();

if (showIncomingTransactionsNetworks[chainId]) {
startIncomingTransactionPolling([networkClientId]);
startIncomingTransactionPolling([chainId]);
}
}, [chainId, networkClientId, showIncomingTransactionsNetworks]);

Expand Down Expand Up @@ -178,11 +178,11 @@ const Main = (props) => {
removeNotVisibleNotifications();

BackgroundTimer.runBackgroundTimer(async () => {
await updateIncomingTransactions([props.networkClientId]);
await updateIncomingTransactions([props.chainId]);
}, AppConstants.TX_CHECK_BACKGROUND_FREQUENCY);
}
},
[backgroundMode, removeNotVisibleNotifications, props.networkClientId],
[backgroundMode, removeNotVisibleNotifications, props.chainId],
);

const initForceReload = () => {
Expand Down
18 changes: 16 additions & 2 deletions app/components/UI/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1740,9 +1740,16 @@ export function getSwapsQuotesNavbar(navigation, route, themeColors) {
MetaMetricsEvents.QUOTES_REQUEST_CANCELLED,
)
.addProperties({
...trade,
token_from: trade.token_from,
token_to: trade.token_to,
request_type: trade.request_type,
custom_slippage: trade.custom_slippage,
chain_id: trade.chain_id,
responseTime: new Date().getTime() - quoteBegin,
})
.addSensitiveProperties({
token_from_amount: trade.token_from_amount,
})
.build(),
);
}
Expand All @@ -1759,9 +1766,16 @@ export function getSwapsQuotesNavbar(navigation, route, themeColors) {
MetaMetricsEvents.QUOTES_REQUEST_CANCELLED,
)
.addProperties({
...trade,
token_from: trade.token_from,
token_to: trade.token_to,
request_type: trade.request_type,
custom_slippage: trade.custom_slippage,
chain_id: trade.chain_id,
responseTime: new Date().getTime() - quoteBegin,
})
.addSensitiveProperties({
token_from_amount: trade.token_from_amount,
})
.build(),
);
}
Expand Down
10 changes: 4 additions & 6 deletions app/components/UI/NetworkCell/NetworkCell.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import React from 'react';
import { Switch, ImageSourcePropType } from 'react-native';
import { ETHERSCAN_SUPPORTED_NETWORKS } from '@metamask/transaction-controller';
import { useStyles } from '../../../component-library/hooks';
import Cell from '../../../component-library/components/Cells/Cell/Cell';
import { CellVariant } from '../../../component-library/components/Cells/Cell';
import { AvatarVariant } from '../../../component-library/components/Avatars/Avatar/Avatar.types';
import { useTheme } from '../../../util/theme';
import { EtherscanSupportedHexChainId } from '@metamask/preferences-controller';
import styleSheet from './NetworkCell.styles';
import { Hex } from '@metamask/utils';

const supportedNetworks = ETHERSCAN_SUPPORTED_NETWORKS;
interface NetworkCellProps {
name: string;
chainId: EtherscanSupportedHexChainId | keyof typeof supportedNetworks;
chainId: Hex;
imageSource: ImageSourcePropType;
secondaryText: string;
secondaryText?: string;
showIncomingTransactionsNetworks: Record<string, boolean>;
toggleEnableIncomingTransactions: (
chainId: EtherscanSupportedHexChainId,
chainId: Hex,
value: boolean,
) => void;
testID?: string;
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/Notification/BaseNotification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const getTitle = (status, { nonce, amount, assetType }) => {
};

export const getDescription = (status, { amount = null, type = null }) => {
if (amount && typeof amount !== 'object') {
if (amount && typeof amount !== 'object' && type) {
return strings(`notifications.${type}_${status}_message`, { amount });
}
return strings(`notifications.${status}_message`);
Expand Down
3 changes: 3 additions & 0 deletions app/components/UI/PermissionsSummary/PermissionsSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ const PermissionsSummary = ({
<Button
variant={ButtonVariants.Secondary}
label={strings('permissions.choose_from_permitted_networks')}
testID={
NetworkNonPemittedBottomSheetSelectorsIDs.CHOOSE_FROM_PERMITTED_NETWORKS_BUTTON
}
onPress={onChooseFromPermittedNetworks}
size={ButtonSize.Lg}
style={{
Expand Down
117 changes: 68 additions & 49 deletions app/components/UI/Swaps/QuotesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ function SwapsQuotesView({

trackEvent(
createEventBuilder(MetaMetricsEvents.GAS_FEES_CHANGED)
.addSensitiveProperties(parameters)
.addProperties(parameters)
.build(),
);
},
Expand Down Expand Up @@ -871,15 +871,7 @@ function SwapsQuotesView({
const parameters = {
account_type: getAddressAccountType(selectedAddress),
token_from: sourceToken.symbol,
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to: destinationToken.symbol,
token_to_amount: fromTokenMinimalUnitString(
selectedQuote.destinationAmount,
destinationToken.decimals,
),
request_type: hasEnoughTokenBalance ? 'Order' : 'Quote',
slippage,
custom_slippage: slippage !== AppConstants.SWAPS.DEFAULT_SLIPPAGE,
Expand All @@ -895,9 +887,20 @@ function SwapsQuotesView({
chain_id: getDecimalChainId(chainId),
is_smart_transaction: shouldUseSmartTransaction,
};
const sensitiveParameters = {
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to_amount: fromTokenMinimalUnitString(
selectedQuote.destinationAmount,
destinationToken.decimals,
),
};
trackEvent(
createEventBuilder(MetaMetricsEvents.SWAP_STARTED)
.addSensitiveProperties(parameters)
.addProperties(parameters)
.addSensitiveProperties(sensitiveParameters)
.build(),
);
},
Expand Down Expand Up @@ -1157,15 +1160,7 @@ function SwapsQuotesView({

const parameters = {
token_from: sourceToken.symbol,
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to: destinationToken.symbol,
token_to_amount: fromTokenMinimalUnitString(
selectedQuote.destinationAmount,
destinationToken.decimals,
),
request_type: hasEnoughTokenBalance ? 'Order' : 'Quote',
slippage,
custom_slippage: slippage !== AppConstants.SWAPS.DEFAULT_SLIPPAGE,
Expand All @@ -1181,9 +1176,20 @@ function SwapsQuotesView({
custom_spend_limit_amount: currentAmount,
chain_id: getDecimalChainId(chainId),
};
const sensitiveParameters = {
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to_amount: fromTokenMinimalUnitString(
selectedQuote.destinationAmount,
destinationToken.decimals,
),
};
trackEvent(
createEventBuilder(MetaMetricsEvents.EDIT_SPEND_LIMIT_OPENED)
.addSensitiveProperties(parameters)
.addProperties(parameters)
.addSensitiveProperties(sensitiveParameters)
.build(),
);
}, [
Expand All @@ -1209,15 +1215,7 @@ function SwapsQuotesView({
if (!selectedQuote || !selectedQuoteValue) return;
const parameters = {
token_from: sourceToken.symbol,
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to: destinationToken.symbol,
token_to_amount: fromTokenMinimalUnitString(
selectedQuote.destinationAmount,
destinationToken.decimals,
),
request_type: hasEnoughTokenBalance ? 'Order' : 'Quote',
slippage,
custom_slippage: slippage !== AppConstants.SWAPS.DEFAULT_SLIPPAGE,
Expand All @@ -1232,9 +1230,20 @@ function SwapsQuotesView({
available_quotes: allQuotes.length,
chain_id: getDecimalChainId(chainId),
};
const sensitiveParameters = {
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to_amount: fromTokenMinimalUnitString(
selectedQuote.destinationAmount,
destinationToken.decimals,
),
};
trackEvent(
createEventBuilder(MetaMetricsEvents.QUOTES_RECEIVED)
.addSensitiveProperties(parameters)
.addProperties(parameters)
.addSensitiveProperties(sensitiveParameters)
.build(),
);
}, [
Expand All @@ -1258,15 +1267,7 @@ function SwapsQuotesView({
toggleQuotesModal();
const parameters = {
token_from: sourceToken.symbol,
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to: destinationToken.symbol,
token_to_amount: fromTokenMinimalUnitString(
selectedQuote.destinationAmount,
destinationToken.decimals,
),
request_type: hasEnoughTokenBalance ? 'Order' : 'Quote',
slippage,
custom_slippage: slippage !== AppConstants.SWAPS.DEFAULT_SLIPPAGE,
Expand All @@ -1281,10 +1282,21 @@ function SwapsQuotesView({
available_quotes: allQuotes.length,
chain_id: getDecimalChainId(chainId),
};
const sensitiveParameters = {
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to_amount: fromTokenMinimalUnitString(
selectedQuote.destinationAmount,
destinationToken.decimals,
),
};

trackEvent(
createEventBuilder(MetaMetricsEvents.ALL_AVAILABLE_QUOTES_OPENED)
.addSensitiveProperties(parameters)
.addProperties(parameters)
.addSensitiveProperties(sensitiveParameters)
.build(),
);
}, [
Expand All @@ -1308,16 +1320,18 @@ function SwapsQuotesView({
(error) => {
const data = {
token_from: sourceToken.symbol,
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to: destinationToken.symbol,
request_type: hasEnoughTokenBalance ? 'Order' : 'Quote',
slippage,
custom_slippage: slippage !== AppConstants.SWAPS.DEFAULT_SLIPPAGE,
chain_id: getDecimalChainId(chainId),
};
const sensitiveData = {
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
};
if (error?.key === swapsUtils.SwapsError.QUOTES_EXPIRED_ERROR) {
const parameters = {
...data,
Expand All @@ -1326,7 +1340,8 @@ function SwapsQuotesView({

trackEvent(
createEventBuilder(MetaMetricsEvents.QUOTES_TIMED_OUT)
.addSensitiveProperties(parameters)
.addProperties(parameters)
.addSensitiveProperties(sensitiveData)
.build(),
);
} else if (
Expand All @@ -1335,7 +1350,8 @@ function SwapsQuotesView({
const parameters = { ...data };
trackEvent(
createEventBuilder(MetaMetricsEvents.NO_QUOTES_AVAILABLE)
.addSensitiveProperties(parameters)
.addProperties(parameters)
.addSensitiveProperties(sensitiveData)
.build(),
);
} else {
Expand Down Expand Up @@ -1606,22 +1622,25 @@ function SwapsQuotesView({
setTrackedRequestedQuotes(true);
const data = {
token_from: sourceToken.symbol,
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
token_to: destinationToken.symbol,
request_type: hasEnoughTokenBalance ? 'Order' : 'Quote',
custom_slippage: slippage !== AppConstants.SWAPS.DEFAULT_SLIPPAGE,
chain_id: getDecimalChainId(chainId),
};
navigation.setParams({ requestedTrade: data });
const sensitiveData = {
token_from_amount: fromTokenMinimalUnitString(
sourceAmount,
sourceToken.decimals,
),
};
navigation.setParams({ requestedTrade: { ...data, ...sensitiveData } });
navigation.setParams({ selectedQuote: undefined });
navigation.setParams({ quoteBegin: Date.now() });

trackEvent(
createEventBuilder(MetaMetricsEvents.QUOTES_REQUESTED)
.addSensitiveProperties(data)
.addProperties(data)
.addSensitiveProperties(sensitiveData)
.build(),
);
}, [
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/Swaps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function SwapsAmountView({

trackEvent(
createEventBuilder(MetaMetricsEvents.SWAPS_OPENED)
.addSensitiveProperties(parameters)
.addProperties(parameters)
.build(),
);
});
Expand Down
Loading

0 comments on commit 8543a56

Please sign in to comment.