Skip to content

Commit

Permalink
Merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
Cal-L committed Jul 21, 2023
2 parents 03a0d06 + a8d0613 commit 57f2450
Show file tree
Hide file tree
Showing 261 changed files with 975 additions and 1,490 deletions.
1 change: 1 addition & 0 deletions .detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
jest: {
setupTimeout: 120000,
},
retries: 2,
},

configurations: {
Expand Down
6 changes: 2 additions & 4 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import WC2Manager, {
} from '../../../../app/core/WalletConnect/WalletConnectV2';
import NavigationService from '../../../core/NavigationService';
import LockScreen from '../../Views/LockScreen';
import { selectFrequentRpcList } from '../../../selectors/preferencesController';

const clearStackNavigatorOptions = {
headerShown: false,
Expand Down Expand Up @@ -233,10 +234,7 @@ const App = ({ userLoggedIn }) => {
dispatch(setCurrentBottomNavRoute(route));
}
};
const frequentRpcList = useSelector(
(state) =>
state?.engine?.backgroundState?.PreferencesController?.frequentRpcList,
);
const frequentRpcList = useSelector(selectFrequentRpcList);

useEffect(() => {
if (prevNavigator.current || !navigator) return;
Expand Down
20 changes: 10 additions & 10 deletions app/components/Nav/Main/MainNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ import SwapsQuotesView from '../../UI/Swaps/QuotesView';
import CollectiblesDetails from '../../UI/CollectibleModal';
import OptinMetrics from '../../UI/OptinMetrics';
import Drawer from '../../UI/Drawer';
import { FiatOnRampSDKProvider } from '../../UI/FiatOnRampAggregator/sdk';
import GetStarted from '../../../components/UI/FiatOnRampAggregator/Views/GetStarted';
import PaymentMethods from '../../UI/FiatOnRampAggregator/Views/PaymentMethods/PaymentMethods';
import AmountToBuy from '../../../components/UI/FiatOnRampAggregator/Views/AmountToBuy';
import Quotes from '../../../components/UI/FiatOnRampAggregator/Views/Quotes';
import CheckoutWebView from '../../UI/FiatOnRampAggregator/Views/Checkout';
import OnRampSettings from '../../UI/FiatOnRampAggregator/Views/Settings';
import OnrampAddActivationKey from '../../UI/FiatOnRampAggregator/Views/Settings/AddActivationKey';
import Regions from '../../UI/FiatOnRampAggregator/Views/Regions';
import { FiatOnRampSDKProvider } from '../../UI/Ramp/sdk';
import GetStarted from '../../UI/Ramp/Views/GetStarted';
import PaymentMethods from '../../UI/Ramp/Views/PaymentMethods/PaymentMethods';
import AmountToBuy from '../../UI/Ramp/Views/AmountToBuy';
import Quotes from '../../UI/Ramp/Views/Quotes';
import CheckoutWebView from '../../UI/Ramp/Views/Checkout';
import OnRampSettings from '../../UI/Ramp/Views/Settings';
import OnrampAddActivationKey from '../../UI/Ramp/Views/Settings/AddActivationKey';
import Regions from '../../UI/Ramp/Views/Regions';
import { colors as importedColors } from '../../../styles/common';
import OrderDetails from '../../UI/FiatOnRampAggregator/Views/OrderDetails';
import OrderDetails from '../../UI/Ramp/Views/OrderDetails';
import TabBar from '../../../component-library/components/Navigation/TabBar';
import BrowserUrlModal from '../../Views/BrowserUrlModal';
import Routes from '../../../constants/navigation/Routes';
Expand Down
4 changes: 2 additions & 2 deletions app/components/Nav/Main/RootRPCMethodsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
import { selectTokenList } from '../../../selectors/tokenListController';
import { selectTokens } from '../../../selectors/tokensController';
import { selectAccountsLength } from '../../../selectors/accountTrackerController';
import { selectSelectedAddress } from '../../../selectors/preferencesController';
import { createAccountConnectNavDetails } from '../../Views/AccountConnect';
import { ApprovalResult } from '../../UI/Approval/ApprovalResult';
import { ApprovalResultType } from '../../UI/Approval/ApprovalResult/ApprovalResult';
Expand Down Expand Up @@ -953,8 +954,7 @@ RootRPCMethodsUI.propTypes = {
};

const mapStateToProps = (state) => ({
selectedAddress:
state.engine.backgroundState.PreferencesController.selectedAddress,
selectedAddress: selectSelectedAddress(state),
chainId: selectChainId(state),
tokens: selectTokens(state),
swapsTransactions:
Expand Down
4 changes: 2 additions & 2 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import FadeOutOverlay from '../../UI/FadeOutOverlay';
import Device from '../../../util/device';
import BackupAlert from '../../UI/BackupAlert';
import Notification from '../../UI/Notification';
import FiatOrders from '../../UI/FiatOnRampAggregator';
import RampOrders from '../../UI/Ramp';
import {
showTransactionNotification,
hideCurrentNotification,
Expand Down Expand Up @@ -361,7 +361,7 @@ const Main = (props) => {
<GlobalAlert />
<FadeOutOverlay />
<Notification navigation={props.navigation} />
<FiatOrders />
<RampOrders />
<SwapsLiveness />
<BackupAlert
onDismiss={toggleRemindLater}
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/AccountApproval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from '../../../selectors/networkController';
import { selectTokensLength } from '../../../selectors/tokensController';
import { selectAccountsLength } from '../../../selectors/accountTrackerController';
import { selectSelectedAddress } from '../../../selectors/preferencesController';
import AppConstants from '../../../../app/core/AppConstants';
import { shuffle } from 'lodash';
import SDKConnect from '../../../core/SDKConnect/SDKConnect';
Expand Down Expand Up @@ -462,9 +463,8 @@ class AccountApproval extends PureComponent {

const mapStateToProps = (state) => ({
accountsLength: selectAccountsLength(state),
selectedAddress:
state.engine.backgroundState.PreferencesController.selectedAddress,
tokensLength: selectTokensLength(state),
selectedAddress: selectSelectedAddress(state),
networkType: selectProviderType(state),
chainId: selectChainId(state),
});
Expand Down
22 changes: 2 additions & 20 deletions app/components/UI/AccountApproval/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,13 @@ import React from 'react';
import AccountApproval from './';
import { shallow } from 'enzyme';
import configureMockStore from 'redux-mock-store';
import { SEPOLIA } from '../../../constants/network';
import { Provider } from 'react-redux';
import initialBackgroundState from '../../../util/test/initial-background-state.json';

const mockStore = configureMockStore();
const initialState = {
engine: {
backgroundState: {
AccountTrackerController: {
accounts: { '0x2': { balance: '0' } },
},
NetworkController: {
providerConfig: {
type: SEPOLIA,
},
},
TokensController: {
tokens: [],
},
PreferencesController: {
selectedAddress: '0xe7E125654064EEa56229f273dA586F10DF96B0a1',
identities: {
'0xe7E125654064EEa56229f273dA586F10DF96B0a1': { name: 'Account 1' },
},
},
},
backgroundState: initialBackgroundState,
},
};
const store = mockStore(initialState);
Expand Down
137 changes: 44 additions & 93 deletions app/components/UI/AccountFromToInfoCard/AccountFromToInfoCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,13 @@ import { ENSCache } from '../../../util/ENSUtils';
import { Transaction } from './AccountFromToInfoCard.types';
import AccountFromToInfoCard from '.';
import Engine from '../../../core/Engine';
import initialBackgroundState from '../../../util/test/initial-background-state.json';

jest.mock('../../../util/address', () => ({
...jest.requireActual('../../../util/address'),
isQRHardwareAccount: () => false,
}));

jest.mock('../../../core/Engine', () => ({
context: {
TokensController: {
addToken: () => undefined,
},
},
}));

jest.mock('../../../util/ENSUtils', () => ({
...jest.requireActual('../../../util/ENSUtils'),
doENSReverseLookup: jest.fn(),
}));

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: (fn: any) =>
fn({
engine: {
backgroundState: {
PreferencesController: {
selectedAddress: '0x0',
identities: {
'0x0': {
address: '0x0',
name: 'Account 1',
},
'0x1': {
address: '0x1',
name: 'Account 2',
},
},
},
NetworkController: {
provider: {
ticker: 'eth',
},
},
AddressBookController: {
addressBook: {},
},
},
},
}),
}));

jest.mock('../../../util/address', () => ({
...jest.requireActual('../../../util/address'),
isQRHardwareAccount: jest.fn(),
}));

const mockStore = configureMockStore();
const initialState = {
const mockInitialState = {
settings: {},
engine: {
backgroundState: {
...initialBackgroundState,
AccountTrackerController: {
accounts: {
'0x0': {
Expand All @@ -84,7 +30,6 @@ const initialState = {
'0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': '0x5',
},
},
TokensController: {},
PreferencesController: {
selectedAddress: '0x0',
identities: {
Expand All @@ -98,40 +43,46 @@ const initialState = {
},
},
},
CurrencyRateController: {
conversionRate: 10,
currentCurrency: 'usd',
},
NetworkController: {
provider: {
ticker: 'eth',
},
network: '1',
},
AddressBookController: {
addressBook: {
'1': {
'0x0': {
address: '0x0',
name: 'Account 1',
},
'0x1': {
address: '0x1',
name: 'Account 2',
},
},
},
},
},
},
};
const store = mockStore(initialState);

jest.mock('../../../util/address', () => ({
...jest.requireActual('../../../util/address'),
isQRHardwareAccount: () => false,
}));

jest.mock('../../../core/Engine', () => ({
context: {
TokensController: {
addToken: () => undefined,
},
},
}));

jest.mock('../../../util/ENSUtils', () => ({
...jest.requireActual('../../../util/ENSUtils'),
doENSReverseLookup: jest.fn(),
}));

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: (fn: any) => fn(mockInitialState),
}));

jest.mock('../../../util/address', () => ({
...jest.requireActual('../../../util/address'),
isQRHardwareAccount: jest.fn(),
}));

const mockStore = configureMockStore();
const store = mockStore(mockInitialState);

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: jest
.fn()
.mockImplementation((callback) => callback(initialState)),
.mockImplementation((callback) => callback(mockInitialState)),
}));

const transactionState: Transaction = {
Expand All @@ -155,39 +106,39 @@ describe('AccountFromToInfoCard', () => {
it('should match snapshot', async () => {
const container = renderWithProvider(
<AccountFromToInfoCard transactionState={transactionState} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(container).toMatchSnapshot();
});

it('should render from address', async () => {
const { findByText } = renderWithProvider(
<AccountFromToInfoCard transactionState={transactionState} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(await findByText('Account 1')).toBeDefined();
});

it('should render balance of from address', async () => {
const { findByText } = renderWithProvider(
<AccountFromToInfoCard transactionState={transactionState} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(await findByText('Balance: < 0.00001 ETH')).toBeDefined();
});

it('should render to account name', async () => {
const { findByText } = renderWithProvider(
<AccountFromToInfoCard transactionState={transactionState} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(await findByText('Account 2')).toBeDefined();
});

it('should render to address', async () => {
const { findByText } = renderWithProvider(
<AccountFromToInfoCard transactionState={transactionState} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(await findByText('0x1...0x1')).toBeDefined();
});
Expand All @@ -213,7 +164,7 @@ describe('AccountFromToInfoCard', () => {
};
const { findByText } = renderWithProvider(
<AccountFromToInfoCard transactionState={NFTTransaction as any} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(await findByText('0xF4e8...287B')).toBeDefined();
});
Expand All @@ -236,7 +187,7 @@ describe('AccountFromToInfoCard', () => {
};
const { queryByText } = renderWithProvider(
<AccountFromToInfoCard transactionState={txState} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(await queryByText('test1.eth')).toBeDefined();
expect(await queryByText('test3.eth')).toBeDefined();
Expand Down Expand Up @@ -274,7 +225,7 @@ describe('AccountFromToInfoCard', () => {
it('should render balance from AssetsContractController.getERC20BalanceOf if selectedAddress is different from fromAddress', async () => {
const { findByText } = renderWithProvider(
<AccountFromToInfoCard transactionState={ERC20Transaction as any} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(mockGetERC20BalanceOf).toBeCalledTimes(1);
expect(await findByText('Balance: 10 TST')).toBeDefined();
Expand All @@ -291,7 +242,7 @@ describe('AccountFromToInfoCard', () => {
};
const { findByText } = renderWithProvider(
<AccountFromToInfoCard transactionState={transaction as any} />,
{ state: initialState },
{ state: mockInitialState },
);
expect(mockGetERC20BalanceOf).toBeCalledTimes(0);
expect(await findByText('Balance: 0.0005 TST')).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
selectNetwork,
selectTicker,
} from '../../../selectors/networkController';
import { selectIdentities } from '../../../selectors/preferencesController';
import { collectConfusables } from '../../../util/confusables';
import { decodeTransferData } from '../../../util/transactions';
import { doENSReverseLookup } from '../../../util/ENSUtils';
Expand Down Expand Up @@ -172,7 +173,7 @@ const AccountFromToInfoCard = (props: AccountFromToInfoCardProps) => {
};

const mapStateToProps = (state: any) => ({
identities: state.engine.backgroundState.PreferencesController.identities,
identities: selectIdentities(state),
network: selectNetwork(state),
ticker: selectTicker(state),
});
Expand Down
Loading

0 comments on commit 57f2450

Please sign in to comment.