Skip to content

Preflight device registration and wallet subscription for REST calls#592

Open
DRadmir wants to merge 3 commits into
mainfrom
wt3/android-device-rest-preflight
Open

Preflight device registration and wallet subscription for REST calls#592
DRadmir wants to merge 3 commits into
mainfrom
wt3/android-device-rest-preflight

Conversation

@DRadmir

@DRadmir DRadmir commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Wallet-scoped device REST calls could 404 on fresh state:

  • Device not found — the call fired before the device was registered.
  • Wallet not found — a new wallet's assets were fetched before it was subscribed on the backend.

Both are fixed with a transport-level preflight: wallet-tagged requests wait until the device is registered and its subscriptions are synced before proceeding. Subscriptions are marked dirty on wallet create/import and reconciled lazily, matching iOS.

Closes #550
Closes #603
Closes #620

TODO: testing

  • Manual on-device testing

@DRadmir DRadmir self-assigned this Jul 1, 2026
@DRadmir DRadmir marked this pull request as ready for review July 2, 2026 09:15
@DRadmir DRadmir requested review from gemcoder21 and gemdev111 July 2, 2026 09:15
}

private suspend fun getOrCreateDevice(device: Device): Device {
override suspend fun invoke() {

@gemdev111 gemdev111 Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you recheck this please:

Wallet calls that fire during the first registration each also run a full syncDeviceInfo() - they pass the isDeviceRegistered() check before the flag flips. The mutex prevents double-register, but each still does an extra GET /devices. A few redundant calls on first launch

iOS coalesces this in its sync coordinator

@DRadmir DRadmir changed the title Add device registration preflight for Android REST calls Preflight device registration and wallet subscription for REST calls Jul 2, 2026
DRadmir added 3 commits July 3, 2026 13:56
Wallet-scoped device REST calls could 404 before the device was
registered. Add a DeviceRegistrationInterceptor that ensures the device
is registered (via EnsureDeviceRegistered) before wallet-tagged requests
proceed, and provide a separate device API client without the preflight
to avoid recursion during registration itself.

Closes #550
A newly created or imported wallet could fire GET /v2/devices/assets
before it was subscribed on the backend, returning 404 "Wallet not
found": the subscription reconcile ran inline, racing the eager asset
sync triggered by session activation.

Mirror the device-registration preflight one level up: mark
subscriptions dirty on wallet create/import (InvalidateSubscriptions in
setupWallet, before session activation) and reconcile them lazily via a
SubscriptionSyncInterceptor that ensures subscriptions are synced before
any wallet-tagged request proceeds. Reconcile runs through the
registration-free device client to avoid interceptor recursion and is
serialized with a mutex to prevent concurrent reconciles.

Closes #603
Concurrent wallet-scoped requests each ran a full device sync — an extra
GET /devices per request on first launch. Add DeviceSyncCoordinator
(mirroring iOS) that dedupes concurrent syncs into one;
ensureSubscriptionsSynced waits for any in-flight sync, then re-checks the
dirty flag before syncing.
@DRadmir DRadmir force-pushed the wt3/android-device-rest-preflight branch from 4261da8 to 771c0c2 Compare July 3, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants