fix(walletapi): persist network setting and reset Connected on connectivity failure#12
Conversation
Simulator daemon returns Testnet=false but is not mainnet. This caused wallet connections to fail with Mainnet/TestNet mismatch. Check for simulator network before mainnet/testnet validation.
The mainnet field in Account struct was lowercase, so json.Marshal skipped it during wallet serialization. When wallets were reopened, mainnet defaulted to false (testnet) regardless of original setting. Changed mainnet to Mainnet with json tag so network setting persists correctly across wallet save/load cycles.
The Connect() function sets Connected=true after a successful WebSocket dial, but returns directly from test_connectivity() without resetting it on failure. This causes consumers to observe Connected==true even when the daemon connection is invalid (e.g., mainnet/testnet mismatch). Downstream code then incorrectly proceeds with background tasks against a broken connection. Reset Connected=false explicitly before returning the error.
|
Updated this PR with an additional fix: Problem: `walletapi.Connect()` sets `Connected=true` immediately after a successful WebSocket dial, but then returns directly from `test_connectivity()` without resetting it if that subsequent check fails. This causes consumers (e.g., Engram) to observe `walletapi.Connected == true` even when the daemon connection is actually invalid — such as when a mainnet/testnet network mismatch is detected, or when `DERO.Echo`/`DERO.GetInfo` RPC calls fail. Downstream code then incorrectly proceeds with wallet registration PoW and other background tasks against a broken connection, wasting CPU and producing confusing UI state. Fix: In `daemon_connectivity.go`, reset `Connected = false` explicitly before returning from `Connect()` when `test_connectivity()` returns an error. This change is minimal, defensive, and preserves the existing happy path. Both fixes are in `walletapi/daemon_connectivity.go` and are ready for review. |
fix(walletapi): persist wallet network setting in JSON
Problem:
The
mainnetfield in theAccountstruct was lowercase (unexported),which caused
json.Marshal()to skip it during wallet serialization.When wallets were saved and reopened, the network setting defaulted to
false(testnet) regardless of what the wallet was originally createdwith.
Impact:
deto1...)after reopening
the wallet reverted to testnet format
SetNetwork() after every wallet open
Root Cause:
Go's encoding/json only serializes exported (uppercase) fields.
The field
mainnet boolwas lowercase, so it was invisible to JSON.Fix:
Changed
mainnettoMainnetwithjson:"mainnet"tag so thenetwork setting is properly persisted across save/load cycles.
Files Changed:
Backward Compatibility:
"mainnet"in JSON: default to false (testnet)Testing:
dero1...(mainnet)deto1...(testnet)Related Issues:
Note: Pre-existing test failures (Test_Payload_TX, Test_Creation_TX_morecheck) are unrelated to this change and present on base branch community-dev.