import { WalletKit } from '@reown/walletkit';
import messaging from '@react-native-firebase/messaging';
messaging().onMessage(async notification => {
// get the topic, encrypted message & tag from the notification payload
const { topic, message, tag } = notification.data;
// decrypt the message
// note this is static method and can be called without initializing the walletKit
const decryptedMessage = await WalletKit.notifications.decryptMessage({
topic,
encryptedMessage: message,
});
/*
* `decryptedMessage` is JsonRpcRequest object, with the full payload of the incoming request such as method, params, id, etc.
* You can use it to emit local push notification with the request to the user and ask for their approval.
**/
/*
* the metadata contains name, description, icon and url of the dapp that initiated the request
* note that only notifications with tag `1108`(session requests) will have metadata,
**/
let metadata
if(tag == 1108) {
metadata = await WalletKit.notifications.getMetadata({ topic });
} else {
// session proposals contain metadata in the request itself
metadata = decryptedMessage.params.proposer.metadata
}
// with this information you can show a local push notification to the user
...
});