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

refactor: Update controller packages to v44 #6872

Merged
merged 8 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ import {
import {
selectChainId,
selectNetwork,
selectNetworkConfigurations,
selectProviderType,
selectRpcTarget,
} from '../../../../selectors/networkController';
import {
selectFrequentRpcList,
selectIdentities,
} from '../../../../selectors/preferencesController';
import { selectIdentities } from '../../../../selectors/preferencesController';

const getAnalyticsParams = () => ({});

Expand All @@ -56,7 +54,7 @@ const AddNickname = (props: AddNicknameProps) => {
providerRpcTarget,
addressBook,
identities,
frequentRpcList,
networkConfigurations,
} = props;

const [newNickname, setNewNickname] = useState(addressNickname);
Expand Down Expand Up @@ -159,7 +157,7 @@ const AddNickname = (props: AddNicknameProps) => {
const hasBlockExplorer = shouldShowBlockExplorer({
providerType,
providerRpcTarget,
frequentRpcList,
networkConfigurations,
});

return (
Expand All @@ -173,7 +171,7 @@ const AddNickname = (props: AddNicknameProps) => {
headerTextStyle={styles.headerText}
iconStyle={styles.icon}
providerRpcTarget={providerRpcTarget}
frequentRpcList={[]}
networkConfigurations={{}}
/>
) : (
<>
Expand Down Expand Up @@ -268,7 +266,7 @@ const mapStateToProps = (state: any) => ({
providerNetwork: selectNetwork(state),
addressBook: state.engine.backgroundState.AddressBookController.addressBook,
identities: selectIdentities(state),
frequentRpcList: selectFrequentRpcList(state),
networkConfigurations: selectNetworkConfigurations(state),
});

const mapDispatchToProps = (dispatch: any) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { NetworkState } from '@metamask/network-controller';

export interface AddNicknameProps {
closeModal: () => void;
address: string;
addressNickname: string;
frequentRpcList: any;
networkConfigurations: NetworkState['networkConfigurations'];
nicknameExists: boolean;
showModalAlert: (config: any) => void;
providerType: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import { SafeAreaView, StyleSheet, View } from 'react-native';
import AntDesignIcon from 'react-native-vector-icons/AntDesign';
import { WebView } from 'react-native-webview';
import type { NetworkState } from '@metamask/network-controller';

import Text, {
TextVariant,
Expand Down Expand Up @@ -37,7 +38,7 @@ interface ShowBlockExplorerProps {
headerTextStyle?: any;
iconStyle?: any;
providerRpcTarget?: string;
frequentRpcList: any[];
networkConfigurations: NetworkState['networkConfigurations'];
learnMoreURL?: string;
}

Expand All @@ -50,7 +51,7 @@ const ShowBlockExplorer = (props: ShowBlockExplorerProps) => {
headerTextStyle,
iconStyle,
providerRpcTarget,
frequentRpcList,
networkConfigurations,
learnMoreURL,
} = props;

Expand All @@ -61,13 +62,14 @@ const ShowBlockExplorer = (props: ShowBlockExplorerProps) => {
(type === RPC
? `${findBlockExplorerForRpc(
providerRpcTarget,
frequentRpcList,
networkConfigurations,
)}/address/${address}`
: getEtherscanAddressUrl(type, address));
const title =
type === RPC
? new URL(findBlockExplorerForRpc(providerRpcTarget, frequentRpcList))
.hostname
? new URL(
findBlockExplorerForRpc(providerRpcTarget, networkConfigurations),
).hostname
: getEtherscanBaseUrl(type).replace('https://', '');

const onLoadProgress = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('VerifyContractDetails', () => {
tokenStandard={''}
providerType={''}
providerRpcTarget={''}
frequentRpcList={[]}
networkConfigurations={{}}
/>,
{ state: initialState },
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const VerifyContractDetails = ({
savedContactListToArray,
providerType,
providerRpcTarget,
frequentRpcList,
networkConfigurations,
tokenStandard,
tokenSymbol,
}: VerifyContractDetailsProps) => {
Expand Down Expand Up @@ -68,10 +68,10 @@ const VerifyContractDetails = ({

const showBlockExplorerIcon = useCallback(() => {
if (providerType === RPC) {
return findBlockExplorerForRpc(providerRpcTarget, frequentRpcList);
return findBlockExplorerForRpc(providerRpcTarget, networkConfigurations);
}
return true;
}, [providerType, providerRpcTarget, frequentRpcList]);
}, [providerType, providerRpcTarget, networkConfigurations]);

const hasBlockExplorer = showBlockExplorerIcon();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { NetworkState } from '@metamask/network-controller';

export interface VerifyContractDetailsProps {
/**
* contract address
Expand All @@ -22,5 +24,5 @@ export interface VerifyContractDetailsProps {
tokenSymbol: string;
providerType: string;
providerRpcTarget: string;
frequentRpcList: any[];
networkConfigurations: NetworkState['networkConfigurations'];
}
22 changes: 12 additions & 10 deletions app/components/UI/ApproveTransactionReview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ import createStyles from './styles';
import {
selectChainId,
selectNetwork,
selectNetworkConfigurations,
selectProviderType,
selectTicker,
selectRpcTarget,
} from '../../../selectors/networkController';
import { selectTokenList } from '../../../selectors/tokenListController';
import { selectTokensLength } from '../../../selectors/tokensController';
import { selectAccountsLength } from '../../../selectors/accountTrackerController';
import { selectFrequentRpcList } from '../../../selectors/preferencesController';
import Text, {
TextVariant,
} from '../../../component-library/components/Texts/Text';
Expand Down Expand Up @@ -251,7 +251,7 @@ class ApproveTransactionReview extends PureComponent {
savedContactListToArray: PropTypes.array,
closeVerifyContractDetails: PropTypes.func,
shouldVerifyContractDetails: PropTypes.bool,
frequentRpcList: PropTypes.array,
networkConfigurations: PropTypes.object,
providerRpcTarget: PropTypes.string,
/**
* Boolean that indicates if the native token buy is supported
Expand Down Expand Up @@ -307,7 +307,9 @@ class ApproveTransactionReview extends PureComponent {
return;
}
try {
const eth = new Eth(Engine.context.NetworkController.provider);
const eth = new Eth(
Engine.context.NetworkController.getProviderAndBlockTracker().provider,
);
const result = await fetchEstimatedMultiLayerL1Fee(eth, {
txParams: transaction.transaction,
chainId,
Expand Down Expand Up @@ -714,7 +716,7 @@ class ApproveTransactionReview extends PureComponent {
showVerifyContractDetails,
providerType,
providerRpcTarget,
frequentRpcList,
networkConfigurations,
isNativeTokenBuySupported,
isGasEstimateStatusIn,
} = this.props;
Expand All @@ -736,7 +738,7 @@ class ApproveTransactionReview extends PureComponent {
const hasBlockExplorer = shouldShowBlockExplorer({
providerType,
providerRpcTarget,
frequentRpcList,
networkConfigurations,
});

const tokenLabel = `${
Expand Down Expand Up @@ -1005,7 +1007,7 @@ class ApproveTransactionReview extends PureComponent {
savedContactListToArray,
toggleModal,
closeVerifyContractDetails,
frequentRpcList,
networkConfigurations,
} = this.props;
const {
transaction: { to },
Expand Down Expand Up @@ -1038,7 +1040,7 @@ class ApproveTransactionReview extends PureComponent {
providerType={providerType}
tokenSymbol={tokenSymbol}
providerRpcTarget={providerRpcTarget}
frequentRpcList={frequentRpcList}
networkConfigurations={networkConfigurations}
tokenStandard={this.state.token?.tokenStandard}
/>
);
Expand All @@ -1048,7 +1050,7 @@ class ApproveTransactionReview extends PureComponent {
const {
providerType,
showVerifyContractDetails,
frequentRpcList,
networkConfigurations,
providerRpcTarget,
} = this.props;
const { showBlockExplorerModal, address, learnMoreURL } = this.state;
Expand All @@ -1071,7 +1073,7 @@ class ApproveTransactionReview extends PureComponent {
headerTextStyle={styles.headerText}
iconStyle={styles.icon}
providerRpcTarget={providerRpcTarget}
frequentRpcList={frequentRpcList}
networkConfigurations={networkConfigurations}
learnMoreURL={learnMoreURL}
/>
);
Expand Down Expand Up @@ -1176,7 +1178,7 @@ class ApproveTransactionReview extends PureComponent {

const mapStateToProps = (state) => ({
ticker: selectTicker(state),
frequentRpcList: selectFrequentRpcList(state),
networkConfigurations: selectNetworkConfigurations(state),
transaction: getNormalizedTxState(state),
tokensLength: selectTokensLength(state),
accountsLength: selectAccountsLength(state),
Expand Down
24 changes: 14 additions & 10 deletions app/components/UI/DrawerView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import { scale } from 'react-native-size-matters';
import generateTestId from '../../../../wdio/utils/generateTestId';
import { DRAWER_VIEW_LOCK_TEXT_ID } from '../../../../wdio/screen-objects/testIDs/Screens/DrawerView.testIds';
import {
selectNetworkConfigurations,
selectProviderConfig,
selectTicker,
} from '../../../selectors/networkController';
Expand All @@ -82,7 +83,6 @@ import { selectTokens } from '../../../selectors/tokensController';
import { selectAccounts } from '../../../selectors/accountTrackerController';
import { selectContractBalances } from '../../../selectors/tokenBalancesController';
import {
selectFrequentRpcList,
selectIdentities,
selectSelectedAddress,
} from '../../../selectors/preferencesController';
Expand Down Expand Up @@ -399,9 +399,9 @@ class DrawerView extends PureComponent {
*/
ticker: PropTypes.string,
/**
* Frequent RPC list from PreferencesController
* Network configurations
*/
frequentRpcList: PropTypes.array,
networkConfigurations: PropTypes.object,
/**
* Array of ERC20 assets
*/
Expand Down Expand Up @@ -712,11 +712,12 @@ class DrawerView extends PureComponent {
};

viewInEtherscan = () => {
const { selectedAddress, providerConfig, frequentRpcList } = this.props;
const { selectedAddress, providerConfig, networkConfigurations } =
this.props;
if (providerConfig.type === RPC) {
const blockExplorer = findBlockExplorerForRpc(
providerConfig.rpcTarget,
frequentRpcList,
networkConfigurations,
);
const url = `${blockExplorer}/address/${selectedAddress}`;
const title = new URL(blockExplorer).hostname;
Expand Down Expand Up @@ -768,12 +769,15 @@ class DrawerView extends PureComponent {
};

hasBlockExplorer = (providerType) => {
const { frequentRpcList } = this.props;
const { networkConfigurations } = this.props;
if (providerType === RPC) {
const {
providerConfig: { rpcTarget },
} = this.props;
const blockExplorer = findBlockExplorerForRpc(rpcTarget, frequentRpcList);
const blockExplorer = findBlockExplorerForRpc(
rpcTarget,
networkConfigurations,
);
if (blockExplorer) {
return true;
}
Expand Down Expand Up @@ -857,11 +861,11 @@ class DrawerView extends PureComponent {
getSections = () => {
const {
providerConfig: { type, rpcTarget },
frequentRpcList,
networkConfigurations,
} = this.props;
let blockExplorer, blockExplorerName;
if (type === RPC) {
blockExplorer = findBlockExplorerForRpc(rpcTarget, frequentRpcList);
blockExplorer = findBlockExplorerForRpc(rpcTarget, networkConfigurations);
blockExplorerName = getBlockExplorerName(blockExplorer);
}
return [
Expand Down Expand Up @@ -1250,7 +1254,7 @@ const mapStateToProps = (state) => ({
accounts: selectAccounts(state),
selectedAddress: selectSelectedAddress(state),
identities: selectIdentities(state),
frequentRpcList: selectFrequentRpcList(state),
networkConfigurations: selectNetworkConfigurations(state),
currentCurrency: selectCurrentCurrency(state),
keyrings: state.engine.backgroundState.KeyringController.keyrings,
networkModalVisible: state.modals.networkModalVisible,
Expand Down
Loading
Loading