Skip to content

Commit

Permalink
chore: use transaction in deep link
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Nov 15, 2024
1 parent 0db8b05 commit 5080ea3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions assets/MessagingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class MessagingService : FirebaseMessagingService() {

val notification = json.optJSONObject("notification") ?: return
val amount = notification.optInt("amount", 0) / 1000
val paymentHash = notification.optString("payment_hash", "")
val transaction = notification.toString()

val notificationText = "You have received $amount sats ⚡️"

val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("alby://payment_received?payment_hash=$paymentHash&wallet_id=${walletInfo.id}")
data = Uri.parse("alby://payment_received?transaction=${Uri.encode(transaction)}&wallet_id=${walletInfo.id}")
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
}

Expand Down
12 changes: 9 additions & 3 deletions assets/NotificationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,20 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withConte

NSDictionary *notificationDict = parsedContent[@"notification"];
NSNumber *amountNumber = notificationDict[@"amount"];
NSString *paymentHash = notificationDict[@"payment_hash"];
if (!amountNumber || !paymentHash) {
if (!amountNumber) {
self.contentHandler(nil);
return;
}

NSString *transactionJSON = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:notificationDict options:0 error:nil] encoding:NSUTF8StringEncoding];
NSString *encodedTransaction = [transactionJSON stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
if (!encodedTransaction) {
self.contentHandler(nil);
return;
}

double amountInSats = [amountNumber doubleValue] / 1000.0;
NSString *deepLink = [NSString stringWithFormat:@"alby://payment_received?payment_hash=%@&wallet_id=%@", paymentHash, walletId.stringValue];
NSString *deepLink = [NSString stringWithFormat:@"alby://payment_received?transaction=%@&wallet_id=%@", encodedTransaction, walletId.stringValue];

NSMutableDictionary *newUserInfo = [self.bestAttemptContent.userInfo mutableCopy];
if (!newUserInfo) {
Expand Down
13 changes: 4 additions & 9 deletions lib/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,21 @@ export const handleLink = async (url: string) => {

if (hostname === "payment_received") {
const urlParams = new URLSearchParams(search);
const paymentHash = urlParams.get("payment_hash");
const walletId = urlParams.get("wallet_id");
if (!paymentHash || !walletId) {
const transaction = urlParams.get("transaction");
if (!transaction || !walletId) {
return;
}
const transactionJSON = decodeURIComponent(transaction);

useAppStore.getState().setSelectedWalletId(Number(walletId));
const nwcClient = useAppStore.getState().nwcClient;
if (!nwcClient) {
return;
}
const tx = await nwcClient.lookupInvoice({
payment_hash: paymentHash,
});
if (!tx) {
return;
}
router.push({
pathname: "/transaction",
params: { transactionJSON: JSON.stringify(tx) },
params: { transactionJSON },
});
return;
}
Expand Down

0 comments on commit 5080ea3

Please sign in to comment.