Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions assets/ios/NotificationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,26 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withConte
return;
}

NSString *transactionJSON = [[NSString alloc] initWithData:transactionData encoding:NSUTF8StringEncoding];
NSString *encodedTransaction = [transactionJSON stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
if (!encodedTransaction) {
NSString *transactionJSON = [[NSString alloc] initWithData:transactionData encoding:NSUTF8StringEncoding];
if (!transactionJSON) {
self.contentHandler(nil);
return;
}

NSURLComponents *components = [[NSURLComponents alloc] init];
components.scheme = @"alby";
components.host = @"payment_notification";
components.queryItems = @[
[NSURLQueryItem queryItemWithName:@"transaction" value:transactionJSON],
[NSURLQueryItem queryItemWithName:@"app_pubkey" value:appPubkey],
];

NSString *deepLink = components.string;
if (!deepLink) {
self.contentHandler(nil);
return;
}

NSString *deepLink = [NSString stringWithFormat:@"alby://payment_notification?transaction=%@&app_pubkey=%@", encodedTransaction, appPubkey];
NSMutableDictionary *newUserInfo = [self.bestAttemptContent.userInfo mutableCopy] ?: [NSMutableDictionary dictionary];
NSMutableDictionary *newBodyDict = [newUserInfo[@"body"] mutableCopy] ?: [NSMutableDictionary dictionary];

Expand Down
38 changes: 38 additions & 0 deletions hooks/__tests__/useHandleLinking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,44 @@ describe("handleLink", () => {
expect(router.push).not.toHaveBeenCalled();
});

it("should preserve decoded callback and app icon params", async () => {
await handleLink(
"nostrnwc://connect?appname=Test%20App&callback=myapp%3A%2F%2Fopen%3Fredirect%3Dhttps%253A%252F%252Fdev.example.com%252Fdone&appicon=https%3A%2F%2Fcdn.example.com%2Ficon.png",
);

await new Promise((resolve) => setTimeout(resolve, 100));

expect(router.push).toHaveBeenCalledWith({
pathname: "/settings/wallets/connect",
params: {
options: JSON.stringify({
icon: "https://cdn.example.com/icon.png",
name: "Test App",
returnTo:
"myapp://open?redirect=https%3A%2F%2Fdev.example.com%2Fdone",
}),
flow: "deeplink",
},
});
});

it("should open payment notifications without decoding nested payloads twice", async () => {
await handleLink(
"alby://payment_notification?app_pubkey=abc&transaction=%7B%22type%22%3A%22incoming%22%2C%22state%22%3A%22settled%22%2C%22invoice%22%3A%22lnbc123%22%2C%22description%22%3A%22myapp%3A%2F%2Fopen%3Fredirect%3Dhttps%253A%252F%252Fdev.example.com%252Fdone%26payload%3D%257B%2522screen%2522%253A%2522payment%2522%257D%22%2C%22description_hash%22%3A%22%22%2C%22preimage%22%3A%22abc%22%2C%22payment_hash%22%3A%22def%22%2C%22amount%22%3A21000%2C%22fees_paid%22%3A0%2C%22created_at%22%3A1753275708%2C%22expires_at%22%3A1753362108%2C%22settled_at%22%3A1753275741%2C%22settle_deadline%22%3Anull%2C%22metadata%22%3Anull%7D",
);

await new Promise((resolve) => setTimeout(resolve, 100));

expect(router.push).toHaveBeenCalledWith({
pathname: "/transaction",
params: {
appPubkey: "abc",
transactionJSON:
'{"type":"incoming","state":"settled","invoice":"lnbc123","description":"myapp://open?redirect=https%3A%2F%2Fdev.example.com%2Fdone&payload=%7B%22screen%22%3A%22payment%22%7D","description_hash":"","preimage":"abc","payment_hash":"def","amount":21000,"fees_paid":0,"created_at":1753275708,"expires_at":1753362108,"settled_at":1753275741,"settle_deadline":null,"metadata":null}',
},
});
});

describe("Expo links", () => {
test.each(Object.entries(testVectors))(
"should parse the URL '%s' and navigate correctly",
Expand Down
14 changes: 5 additions & 9 deletions lib/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@ export const handleLink = async (url: string) => {
if (parsedUrl.protocol.startsWith("nostrnwc")) {
const params = new URLSearchParams(search);
const appname = params.get("appname");
const rawCallback = params.get("callback");
const rawAppIcon = params.get("appicon");
if (!appname || !rawCallback || !rawAppIcon) {
const callback = params.get("callback");
const appicon = params.get("appicon");
if (!appname || !callback || !appicon) {
return;
}

const appicon = decodeURIComponent(rawAppIcon);
const callback = decodeURIComponent(rawCallback);

console.info("Navigating to NWA flow");
safeRouterPush({
pathname: "/settings/wallets/connect",
Expand Down Expand Up @@ -148,11 +145,10 @@ export const handleLink = async (url: string) => {
if (hostname === "payment_notification") {
const urlParams = new URLSearchParams(search);
const appPubkey = urlParams.get("app_pubkey");
const transaction = urlParams.get("transaction");
if (!transaction || !appPubkey) {
const transactionJSON = urlParams.get("transaction");
if (!transactionJSON || !appPubkey) {
return;
}
const transactionJSON = decodeURIComponent(transaction);
safeRouterPush({
pathname: "/transaction",
params: { transactionJSON, appPubkey },
Expand Down
Loading
Loading