fix: improve error handling and network selection in WalletInfoSection

- Enhanced the parsing of network data to ensure robustness against undefined values.
- Updated network selection logic to prioritize valid entries and provide a fallback.
- Improved error logging for better debugging of wallet information loading issues.
- Adjusted balance retrieval to handle cases where chain_id may be missing.
This commit is contained in:
M3gA-Mind
2026-02-06 21:54:03 +05:30
parent 1470b9482e
commit c4837892c4
2 changed files with 33 additions and 23 deletions
+14 -6
View File
@@ -45,17 +45,24 @@ export default function WalletInfoSection() {
if (!cancelled) setError('Could not load networks');
return;
}
const listData = JSON.parse(listText) as { networks?: Array<{ chain_id: string; name: string; chain_type: string }> };
const networks = listData.networks ?? [];
const firstEvm = networks.find((n: { chain_type: string }) => n.chain_type === 'evm');
const first = firstEvm ?? networks[0];
const listData = JSON.parse(listText) as { networks?: Array<{ chain_id?: string; name?: string; chain_type?: string }> };
const networks = Array.isArray(listData.networks) ? listData.networks : [];
const firstEvm = networks.find((n) => n && n.chain_type === 'evm');
const first = firstEvm ?? networks.find(Boolean);
if (!first || cancelled) return;
if (!cancelled) setNetworkName(first.name);
const networkNameVal = first.name ?? first.chain_id ?? 'Unknown';
if (!cancelled) setNetworkName(networkNameVal);
const chainId = first.chain_id ?? '';
if (!chainId) {
if (!cancelled) setBalance('—');
return;
}
const balanceRes = await skillManager.callTool('wallet', 'get_balance', {
address: primaryAddress,
chain_id: first.chain_id,
chain_id: chainId,
chain_type: first.chain_type ?? 'evm',
});
const balanceText = balanceRes.content?.[0]?.text;
@@ -78,6 +85,7 @@ export default function WalletInfoSection() {
const display = value < 0.0001 ? '0' : value.toFixed(4);
if (!cancelled) setBalance(`${display} ${symbol}`);
} catch (e) {
console.error(e);
if (!cancelled) {
setError(e instanceof Error ? e.message : 'Failed to load wallet info');
setBalance(null);
+19 -17
View File
@@ -43,42 +43,44 @@ function deriveConnectionStatus(
// Process is running or ready — use the skill's self-reported state
const hostState = skillState as SkillHostConnectionState | undefined;
if (!hostState) {
// No state pushed yet. Skills that don't maintain an external connection
// (e.g. cron-based skills) may never push host state. If setup is complete
// and the lifecycle says "ready", treat it as connected.
if (setupComplete && lifecycleStatus === "ready") {
const connStatus = hostState?.connection_status;
const authStatus = hostState?.auth_status;
// If the skill hasn't pushed any state, or pushed state without standard
// connection_status / auth_status fields, fall back to lifecycle + setupComplete.
if (!connStatus && !authStatus) {
if (setupComplete && (lifecycleStatus === "ready" || lifecycleStatus === "running")) {
return "connected";
}
if (!hostState) {
return "connecting";
}
// Skill pushed custom state but no connection fields — treat as connecting
return "connecting";
}
const connStatus = hostState.connection_status;
const authStatus = hostState.auth_status;
// Check for errors first
if (connStatus === "error" || authStatus === "error") {
return "error";
}
// Fully connected and authenticated
if (connStatus === "connected" && authStatus === "authenticated") {
return "connected";
}
// Connecting or authenticating
if (connStatus === "connecting" || authStatus === "authenticating") {
return "connecting";
}
// Connected but not authenticated
if (connStatus === "connected" && authStatus === "not_authenticated") {
return "not_authenticated";
// Connected — check auth if the skill uses it
if (connStatus === "connected") {
if (!authStatus || authStatus === "authenticated") {
return "connected";
}
if (authStatus === "not_authenticated") {
return "not_authenticated";
}
}
// Disconnected from service
if (connStatus === "disconnected") {
// If setup is complete but we're disconnected, it might be a reconnecting state
if (setupComplete) {
return "disconnected";
}