Skip to content

[feat] iOS: support persistent NWC connections in background#4067

Open
kaloudis wants to merge 29 commits into
masterfrom
nwc-ios-background-service
Open

[feat] iOS: support persistent NWC connections in background#4067
kaloudis wants to merge 29 commits into
masterfrom
nwc-ios-background-service

Conversation

@kaloudis
Copy link
Copy Markdown
Contributor

@kaloudis kaloudis commented May 8, 2026

Description

This pull request is categorized as a:

  • New feature
  • Bug fix
  • Code refactor
  • Configuration change
  • Locales update
  • Quality assurance
  • Other

Checklist

  • I’ve run yarn run tsc and made sure my code compiles correctly
  • I’ve run yarn run lint and made sure my code didn’t contain any problematic patterns
  • I’ve run yarn run prettier and made sure my code is formatted correctly
  • I’ve run yarn run test and made sure all of the tests pass

Testing

If you modified or added a utility file, did you add new unit tests?

  • No, I’m a fool
  • Yes
  • N/A

I have tested this PR on the following platforms (please specify OS version and phone model/VM):

  • Android
  • iOS

I have tested this PR with the following types of nodes (please specify node version and API version where appropriate):

On-device

  • LDK Node
  • Embedded LND

Remote

  • LND (REST)
  • LND (Lightning Node Connect)
  • Core Lightning (CLNRest)
  • Nostr Wallet Connect
  • LndHub

Locales

  • I’ve added new locale text that requires translations
  • I’m aware that new translations should be made on the ZEUS Transfix page and not directly to this repo

Third Party Dependencies and Packages

  • Contributors will need to run yarn after this PR is merged in
  • 3rd party dependencies have been modified:
    • verify that package.json and yarn.lock have been properly updated
    • verify that dependencies are installed for both iOS and Android platforms

Other:

  • Changes were made that require an update to the README
  • Changes were made that require an update to onboarding

@kaloudis kaloudis added this to the v13.1.0 milestone May 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Nostr Wallet Connect (NWC) background service on iOS by replacing the previous background task manager with a silent audio session to maintain relay connectivity. It also removes the 'Pending Payments' modal and screen, streamlining the user experience. The activity log has been enhanced to support an 'expired' status and display memos, while various UI components were updated to use the standard Amount component for better consistency. Feedback was provided regarding the pingRelay utility to ensure that connection attempts are properly aborted during timeouts to prevent potential resource leaks.

Comment on lines +1531 to +1568
static async pingRelay(relayUrl: string): Promise<{
status: boolean;
error?: string | null;
}> {
let relay: ReturnType<typeof relayInit> | undefined;
let timeoutId: ReturnType<typeof setTimeout> | undefined;
try {
relay = relayInit(relayUrl);
const timeout = new Promise<void>((_, reject) => {
timeoutId = setTimeout(
() =>
reject(
new Error(
localeString(
'views.Settings.NostrWalletConnect.connectionTimeout'
)
)
),
5000
);
});
await Promise.race([relay.connect(), timeout]);
return { status: true, error: null };
} catch (_e) {
return {
status: false,
error: localeString(
'stores.NostrWalletConnectStore.error.failedToConnectRelay',
{ relayUrl }
)
};
} finally {
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
relay?.close();
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In pingRelay, if the timeout triggers, relay.connect() might still be attempting to establish a connection in the background. While relay.close() is called in the finally block, ensuring that the connection attempt is fully aborted is important to prevent resource leaks or unexpected behavior from the underlying socket implementation.

@kaloudis kaloudis force-pushed the nwc-ios-background-service branch 3 times, most recently from 4be32cd to 49523d8 Compare May 18, 2026 03:08
@kaloudis kaloudis force-pushed the nwc-ios-background-service branch from a36d987 to 3d0c13d Compare May 21, 2026 17:00
ajaysehwal added 20 commits May 27, 2026 09:13
@kaloudis kaloudis force-pushed the nwc-ios-background-service branch from 3d0c13d to 6d6b6a0 Compare May 27, 2026 15:22
@kaloudis kaloudis requested a review from shubhamkmr04 May 27, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants