Skip to content

[TD-02] Replace sequential ID loop with getProgramAccounts #2

Description

@licette32

Problem

The frontend discovers assets by iterating IDs from 1 to 10 (or 1 to 5). Any asset with an ID > 10 is invisible — it does not appear, does not generate an error, it simply does not exist from the user's perspective.

Affected files

  • app/src/components/HospitalDashboard.tsx → loop for (let id = 1; id <= 10; id++)
  • app/src/components/TechnicianDashboard.tsx → loop for (let id = 1; id <= 10; id++)
  • app/src/components/EquipmentTable.tsx → loop for (let id = 1; id <= 5; id++)

Plan (Option A — faster, no backend)

Use getProgramAccounts with a filter by hospital pubkey and the MedicalAsset account discriminator. Purely on-chain solution.

const accounts = await program.account.medicalAsset.all([
  { memcmp: { offset: 8, bytes: wallet.publicKey.toBase58() } }
]);

## Plan (Option B  more scalable)

Event indexer (Helius webhooks) that listens for AssetInitialized and builds the list in Supabase. Depends on

## Milestone: v1.1  Week 3-4

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions