Skip to content

Commit

Permalink
Solve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gantunesr committed Nov 24, 2022
2 parents 9e8734c + 1c0ebb4 commit 87c644a
Show file tree
Hide file tree
Showing 40 changed files with 1,665 additions and 138 deletions.
3 changes: 1 addition & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</intent-filter>
</activity>
<activity
android:launchMode="singleInstance"
android:launchMode="singleTask"
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
Expand Down Expand Up @@ -64,7 +64,6 @@
<data android:host="metamask-alternate.app.link" />
<data android:host="metamask.test-app.link" />
<data android:host="metamask-alternate.test-app.link" />
<data android:host="metamask.io" />
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
Expand Down
22 changes: 15 additions & 7 deletions android/app/src/main/java/io/metamask/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,22 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent != null &&
intent.hasExtra("branch_force_new_session") &&
intent.getBooleanExtra("branch_force_new_session",false)) {
RNBranchModule.onNewIntent(intent);
}
super.onNewIntent(intent);
/*
if activity is in foreground (or in backstack but partially visible) launch the same
activity will skip onStart, handle this case with reInit
if reInit() is called without this flag, you will see the following message:
BRANCH_SDK: Warning. Session initialization already happened.
To force a new session,
set intent extra, "branch_force_new_session", to true.
*/
if (intent != null &&
intent.hasExtra("branch_force_new_session") &&
intent.getBooleanExtra("branch_force_new_session", false)) {
RNBranchModule.onNewIntent(intent);
}
}

@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PaymentMethod from '../components/PaymentMethod';
import Title from '../../../Base/Title';
import Text from '../../../Base/Text';
import { useAssetFromTheme } from '../../../../util/theme';
import { NETWORKS_CHAIN_ID } from '../../../../constants/on-ramp';
import { NETWORKS_CHAIN_ID } from '../../../../constants/network';

const styles = StyleSheet.create({
title: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Title from '../../../Base/Title';
import Text from '../../../Base/Text';

import Device from '../../../../util/device';
import { NETWORKS_CHAIN_ID } from '../../../../constants/on-ramp';
import { NETWORKS_CHAIN_ID } from '../../../../constants/network';

const styles = StyleSheet.create({
title: {
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/FiatOrders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { renderNumber } from '../../../util/number';
import {
FIAT_ORDER_PROVIDERS,
FIAT_ORDER_STATES,
NETWORKS_CHAIN_ID,
} from '../../../constants/on-ramp';
import { NETWORKS_CHAIN_ID } from '../../../constants/network';
import {
getPendingOrders,
updateFiatOrder,
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/FiatOrders/orderProcessor/moonpay.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
FIAT_ORDER_PROVIDERS,
FIAT_ORDER_STATES,
MOONPAY_NETWORK_PARAMETERS,
NETWORKS_CHAIN_ID,
} from '../../../../constants/on-ramp';
import { NETWORKS_CHAIN_ID } from '../../../../constants/network';
import AppConstants from '../../../../core/AppConstants';
import Logger from '../../../../util/Logger';

Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/FiatOrders/orderProcessor/transak.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import Logger from '../../../../util/Logger';
import {
FIAT_ORDER_PROVIDERS,
FIAT_ORDER_STATES,
NETWORKS_CHAIN_ID,
TRANSAK_NETWORK_PARAMETERS,
} from '../../../../constants/on-ramp';
import { NETWORKS_CHAIN_ID } from '../../../../constants/network';

//* env vars

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import useCurrency from '../../../Base/Keypad/useCurrency';
import {
FIAT_ORDER_PROVIDERS,
FIAT_ORDER_STATES,
NETWORKS_CHAIN_ID,
} from '../../../../constants/on-ramp';
import { NETWORKS_CHAIN_ID } from '../../../../constants/network';

//* env vars

Expand Down
84 changes: 61 additions & 23 deletions app/components/UI/Swaps/QuotesView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import Eth from 'ethjs-query';
import {
View,
StyleSheet,
Expand Down Expand Up @@ -30,8 +31,13 @@ import {
renderFromWei,
toWei,
weiToFiat,
calculateEthFeeForMultiLayer,
} from '../../../util/number';
import { isMainnetByChainId } from '../../../util/networks';
import {
isMainnetByChainId,
isMultiLayerFeeNetwork,
fetchEstimatedL1FeeOptimism,
} from '../../../util/networks';
import {
getErrorMessage,
getFetchParams,
Expand Down Expand Up @@ -379,6 +385,7 @@ function SwapsQuotesView({

/* State */
const isMainnet = isMainnetByChainId(chainId);
const multiLayerFeeNetwork = isMultiLayerFeeNetwork(chainId);
const [firstLoadTime, setFirstLoadTime] = useState(Date.now());
const [isFirstLoad, setIsFirstLoad] = useState(true);
const [shouldFinishFirstLoad, setShouldFinishFirstLoad] = useState(false);
Expand All @@ -390,6 +397,7 @@ function SwapsQuotesView({
const [trackedError, setTrackedError] = useState(false);
const [animateOnGasChange, setAnimateOnGasChange] = useState(false);
const [isAnimating, setIsAnimating] = useState(false);
const [multiLayerL1FeeTotal, setMultiLayerL1FeeTotal] = useState(null);

/* Selected quote, initially topAggId (see effects) */
const [selectedQuoteId, setSelectedQuoteId] = useState(null);
Expand Down Expand Up @@ -464,15 +472,31 @@ function SwapsQuotesView({
() => allQuotes.find((quote) => quote?.aggregator === selectedQuoteId),
[allQuotes, selectedQuoteId],
);
const selectedQuoteValue = useMemo(
() => quoteValues[selectedQuoteId],
[
// eslint-disable-next-line react-hooks/exhaustive-deps
quoteValues[selectedQuoteId],
quoteValues,
selectedQuoteId,
],
);
const selectedQuoteValue = useMemo(() => {
if (!quoteValues[selectedQuoteId] || multiLayerL1FeeTotal === null) {
return quoteValues[selectedQuoteId];
}
const fees = {
ethFee: calculateEthFeeForMultiLayer({
multiLayerL1FeeTotal,
ethFee: quoteValues[selectedQuoteId].ethFee,
}),
maxEthFee: calculateEthFeeForMultiLayer({
multiLayerL1FeeTotal,
ethFee: quoteValues[selectedQuoteId].maxEthFee,
}),
};
return {
...quoteValues[selectedQuoteId],
...fees,
};
}, [
// eslint-disable-next-line react-hooks/exhaustive-deps
quoteValues[selectedQuoteId],
multiLayerL1FeeTotal,
quoteValues,
selectedQuoteId,
]);

const gasEstimates = useMemo(
() => customGasEstimate || usedGasEstimate,
Expand Down Expand Up @@ -1565,6 +1589,26 @@ function SwapsQuotesView({
handleQuotesErrorMetric(error);
}, [error, handleQuotesErrorMetric, trackedError]);

useEffect(() => {
if (!multiLayerFeeNetwork || !selectedQuote?.trade) {
return;
}
const getEstimatedL1Fee = async () => {
try {
const eth = new Eth(Engine.context.NetworkController.provider);
const result = await fetchEstimatedL1FeeOptimism(eth, {
txParams: selectedQuote.trade,
chainId,
});
setMultiLayerL1FeeTotal(result);
} catch (e) {
Logger.error(e, 'fetchEstimatedL1FeeOptimism call failed');
setMultiLayerL1FeeTotal(null);
}
};
getEstimatedL1Fee();
}, [selectedQuote?.trade, multiLayerFeeNetwork, chainId]);

const openLinkAboutGas = () =>
Linking.openURL(
'https://community.metamask.io/t/what-is-gas-why-do-transactions-take-so-long/3172',
Expand Down Expand Up @@ -1985,19 +2029,12 @@ function SwapsQuotesView({
</View>
</View>
<View style={styles.quotesFiatColumn}>
<TouchableOpacity
disabled={unableToSwap}
onPress={
unableToSwap ? undefined : onEditQuoteTransactionsGas
}
>
<Text link={!unableToSwap} underline={!unableToSwap}>
{renderFromWei(
toWei(selectedQuoteValue?.maxEthFee || '0x0'),
)}{' '}
{getTicker(ticker)}
</Text>
</TouchableOpacity>
<Text>
{renderFromWei(
toWei(selectedQuoteValue?.maxEthFee || '0x0'),
)}{' '}
{getTicker(ticker)}
</Text>
<Text upper>
{` ${
weiToFiat(
Expand Down Expand Up @@ -2187,6 +2224,7 @@ function SwapsQuotesView({
selectedQuote={selectedQuoteId}
showOverallValue={hasConversionRate}
ticker={getTicker(ticker)}
multiLayerL1FeeTotal={multiLayerL1FeeTotal}
/>

<ApprovalTransactionEditionModal
Expand Down
18 changes: 15 additions & 3 deletions app/components/UI/Swaps/components/QuotesModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
renderFromWei,
toWei,
weiToFiat,
calculateEthFeeForMultiLayer,
} from '../../../../util/number';
import { getQuotesSourceMessage } from '../utils';
import Text from '../../../Base/Text';
Expand Down Expand Up @@ -145,6 +146,7 @@ function QuotesModal({
quoteValues,
showOverallValue,
ticker,
multiLayerL1FeeTotal,
}) {
const bestOverallValue =
quoteValues?.[quotes[0].aggregator]?.overallValueOfQuote ?? 0;
Expand Down Expand Up @@ -223,6 +225,11 @@ function QuotesModal({
}
}, [displayDetails, selectedDetailsQuote]);

const selectedDetailsQuoteValuesEthFee = calculateEthFeeForMultiLayer({
multiLayerL1FeeTotal,
ethFee: selectedDetailsQuoteValues?.ethFee,
});

return (
<Modal
isVisible={isVisible}
Expand Down Expand Up @@ -315,14 +322,14 @@ function QuotesModal({
<View style={styles.detailsRow}>
<Text small>{strings('swaps.estimated_network_fees')}</Text>
<Text primary>
{renderFromWei(toWei(selectedDetailsQuoteValues.ethFee))}{' '}
{renderFromWei(toWei(selectedDetailsQuoteValuesEthFee))}{' '}
<Text reset bold>
{ticker}
</Text>{' '}
<Text>
(~
{weiToFiat(
toWei(selectedDetailsQuoteValues.ethFee),
toWei(selectedDetailsQuoteValuesEthFee),
conversionRate,
currentCurrency,
)}
Expand Down Expand Up @@ -386,6 +393,10 @@ function QuotesModal({
const { aggregator } = quote;
const isSelected = aggregator === selectedQuote;
const quoteValue = quoteValues[aggregator];
const quoteEthFee = calculateEthFeeForMultiLayer({
multiLayerL1FeeTotal,
ethFee: quoteValue?.ethFee,
});
return (
<TouchableOpacity
key={aggregator}
Expand All @@ -408,7 +419,7 @@ function QuotesModal({
<View style={styles.columnFee}>
<Text primary bold={isSelected}>
{weiToFiat(
toWei(quoteValue?.ethFee ?? 0),
toWei(quoteEthFee),
conversionRate,
currentCurrency,
)}
Expand Down Expand Up @@ -504,6 +515,7 @@ QuotesModal.propTypes = {
ticker: PropTypes.string,
quoteValues: PropTypes.object,
showOverallValue: PropTypes.bool,
multiLayerL1FeeTotal: PropTypes.string,
};

const mapStateToProps = (state) => ({
Expand Down
4 changes: 4 additions & 0 deletions app/components/UI/Swaps/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ const {
SWAPS_TESTNET_CHAIN_ID,
POLYGON_CHAIN_ID,
AVALANCHE_CHAIN_ID,
ARBITRUM_CHAIN_ID,
OPTIMISM_CHAIN_ID,
} = swapsUtils;

const allowedChainIds = [
ETH_CHAIN_ID,
BSC_CHAIN_ID,
POLYGON_CHAIN_ID,
AVALANCHE_CHAIN_ID,
ARBITRUM_CHAIN_ID,
OPTIMISM_CHAIN_ID,
SWAPS_TESTNET_CHAIN_ID,
];

Expand Down
37 changes: 25 additions & 12 deletions app/components/UI/TypedSign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ class TypedSign extends PureComponent {
);
};

walletConnectNotificationTitle = (confirmation, isError) => {
if (isError) return strings('notifications.wc_signed_failed_title');
return confirmation
? strings('notifications.wc_signed_title')
: strings('notifications.wc_signed_rejected_title');
};

showWalletConnectNotification = (
messageParams = {},
confirmation = false,
isError = false,
) => {
InteractionManager.runAfterInteractions(() => {
messageParams.origin &&
Expand All @@ -125,9 +133,7 @@ class TypedSign extends PureComponent {
NotificationManager.showSimpleNotification({
status: `simple_notification${!confirmation ? '_rejected' : ''}`,
duration: 5000,
title: confirmation
? strings('notifications.wc_signed_title')
: strings('notifications.wc_signed_rejected_title'),
title: this.walletConnectNotificationTitle(confirmation, isError),
description: strings('notifications.wc_description'),
});
});
Expand All @@ -138,15 +144,22 @@ class TypedSign extends PureComponent {
const { KeyringController, TypedMessageManager } = Engine.context;
const messageId = messageParams.metamaskId;
const version = messageParams.version;
const cleanMessageParams = await TypedMessageManager.approveMessage(
messageParams,
);
const rawSig = await KeyringController.signTypedMessage(
cleanMessageParams,
version,
);
TypedMessageManager.setMessageStatusSigned(messageId, rawSig);
this.showWalletConnectNotification(messageParams, true);
let rawSig;
let cleanMessageParams;
try {
cleanMessageParams = await TypedMessageManager.approveMessage(
messageParams,
);
rawSig = await KeyringController.signTypedMessage(
cleanMessageParams,
version,
);
TypedMessageManager.setMessageStatusSigned(messageId, rawSig);
this.showWalletConnectNotification(messageParams, true);
} catch (error) {
TypedMessageManager.setMessageStatusSigned(messageId, error.message);
this.showWalletConnectNotification(messageParams, false, true);
}
};

rejectMessage = () => {
Expand Down
Loading

0 comments on commit 87c644a

Please sign in to comment.