Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { postMessageToNative } from 'web/lib/native/post-message'
|
|
import { api } from '../api/api'
|
|
import { DELETE_PUSH_TOKEN } from 'common/notification'
|
|
|
|
export const setPushToken = async (pushToken: string) => {
|
|
try {
|
|
console.log('setting push token' + pushToken)
|
|
await api('set-push-token', { pushToken })
|
|
} catch (e) {
|
|
console.error('error setting user push token', e)
|
|
postMessageToNative('error', 'Error setting push token')
|
|
}
|
|
}
|
|
|
|
export const handlePushNotificationPermissionStatus = async (
|
|
status: 'denied' | 'undetermined'
|
|
) => {
|
|
const privateUser = await api('me/private')
|
|
if (!privateUser) return
|
|
if (status === 'denied') {
|
|
await setPushTokenRequestDenied()
|
|
}
|
|
}
|
|
|
|
// Removes this account's push token from its private user record. Call on
|
|
// logout so notifications for the now-logged-out account stop being delivered
|
|
// to the device. Unlike setPushTokenRequestDenied, this does NOT mark the user
|
|
// as having rejected push notifications.
|
|
export const clearPushToken = async () => {
|
|
await api('me/private/update', {
|
|
pushToken: DELETE_PUSH_TOKEN,
|
|
})
|
|
}
|
|
|
|
export const setPushTokenRequestDenied = async () => {
|
|
console.log('push token denied')
|
|
await api('me/private/update', {
|
|
rejectedPushNotificationsOn: Date.now(),
|
|
interestedInPushNotifications: false,
|
|
pushToken: DELETE_PUSH_TOKEN,
|
|
})
|
|
}
|