Skip to content

SorokitProvider error state clobbered in Promise.all and not cleared on reconnect or disconnect #583

Description

@k-deejah

Problem

src/context/SorokitProvider.tsx manages a single error state that is overwritten by multiple async operations. In the account-loading effect (lines 52–58), getAccount and getBalances run in Promise.all and both attempt to set the same error state:

if (accountRes.error) setError(accountRes.error);
if (balancesRes.error) setError(balancesRes.error);

If both fail, the second setError silently overwrites the first. Only one error is ever visible at a time.

A second problem: error is never cleared when address changes. If wallet A caused a balance-fetch error, that error string persists in the banner while wallet B's data is loading — the user sees a stale error that no longer applies.

A third problem: disconnectWallet (line 75) clears address, account, and balances but does not clear error or reset network. A stale error from a previous session remains visible after disconnect.

Solution

Reset error to null at the start of the address-change effect, before any fetches run. Collect both errors from the Promise.all and combine them:

useEffect(() => {
  setError(null); // clear stale error first
  if (!address) { setAccount(null); setBalances([]); return; }
  // ...
  .then(([a, b]) => {
    const combined = [a.error, b.error].filter(Boolean).join('; ');
    if (combined) setError(combined);
  });
}, [address, client]);

Also add setError(null) inside disconnectWallet.

Acceptance Criteria

  • Connecting a new wallet clears any error from the previous session before fetching
  • When both getAccount and getBalances fail, the message includes both error strings
  • When only one fails, the correct single error is shown
  • disconnectWallet clears the error state
  • The error banner in TopBar.tsx does not show stale errors after wallet switch

Note for Contributors: If you're assigned to this issue, write a clear and detailed description for your pull request. Explain what was changed, why it was needed, how it was implemented, and include any relevant testing or screenshots where applicable.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programarchitectureCode structure, patterns, or design decisionsbugSomething isn't workingfrontendUI, component, or visual layer concern

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions