-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show notifications for WC requests (#2638)
* feat: show notifications for WC requests * refactor: move notification logic to own file
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { AppInfo } from '.' | ||
|
||
export const showNotification = (title: string, options?: NotificationOptions) => { | ||
if (Notification.permission !== 'granted' || document.hasFocus()) { | ||
return | ||
} | ||
|
||
const notification = new Notification(title, { | ||
icon: '/images/safe-logo-green.png', | ||
...options, | ||
}) | ||
|
||
notification.onclick = () => { | ||
window.focus() | ||
notification.close() | ||
} | ||
|
||
setTimeout(() => { | ||
notification.close() | ||
}, 5_000) | ||
} | ||
|
||
export const NotificationMessages: Record< | ||
string, | ||
(appInfo: AppInfo) => { title: string; options: NotificationOptions } | ||
> = { | ||
SIGNATURE_REQUEST: (appInfo: AppInfo) => ({ | ||
title: 'Signature request', | ||
options: { | ||
body: `${appInfo.name} wants you to sign a message. Open the Safe{Wallet} to continue.`, | ||
}, | ||
}), | ||
TRANSACTION_REQUEST: (appInfo: AppInfo) => ({ | ||
title: 'Transaction request', | ||
options: { | ||
body: `${appInfo.name} wants to submit a transaction. Open the Safe{Wallet} to continue.`, | ||
}, | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters