LIVE-25828: coin-bitcoin use observable event stream#14732
LIVE-25828: coin-bitcoin use observable event stream#14732pvoliveira wants to merge 1 commit intodevelopfrom
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the makeGetAccountShape function in coin-bitcoin to return an Observable instead of a Promise, making it the first coin module to adopt the new Observable-based synchronization pattern introduced in PR #14274. This change supports future async synchronization requirements for ZCash Shielded transactions while maintaining backward compatibility through the framework's normalization layer.
Changes:
- Refactored coin-bitcoin's
makeGetAccountShapeto returnGetAccountShapeStream<BitcoinAccount>(Observable) instead ofGetAccountShape<BitcoinAccount>(Promise) - Added framework support in
jsHelpers.tsfor both Promise and Observable-based getAccountShape implementations with automatic normalization - Extended test coverage to verify Observable behavior including emission patterns, error handling, and subscription cleanup
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| libs/coin-modules/coin-bitcoin/src/synchronisation.ts | Extracted async logic into getAccountShapeAsync and wrapped it with from() Observable in makeGetAccountShape; removed unnecessary await on synchronous getUniquesAddresses call |
| libs/coin-modules/coin-bitcoin/src/tests/unit/synchronisation.unit.test.ts | Added tests for Observable behavior: error propagation, single-value emission, and completion |
| libs/coin-framework/src/bridge/jsHelpers.ts | Added GetAccountShapeStream type, normalizeToObservable helper, updated makeSync and makeScanAccounts to support both Promise and Observable patterns with proper subscription management |
| libs/coin-framework/src/bridge/jsHelpers.test.ts | Added comprehensive tests for Observable support in makeSync and makeScanAccounts including multi-emission, subscription cleanup, and error handling |
| .changeset/small-terms-learn.md | Changeset documenting framework Observable support |
| .changeset/red-students-drum.md | Changeset documenting coin-bitcoin migration to Observable pattern |
Comments suppressed due to low confidence (1)
.changeset/red-students-drum.md:5
- The changeset description says "makescanaccountshape" but the function is actually called "makeGetAccountShape" (not "makeScanAccountShape"). This should be corrected to accurately describe the change.
change makescanaccountshape to use the new observable approach
49f7e69 to
2bab0be
Compare
2b496e7 to
9b9de6b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
libs/coin-framework/src/bridge/jsHelpers.test.ts:600
- This test intends to assert that all
discoveredevents are emitted beforecomplete, but it never records the completion event inevents. As written,lastEvent.typewill always be "discovered" regardless of completion ordering. Push a sentinel entry incompletebefore resolving (or track acompletedflag and assert nonexthappens after it).
await new Promise<void>((resolve, reject) => {
scanAccounts({
currency,
deviceId: "deviceId",
syncConfig: { paginationConfig: {} },
}).subscribe({
next: event => events.push(event),
complete: () => resolve(),
error: reject,
});
.changeset/small-terms-learn.md:5
- Grammar in changeset summary: use "add support for observables" (or "add Observable support") instead of "add support to observables".
add support to observables for makeSync and makeScanAccounts
| const account$ = stepAccount(index, res, derivationMode, seedIdentifier); | ||
| const account = await lastValueFrom(account$); | ||
|
|
There was a problem hiding this comment.
lastValueFrom(account$) subscribes to the inner getAccountShape Observable but there is no way to cancel that subscription when the outer scanAccounts subscription is unsubscribed (it only flips finished). This can keep network/device work running after cancellation and can hang the scan if the inner Observable never completes. Consider wiring cancellation into the inner stream (e.g. takeUntil fed by the outer teardown) and/or prefer firstValueFrom if only the first shape is needed.
9b9de6b to
6a4e48d
Compare
6a4e48d to
7e458a6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
libs/coin-modules/coin-bitcoin/src/tests/unit/synchronisation.unit.test.ts:6
BitcoinAccountis only used in a type position here; in this test suite the convention is to useimport typefor type-only imports (e.g.signOperation.test.ts). Switching this to a type-only import avoids emitting an unnecessary runtime import and keeps consistency across the tests.
import { createFixtureAccount, mockSignerContext } from "../../fixtures/common.fixtures";
import { BitcoinAccount } from "../../types";
7e458a6 to
0e755e5
Compare
0e755e5 to
31cf405
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
.changeset/small-terms-learn.md:5
- Changeset summary reads a bit ungrammatical (“add support to observables…”). Consider rephrasing to “add support for Observables in makeSync and makeScanAccounts” to be clearer in release notes.
add support to observables for makeSync and makeScanAccounts
31cf405 to
db0cbdd
Compare
db0cbdd to
f84e544
Compare
f84e544 to
88a51ff
Compare
88a51ff to
b3d22e0
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
.changeset/small-terms-learn.md:5
- Changeset text is grammatically off: "add support to observables" reads like you’re adding support to observables rather than for observables. Consider rewording to something like "add support for Observables in makeSync and makeScanAccounts" for clarity.
add support to observables for makeSync and makeScanAccounts
b3d22e0 to
4b39687
Compare
4b39687 to
6ef1156
Compare
6ef1156 to
39c2083
Compare
|



✅ Checklist
npx changesetwas attached.📝 Description
Refactor makeGetAccountShape in coin-bitcoin so it returns a synchronous function that yields an Observable emitting the account shape (one value then complete).
Note: this PR is based on the changes from #14274.
❓ Context
🧐 Checklist for the PR Reviewers