Skip to content

Commit e48fb62

Browse files
fix: better address page error handling (#90)
* fix: remove NotFoundError handling and simplify error check in useAddressData * fix: handle missing account data in useAddressData and adjust tab disabling logic
1 parent e6e7e01 commit e48fb62

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/routes/$chainSlug/_layout/address/$addressAddress.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { AddressWorkerpoolsTable } from '@/modules/addresses/address/workerpools
2727
import { AddressContributionTable } from '@/modules/addresses/address/workers/beneficiaryDeals/addressContributionTable';
2828
import { SearcherBar } from '@/modules/search/SearcherBar';
2929
import useUserStore from '@/stores/useUser.store';
30-
import { NotFoundError } from '@/utils/NotFoundError';
3130
import { isValidAddress } from '@/utils/addressOrIdCheck';
3231
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
3332

@@ -49,9 +48,24 @@ function useAddressData(address: string, chainId: number) {
4948
length: TABLE_LENGTH,
5049
address,
5150
});
51+
5252
if (!result?.account) {
53-
throw new NotFoundError();
53+
return {
54+
account: {
55+
address: address,
56+
allApps: [],
57+
allContributions: [],
58+
allDatasets: [],
59+
allDealBeneficiary: [],
60+
allDealRequester: [],
61+
allWorkerpools: [],
62+
locked: '0',
63+
score: '0',
64+
staked: '0',
65+
},
66+
};
5467
}
68+
5569
return result;
5670
},
5771
refetchInterval: TABLE_REFETCH_INTERVAL,
@@ -123,24 +137,26 @@ function AddressRoute() {
123137
const disabledTabs: number[] = [];
124138
const disabledReasons: Record<number, string> = {};
125139

126-
// TODO like for other tab we have to check REQUESTS
140+
// Only disable tabs if we have no data AND we're not loading
141+
// This allows showing tabs with zero values when address exists but has no data
142+
const hasAddressData = address !== null;
127143

128-
if (!address?.allContributions?.length) {
144+
if (!isLoading && hasAddressData && !address?.allContributions?.length) {
129145
disabledTabs.push(2);
130146
disabledReasons[2] = 'No contributions for this address.';
131147
}
132148

133-
if (!address?.allApps?.length) {
149+
if (!isLoading && hasAddressData && !address?.allApps?.length) {
134150
disabledTabs.push(3);
135151
disabledReasons[3] = 'No apps for this address.';
136152
}
137153

138-
if (!address?.allDatasets?.length) {
154+
if (!isLoading && hasAddressData && !address?.allDatasets?.length) {
139155
disabledTabs.push(4);
140156
disabledReasons[4] = 'No datasets for this address.';
141157
}
142158

143-
if (!address?.allWorkerpools?.length) {
159+
if (!isLoading && hasAddressData && !address?.allWorkerpools?.length) {
144160
disabledTabs.push(5);
145161
disabledReasons[5] = 'No workerpools for this address.';
146162
}
@@ -149,7 +165,7 @@ function AddressRoute() {
149165
return <ErrorAlert className="my-16" message="Invalid address." />;
150166
}
151167

152-
if (isError && error instanceof NotFoundError) {
168+
if (isError && error && address === null) {
153169
return (
154170
<ErrorAlert className="my-16" message="No data found for this address." />
155171
);

0 commit comments

Comments
 (0)