Skip to content

Commit

Permalink
Merge branch 'hotfix/fix-breaking-selector' of github.com:MetaMask/me…
Browse files Browse the repository at this point in the history
…tamask-mobile into hotfix/fix-breaking-selector
  • Loading branch information
Prithpal-Sooriya committed Nov 22, 2024
2 parents 01a1859 + 4540de3 commit 825d2a4
Show file tree
Hide file tree
Showing 30 changed files with 847 additions and 68 deletions.
5 changes: 5 additions & 0 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import OnboardingAssetsSettings from '../../Views/OnboardingSuccess/OnboardingAs
import OnboardingSecuritySettings from '../../Views/OnboardingSuccess/OnboardingSecuritySettings';
import BasicFunctionalityModal from '../../UI/BasicFunctionality/BasicFunctionalityModal/BasicFunctionalityModal';
import ProfileSyncingModal from '../../UI/ProfileSyncing/ProfileSyncingModal/ProfileSyncingModal';
import PermittedNetworksInfoSheet from '../../Views/AccountPermissions/PermittedNetworksInfoSheet/PermittedNetworksInfoSheet';
import ResetNotificationsModal from '../../UI/Notification/ResetNotificationsModal';
import NFTAutoDetectionModal from '../../../../app/components/Views/NFTAutoDetectionModal/NFTAutoDetectionModal';
import NftOptions from '../../../components/Views/NftOptions';
Expand Down Expand Up @@ -430,6 +431,10 @@ const RootModalFlow = () => (
name={Routes.SHEET.CONNECTION_DETAILS}
component={ConnectionDetails}
/>
<Stack.Screen
name={Routes.SHEET.PERMITTED_NETWORKS_INFO_SHEET}
component={PermittedNetworksInfoSheet}
/>
<Stack.Screen
name={Routes.SHEET.NETWORK_SELECTOR}
component={NetworkSelector}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { StyleSheet } from 'react-native';

const styleSheet = () =>
StyleSheet.create({
networkItemContainer: {
paddingHorizontal: 10,
paddingVertical: 14,
},
networkAvatar: {
marginHorizontal: 10,
},
Expand Down
2 changes: 0 additions & 2 deletions app/components/UI/NetworkSelectorList/NetworkSelectorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const NetworkSelectorList = ({
size: AvatarSize.Sm,
}}
disabled={isDisabled}
style={styles.networkItemContainer}
>
{renderRightAccessory?.(id, name)}
</Cell>
Expand All @@ -79,7 +78,6 @@ const NetworkSelectorList = ({
renderRightAccessory,
isSelectionDisabled,
onSelectNetwork,
styles,
isMultiSelect,
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ const createStyles = (params: {
marginLeft: 24,
},
bottomButtonsContainer: {
marginTop: 16,
marginTop: 8,
},
actionButtonsContainer: {
flex: 0,
flexDirection: 'row',
paddingHorizontal: 24,
marginTop: 8,
},
buttonPositioning: {
flex: 1,
Expand All @@ -59,6 +60,9 @@ const createStyles = (params: {
justifyContent: 'center',
alignItems: 'center',
},
logoContainerNonDapp: {
marginTop: 8,
},
domainLogoContainer: {
width: 32,
height: 32,
Expand All @@ -81,6 +85,7 @@ const createStyles = (params: {
maxWidth: '75%',
},
permissionRequestNetworkName: {
marginRight: 4,
maxWidth: '75%',
},
avatarGroup: {
Expand Down Expand Up @@ -122,13 +127,21 @@ const createStyles = (params: {
dataIcon: { alignSelf: 'flex-start' },
disconnectAllContainer: {
marginHorizontal: 24,
marginTop: 8,
flexDirection: 'row',
},
disconnectButton: { flex: 1 },
editTextContainer: {
width: 56,
alignItems: 'center',
},
nonDappNetworkSwitchButtons: {
gap: 16,
},
description: {
marginHorizontal: 24,
marginBottom: 16,
},
});
};

Expand Down
92 changes: 79 additions & 13 deletions app/components/UI/PermissionsSummary/PermissionsSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useMemo } from 'react';
import StyledButton from '../StyledButton';
import {
ImageSourcePropType,
Expand Down Expand Up @@ -42,6 +42,9 @@ import ButtonIcon, {
import { getNetworkImageSource } from '../../../util/networks';
import Engine from '../../../core/Engine';
import { SDKSelectorsIDs } from '../../../../e2e/selectors/Settings/SDK.selectors';
import { useSelector } from 'react-redux';
import { selectProviderConfig } from '../../../selectors/networkController';
import { useNetworkInfo } from '../../../selectors/selectedNetworkController';

const PermissionsSummary = ({
currentPageInformation,
Expand All @@ -57,16 +60,24 @@ const PermissionsSummary = ({
isRenderedAsBottomSheet = true,
isDisconnectAllShown = true,
isNetworkSwitch = false,
isNonDappNetworkSwitch = false,
accountAddresses = [],
accounts = [],
networkAvatars = [],
onAddNetwork = () => undefined,
onChooseFromPermittedNetworks = () => undefined,
}: PermissionsSummaryProps) => {
const { colors } = useTheme();
const { styles } = useStyles(styleSheet, { isRenderedAsBottomSheet });
const { navigate } = useNavigation();
const selectedAccount = useSelectedAccount();
const providerConfig = useSelector(selectProviderConfig);

const hostname = new URL(currentPageInformation.url).hostname;
const hostname = useMemo(
() => new URL(currentPageInformation.url).hostname,
[currentPageInformation.url],
);
const networkInfo = useNetworkInfo(hostname);

// if network switch, we get the chain name from the customNetworkInformation
let chainName = '';
Expand Down Expand Up @@ -117,7 +128,7 @@ const PermissionsSummary = ({
return (
<View style={styles.header}>
<View style={styles.startAccessory}>
{onBack && (
{onBack && !isNonDappNetworkSwitch && (
<ButtonIcon
size={ButtonIconSizes.Sm}
iconColor={IconColor.Default}
Expand All @@ -127,7 +138,14 @@ const PermissionsSummary = ({
)}
</View>

<View style={styles.logoContainer}>{renderTopIcon()}</View>
<View
style={[
styles.logoContainer,
isNonDappNetworkSwitch && styles.logoContainerNonDapp,
]}
>
{renderTopIcon()}
</View>
<View style={styles.endAccessory}>
{!isRenderedAsBottomSheet && (
<ButtonIcon
Expand Down Expand Up @@ -321,27 +339,40 @@ const PermissionsSummary = ({
{strings('permissions.use_enabled_networks')}
</TextComponent>
<View style={styles.permissionRequestNetworkInfo}>
{isNetworkSwitch && (
{(isNetworkSwitch || isNonDappNetworkSwitch) && (
<>
<View style={styles.permissionRequestNetworkName}>
<TextComponent numberOfLines={1} ellipsizeMode="tail">
<TextComponent variant={TextVariant.BodySM}>
{strings('permissions.requesting_for')}
</TextComponent>
<TextComponent variant={TextVariant.BodySMMedium}>
{chainName}
{isNonDappNetworkSwitch
? networkInfo?.networkName || providerConfig.nickname
: chainName}
</TextComponent>
</TextComponent>
</View>
<Avatar
variant={AvatarVariant.Network}
size={AvatarSize.Xs}
name={chainName}
imageSource={chainImage}
name={
isNonDappNetworkSwitch
? networkInfo?.networkName || providerConfig.nickname
: chainName
}
imageSource={
isNonDappNetworkSwitch
? // @ts-expect-error getNetworkImageSource is not implemented in typescript
getNetworkImageSource({
chainId: providerConfig.chainId,
})
: chainImage
}
/>
</>
)}
{!isNetworkSwitch && (
{!isNetworkSwitch && !isNonDappNetworkSwitch && (
<>
<View style={styles.permissionRequestNetworkName}>
<TextComponent numberOfLines={1} ellipsizeMode="tail">
Expand All @@ -363,7 +394,7 @@ const PermissionsSummary = ({
)}
</View>
</View>
{!isNetworkSwitch && renderEndAccessory()}
{!isNetworkSwitch && !isNonDappNetworkSwitch && renderEndAccessory()}
</View>
</TouchableOpacity>
);
Expand All @@ -376,7 +407,9 @@ const PermissionsSummary = ({
{renderHeader()}
<View style={styles.title}>
<TextComponent variant={TextVariant.HeadingSM}>
{!isAlreadyConnected || isNetworkSwitch
{isNonDappNetworkSwitch
? strings('permissions.title_add_network_permission')
: !isAlreadyConnected || isNetworkSwitch
? strings('permissions.title_dapp_url_wants_to', {
dappUrl: hostname,
})
Expand All @@ -385,7 +418,14 @@ const PermissionsSummary = ({
})}
</TextComponent>
</View>
{/*TODO These should be conditional upon which permissions are being requested*/}
{isNonDappNetworkSwitch && (
<TextComponent
variant={TextVariant.BodyMD}
style={styles.description}
>
{strings('permissions.non_permitted_network_description')}
</TextComponent>
)}
{!isNetworkSwitch && renderAccountPermissionsRequestInfoCard()}
{renderNetworkPermissionsRequestInfoCard()}
</View>
Expand All @@ -405,7 +445,7 @@ const PermissionsSummary = ({
/>
</View>
)}
{showActionButtons && (
{showActionButtons && !isNonDappNetworkSwitch && (
<View style={styles.actionButtonsContainer}>
<StyledButton
type={'cancel'}
Expand All @@ -430,6 +470,32 @@ const PermissionsSummary = ({
</StyledButton>
</View>
)}
{isNonDappNetworkSwitch && (
<View style={styles.nonDappNetworkSwitchButtons}>
<View style={styles.actionButtonsContainer}>
<Button
variant={ButtonVariants.Primary}
label={strings('permissions.add_this_network')}
onPress={onAddNetwork}
size={ButtonSize.Lg}
style={{
...styles.disconnectButton,
}}
/>
</View>
<View style={styles.actionButtonsContainer}>
<Button
variant={ButtonVariants.Secondary}
label={strings('permissions.choose_from_permitted_networks')}
onPress={onChooseFromPermittedNetworks}
size={ButtonSize.Lg}
style={{
...styles.disconnectButton,
}}
/>
</View>
</View>
)}
</View>
</View>
</SafeAreaView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface PermissionsSummaryProps {
onCancel?: () => void;
onConfirm?: () => void;
onUserAction?: React.Dispatch<React.SetStateAction<USER_INTENT>>;
onAddNetwork?: () => void;
showActionButtons?: boolean;
isAlreadyConnected?: boolean;
isRenderedAsBottomSheet?: boolean;
Expand All @@ -25,4 +26,6 @@ export interface PermissionsSummaryProps {
accounts?: Account[];
accountAddresses?: string[];
networkAvatars?: ({ name: string; imageSource: string } | null)[];
isNonDappNetworkSwitch?: boolean;
onChooseFromPermittedNetworks?: () => void;
}
Loading

0 comments on commit 825d2a4

Please sign in to comment.