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

feat: Add Chain Permissions #10650

Merged
merged 32 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
998faa3
Adding Chain Permissions
adonesky1 Aug 14, 2024
1f2776a
gluing
adonesky1 Sep 13, 2024
295cae8
refactor switchEthereumChain + addEthereumChain handlers
adonesky1 Sep 16, 2024
8e30da4
fix
adonesky1 Sep 16, 2024
a1c738a
adding permission logic
adonesky1 Sep 16, 2024
399938f
unit tests passing
adonesky1 Oct 7, 2024
8b82148
fix test
adonesky1 Oct 7, 2024
3af5922
env variable not set correctly
adonesky1 Oct 7, 2024
8d9ebf3
fixed env variable issue
adonesky1 Oct 7, 2024
2475405
wallet_addEthereumChain tests passing, rename env variables, cleanup
adonesky1 Oct 7, 2024
6543246
add wallet_switchEthereumChain tests
adonesky1 Oct 8, 2024
ea5c2b8
cleanup
adonesky1 Oct 8, 2024
2cb7c1d
wiring up
adonesky1 Oct 8, 2024
90e9e86
WIP
adonesky1 Oct 9, 2024
5a1ef60
cleanup
adonesky1 Oct 9, 2024
4557221
refactor & cleanup
adonesky1 Oct 9, 2024
dc8e896
lint
adonesky1 Oct 9, 2024
6323cde
cleanup
adonesky1 Oct 9, 2024
a9f5aac
modify snapshot
adonesky1 Oct 9, 2024
23f7d06
final cleanup?
adonesky1 Oct 9, 2024
d87da01
fix
adonesky1 Oct 10, 2024
3feefbb
add test
adonesky1 Oct 10, 2024
63e47d5
fix test
adonesky1 Oct 10, 2024
7b81a87
Merge remote-tracking branch 'origin' into ad/permitted-chains-permis…
adonesky1 Oct 11, 2024
e5ee3c3
fix up merge commit
adonesky1 Oct 14, 2024
59de68f
update snapshot
adonesky1 Oct 14, 2024
97dbf91
revert unnecessary selector
adonesky1 Oct 14, 2024
663b315
fix preloaded networks issue
adonesky1 Oct 15, 2024
f103c44
another cleanup
adonesky1 Oct 15, 2024
9e0e643
remove unneeded comments
adonesky1 Oct 18, 2024
0a66b14
Merge branch 'main' into ad/permitted-chains-permission
adonesky1 Oct 18, 2024
ddea8bc
Merge branch 'main' into ad/permitted-chains-permission
adonesky1 Oct 18, 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
7 changes: 5 additions & 2 deletions .js.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export MM_ENABLE_SETTINGS_PAGE_DEV_OPTIONS="true"
# The endpoint used to submit errors and tracing data to Sentry for dev environment.
# export MM_SENTRY_DSN_DEV=

# Multichain Feature flag
export MULTICHAIN_V1=""
# Per dapp selected network (Amon Hen) feature flag
export MM_PER_DAPP_SELECTED_NETWORK=""

export MM_CHAIN_PERMISSIONS=""

#Multichain feature flag specific to UI changes
export MM_MULTICHAIN_V1_ENABLED=""
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ const mockInitialState = {
};

