Skip to content

Comments

Migrate liquidity_pool_id.js file to TS#862

Open
quietbits wants to merge 3 commits intotypescript-migrationfrom
tsm-lp-id
Open

Migrate liquidity_pool_id.js file to TS#862
quietbits wants to merge 3 commits intotypescript-migrationfrom
tsm-lp-id

Conversation

@quietbits
Copy link
Contributor

No description provided.

@quietbits quietbits linked an issue Feb 20, 2026 that may be closed by this pull request
5 tasks
@github-actions
Copy link

github-actions bot commented Feb 20, 2026

Size Change: +275 B (+0.01%)

Total Size: 3.53 MB

Filename Size Change
dist/stellar-base.js 2.6 MB +224 B (+0.01%)
dist/stellar-base.min.js 926 kB +51 B (+0.01%)

compressed-size-action

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the liquidity_pool_id.js file from JavaScript to TypeScript, maintaining the same functionality while adding type safety. The migration follows established patterns in the codebase for TypeScript conversions, using vitest for testing and generating appropriate type definitions.

Changes:

  • Migrated src/liquidity_pool_id.js to TypeScript with proper type annotations
  • Added comprehensive TypeScript test file using vitest
  • Generated type definition file with complete method signatures
  • Updated .gitignore to include TypeScript build artifacts

Reviewed changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/liquidity_pool_id.ts New TypeScript implementation with type annotations and XDR type workarounds for compatibility
src/liquidity_pool_id.js Removed old JavaScript implementation
test/unit/liquidity_pool_id.test.ts New comprehensive test suite using vitest framework
type_validation/liquidity_pool_id.d.ts Generated type definitions matching the implementation
type_validation/strkey.d.ts Alphabetically sorted union type members for consistency
.gitignore Added tsconfig.tsbuildinfo for TypeScript build cache

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 7 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +36
static fromOperation(tlAssetXdr: xdr.TrustLineAsset): LiquidityPoolId {
const assetType = tlAssetXdr.switch();
if (assetType === xdr.AssetType.assetTypePoolShare()) {
// tlAssetXdr.liquidityPoolId() is Buffer at runtime
const liquidityPoolId = (
tlAssetXdr.liquidityPoolId() as unknown as Buffer
).toString("hex");
return new LiquidityPoolId(liquidityPoolId);
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

fromOperation previously returned new this(liquidityPoolId) (allowing subclasses to reuse the factory). The TS version always returns new LiquidityPoolId(...), which is a behavioral/API change. If subclassing support is intended, consider typing the static method with a this constructor type and returning new this(...) instead.

Suggested change
static fromOperation(tlAssetXdr: xdr.TrustLineAsset): LiquidityPoolId {
const assetType = tlAssetXdr.switch();
if (assetType === xdr.AssetType.assetTypePoolShare()) {
// tlAssetXdr.liquidityPoolId() is Buffer at runtime
const liquidityPoolId = (
tlAssetXdr.liquidityPoolId() as unknown as Buffer
).toString("hex");
return new LiquidityPoolId(liquidityPoolId);
static fromOperation<T extends LiquidityPoolId>(
this: new (liquidityPoolId: string) => T,
tlAssetXdr: xdr.TrustLineAsset,
): T {
const assetType = tlAssetXdr.switch();
if (assetType === xdr.AssetType.assetTypePoolShare()) {
// tlAssetXdr.liquidityPoolId() is Buffer at runtime
const liquidityPoolId = (
tlAssetXdr.liquidityPoolId() as unknown as Buffer
).toString("hex");
return new this(liquidityPoolId);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new this() was intentional in the original JS, but since no subclasses exist and TypeScript favors explicit return types, using new LiquidityPoolId(...) is the idiomatic choice here and does not constitute a breaking change (public facing code won't be affected by this).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +59 to +62
// TODO: check generated XDR types to make sure they are up to date.
// arm() exists at runtime on XDR union types but is not declared in types/curr.d.ts.
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
expect((tlAsset as any).arm()).toBe("liquidityPoolId");
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

The test asserts the union arm via (tlAsset as any).arm() and disables lint rules to allow any/unsafe access. Since TrustLineAsset.switch().name is already typed (see types/curr.d.ts), consider asserting on tlAsset.switch().name instead so the test stays type-safe and doesn’t depend on an undeclared runtime-only method.

Suggested change
// TODO: check generated XDR types to make sure they are up to date.
// arm() exists at runtime on XDR union types but is not declared in types/curr.d.ts.
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
expect((tlAsset as any).arm()).toBe("liquidityPoolId");
expect(tlAsset.switch().name).toBe("liquidityPoolId");

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This suggestion is wrong tlAsset.switch().name produces assetTypePoolShare instead of liquidityPoolId.

@quietbits quietbits requested a review from Ryang-21 February 23, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate liquidity_pool_id.js file to TS

2 participants