This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notifications server with push subscriptions and service worker
- Loading branch information
1 parent
2994303
commit 5250352
Showing
25 changed files
with
1,570 additions
and
37 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,50 @@ | ||
self.addEventListener('push', event => { | ||
const { account, body, offerId, title } = event.data.json() | ||
const promiseChain = self.registration.showNotification(title, { | ||
body, | ||
data: { account, offerId }, | ||
icon: '/images/app-icon.png', | ||
lang: 'en-US', | ||
requireInteraction: true, | ||
vibrate: [300, 100, 400] | ||
}) | ||
|
||
event.waitUntil(promiseChain) | ||
}) | ||
|
||
self.addEventListener('notificationclick', event => { | ||
event.notification.close() | ||
|
||
const { account, offerId } = event.notification.data | ||
const purchaseDetailPath = `/#/purchases/${offerId}?account=${account}` | ||
const urlToOpen = new URL(purchaseDetailPath, self.location.origin).href | ||
|
||
const promiseChain = clients.matchAll({ | ||
type: 'window', | ||
includeUncontrolled: true | ||
}).then((windowClients) => { | ||
let matchingClient = null | ||
|
||
for (let i = 0; i < windowClients.length; i++) { | ||
const windowClient = windowClients[i] | ||
|
||
if (windowClient.url === urlToOpen) { | ||
matchingClient = windowClient | ||
|
||
break | ||
} | ||
} | ||
|
||
if (matchingClient) { | ||
return matchingClient.focus() | ||
} else { | ||
return clients.openWindow(urlToOpen) | ||
} | ||
}) | ||
|
||
event.waitUntil(promiseChain) | ||
}) | ||
|
||
self.addEventListener('notificationclose', event => { | ||
// track dismissal | ||
}) |
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
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
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
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
115 changes: 115 additions & 0 deletions
115
origin-dapp/src/components/modals/notifications-modals.js
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,115 @@ | ||
import React from 'react' | ||
import { FormattedMessage } from 'react-intl' | ||
|
||
import Modal from 'components/modal' | ||
|
||
export const RecommendationModal = ({ | ||
isOpen = false, | ||
onCancel, | ||
onSubmit, | ||
role | ||
}) => ( | ||
<Modal | ||
className="notifications-modal recommendation" | ||
isOpen={isOpen} | ||
handleToggle={onCancel} | ||
> | ||
<div className="image-container"> | ||
<img src="images/notifications-computer.svg" role="presentation" /> | ||
</div> | ||
<h2> | ||
<FormattedMessage | ||
id={'notificationsModals.recommendationHeading'} | ||
defaultMessage={'Get Updates'} | ||
/> | ||
</h2> | ||
<div className="text"> | ||
<p> | ||
<em> | ||
<FormattedMessage | ||
id={'notificationsModals.questionBuyer'} | ||
defaultMessage={'We highly recommend enabling notifications.'} | ||
/> | ||
</em> | ||
<br /> | ||
{role === 'buyer' && | ||
<FormattedMessage | ||
id={'arbitrationModals.valuePropositionBuyer'} | ||
defaultMessage={`Without them, you will have to return to the Origin marketplace to know if your offer is accepted or when the seller leaves you a review.`} | ||
/> | ||
} | ||
{role === 'seller' && | ||
<FormattedMessage | ||
id={'notificationsModals.valuePropositionSeller'} | ||
defaultMessage={`Without them, you will have to return to the Origin marketplace to know when a buyer makes an offer on your listing or leaves you a review.`} | ||
/> | ||
} | ||
</p> | ||
</div> | ||
<div className="button-container"> | ||
<button className="btn btn-success" onClick={onSubmit}> | ||
<FormattedMessage | ||
id={'notificationsModals.enable'} | ||
defaultMessage={'Enable Notifications'} | ||
/> | ||
</button> | ||
</div> | ||
<a href="#" onClick={onCancel}> | ||
<FormattedMessage | ||
id={'notificationsModals.dismiss'} | ||
defaultMessage={'Dismiss'} | ||
/> | ||
</a> | ||
</Modal> | ||
) | ||
|
||
export const WarningModal = ({ | ||
isOpen = false, | ||
onCancel, | ||
onSubmit | ||
}) => ( | ||
<Modal | ||
className="notifications-modal warning" | ||
isOpen={isOpen} | ||
handleToggle={onCancel} | ||
> | ||
<div className="image-container"> | ||
<img src="images/notifications-warning.svg" role="presentation" /> | ||
</div> | ||
<h2> | ||
<FormattedMessage | ||
id={'notificationsModals.warningHeading'} | ||
defaultMessage={`Wait! Don't you want updates?`} | ||
/> | ||
</h2> | ||
<div className="text"> | ||
<p> | ||
<em> | ||
<FormattedMessage | ||
id={'notificationsModals.disclaimer'} | ||
defaultMessage={'Notifications are critical.'} | ||
/> | ||
</em> | ||
| ||
<FormattedMessage | ||
id={'notificationsModals.explanation'} | ||
defaultMessage={`Because the Origin marketplace is fully-decentralized, you won't receive any emails when there is something important to tell you. You are likely to miss important updates about your transactions.`} | ||
/> | ||
</p> | ||
</div> | ||
<div className="button-container"> | ||
<button className="btn btn-success" onClick={onSubmit}> | ||
<FormattedMessage | ||
id={'notificationsModals.enable'} | ||
defaultMessage={'Enable Notifications'} | ||
/> | ||
</button> | ||
</div> | ||
<a href="#" onClick={onCancel}> | ||
<FormattedMessage | ||
id={'notificationsModals.dismiss'} | ||
defaultMessage={'Dismiss'} | ||
/> | ||
</a> | ||
</Modal> | ||
) |
Oops, something went wrong.