describe('PermissionsSummary', () => {
it('should render correctly for network switch', () => {
const { toJSON } = renderWithProvider(
<PermissionsSummary
currentPageInformation={{
currentEnsName: '',
icon: '',
url: 'https://app.uniswap.org/',
}}
customNetworkInformation={{
chainName: 'Sepolia',
chainId: '0x1',
}}
isNetworkSwitch
/>,
{ state: mockInitialState },
);
expect(toJSON()).toMatchSnapshot();
});
it('should render correctly', () => {
const { toJSON } = renderWithProvider(
<PermissionsSummary
Expand Down
70 changes: 51 additions & 19 deletions app/components/UI/PermissionsSummary/PermissionsSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React, { useCallback } from 'react';
import StyledButton from '../StyledButton';
import { SafeAreaView, TouchableOpacity, View } from 'react-native';
import {
ImageSourcePropType,
SafeAreaView,
TouchableOpacity,
View,
} from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { strings } from '../../../../locales/i18n';
import { useTheme } from '../../../util/theme';
Expand Down Expand Up @@ -30,19 +35,21 @@ import useSelectedAccount from '../Tabs/TabThumbnail/useSelectedAccount';
import styleSheet from './PermissionsSummary.styles';
import { useStyles } from '../../../component-library/hooks';
import { PermissionsSummaryProps } from './PermissionsSummary.types';
import { useSelector } from 'react-redux';
import { selectNetworkName } from '../../../selectors/networkInfos';
import { USER_INTENT } from '../../../constants/permissions';
import Routes from '../../../constants/navigation/Routes';
import ButtonIcon, {
ButtonIconSizes,
} from '../../../component-library/components/Buttons/ButtonIcon';
import { getNetworkImageSource } from '../../../util/networks';

const PermissionsSummary = ({
currentPageInformation,
customNetworkInformation,
onEdit,
onEditNetworks,
onBack,
onCancel,
onConfirm,
onUserAction,
showActionButtons = true,
isAlreadyConnected = true,
Expand All @@ -54,14 +61,26 @@ const PermissionsSummary = ({
const { styles } = useStyles(styleSheet, { isRenderedAsBottomSheet });
const { navigate } = useNavigation();
const selectedAccount = useSelectedAccount();
const networkName = useSelector(selectNetworkName);

// if network switch, we get the chain name from the customNetworkInformation
let chainName = '';
let chainImage: ImageSourcePropType;
if (isNetworkSwitch && customNetworkInformation?.chainId) {
chainName = customNetworkInformation?.chainName;
// @ts-expect-error getNetworkImageSource is not implemented in typescript
chainImage = getNetworkImageSource({
chainId: customNetworkInformation?.chainId,
});
}

const confirm = () => {
onUserAction?.(USER_INTENT.Confirm);
onConfirm?.();
};

const cancel = () => {
onUserAction?.(USER_INTENT.Cancel);
onCancel?.();
};

const handleEditAccountsButtonPress = () => {
Expand Down Expand Up @@ -208,21 +227,33 @@ const PermissionsSummary = ({
{strings('permissions.use_enabled_networks')}
</TextComponent>
<View style={styles.permissionRequestNetworkInfo}>
<View style={styles.permissionRequestNetworkName}>
<TextComponent numberOfLines={1} ellipsizeMode="tail">
<TextComponent variant={TextVariant.BodySM}>
{strings('permissions.requesting_for')}
</TextComponent>
<TextComponent variant={TextVariant.BodySMMedium}>
{networkName}
</TextComponent>
</TextComponent>
</View>
<View style={styles.avatarGroup}>
<AvatarGroup
avatarPropsList={SAMPLE_AVATARGROUP_PROPS.avatarPropsList}
/>
</View>
{isNetworkSwitch && (
<>
<View style={styles.permissionRequestNetworkName}>
<TextComponent numberOfLines={1} ellipsizeMode="tail">
<TextComponent variant={TextVariant.BodySM}>
{strings('permissions.requesting_for')}
</TextComponent>
<TextComponent variant={TextVariant.BodySMMedium}>
{chainName}
</TextComponent>
</TextComponent>
</View>
<Avatar
variant={AvatarVariant.Network}
size={AvatarSize.Xs}
name={chainName}
imageSource={chainImage}
/>
</>
)}
{!isNetworkSwitch && (
<View style={styles.avatarGroup}>
<AvatarGroup
avatarPropsList={SAMPLE_AVATARGROUP_PROPS.avatarPropsList}
/>
</View>
)}
</View>
</View>
{!isNetworkSwitch && renderEndAccessory()}
Expand All @@ -247,6 +278,7 @@ const PermissionsSummary = ({
})}
</TextComponent>
</View>
{/*TODO These should be conditional upon which permissions are being requested*/}
{!isNetworkSwitch && renderAccountPermissionsRequestInfoCard()}
{renderNetworkPermissionsRequestInfoCard()}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ export interface PermissionsSummaryProps {
onEdit?: () => void;
onEditNetworks?: () => void;
onBack?: () => void;
onCancel?: () => void;
onConfirm?: () => void;
onUserAction?: React.Dispatch<React.SetStateAction<USER_INTENT>>;
showActionButtons?: boolean;
isAlreadyConnected?: boolean;
isRenderedAsBottomSheet?: boolean;
isDisconnectAllShown?: boolean;
isNetworkSwitch?: boolean;
customNetworkInformation?: {
chainName: string;
chainId: string;
};
}
Loading
Loading