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

Temp/notification integration sdk fixes #10116

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c299cd2
feat: adding search to the network bottomsheet as part of the network…
EtherWizard33 Jun 24, 2024
dfab04b
Merge branch 'main' of github.com:MetaMask/metamask-mobile into feat/…
Prithpal-Sooriya Jun 24, 2024
671392a
fix: fix engine configuration and snapshot test
Prithpal-Sooriya Jun 25, 2024
f213a60
refactor: fix types, mocks, and tests
Prithpal-Sooriya Jun 26, 2024
f39a72e
chore: minor adjustment on toggle
Jonathansoufer Jun 26, 2024
a30cb5c
chore: refactor selectors
Jonathansoufer Jun 26, 2024
5c7f6b4
refactor: add types and fix tests
Prithpal-Sooriya Jun 26, 2024
87f944e
refactor: add types and account switch logic
Prithpal-Sooriya Jun 27, 2024
66ce66a
refactor: fix and add util unit tests
Prithpal-Sooriya Jun 27, 2024
2ddf806
chore: Refactor Snaps integration (#10063)
FrederikBolding Jun 24, 2024
4df2a97
chore: update attribution (#10070)
NicolasMassart Jun 24, 2024
db54ae8
fix: fix stuck after `nonce too low` error (#10049)
OGPoyraz Jun 24, 2024
fb78c8a
fix: Always mark the STX Opt In modal as seen (#10064)
dan437 Jun 24, 2024
2310745
fix: Swap with unapproved token (#10088)
tommasini Jun 24, 2024
ba67fb7
fix: stx on ramps missing origin (#10099)
infiniteflower Jun 24, 2024
7a453b9
feat: Add team label to pr (#10086)
itsyoboieltr Jun 25, 2024
bc2bd59
feat: adjusting the 'add network screen' in network bottom sheet, for…
EtherWizard33 Jun 25, 2024
443c2f3
test: add E2E for increase allowance (#9969)
vinistevam Jun 25, 2024
319d84e
feat: support security alerts API (#10000)
matthewwalsh0 Jun 26, 2024
f3dfa35
chore: Add Notification devs to codeowners file (#9811)
Jonathansoufer Jun 26, 2024
57cc4d1
feat: add i18n to for the add/edit network ui re-design (#10120)
EtherWizard33 Jun 26, 2024
9277594
feat: 7.24.4 (#10094)
github-actions[bot] Jun 26, 2024
6abaa20
feat: add api spec test infrastructure (#9356)
tmashuang Jun 26, 2024
6ac4e06
feat: Add the "is_smart_transaction" prop for the "Swap Started" even…
dan437 Jun 26, 2024
7f8d152
fix: create nft auto detection modal and remove nft polling logic (#9…
sahar-fehri Jun 26, 2024
633039f
fix: updated changelog for 7.24.4 (#10122)
sethkfman Jun 26, 2024
18cd1d5
chore: Update create-cherry-pick-pr.sh to auto add label (#10125)
chrisleewilcox Jun 26, 2024
9f901e9
refactor: update bitrise e2e check to not run on forks (#10128)
NicholasEllul Jun 26, 2024
a6100d6
test: disable privacy policy toast and whats new modal using fixtures…
cortisiko Jun 27, 2024
d11e297
chore: fix the incorrect URL displayed during transaction confirmatio…
omridan159 Jun 27, 2024
41bf7bb
feat: enables snaps feature flag on mobile (#10121)
Jonathansoufer Jun 27, 2024
5b324ae
fix: Fix BaseControllerV1 state rehydration (#10133)
Gudahtt Jun 27, 2024
e1fa847
feat: Integrate Firebase libraries and initial config to enable Push …
Jonathansoufer Jun 27, 2024
f3cf1c3
fix: fix engine configuration and snapshot test
Prithpal-Sooriya Jun 25, 2024
39669f1
refactor: add types and fix tests
Prithpal-Sooriya Jun 26, 2024
81f1897
refactor: add types and account switch logic
Prithpal-Sooriya Jun 27, 2024
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
60 changes: 59 additions & 1 deletion app/components/Views/NetworkSelector/NetworkSelector.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Device from '../../../util/device';
import { StyleSheet } from 'react-native';
import { fontStyles } from '../../../styles/common';
import { isNetworkUiRedesignEnabled } from '../../../util/networks';
/**
* Style sheet function for NetworkSelector screen.
* @returns StyleSheet object.
Expand All @@ -12,7 +13,11 @@ const createStyles = (colors: any) =>
StyleSheet.create({
addNetworkButton: {
marginHorizontal: 16,
marginBottom: Device.isAndroid() ? 16 : 0,
marginBottom: Device.isAndroid()
? 16
: isNetworkUiRedesignEnabled
? 12
: 0,
},
switchContainer: {
flexDirection: 'row',
Expand All @@ -39,6 +44,59 @@ const createStyles = (colors: any) =>
color: colors.primary.default,
marginTop: 1,
},
networkListContainer: {
height: isNetworkUiRedesignEnabled ? '100%' : undefined,
},
networkIcon: {
width: 20,
height: 20,
borderRadius: 10,
marginTop: 2,
marginRight: 16,
},
network: {
flex: 1,
flexDirection: 'row',
paddingVertical: 12,
alignItems: 'center',
},
networkLabel: {
fontSize: 16,
color: colors.text.default,
...fontStyles.normal,
},
inputWrapper: {
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 10,
paddingVertical: 10,
borderRadius: 5,
borderWidth: 1,
borderColor: colors.border.default,
color: colors.text.default,
marginLeft: 16,
marginRight: 16,
marginBottom: 8,
},
input: {
flex: 1,
fontSize: 14,
color: colors.text.default,
...fontStyles.normal,
paddingLeft: 10,
},
icon: {
marginLeft: 8,
},
no_match_text: {
marginVertical: 10,
},
text: {
textAlign: 'center',
color: colors.text.default,
fontSize: 10,
marginTop: 4,
},
});

export default createStyles;
134 changes: 117 additions & 17 deletions app/components/Views/NetworkSelector/NetworkSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// Third party dependencies.
import React, { useRef, useState } from 'react';
import { Linking, Switch, View } from 'react-native';
import { Linking, Switch, TextInput, View } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
import images from 'images/image-icons';
import { useNavigation } from '@react-navigation/native';
Expand Down Expand Up @@ -64,11 +65,15 @@ import { TESTNET_TICKER_SYMBOLS } from '@metamask/controller-utils';
import InfoModal from '../../../../app/components/UI/Swaps/components/InfoModal';
import hideKeyFromUrl from '../../../util/hideKeyFromUrl';
import CustomNetwork from '../Settings/NetworksSettings/NetworkSettings/CustomNetworkView/CustomNetwork';
import { NetworksViewSelectorsIDs } from '../../../../e2e/selectors/Settings/NetworksView.selectors';
import { PopularList } from '../../../util/networks/customNetworks';
import Icon from 'react-native-vector-icons/Ionicons';

const NetworkSelector = () => {
const [showPopularNetworkModal, setShowPopularNetworkModal] = useState(false);
const [popularNetwork, setPopularNetwork] = useState(undefined);
const [showWarningModal, setShowWarningModal] = useState(false);
const [searchString, setSearchString] = useState('');
const { navigate } = useNavigation();
const theme = useTheme();
const { trackEvent } = useMetrics();
Expand Down Expand Up @@ -167,8 +172,34 @@ const NetworkSelector = () => {
Linking.openURL(strings('networks.learn_more_url'));
};

const filterNetworksByName = (networks: any[], networkName: string) => {
const searchResult: any = networks.filter(({ name }) =>
name.toLowerCase().includes(networkName.toLowerCase()),
);

return searchResult;
};

const isNoSearchResults = (networkIdenfier: string) => {
if (!searchString || !networkIdenfier) {
return false;
}

if (networkIdenfier === MAINNET || networkIdenfier === LINEA_MAINNET) {
return (
filterNetworksByName([Networks[networkIdenfier]], searchString)
.length === 0
);
}

return !networkIdenfier.includes(searchString);
};

const renderMainnet = () => {
const { name: mainnetName, chainId } = Networks.mainnet;

if (isNetworkUiRedesignEnabled && isNoSearchResults(MAINNET)) return null;

return (
<Cell
variant={CellVariant.Select}
Expand All @@ -190,6 +221,10 @@ const NetworkSelector = () => {

const renderLineaMainnet = () => {
const { name: lineaMainnetName, chainId } = Networks['linea-mainnet'];

if (isNetworkUiRedesignEnabled && isNoSearchResults('linea-mainnet'))
return null;

return (
<Cell
variant={CellVariant.Select}
Expand All @@ -211,6 +246,9 @@ const NetworkSelector = () => {
({ nickname, rpcUrl, chainId }) => {
if (!chainId) return null;
const { name } = { name: nickname || rpcUrl };

if (isNetworkUiRedesignEnabled && isNoSearchResults(name)) return null;

//@ts-expect-error - The utils/network file is still JS and this function expects a networkType, and should be optional
const image = getNetworkImageSource({ chainId: chainId?.toString() });

Expand Down Expand Up @@ -243,6 +281,8 @@ const NetworkSelector = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { name, imageSource, chainId } = (Networks as any)[networkType];

if (isNetworkUiRedesignEnabled && isNoSearchResults(name)) return null;

return (
<Cell
key={chainId}
Expand Down Expand Up @@ -293,18 +333,32 @@ const NetworkSelector = () => {
</View>
);

const renderAdditonalNetworks = () => (
<View style={styles.addtionalNetworksContainer}>
<CustomNetwork
isNetworkModalVisible={showPopularNetworkModal}
closeNetworkModal={onCancel}
selectedNetwork={popularNetwork}
toggleWarningModal={toggleWarningModal}
showNetworkModal={showNetworkModal}
shouldNetworkSwitchPopToWallet={false}
/>
</View>
);
const renderAdditonalNetworks = () => {
let filteredNetworks;

if (isNetworkUiRedesignEnabled && searchString.length > 0)
filteredNetworks = PopularList.filter(({ nickname }) =>
nickname.toLowerCase().includes(searchString.toLowerCase()),
);

return (
<View style={styles.addtionalNetworksContainer}>
<CustomNetwork
isNetworkModalVisible={showPopularNetworkModal}
closeNetworkModal={onCancel}
selectedNetwork={popularNetwork}
toggleWarningModal={toggleWarningModal}
showNetworkModal={showNetworkModal}
switchTab={undefined}
shouldNetworkSwitchPopToWallet={false}
customNetworksList={
searchString.length > 0 ? filteredNetworks : undefined
}
showCompletionMessage={false}
/>
</View>
);
};

const renderTitle = (title: string) => (
<View style={styles.switchContainer}>
Expand All @@ -314,18 +368,51 @@ const NetworkSelector = () => {
</View>
);

return (
<BottomSheet ref={sheetRef}>
const handleSearchTextChange = (text: any) => {
setSearchString(text);
};

const clearSearchInput = () => {
setSearchString('');
};

const renderBottomSheetContent = () => (
<>
<SheetHeader title={strings('networks.select_network')} />
<ScrollView testID={NetworkListModalSelectorsIDs.SCROLL}>
{isNetworkUiRedesignEnabled && renderTitle('networks.enabled_networks')}
{isNetworkUiRedesignEnabled && (
<View style={styles.inputWrapper}>
<Icon name="ios-search" size={20} color={colors.icon.default} />
<TextInput
style={styles.input}
placeholder={strings('networks.search')}
placeholderTextColor={colors.text.default}
value={searchString}
onChangeText={handleSearchTextChange}
testID={NetworksViewSelectorsIDs.SEARCH_NETWORK_INPUT_BOX_ID}
/>
{searchString.length > 0 && (
<Icon
name="ios-close"
size={20}
color={colors.icon.default}
onPress={clearSearchInput}
testID={NetworksViewSelectorsIDs.CLOSE_ICON}
/>
)}
</View>
)}
{isNetworkUiRedesignEnabled &&
searchString.length === 0 &&
renderTitle('networks.enabled_networks')}
{renderMainnet()}
{renderLineaMainnet()}
{renderRpcNetworks()}
{isNetworkUiRedesignEnabled &&
searchString.length === 0 &&
renderTitle('networks.additional_networks')}
{isNetworkUiRedesignEnabled && renderAdditonalNetworks()}
{renderTestNetworksSwitch()}
{searchString.length === 0 && renderTestNetworksSwitch()}
{showTestNetworks && renderOtherNetworks()}
</ScrollView>

Expand All @@ -338,6 +425,19 @@ const NetworkSelector = () => {
style={styles.addNetworkButton}
testID={NetworkListModalSelectorsIDs.ADD_BUTTON}
/>
</>
);

return (
<BottomSheet ref={sheetRef}>
{isNetworkUiRedesignEnabled ? (
<View style={styles.networkListContainer}>
{renderBottomSheetContent()}
</View>
) : (
renderBottomSheetContent()
)}

{showWarningModal ? (
<InfoModal
isVisible={showWarningModal}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const CustomNetwork = ({
onNetworkSwitch,
showAddedNetworks,
customNetworksList,
showCompletionMessage = true,
}: CustomNetworkProps) => {
const networkConfigurations = useSelector(selectNetworkConfigurations);

Expand All @@ -52,7 +53,7 @@ const CustomNetwork = ({
? supportedNetworkList
: supportedNetworkList.filter((n) => !n.isAdded);

if (filteredPopularList.length === 0) {
if (filteredPopularList.length === 0 && showCompletionMessage) {
return (
<EmptyPopularList goToCustomNetwork={() => switchTab?.goToPage?.(1)} />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ export interface CustomNetworkProps {
* List of custom networks
*/
customNetworksList?: Network[];
/**
* If this list of networks is used in a filtered way for example when the user is using a search box to filter networks,
* we should take that into consideration before displaying an empty state telling the user he has already added all networks.
* This is the main use case for this prop.
*/
showCompletionMessage?: boolean;
}
64 changes: 36 additions & 28 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,34 @@ class Engine {
],
});

const snapController = new SnapController({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional - just moved this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE - we need to discuss how we will ship notifications when snaps are not in main.

We reply on the snap controller (and potentially other snap functionality) to call our pre-installed snap. So we kinda need snaps to be enabled (at least from the background perspective, we can still hide in UI)

environmentEndowmentPermissions: Object.values(EndowmentPermissions),
featureFlags: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
requireAllowlist,
},
state: initialState.SnapController || undefined,
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
messenger: snapControllerMessenger as any,
detectSnapLocation: (
location: string | URL,
options?: DetectSnapLocationOptions,
) =>
detectSnapLocation(location, {
...options,
allowLocal: allowLocalSnaps,
fetch: fetchFunction,
}),
//@ts-expect-error types need to be aligned with snaps-controllers
preinstalledSnaps: PREINSTALLED_SNAPS,
//@ts-expect-error types need to be aligned between new encryptor and snaps-controllers
encryptor,
getMnemonic: getPrimaryKeyringMnemonic.bind(this),
});
///: END:ONLY_INCLUDE_IF

const authenticationController = new AuthenticationController.Controller({
state: initialState.AuthenticationController,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -1056,36 +1084,16 @@ class Engine {
allowedEvents: ['KeyringController:stateChange'],
}),
state: initialState.NotificationServicesController,
env: {
isPushIntegrated: false, // temporary until we integrate push notifications
featureAnnouncements: {
platform: 'mobile',
accessToken: 'TODO from env',
spaceId: 'TODO from env',
},
},
Comment on lines +1094 to +1101
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New fields in controller.

});

const snapController = new SnapController({
environmentEndowmentPermissions: Object.values(EndowmentPermissions),
featureFlags: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
requireAllowlist,
},
state: initialState.SnapController || undefined,
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
messenger: snapControllerMessenger as any,
detectSnapLocation: (
location: string | URL,
options?: DetectSnapLocationOptions,
) =>
detectSnapLocation(location, {
...options,
allowLocal: allowLocalSnaps,
fetch: fetchFunction,
}),
//@ts-expect-error types need to be aligned with snaps-controllers
preinstalledSnaps: PREINSTALLED_SNAPS,
//@ts-expect-error types need to be aligned between new encryptor and snaps-controllers
encryptor,
getMnemonic: getPrimaryKeyringMnemonic.bind(this),
});
///: END:ONLY_INCLUDE_IF

this.transactionController = new TransactionController({
// @ts-expect-error at this point in time the provider will be defined by the `networkController.initializeProvider`
blockTracker: networkController.getProviderAndBlockTracker().blockTracker,
Expand Down
Loading
Loading