fix: prevent "cannot read properties of undefined (reading 'map')" crash (#532)

This commit is contained in:
paisley
2026-03-16 19:52:01 +08:00
committed by GitHub
Unverified
parent 925fbab86d
commit 11e28a2cfa
6 changed files with 23 additions and 20 deletions

View File

@@ -97,11 +97,14 @@ export function buildProviderListItems(
vendors: ProviderVendorInfo[],
defaultAccountId: string | null,
): ProviderListItem[] {
const vendorMap = new Map(vendors.map((vendor) => [vendor.id, vendor]));
const statusMap = new Map(statuses.map((status) => [status.id, status]));
const safeAccounts = accounts ?? [];
const safeStatuses = statuses ?? [];
const safeVendors = vendors ?? [];
const vendorMap = new Map(safeVendors.map((vendor) => [vendor.id, vendor]));
const statusMap = new Map(safeStatuses.map((status) => [status.id, status]));
if (accounts.length > 0) {
return accounts
if (safeAccounts.length > 0) {
return safeAccounts
.map((account) => ({
account,
vendor: vendorMap.get(account.vendorId),
@@ -114,7 +117,7 @@ export function buildProviderListItems(
});
}
return statuses.map((status) => ({
return safeStatuses.map((status) => ({
account: legacyProviderToAccount(status),
vendor: vendorMap.get(status.type),
status,