Skip to content

Commit

Permalink
fix: immediately call onConnecting callback if provider is already co…
Browse files Browse the repository at this point in the history
…nnecting when subscription is created
  • Loading branch information
rolznz committed Jan 9, 2024
1 parent add32fc commit 3aa4a63
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ type LaunchPaymentModalArgs = {
};

/**
* Listen to onConnected events which will fire when a wallet is connected (either
* Subscribe to onConnected events which will fire when a wallet is connected (either
* the user connects to a new wallet or when Bitcoin Connect boots and connects to a previously-connected wallet).
*
* If a provider is already available, the callback will be immediately fired.
* If a provider is already available when the subscription is created, the callback will be immediately fired.
* @param callback includes the webln provider that was (or is already) connected
* @returns unsubscribe function
*/
Expand All @@ -67,11 +67,17 @@ export function onConnected(callback: (provider: WebLNProvider) => void) {
}

/**
* Listen to onConnecting events which will fire when a user is connecting to their wallet
* Subscribe to onConnecting events which will fire when a user is connecting to their wallet
*
* If a provider is already being connected to when the subscription is created, the callback will be immediately fired.
* @param callback
* @returns unsubscribe function
*/
export function onConnecting(callback: () => void) {
if (store.getState().connecting) {
callback();
}

const zustandUnsubscribe = store.subscribe(async (state, prevState) => {
if (state.connecting && !prevState.connecting) {
callback();
Expand Down

0 comments on commit 3aa4a63

Please sign in to comment.