Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cryptodev2s/bump-pref…
Browse files Browse the repository at this point in the history
…erences-controller-13.1.0
  • Loading branch information
cryptodev-2s committed Oct 30, 2024
2 parents 3dfaedf + dceb552 commit 2944d3d
Show file tree
Hide file tree
Showing 70 changed files with 698 additions and 576 deletions.
2 changes: 1 addition & 1 deletion app/components/Base/DetailsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Ionicons from 'react-native-vector-icons/Ionicons';
import { fontStyles } from '../../styles/common';
import Text from './Text';
import { useTheme } from '../../util/theme';
import { TransactionDetailsModalSelectorsIDs } from '../../../e2e/selectors/Modals/TransactionDetailsModal.selectors';
import { TransactionDetailsModalSelectorsIDs } from '../../../e2e/selectors/Transactions/TransactionDetailsModal.selectors';

const createStyles = (colors) =>
StyleSheet.create({
Expand Down
37 changes: 25 additions & 12 deletions app/components/Base/RemoteImage/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import {
Image,
Expand Down Expand Up @@ -67,23 +67,36 @@ const RemoteImage = (props) => {
const chainId = useSelector(selectChainId);
const ticker = useSelector(selectTicker);
const networkName = useSelector(selectNetworkName);
const resolvedIpfsUrl = useMemo(() => {
try {
const url = new URL(props.source.uri);
if (url.protocol !== 'ipfs:') return false;
const ipfsUrl = getFormattedIpfsUrl(ipfsGateway, props.source.uri, false);
return ipfsUrl;
} catch {
return false;
}
}, [props.source.uri, ipfsGateway]);
const [resolvedIpfsUrl, setResolvedIpfsUrl] = useState(false);

const uri = resolvedIpfsUrl || source.uri;
const uri =
resolvedIpfsUrl ||
(source.uri === undefined || source.uri?.startsWith('ipfs')
? ''
: source.uri);

const onError = ({ nativeEvent: { error } }) => setError(error);

const [dimensions, setDimensions] = useState(null);

useEffect(() => {
resolveIpfsUrl();
async function resolveIpfsUrl() {
try {
const url = new URL(props.source.uri);
if (url.protocol !== 'ipfs:') setResolvedIpfsUrl(false);
const ipfsUrl = await getFormattedIpfsUrl(
ipfsGateway,
props.source.uri,
false,
);
setResolvedIpfsUrl(ipfsUrl);
} catch (err) {
setResolvedIpfsUrl(false);
}
}
}, [props.source.uri, ipfsGateway]);

useEffect(() => {
const calculateImageDimensions = (imageWidth, imageHeight) => {
const deviceWidth = Dimensions.get('window').width;
Expand Down
18 changes: 15 additions & 3 deletions app/components/Base/RemoteImage/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { shallow } from 'enzyme';
import RemoteImage from './';
import { getFormattedIpfsUrl } from '@metamask/assets-controllers';
import { act, render } from '@testing-library/react-native';

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
Expand All @@ -11,6 +13,12 @@ jest.mock('react-redux', () => ({

jest.mock('../../../components/hooks/useIpfsGateway', () => jest.fn());

jest.mock('@metamask/assets-controllers', () => ({
getFormattedIpfsUrl: jest.fn(),
}));

const mockGetFormattedIpfsUrl = getFormattedIpfsUrl as jest.Mock;

describe('RemoteImage', () => {
it('should render svg correctly', () => {
const wrapper = shallow(
Expand All @@ -34,14 +42,18 @@ describe('RemoteImage', () => {
expect(wrapper).toMatchSnapshot();
});

it('should render ipfs sources', () => {
const wrapper = shallow(
it('should render ipfs sources', async () => {
const testIpfsUri = 'ipfs://QmeE94srcYV9WwJb1p42eM4zncdLUai2N9zmMxxukoEQ23';
mockGetFormattedIpfsUrl.mockResolvedValue(testIpfsUri);
const wrapper = render(
<RemoteImage
source={{
uri: 'ipfs://QmeE94srcYV9WwJb1p42eM4zncdLUai2N9zmMxxukoEQ23',
uri: testIpfsUri,
}}
/>,
);
// eslint-disable-next-line no-empty-function
await act(async () => {});
expect(wrapper).toMatchSnapshot();
});
});
6 changes: 3 additions & 3 deletions app/components/UI/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import PickerNetwork from '../../../component-library/components/Pickers/PickerN
import BrowserUrlBar from '../BrowserUrlBar';
import generateTestId from '../../../../wdio/utils/generateTestId';
import { NAV_ANDROID_BACK_BUTTON } from '../../../../wdio/screen-objects/testIDs/Screens/NetworksScreen.testids';
import { REQUEST_SEARCH_RESULTS_BACK_BUTTON } from '../../../../wdio/screen-objects/testIDs/Screens/RequestToken.testIds';
import { BACK_BUTTON_SIMPLE_WEBVIEW } from '../../../../wdio/screen-objects/testIDs/Components/SimpleWebView.testIds';
import Routes from '../../../constants/navigation/Routes';

Expand All @@ -43,7 +42,7 @@ import {
import { CommonSelectorsIDs } from '../../../../e2e/selectors/Common.selectors';
import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors';
import { NetworksViewSelectorsIDs } from '../../../../e2e/selectors/Settings/NetworksView.selectors';
import { SendLinkViewSelectorsIDs } from '../../../../e2e/selectors/SendLinkView.selectors';
import { SendLinkViewSelectorsIDs } from '../../../../e2e/selectors/Receive/SendLinkView.selectors';
import { SendViewSelectorsIDs } from '../../../../e2e/selectors/SendView.selectors';
import { getBlockaidTransactionMetricsParams } from '../../../util/blockaid';
import Icon, {
Expand All @@ -52,6 +51,7 @@ import Icon, {
IconColor,
} from '../../../component-library/components/Icons/Icon';
import { AddContactViewSelectorsIDs } from '../../../../e2e/selectors/Settings/Contacts/AddContactView.selectors';
import { RequestPaymentViewSelectors } from '../../../../e2e/selectors/Receive/RequestPaymentView.selectors';

const trackEvent = (event, params = {}) => {
MetaMetrics.getInstance().trackEvent(event, params);
Expand Down Expand Up @@ -360,7 +360,7 @@ export function getPaymentRequestOptionsTitle(
<TouchableOpacity
onPress={goBack}
style={styles.backButton}
{...generateTestId(Platform, REQUEST_SEARCH_RESULTS_BACK_BUTTON)}
testID={RequestPaymentViewSelectors.BACK_BUTTON_ID}
>
<IonicIcon
name={Device.isAndroid() ? 'md-arrow-back' : 'ios-arrow-back'}
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/PaymentRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { selectTokens } from '../../../selectors/tokensController';
import { selectContractExchangeRates } from '../../../selectors/tokenRatesController';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';

import { RequestPaymentViewSelectors } from '../../../../e2e/selectors/RequestPaymentView.selectors';
import { RequestPaymentViewSelectors } from '../../../../e2e/selectors/Receive/RequestPaymentView.selectors';

const KEYBOARD_OFFSET = 120;
const createStyles = (colors) =>
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/PaymentRequestSuccess/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { protectWalletModalVisible } from '../../../actions/user';
import ClipboardManager from '../../../core/ClipboardManager';
import { ThemeContext, mockTheme } from '../../../util/theme';
import generateTestId from '../../../../wdio/utils/generateTestId';
import { SendLinkViewSelectorsIDs } from '../../../../e2e/selectors/SendLinkView.selectors';
import { SendLinkViewSelectorsIDs } from '../../../../e2e/selectors/Receive/SendLinkView.selectors';

const isIos = Device.isIos();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8717,7 +8717,7 @@ exports[`BuildQuote View renders correctly 1`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down Expand Up @@ -11839,7 +11839,7 @@ exports[`BuildQuote View renders correctly 2`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/ReceiveRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { isNetworkRampSupported } from '../Ramp/utils';
import { createBuyNavigationDetails } from '../Ramp/routes/utils';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { getRampNetworks } from '../../../reducers/fiatOrders';
import { RequestPaymentModalSelectorsIDs } from '../../../../e2e/selectors/Modals/RequestPaymentModal.selectors';
import { RequestPaymentModalSelectorsIDs } from '../../../../e2e/selectors/Receive/RequestPaymentModal.selectors';
import { withMetricsAwareness } from '../../../components/hooks/useMetrics';
import { getDecimalChainId } from '../../../util/networks';
import QRAccountDisplay from '../../Views/QRAccountDisplay';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports[`StakeConfirmationView render matches snapshot 1`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports[`UnstakeConfirmationView render matches snapshot 1`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports[`StakingBalance render matches snapshot 1`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports[`TokenValueStack render matches snapshot 1`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down
6 changes: 3 additions & 3 deletions app/components/UI/Tokens/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ exports[`Tokens should hide zero balance tokens when setting is on 1`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down Expand Up @@ -1795,7 +1795,7 @@ exports[`Tokens should render correctly 1`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down Expand Up @@ -3059,7 +3059,7 @@ exports[`Tokens should show all balance tokens when hideZeroBalanceTokens settin
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`NotificationBadge should renders correctly 1`] = `
onLoadEnd={[Function]}
source={
{
"uri": undefined,
"uri": "",
}
}
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { selectChainId } from '../../../../../selectors/networkController';
import ApproveTransactionHeader from '../ApproveTransactionHeader';
import { getActiveTabUrl } from '../../../../../util/transactions';
import { isEqual } from 'lodash';
import { AssetWatcherSelectorsIDs } from '../../../../../../e2e/selectors/Modals/AssetWatcher.selectors';
import { AssetWatcherSelectorsIDs } from '../../../../../../e2e/selectors/Transactions/AssetWatcher.selectors';
import { getDecimalChainId } from '../../../../../util/networks';
import { useMetrics } from '../../../../../components/hooks/useMetrics';

Expand Down
8 changes: 7 additions & 1 deletion app/core/Engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ describe('Engine', () => {
const engine = Engine.init({});
const initialBackgroundState = engine.datamodel.state;

expect(initialBackgroundState).toStrictEqual(backgroundState);
// AssetsContractController is stateless in v37 resulting in an undefined state
const newBackgroundState = {
...backgroundState,
AssetsContractController: undefined,
};

expect(initialBackgroundState).toStrictEqual(newBackgroundState);
});

it('setSelectedAccount throws an error if no account exists for the given address', () => {
Expand Down
Loading

0 comments on commit 2944d3d

Please sign in to comment.