From adc2d4f2f87b7259db899265b5e93accf2e6dbc8 Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Wed, 18 Mar 2026 16:22:56 -0700 Subject: [PATCH] refactor: extract Recipient type in intentBuilder PaymentIntent and ConsolidateIntent both had identical inline recipient shapes. Extract into a shared Recipient interface and export it from the package. Addresses review feedback from Otto on PR #208. --- packages/wasm-solana/js/index.ts | 1 + packages/wasm-solana/js/intentBuilder.ts | 34 ++++++++++-------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/wasm-solana/js/index.ts b/packages/wasm-solana/js/index.ts index 38cb1d8..6ba4486 100644 --- a/packages/wasm-solana/js/index.ts +++ b/packages/wasm-solana/js/index.ts @@ -41,6 +41,7 @@ export type { CustomTxKey, SolanaIntent, StakePoolConfig, + Recipient, BuildFromIntentParams, BuildFromIntentResult, GeneratedKeypair, diff --git a/packages/wasm-solana/js/intentBuilder.ts b/packages/wasm-solana/js/intentBuilder.ts index 4d36b58..0a109da 100644 --- a/packages/wasm-solana/js/intentBuilder.ts +++ b/packages/wasm-solana/js/intentBuilder.ts @@ -85,19 +85,22 @@ export interface BaseIntent { memo?: string; } +/** A recipient in a transaction — native SOL or SPL token transfer */ +export interface Recipient { + address?: { address: string }; + amount?: { value: bigint; symbol?: string }; + /** Mint address (base58) — if set, this is an SPL token transfer */ + tokenAddress?: string; + /** Token program ID (defaults to SPL Token Program) */ + tokenProgramId?: string; + /** Decimal places for the token (required for transfer_checked) */ + decimalPlaces?: number; +} + /** Payment intent */ export interface PaymentIntent extends BaseIntent { intentType: "payment"; - recipients?: Array<{ - address?: { address: string }; - amount?: { value: bigint; symbol?: string }; - /** Mint address (base58) — if set, this is an SPL token transfer */ - tokenAddress?: string; - /** Token program ID (defaults to SPL Token Program) */ - tokenProgramId?: string; - /** Decimal places for the token (required for transfer_checked) */ - decimalPlaces?: number; - }>; + recipients?: Recipient[]; } /** Stake intent */ @@ -176,16 +179,7 @@ export interface ConsolidateIntent extends BaseIntent { /** The child address to consolidate from (sender) */ receiveAddress: string; /** Recipients (root address for native SOL, wallet ATAs for tokens) */ - recipients?: Array<{ - address?: { address: string }; - amount?: { value: bigint; symbol?: string }; - /** Mint address (base58) — if set, this is an SPL token transfer */ - tokenAddress?: string; - /** Token program ID (defaults to SPL Token Program) */ - tokenProgramId?: string; - /** Decimal places for the token (required for transfer_checked) */ - decimalPlaces?: number; - }>; + recipients?: Recipient[]; } /** Authorize intent - pre-built transaction message */