Skip to content

Commit 8a7e387

Browse files
committed
return null instead of throwing if no accounts are found
1 parent aad70f4 commit 8a7e387

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

packages/snaps-controllers/coverage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"branches": 94.6,
2+
"branches": 94.61,
33
"functions": 98.45,
44
"lines": 98.71,
55
"statements": 98.55

packages/snaps-controllers/src/interface/utils.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ describe('getAccountSelectorDefaultStateValue', () => {
17721772

17731773
const listAccounts = jest.fn().mockReturnValue([]);
17741774

1775-
expect(() =>
1775+
expect(
17761776
getAccountSelectorDefaultStateValue(
17771777
<AccountSelector
17781778
name="foo"
@@ -1786,7 +1786,7 @@ describe('getAccountSelectorDefaultStateValue', () => {
17861786
snapOwnsAccount: jest.fn(),
17871787
},
17881788
),
1789-
).toThrow('No accounts found for the provided chain IDs.');
1789+
).toBeNull();
17901790
});
17911791

17921792
it('throws if no account that the snap owns is found for the given chain IDs', () => {
@@ -1800,7 +1800,7 @@ describe('getAccountSelectorDefaultStateValue', () => {
18001800

18011801
const snapOwnsAccount = jest.fn().mockReturnValue(false);
18021802

1803-
expect(() =>
1803+
expect(
18041804
getAccountSelectorDefaultStateValue(
18051805
<AccountSelector
18061806
name="foo"
@@ -1815,7 +1815,7 @@ describe('getAccountSelectorDefaultStateValue', () => {
18151815
snapOwnsAccount,
18161816
},
18171817
),
1818-
).toThrow('No accounts found for the provided chain IDs.');
1818+
).toBeNull();
18191819
});
18201820
});
18211821

packages/snaps-controllers/src/interface/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@ export function getAccountSelectorDefaultStateValue(
313313
? accounts.filter((account) => snapOwnsAccount(account))
314314
: accounts;
315315

316-
assert(
317-
filteredAccounts.length > 0,
318-
'No accounts found for the provided chain IDs.',
319-
);
316+
// The AccountSelector component in the UI will be disabled if there is no account available for the networks provided.
317+
// In this case, we return null to indicate that there is no default selected account.
318+
if (filteredAccounts.length === 0) {
319+
return null;
320+
}
320321

321322
return formatAccountSelectorStateValue(filteredAccounts[0], chainIds);
322323
}

0 commit comments

Comments
 (0)