-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix(per-dapp-selected-network): restore per-dapp network picker in permissions view #13686
base: main
Are you sure you want to change the base?
Changes from all commits
988bdf1
84a8171
21bc3a2
421fc5c
ae28079
b82b7ac
dd41af7
bd097ce
5c02c47
339d998
ae30f01
1aa5cc5
e7fa261
2589252
f49d889
3c2de6e
f6783d3
f3dfe54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,10 @@ import Routes from '../../../constants/navigation/Routes'; | |
import ButtonIcon, { | ||
ButtonIconSizes, | ||
} from '../../../component-library/components/Buttons/ButtonIcon'; | ||
import { getNetworkImageSource } from '../../../util/networks'; | ||
import { | ||
getNetworkImageSource, | ||
isPerDappSelectedNetworkEnabled, | ||
} from '../../../util/networks'; | ||
import Engine from '../../../core/Engine'; | ||
import { SDKSelectorsIDs } from '../../../../e2e/selectors/Settings/SDK.selectors'; | ||
import { useSelector } from 'react-redux'; | ||
|
@@ -48,6 +51,12 @@ import { useNetworkInfo } from '../../../selectors/selectedNetworkController'; | |
import { ConnectedAccountsSelectorsIDs } from '../../../../e2e/selectors/Browser/ConnectedAccountModal.selectors'; | ||
import { PermissionSummaryBottomSheetSelectorsIDs } from '../../../../e2e/selectors/Browser/PermissionSummaryBottomSheet.selectors'; | ||
import { NetworkNonPemittedBottomSheetSelectorsIDs } from '../../../../e2e/selectors/Network/NetworkNonPemittedBottomSheet.selectors'; | ||
import BadgeWrapper from '../../../component-library/components/Badges/BadgeWrapper'; | ||
import Badge, { | ||
BadgeVariant, | ||
} from '../../../component-library/components/Badges/Badge'; | ||
import AvatarFavicon from '../../../component-library/components/Avatars/Avatar/variants/AvatarFavicon'; | ||
import AvatarToken from '../../../component-library/components/Avatars/Avatar/variants/AvatarToken'; | ||
|
||
const PermissionsSummary = ({ | ||
currentPageInformation, | ||
|
@@ -80,7 +89,7 @@ const PermissionsSummary = ({ | |
() => new URL(currentPageInformation.url).hostname, | ||
[currentPageInformation.url], | ||
); | ||
const networkInfo = useNetworkInfo(hostname); | ||
const { networkName, networkImageSource } = useNetworkInfo(hostname); | ||
|
||
// if network switch, we get the chain name from the customNetworkInformation | ||
let chainName = ''; | ||
|
@@ -111,12 +120,62 @@ const PermissionsSummary = ({ | |
onEditNetworks?.(); | ||
}; | ||
|
||
const switchNetwork = useCallback(() => { | ||
navigate(Routes.MODAL.ROOT_MODAL_FLOW, { | ||
screen: Routes.SHEET.NETWORK_SELECTOR, | ||
}); | ||
}, [navigate]); | ||
|
||
const renderTopIcon = () => { | ||
const { currentEnsName, icon } = currentPageInformation; | ||
const url = currentPageInformation.url; | ||
const iconTitle = getHost(currentEnsName || url); | ||
|
||
return ( | ||
if (!isAlreadyConnected) { | ||
return ( | ||
<WebsiteIcon | ||
style={styles.domainLogoContainer} | ||
viewStyle={styles.assetLogoContainer} | ||
title={iconTitle} | ||
url={currentEnsName || url} | ||
icon={typeof icon === 'string' ? icon : icon?.uri} | ||
/> | ||
); | ||
} | ||
|
||
return isPerDappSelectedNetworkEnabled() ? ( | ||
<View style={[styles.domainLogoContainer, styles.assetLogoContainer]}> | ||
<TouchableOpacity | ||
onPress={switchNetwork} | ||
testID={ConnectedAccountsSelectorsIDs.NETWORK_PICKER} | ||
> | ||
<BadgeWrapper | ||
badgeElement={ | ||
<Badge | ||
variant={BadgeVariant.Network} | ||
name={networkName} | ||
imageSource={networkImageSource} | ||
/> | ||
} | ||
> | ||
{icon ? ( | ||
<AvatarFavicon | ||
imageSource={{ | ||
uri: typeof icon === 'string' ? icon : icon?.uri, | ||
}} | ||
size={AvatarSize.Md} | ||
/> | ||
) : ( | ||
<AvatarToken | ||
name={iconTitle} | ||
isHaloEnabled | ||
size={AvatarSize.Md} | ||
/> | ||
)} | ||
</BadgeWrapper> | ||
</TouchableOpacity> | ||
</View> | ||
) : ( | ||
Comment on lines
+146
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this conditional required? Not understanding what's changed here. Could you explain? |
||
<WebsiteIcon | ||
style={styles.domainLogoContainer} | ||
viewStyle={styles.assetLogoContainer} | ||
|
@@ -361,7 +420,7 @@ const PermissionsSummary = ({ | |
</TextComponent> | ||
<TextComponent variant={TextVariant.BodySMMedium}> | ||
{isNonDappNetworkSwitch | ||
? networkInfo?.networkName || providerConfig.nickname | ||
? networkName || providerConfig.nickname | ||
: chainName} | ||
</TextComponent> | ||
</TextComponent> | ||
|
@@ -371,7 +430,7 @@ const PermissionsSummary = ({ | |
size={AvatarSize.Xs} | ||
name={ | ||
isNonDappNetworkSwitch | ||
? networkInfo?.networkName || providerConfig.nickname | ||
? networkName || providerConfig.nickname | ||
: chainName | ||
} | ||
imageSource={ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,6 @@ import downloadFile from '../../../util/browser/downloadFile'; | |
import { MAX_MESSAGE_LENGTH } from '../../../constants/dapp'; | ||
import sanitizeUrlInput from '../../../util/url/sanitizeUrlInput'; | ||
import { getPermittedAccountsByHostname } from '../../../core/Permissions'; | ||
import Routes from '../../../constants/navigation/Routes'; | ||
import { | ||
selectIpfsGateway, | ||
selectIsIpfsGatewayEnabled, | ||
|
@@ -75,10 +74,7 @@ import trackErrorAsAnalytics from '../../../util/metrics/TrackError/trackErrorAs | |
import { selectPermissionControllerState } from '../../../selectors/snaps/permissionController'; | ||
import { isTest } from '../../../util/test/utils.js'; | ||
import { EXTERNAL_LINK_TYPE } from '../../../constants/browser'; | ||
import { PermissionKeys } from '../../../core/Permissions/specifications'; | ||
import { CaveatTypes } from '../../../core/Permissions/constants'; | ||
import { AccountPermissionsScreens } from '../AccountPermissions/AccountPermissions.types'; | ||
import { useIsFocused, useNavigation } from '@react-navigation/native'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
import { useStyles } from '../../hooks/useStyles'; | ||
import styleSheet from './styles'; | ||
import { type RootState } from '../../../reducers'; | ||
|
@@ -119,7 +115,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({ | |
addToWhitelist: triggerAddToWhitelist, | ||
showTabs, | ||
linkType, | ||
isInTabsView, | ||
wizardStep, | ||
updateTabInfo, | ||
addToBrowserHistory, | ||
|
@@ -204,8 +199,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({ | |
*/ | ||
const whitelist = useSelector((state: RootState) => state.browser.whitelist); | ||
|
||
const isFocused = useIsFocused(); | ||
|
||
/** | ||
* Checks if a given url or the current url is the homepage | ||
*/ | ||
|
@@ -607,57 +600,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({ | |
], | ||
); | ||
|
||
const checkTabPermissions = useCallback(() => { | ||
if (!(isFocused && !isInTabsView && isTabActive)) { | ||
return; | ||
} | ||
if (!resolvedUrlRef.current) return; | ||
const hostname = new URLParse(resolvedUrlRef.current).hostname; | ||
const permissionsControllerState = | ||
Engine.context.PermissionController.state; | ||
const permittedAccounts = getPermittedAccountsByHostname( | ||
permissionsControllerState, | ||
hostname, | ||
); | ||
|
||
const isConnected = permittedAccounts.length > 0; | ||
|
||
if (isConnected) { | ||
let permittedChains = []; | ||
try { | ||
const caveat = Engine.context.PermissionController.getCaveat( | ||
hostname, | ||
PermissionKeys.permittedChains, | ||
CaveatTypes.restrictNetworkSwitching, | ||
); | ||
permittedChains = Array.isArray(caveat?.value) ? caveat.value : []; | ||
|
||
const currentChainId = activeChainId; | ||
const isCurrentChainIdAlreadyPermitted = | ||
permittedChains.includes(currentChainId); | ||
|
||
if (!isCurrentChainIdAlreadyPermitted) { | ||
navigation.navigate(Routes.MODAL.ROOT_MODAL_FLOW, { | ||
screen: Routes.SHEET.ACCOUNT_PERMISSIONS, | ||
params: { | ||
isNonDappNetworkSwitch: true, | ||
hostInfo: { | ||
metadata: { | ||
origin: hostname, | ||
}, | ||
}, | ||
isRenderedAsBottomSheet: true, | ||
initialScreen: AccountPermissionsScreens.Connected, | ||
}, | ||
}); | ||
} | ||
} catch (e) { | ||
const checkTabPermissionsError = e as Error; | ||
Logger.error(checkTabPermissionsError, 'Error in checkTabPermissions'); | ||
} | ||
} | ||
}, [activeChainId, navigation, isFocused, isInTabsView, isTabActive]); | ||
|
||
/** | ||
* Handles state changes for when the url changes | ||
*/ | ||
|
@@ -700,8 +642,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({ | |
name: siteInfo.title, | ||
url: getMaskedUrl(siteInfo.url, sessionENSNamesRef.current), | ||
}); | ||
|
||
checkTabPermissions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this no longer required? |
||
}, | ||
[ | ||
isUrlBarFocused, | ||
|
@@ -711,7 +651,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({ | |
updateTabInfo, | ||
addToBrowserHistory, | ||
navigation, | ||
checkTabPermissions, | ||
], | ||
); | ||
|
||
|
@@ -1019,10 +958,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({ | |
[linkType], | ||
); | ||
|
||
useEffect(() => { | ||
checkTabPermissions(); | ||
}, [checkTabPermissions, isFocused, isInTabsView, isTabActive]); | ||
|
||
const handleEnsUrl = useCallback( | ||
async (ens: string) => { | ||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,7 @@ const NetworkSelector = () => { | |
|
||
// origin is defined if network selector is opened from a dapp | ||
const origin = route.params?.hostInfo?.metadata?.origin || ''; | ||
|
||
const parentSpan = trace({ | ||
name: TraceName.NetworkSwitch, | ||
tags: getTraceTags(store.getState()), | ||
|
@@ -245,12 +246,13 @@ const NetworkSelector = () => { | |
origin, | ||
networkConfigurationId, | ||
); | ||
sheetRef.current?.dismissModal(); | ||
} else { | ||
const { networkClientId } = rpcEndpoints[defaultRpcEndpointIndex]; | ||
try { | ||
await MultichainNetworkController.setActiveNetwork(networkClientId); | ||
} catch (error) { | ||
Logger.error(new Error(`Error in setActiveNetwork: ${error}`)); | ||
Logger.error(new Error(`Error i setActiveNetwork: ${error}`)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 whats this change about? |
||
} | ||
} | ||
|
||
|
@@ -364,8 +366,10 @@ const NetworkSelector = () => { | |
AccountTrackerController, | ||
SelectedNetworkController, | ||
} = Engine.context; | ||
|
||
if (domainIsConnectedDapp && isMultichainV1Enabled()) { | ||
SelectedNetworkController.setNetworkClientIdForDomain(origin, type); | ||
closeRpcModal(); | ||
} else { | ||
const networkConfiguration = | ||
networkConfigurations[BUILT_IN_NETWORKS[type].chainId]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 if you're passing in the origin here, the
useNetworkInfo
selector should be selecting the correct state based on that parameter. Is the comment outdated?