mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2025-12-24 01:14:22 +01:00
* feat: add random keypair generation * Encapsulate decode_keypair in SendSwap::get_refund_keypair() * Add refund_tx_id and refund_tx_amount_sat to Payment * fix: remove blocking on refund * fix: change `refund_private_key` order * fix: rebasing * fix: set `next_unused_address` as refund output * Handle refunds in `get_info`, `list_payments` (#226) * Exclude refund txs from payment list * Adjust balance calculation to account for refunds * fix: revert boltz changes and fix locktime * Replace subquery with LEFT JOIN to get refund data * Rewrite locktime check for more clarity * Rewrite locktime check for more clarity * Fix select_payment_query in case of refunds * Include boltz-client fixes (handling of unwraps for failed broadcasts) * Cargo.toml: Use boltz-client branch instead of commit --------- Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
195 lines
4.8 KiB
TypeScript
195 lines
4.8 KiB
TypeScript
import { NativeModules, Platform, NativeEventEmitter } from "react-native"
|
|
|
|
const LINKING_ERROR =
|
|
`The package 'react-native-breez-liquid-sdk' doesn't seem to be linked. Make sure: \n\n` +
|
|
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
"- You rebuilt the app after installing the package\n" +
|
|
"- You are not using Expo managed workflow\n"
|
|
|
|
const BreezLiquidSDK = NativeModules.RNBreezLiquidSDK
|
|
? NativeModules.RNBreezLiquidSDK
|
|
: new Proxy(
|
|
{},
|
|
{
|
|
get() {
|
|
throw new Error(LINKING_ERROR)
|
|
}
|
|
}
|
|
)
|
|
|
|
const BreezLiquidSDKEmitter = new NativeEventEmitter(BreezLiquidSDK)
|
|
|
|
export interface BackupRequest {
|
|
backupPath?: string
|
|
}
|
|
|
|
export interface ConnectRequest {
|
|
mnemonic: string
|
|
network: Network
|
|
dataDir?: string
|
|
}
|
|
|
|
export interface GetInfoRequest {
|
|
withScan: boolean
|
|
}
|
|
|
|
export interface GetInfoResponse {
|
|
balanceSat: number
|
|
pendingSendSat: number
|
|
pendingReceiveSat: number
|
|
pubkey: string
|
|
}
|
|
|
|
export interface Payment {
|
|
txId: string
|
|
swapId?: string
|
|
timestamp: number
|
|
amountSat: number
|
|
feesSat?: number
|
|
preimage?: string
|
|
refundTxId?: string
|
|
refundTxAmountSat?: number
|
|
paymentType: PaymentType
|
|
status: PaymentState
|
|
}
|
|
|
|
export interface PrepareReceiveRequest {
|
|
payerAmountSat: number
|
|
}
|
|
|
|
export interface PrepareReceiveResponse {
|
|
payerAmountSat: number
|
|
feesSat: number
|
|
}
|
|
|
|
export interface PrepareSendRequest {
|
|
invoice: string
|
|
}
|
|
|
|
export interface PrepareSendResponse {
|
|
invoice: string
|
|
feesSat: number
|
|
}
|
|
|
|
export interface ReceivePaymentResponse {
|
|
id: string
|
|
invoice: string
|
|
}
|
|
|
|
export interface RestoreRequest {
|
|
backupPath?: string
|
|
}
|
|
|
|
export interface SendPaymentResponse {
|
|
txid: string
|
|
}
|
|
|
|
export enum LiquidSdkEventVariant {
|
|
PAYMENT_FAILED = "paymentFailed",
|
|
PAYMENT_PENDING = "paymentPending",
|
|
PAYMENT_REFUNDED = "paymentRefunded",
|
|
PAYMENT_REFUND_PENDING = "paymentRefundPending",
|
|
PAYMENT_SUCCEED = "paymentSucceed",
|
|
PAYMENT_WAITING_CONFIRMATION = "paymentWaitingConfirmation",
|
|
SYNCED = "synced"
|
|
}
|
|
|
|
export type LiquidSdkEvent = {
|
|
type: LiquidSdkEventVariant.PAYMENT_FAILED,
|
|
details: Payment
|
|
} | {
|
|
type: LiquidSdkEventVariant.PAYMENT_PENDING,
|
|
details: Payment
|
|
} | {
|
|
type: LiquidSdkEventVariant.PAYMENT_REFUNDED,
|
|
details: Payment
|
|
} | {
|
|
type: LiquidSdkEventVariant.PAYMENT_REFUND_PENDING,
|
|
details: Payment
|
|
} | {
|
|
type: LiquidSdkEventVariant.PAYMENT_SUCCEED,
|
|
details: Payment
|
|
} | {
|
|
type: LiquidSdkEventVariant.PAYMENT_WAITING_CONFIRMATION,
|
|
details: Payment
|
|
} | {
|
|
type: LiquidSdkEventVariant.SYNCED
|
|
}
|
|
|
|
export enum Network {
|
|
LIQUID = "liquid",
|
|
LIQUID_TESTNET = "liquidTestnet"
|
|
}
|
|
|
|
export enum PaymentState {
|
|
CREATED = "created",
|
|
PENDING = "pending",
|
|
COMPLETE = "complete",
|
|
FAILED = "failed"
|
|
}
|
|
|
|
export enum PaymentType {
|
|
RECEIVE = "receive",
|
|
SEND = "send"
|
|
}
|
|
|
|
export type EventListener = (e: LiquidSdkEvent) => void
|
|
|
|
export const connect = async (req: ConnectRequest): Promise<void> => {
|
|
const response = await BreezLiquidSDK.connect(req)
|
|
return response
|
|
}
|
|
|
|
export const addEventListener = async (listener: EventListener): Promise<string> => {
|
|
const response = await BreezLiquidSDK.addEventListener()
|
|
BreezLiquidSDKEmitter.addListener(`event-${response}`, listener)
|
|
|
|
return response
|
|
}
|
|
|
|
export const removeEventListener = async (id: string): Promise<void> => {
|
|
await BreezLiquidSDK.removeEventListener(id)
|
|
}
|
|
|
|
export const getInfo = async (req: GetInfoRequest): Promise<GetInfoResponse> => {
|
|
const response = await BreezLiquidSDK.getInfo(req)
|
|
return response
|
|
}
|
|
|
|
export const prepareSendPayment = async (req: PrepareSendRequest): Promise<PrepareSendResponse> => {
|
|
const response = await BreezLiquidSDK.prepareSendPayment(req)
|
|
return response
|
|
}
|
|
|
|
export const sendPayment = async (req: PrepareSendResponse): Promise<SendPaymentResponse> => {
|
|
const response = await BreezLiquidSDK.sendPayment(req)
|
|
return response
|
|
}
|
|
|
|
export const prepareReceivePayment = async (req: PrepareReceiveRequest): Promise<PrepareReceiveResponse> => {
|
|
const response = await BreezLiquidSDK.prepareReceivePayment(req)
|
|
return response
|
|
}
|
|
|
|
export const receivePayment = async (req: PrepareReceiveResponse): Promise<ReceivePaymentResponse> => {
|
|
const response = await BreezLiquidSDK.receivePayment(req)
|
|
return response
|
|
}
|
|
|
|
export const listPayments = async (): Promise<Payment[]> => {
|
|
const response = await BreezLiquidSDK.listPayments()
|
|
return response
|
|
}
|
|
|
|
export const sync = async (): Promise<void> => {
|
|
await BreezLiquidSDK.sync()
|
|
}
|
|
|
|
export const backup = async (req: BackupRequest): Promise<void> => {
|
|
await BreezLiquidSDK.backup(req)
|
|
}
|
|
|
|
export const restore = async (req: RestoreRequest): Promise<void> => {
|
|
await BreezLiquidSDK.restore(req)
|
|
}
|