Skip to content

Commit 856de4e

Browse files
committed
fix: handle missing account data in useAddressData and adjust tab disabling logic
1 parent 2620954 commit 856de4e

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ function useAddressData(address: string, chainId: number) {
4848
length: TABLE_LENGTH,
4949
address,
5050
});
51+
52+
if (!result?.account) {
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+
};
67+
}
68+
5169
return result;
5270
},
5371
refetchInterval: TABLE_REFETCH_INTERVAL,
@@ -119,24 +137,26 @@ function AddressRoute() {
119137
const disabledTabs: number[] = [];
120138
const disabledReasons: Record<number, string> = {};
121139

122-
// 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;
123143

124-
if (!address?.allContributions?.length) {
144+
if (!isLoading && hasAddressData && !address?.allContributions?.length) {
125145
disabledTabs.push(2);
126146
disabledReasons[2] = 'No contributions for this address.';
127147
}
128148

129-
if (!address?.allApps?.length) {
149+
if (!isLoading && hasAddressData && !address?.allApps?.length) {
130150
disabledTabs.push(3);
131151
disabledReasons[3] = 'No apps for this address.';
132152
}
133153

134-
if (!address?.allDatasets?.length) {
154+
if (!isLoading && hasAddressData && !address?.allDatasets?.length) {
135155
disabledTabs.push(4);
136156
disabledReasons[4] = 'No datasets for this address.';
137157
}
138158

139-
if (!address?.allWorkerpools?.length) {
159+
if (!isLoading && hasAddressData && !address?.allWorkerpools?.length) {
140160
disabledTabs.push(5);
141161
disabledReasons[5] = 'No workerpools for this address.';
142162
}
@@ -145,7 +165,7 @@ function AddressRoute() {
145165
return <ErrorAlert className="my-16" message="Invalid address." />;
146166
}
147167

148-
if (isError && error) {
168+
if (isError && error && address === null) {
149169
return (
150170
<ErrorAlert className="my-16" message="No data found for this address." />
151171
);

0 commit comments

Comments
 (0)