Skip to content

Commit a60e8fc

Browse files
committed
fix: handle invalid URLs in PermissionsSummary component
Updated the hostname extraction logic in the PermissionsSummary component to gracefully handle invalid URLs by returning the original string or an empty string. This prevents potential errors when processing URLs. Additionally, removed outdated tests related to SDK URL status from AccountConnect.test.tsx to streamline the test suite.
1 parent 4656d42 commit a60e8fc

File tree

2 files changed

+9
-63
lines changed

2 files changed

+9
-63
lines changed

app/components/UI/PermissionsSummary/PermissionsSummary.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ const PermissionsSummary = ({
8080
const providerConfig = useSelector(selectProviderConfig);
8181
const chainId = useSelector(selectEvmChainId);
8282

83-
const hostname = useMemo(
84-
() => new URL(currentPageInformation.url).hostname,
85-
[currentPageInformation.url],
86-
);
83+
const hostname = useMemo(() => {
84+
try {
85+
return new URL(currentPageInformation.url).hostname;
86+
} catch (e) {
87+
// Handle invalid URL, default to the original string or an empty string
88+
return currentPageInformation.url || '';
89+
}
90+
}, [currentPageInformation.url]);
91+
8792
const networkInfo = useNetworkInfo(hostname);
8893

8994
// if network switch, we get the chain name from the customNetworkInformation

app/components/Views/AccountConnect/AccountConnect.test.tsx

-59
Original file line numberDiff line numberDiff line change
@@ -171,65 +171,6 @@ describe('AccountConnect', () => {
171171
expect(toJSON()).toMatchSnapshot();
172172
});
173173

174-
describe('Renders different screens based on SDK URL status', () => {
175-
it('should render SingleConnect screen when isSdkUrlUnknown is true', () => {
176-
const mockPropsForUnknownUrl = {
177-
route: {
178-
params: {
179-
hostInfo: {
180-
metadata: {
181-
id: 'mockId',
182-
// Using an invalid/unknown format for origin
183-
origin: '',
184-
},
185-
permissions: {
186-
eth_accounts: {
187-
parentCapability: 'eth_accounts',
188-
},
189-
},
190-
},
191-
permissionRequestId: 'test',
192-
},
193-
},
194-
};
195-
196-
const { getByTestId } = renderWithProvider(
197-
<AccountConnect {...mockPropsForUnknownUrl} />,
198-
{ state: mockInitialState },
199-
);
200-
201-
expect(getByTestId('connect-account-modal')).toBeDefined();
202-
});
203-
204-
it('should render PermissionsSummary screen when isSdkUrlUnknown is false', () => {
205-
const mockPropsForKnownUrl = {
206-
route: {
207-
params: {
208-
hostInfo: {
209-
metadata: {
210-
id: 'mockId',
211-
// Using a valid URL format
212-
origin: 'https://example.com',
213-
},
214-
permissions: {
215-
eth_accounts: {
216-
parentCapability: 'eth_accounts',
217-
},
218-
},
219-
},
220-
permissionRequestId: 'test',
221-
},
222-
},
223-
};
224-
225-
const { getByTestId } = renderWithProvider(
226-
<AccountConnect {...mockPropsForKnownUrl} />,
227-
{ state: mockInitialState },
228-
);
229-
230-
expect(getByTestId('permission-summary-container')).toBeDefined();
231-
});
232-
});
233174

234175
describe('AccountConnectMultiSelector handlers', () => {
235176
it('invokes onPrimaryActionButtonPress property and renders permissions summary', async () => {

0 commit comments

Comments
 (0)