Skip to content

Commit

Permalink
fix: obs bug for transaction updates
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasDeco committed May 30, 2024
1 parent 125fc62 commit c49f247
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export class TransactionSender {
private async handleTransactionUpdate(
update: TransactionProcessingUpdate,
connection: Connection,
signatureSubscriptionIds: number[]
signatureSubscriptionIds: number[],
subscriber: Subscriber<TransactionProcessingUpdate>
) {
if (update.status === "failed") {
//TODO stop subscribing
Expand All @@ -77,6 +78,7 @@ export class TransactionSender {
);
}
this.onTransactionUpdate?.(update);
subscriber.next(update);
}

send<T extends Transaction | VersionedTransaction>(
Expand All @@ -85,7 +87,7 @@ export class TransactionSender {
opts?: SendTransactionOptions,
displayMetadata?: TransactionDisplayMetadata
): Observable<TransactionProcessingUpdate> {
return new Observable<TransactionProcessingUpdate>((subscriber) => {
const obs = new Observable<TransactionProcessingUpdate>((subscriber) => {
let signatureSubscriptionIds: number[] = [];
this.sendInner(tx, connection, opts)
.then((sendRes) => {
Expand All @@ -104,9 +106,9 @@ export class TransactionSender {
this.handleTransactionUpdate(
txUpdate,
connection,
signatureSubscriptionIds
signatureSubscriptionIds,
subscriber
);
subscriber.next(txUpdate);
return;
}
const txUpdate: TransactionProcessingUpdate = {
Expand All @@ -118,9 +120,9 @@ export class TransactionSender {
this.handleTransactionUpdate(
txUpdate,
connection,
signatureSubscriptionIds
signatureSubscriptionIds,
subscriber
);
subscriber.next(txUpdate);
return;
}
if (!sendRes?.signatures[0]) {
Expand All @@ -138,7 +140,8 @@ export class TransactionSender {
this.handleTransactionUpdate(
txUpdate,
connection,
signatureSubscriptionIds
signatureSubscriptionIds,
subscriber
);
subscriber.next(txUpdate);
return;
Expand All @@ -153,7 +156,8 @@ export class TransactionSender {
displayMetadata
},
connection,
signatureSubscriptionIds
signatureSubscriptionIds,
subscriber
);
signatureSubscriptionIds = COMMITMENTS_TO_WATCH.map((s) => {
return connection.onSignature(
Expand Down Expand Up @@ -186,14 +190,16 @@ export class TransactionSender {
displayMetadata
},
connection,
signatureSubscriptionIds
signatureSubscriptionIds,
subscriber
);
return {
signatures: [],
errors: [error]
};
});
});
return obs;
}

private async handleSignatureResult(
Expand Down Expand Up @@ -223,9 +229,9 @@ export class TransactionSender {
this.handleTransactionUpdate(
txUpdate,
connection,
signatureSubscriptionIds
signatureSubscriptionIds,
txObserverSubscriber
);
txObserverSubscriber.next(txUpdate);
return;
}

Expand All @@ -241,7 +247,8 @@ export class TransactionSender {
this.handleTransactionUpdate(
txUpdate,
connection,
signatureSubscriptionIds
signatureSubscriptionIds,
txObserverSubscriber
);
} else {
// error
Expand Down

0 comments on commit c49f247

Please sign in to comment.