Skip to content

Commit ca99fea

Browse files
authored
feat: add account data revalidation after undelegation (#488)
* feat: add account data revalidation after undelegation Enhances the Undelegate component by introducing a revalidation mechanism for account data using SWR. After a successful undelegation, the account data is refreshed after a 15-second delay to ensure the UI reflects the latest state. * feat: use hybrid approach to data fetching, where static props are a fallback - Removed unused SWR configuration in Undelegate component. - Updated AccountLayout to fetch fresh account data client-side, prioritizing it over static props. - Adjusted logic to ensure the UI reflects the latest account state by using the newly fetched data for various components.
1 parent 17c6fac commit ca99fea

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

layouts/account.tsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ const AccountLayout = ({
9090
pollInterval,
9191
});
9292

93+
// Fetch fresh account data client-side, using static props as fallback
94+
const { data: dataViewedAccount } = useAccountQuery({
95+
variables: {
96+
account: accountId ?? "",
97+
},
98+
skip: !accountId,
99+
pollInterval,
100+
});
101+
102+
// Prefer client-fetched data over static props
103+
const viewedAccount = dataViewedAccount ?? account;
104+
93105
const { data: bondingManagerAddress } = useBondingManagerAddress();
94106
const { data: treasuryRewardCutRate = BigInt(0.0) } = useReadContract({
95107
query: { enabled: Boolean(bondingManagerAddress) },
@@ -109,15 +121,18 @@ const AccountLayout = ({
109121
}, [latestTransaction?.step]);
110122

111123
const isActive = useMemo(
112-
() => Boolean(account?.transcoder?.active),
113-
[account?.transcoder]
124+
() => Boolean(viewedAccount?.transcoder?.active),
125+
[viewedAccount?.transcoder]
114126
);
115127

116128
const isMyAccount = useMemo(
117129
() => checkAddressEquality(accountAddress ?? "", accountId ?? ""),
118130
[accountAddress, accountId]
119131
);
120-
const isOrchestrator = useMemo(() => Boolean(account?.transcoder), [account]);
132+
const isOrchestrator = useMemo(
133+
() => Boolean(viewedAccount?.transcoder),
134+
[viewedAccount]
135+
);
121136
const isMyDelegate = useMemo(
122137
() => accountId === dataMyAccount?.delegator?.delegate?.id.toLowerCase(),
123138
[accountId, dataMyAccount]
@@ -214,9 +229,9 @@ const AccountLayout = ({
214229
transcoder={
215230
isDelegatingAndIsMyAccountView
216231
? dataMyAccount?.delegator?.delegate
217-
: account?.transcoder
232+
: viewedAccount?.transcoder
218233
}
219-
protocol={account?.protocol}
234+
protocol={viewedAccount?.protocol}
220235
treasury={treasury}
221236
delegateProfile={identity}
222237
/>
@@ -252,9 +267,9 @@ const AccountLayout = ({
252267
transcoder={
253268
isDelegatingAndIsMyAccountView
254269
? dataMyAccount?.delegator?.delegate
255-
: account?.transcoder
270+
: viewedAccount?.transcoder
256271
}
257-
protocol={account?.protocol}
272+
protocol={viewedAccount?.protocol}
258273
treasury={treasury}
259274
delegateProfile={identity}
260275
/>
@@ -298,16 +313,16 @@ const AccountLayout = ({
298313
{view === "orchestrating" && (
299314
<OrchestratingView
300315
isActive={isActive}
301-
currentRound={account?.protocol?.currentRound}
302-
transcoder={account?.transcoder}
316+
currentRound={viewedAccount?.protocol?.currentRound}
317+
transcoder={viewedAccount?.transcoder}
303318
/>
304319
)}
305320
{view === "delegating" && (
306321
<DelegatingView
307322
transcoders={sortedOrchestrators?.transcoders}
308-
delegator={account?.delegator}
309-
protocol={account?.protocol}
310-
currentRound={account?.protocol?.currentRound}
323+
delegator={viewedAccount?.delegator}
324+
protocol={viewedAccount?.protocol}
325+
currentRound={viewedAccount?.protocol?.currentRound}
311326
/>
312327
)}
313328
{view === "history" && <HistoryView />}
@@ -334,9 +349,9 @@ const AccountLayout = ({
334349
transcoder={
335350
isDelegatingAndIsMyAccountView
336351
? dataMyAccount?.delegator?.delegate
337-
: account?.transcoder
352+
: viewedAccount?.transcoder
338353
}
339-
protocol={account?.protocol}
354+
protocol={viewedAccount?.protocol}
340355
treasury={treasury}
341356
delegateProfile={identity}
342357
/>
@@ -350,9 +365,9 @@ const AccountLayout = ({
350365
transcoder={
351366
isDelegatingAndIsMyAccountView
352367
? dataMyAccount?.delegator?.delegate
353-
: account?.transcoder
368+
: viewedAccount?.transcoder
354369
}
355-
protocol={account?.protocol}
370+
protocol={viewedAccount?.protocol}
356371
treasury={treasury}
357372
delegateProfile={identity}
358373
/>

0 commit comments

Comments
 (0)