When the background saves a network switch after the user approves a
site's request, an open popup now notices the stored record change and
takes the new network from it, holding the lock, inside a save. It then
leaves the page as a switch in Settings does: the stack is cut, every
screen counts as not yet rendered, and the screen on top is drawn again.
The cut and the redraw are now two functions in the Settings view that
both paths call. A record already on the popup's network, such as its
own Settings switch, changes nothing. The popup never switches the
network itself.
Model: opus-5-5
The popup's doRefreshAndRender() and the background's backgroundRefresh()
each note the network a refresh starts on and write its balances only if
that network is still the active one when the requests return. Otherwise
nothing is written and lastBalanceRefresh stays as the switch left it. The
background checks inside updateState(). The popup refreshes a copy of its
wallets and copies the results onto `state` from inside its save, under the
lock, only if both its own network and the stored record's still match, so
a switch the background makes is caught too. saveState() takes an optional
function, run there on the stored record before the page's state is
compared, that may change `state` or return false to cancel the write.
Model: opus-5-5