Skip to content

Commit

Permalink
fix: add multiple BTC recipients support (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhaseeb4239 authored and janniks committed Feb 9, 2023
1 parent 3f57437 commit 8a686cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
17 changes: 13 additions & 4 deletions packages/connect/src/transactions/btc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createUnsecuredToken, Json } from 'jsontokens';
import { BTCTransferOptions, BTCTransferPayload, TransactionTypes } from 'src/types';
import { getStacksProvider } from 'src/utils';
import { getDefaults, getStxAddress } from '.';
import { BtcRecipient, BTCTransferOptions, BTCTransferPayload, TransactionTypes } from '../types';
import { getStacksProvider } from '../utils';

const openGenericTransactionPopup = async ({
token,
Expand All @@ -25,15 +26,23 @@ const openGenericTransactionPopup = async ({
};

export function openBTCTransfer(options: BTCTransferOptions): Promise<void> {
const { amount, ..._options } = {
const { recipients, ..._options } = {
// todo: do we maybe want userSession, stxAddress, ...?
// ...getDefaults(options),
...options,
};

const payLoadRecipients: BtcRecipient[] = [];
recipients.forEach(recipient => {
payLoadRecipients.push({
recipient: recipient.recipient,
amount: recipient.amount.toString(10),
});
});

const payload: Partial<BTCTransferPayload> = {
..._options,
amount: amount.toString(10),
recipients: payLoadRecipients,
txType: TransactionTypes.BTCTransfer,
};

Expand Down
21 changes: 16 additions & 5 deletions packages/connect/src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ export interface STXTransferPayload extends STXTransferBase {
* Transaction Popup
*/

export type TransactionOptions = ContractCallOptions | ContractDeployOptions | STXTransferOptions;
export type TransactionPayload = ContractCallPayload | ContractDeployPayload | STXTransferPayload;
export type TransactionOptions =
| ContractCallOptions
| ContractDeployOptions
| STXTransferOptions
| BTCTransferOptions;
export type TransactionPayload =
| ContractCallPayload
| ContractDeployPayload
| STXTransferPayload
| BTCTransferPayload;

export interface TransactionPopup {
token: string;
Expand All @@ -166,13 +174,16 @@ export interface TransactionPopup {
* BTC Transfer
*/

export interface BTCTransferOptions extends RegularOptionsBase {
export interface BtcRecipient {
recipient: string;
amount: bigint | number | string;
}

export interface BTCTransferOptions extends RegularOptionsBase {
recipients: BtcRecipient[];
}

export interface BTCTransferPayload extends BTCTransferOptions {
recipient: string;
amount: string;
recipients: BtcRecipient[];
txType: TransactionTypes.BTCTransfer;
}

0 comments on commit 8a686cf

Please sign in to comment.