fedimint / fedimint-web-sdk

Tools for developing Fedimint web clients
https://web.fedimint.org
MIT License
18 stars 8 forks source link

Update RPC types to have consistent `status` key #83

Open alexlwn123 opened 2 hours ago

alexlwn123 commented 2 hours ago

Currently, the subscribeLnReceive and subscribeLnPay functions return a status with the following types:

type LnPayState =
  | 'created'
  | 'canceled'
  | { funded: { block_height: number } }
  | { waiting_for_refund: { error_reason: string } }
  | 'awaiting_change'
  | { Success: { preimage: string } }
  | { refunded: { gateway_error: string } }
  | { unexpected_error: { error_message: string } }

type LnReceiveState =
  | 'created'
  | { waiting_for_payment: { invoice: string; timeout: number } }
  | { canceled: { reason: string } }
  | 'funded'
  | 'awaiting_funds'
  | 'claimed'

This makes pattern matching a bit ugly for the SDK because objects and strings are mixed.

Let's changes the types to have a consistent shape:

type LnPayState =
  | { status: 'created' }
  | { status: 'canceled' }
  | { status: 'funded'; block_height: number }
  | { status: 'waiting_for_refund'; error_reason: string }
  | { status: 'awaiting_change' }
  | { status: 'Success'; preimage: string }
  | { status: 'refunded'; gateway_error: string }
  | { status: 'unexpected_error'; error_message: string } 

type LnReceiveState =
  | { status: 'created' }
  | { status: 'waiting_for_payment'; invoice: string; timeout: number }
  | { status: 'canceled'; reason: string }
  | { status: 'funded' }
  | { status: 'awaiting_funds' }
  | { status: 'claimed' }
alexlwn123 commented 2 hours ago

@maan2003