WalletConnect / walletconnect-monorepo

WalletConnect Monorepo
Apache License 2.0
1.29k stars 645 forks source link

Not able to display WalletConnect FCM push notifications from background mode on Android #5181

Open vaniyokk opened 1 month ago

vaniyokk commented 1 month ago

I was able to set up and receive notifications using WalletConnect cloud, FCM and react-native-firebase + Notifee. Notification is displaying when app is not started (killed);

However, It's not possible to display data-only background notification in Android 12+ according known issue with background notifications handling on Android (Well described here: https://github.com/invertase/notifee/issues/830#issuecomment-1951528249, see whole thread)

It's because WalletConnect notifications are data-only (using data instead of notification property), and the system just ignores them in background state.

Is there any way to force display this kind of notifications? Notification received in background shows only when I open app (move it to foreground)

Here is my code for displaying notifications. I believe this is not an issue with web3wallet itself, but, seems like there is no possibility to properly handle data-only messages to notify user when app is in background but not killed.

await web3wallet.registerDeviceToken({
    token: await messaging().getToken(),
    clientId: await web3wallet.core.crypto.getClientId(),
    notificationType: "fcm",
    enableEncrypted: true
  });

...

// Create a channel (required for Android)
const channelId = await notifee.createChannel({
  id: "wallet-connect",
  name: "WalletConnect Notifications",
  importance: AndroidImportance.HIGH
});

try {
  // Display a notification
  await notifee.displayNotification({
    title: "Wallet Action Required",
    body: "Tap notification to open app and perform action on WalletConnect request",
    android: {
      importance: AndroidImportance.HIGH,
      channelId,
      smallIcon: "ic_small_icon",
      color: "#22C55E",
      // pressAction is needed if you want the notification to open the app when pressed
      pressAction: {
        id: "default"
      }
    }
  });
} catch (e) {
  // eslint-disable-next-line no-console
  console.log(e);
}

Also, here is my message I receive in background and which I can't display to user. Shouldn't it contain "priority": "high", "contentAvailable": true fields as per https://rnfirebase.io/messaging/usage#data-only-messages?

 {
  "sentTime":1720796459112,
  "data":{
    "message":"AMsv4PoyASwWoh/7IWybkGhbfd9ab1UW4RtlBG5vNtsOCDq5e5Z/RUClsNE0GTJ7FBMzBcUNuAN8ySrNH0MGGg7jGALhPl8PHnFD6ZtTYA/+Dkh52AobO8C83DqNVzGvqAGFcYUuLWE6FJRpr196EHTtLNaUSFAoqiDOT+jF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6asMfYQwCb8/pUNSuVJ39nwwQndinvbIXBjKYmz9L2B8S9vy8J2y/N+rkEB8SuJAOn3aR/mGoapCFv2UMffcdBlJdwAL18Xzs7/3liEt+lKERUypdMlQyMHhir1b8oyUou1q3TSFeXlSGTM0MIZyfHc/8jORA37t31LB7cmTrpN8eDPdl19K2aSYGTkU5wj9+5H8HP/J784scsTrp9Nl+qel0RcA8M3xE3rxtc2Bu7TLGvWcY62cRoKFjb1ncZw8UDmvScoapclRNqEdINshAT/JVA/H9ughYbeu8olK8GXKJQiDSILNzTeTjdJJSUgw+Eo+tvrp28vmicVT8cdNTgcF9WKkHGBxDoDwE55D+1XIot/55iLEB3dNQ37ROT2ED5KGYFgsLzKhLKqeui",
    "topic":"ac94b1f8926ffd4121f920251f482cbd526a02e7fab3559e70327d5af940f26d",
    "tag":"1108"
  },
  "messageId":"0:1720796459128835%72925286f9fd7ecd",
  "ttl":2419200,
  "from":"830012384765"
}

SDK Version (if relevant)

Expected behavior There should be a way to receive and notify user about WalletConnect request if wallet app is hidden (in background)

Smartphone (please complete the following information):

linear[bot] commented 1 month ago

CR-483 Not able to display FCM push notifications from background mode on Android