[feat] iOS: support persistent NWC connections in background#4067
[feat] iOS: support persistent NWC connections in background#4067kaloudis wants to merge 29 commits into
Conversation
There was a problem hiding this comment.
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.
| 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(); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
4be32cd to
49523d8
Compare
a36d987 to
3d0c13d
Compare
3d0c13d to
6d6b6a0
Compare
Description
This pull request is categorized as a:
Checklist
yarn run tscand made sure my code compiles correctlyyarn run lintand made sure my code didn’t contain any problematic patternsyarn run prettierand made sure my code is formatted correctlyyarn run testand made sure all of the tests passTesting
If you modified or added a utility file, did you add new unit tests?
I have tested this PR on the following platforms (please specify OS version and phone model/VM):
I have tested this PR with the following types of nodes (please specify node version and API version where appropriate):
On-device
Remote
Locales
Third Party Dependencies and Packages
yarnafter this PR is merged inpackage.jsonandyarn.lockhave been properly updatedOther: