Handle the primary account, authorized account arrays, silent reconnects, and provider lifecycle events.
connect() and getAccounts() return a backward-compatible result:
type ZcashConnectResult = {
transparent: string
shielded: string
accounts: Array<{
id: string
label: string
walletId: string
accountId: string
addresses: {
transparent: string
shielded: string
}
}>
}The top-level addresses belong to the primary connected account. Use each accounts[i].id when requesting an account-specific balance.
const connection = await wallet.zcash.getAccounts()
if (connection) {
const selected = connection.accounts[0]
const balance = await wallet.zcash.getBalance(selected.id)
console.log(balance.available)
}getNoirWallet().getAccounts() silently.connect() after the user chooses to connect.Subscribe to accountsChanged and refresh account-scoped data when it fires.
function handleAccountsChanged() {
void refreshConnectedState()
}
wallet.zcash.on('accountsChanged', handleAccountsChanged)
// During cleanup:
wallet.zcash.removeListener('accountsChanged', handleAccountsChanged)Treat an empty or null-like payload as unavailable and verify the current state with getAccounts(). Do not keep using cached account authorization after the provider reports a disconnect.