Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into deploy/amp
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmell committed Aug 16, 2023
2 parents fc9a8a9 + ecedb19 commit 5386527
Show file tree
Hide file tree
Showing 31 changed files with 2,482 additions and 807 deletions.
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ NEXT_PUBLIC_SQUID_URL=<supply this if you want to use squid instead of blockchai
NEXT_PUBLIC_COMMUNITY_HUB_ID=<supply this if you want to have community creation feature>

COVALENT_API_KEY=<covalent api key, for getting nft data>

# Firebase API Keys
NEXT_PUBLIC_NOTIFICATION_APP_ID=<fireabse notification id>
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=<firebase project domain>
NEXT_PUBLIC_FIREBASE_PROJECT_ID=<firebase project id>
NEXT_PUBLIC_FIREBASE_API_KEY=<API key for firebase>
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=<firebase storage bucket key>
NEXT_PUBLIC_FIREBASE_MESSAGING_ID=<messaging id for sending push notifications>
NEXT_PUBLIC_FIREBASE_APP_ID=<firebase app id for PWA>
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=<measurement id for analytics>
1 change: 0 additions & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
SERVER_MNEMONIC="bounce clutch hotel number lab imitate grass loop jewel cousin network paddle"
SERVER_DISCUSSION_CREATOR_MNEMONIC=""

# ipfs test values
CRUST_IPFS_AUTH="eyJkYXRhIjp7ImRvbWFpbiI6eyJjaGFpbklkIjoiNSIsIm5hbWUiOiJDbG91ZDMuY2MiLCJ2ZXJpZnlpbmdDb250cmFjdCI6IjB4Q2NDQ2NjY2NDQ0NDY0NDQ0NDQ2NDY0NjY0NjQ0NDY0NjY2NjY2NjQyIsInZlcnNpb24iOiIxIn0sIm1lc3NhZ2UiOnsiZGVzY3JpcHRpb24iOiJTaWduIGZvciBXMyBCdWNrZXQgQWNjZXNzIEF1dGhlbnRpY2F0aW9uIiwic2lnbmluZ0FkZHJlc3MiOiIweDAwNDFjNzA1ZTEwNmVlOWRFMjI3Q2ExMzlBZDRBOTlEQjY0NENCM2EiLCJ0b2tlbkFkZHJlc3MiOiIweDM5ODY2Mzg0MjY4MDMzMkExQWJBM0IwM2JkNmRCNDdhRTk4NDk5NEMiLCJ0b2tlbklkIjoiMzAwMDAzNyIsImVmZmVjdGl2ZVRpbWVzdGFtcCI6MTY3ODUzNzYxNywiZXhwaXJhdGlvblRpbWVzdGFtcCI6MH0sInByaW1hcnlUeXBlIjoiVzNCdWNrZXQiLCJ0eXBlcyI6eyJXM0J1Y2tldCI6W3sibmFtZSI6ImRlc2NyaXB0aW9uIiwidHlwZSI6InN0cmluZyJ9LHsibmFtZSI6InNpZ25pbmdBZGRyZXNzIiwidHlwZSI6ImFkZHJlc3MifSx7Im5hbWUiOiJ0b2tlbkFkZHJlc3MiLCJ0eXBlIjoiYWRkcmVzcyJ9LHsibmFtZSI6InRva2VuSWQiLCJ0eXBlIjoic3RyaW5nIn0seyJuYW1lIjoiZWZmZWN0aXZlVGltZXN0YW1wIiwidHlwZSI6InVpbnQyNTYifSx7Im5hbWUiOiJleHBpcmF0aW9uVGltZXN0YW1wIiwidHlwZSI6InVpbnQyNTYifV19fSwic2lnbmF0dXJlIjoiMHhhMTUxODkyZGNhMTZlMTJkZmViYTFjY2FkMjNmZjM5MGVmODQ1MzdhMGI2MWI4YWQ1NDY1ZGI1ZjI1NjZkMWJmMjc3MGE1OTQyMzFmNzFmYzA5YWVlZGJhNzJkZjM5Y2Y4NDIxMTQ3YzJkNWQyNTFkNDZjNGQyMDFlOGM1MmUzZTFjIn0="
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ jobs:
GH_NEXT_PUBLIC_CAPTCHA_SITE_KEY=6LcnGU0lAAAAANPvuR2I3gZswHpX1GJnpJG2ocVb
GH_SERVER_DISCUSSION_CREATOR_MNEMONIC=${{ secrets.SERVER_DISCUSSION_CREATOR_MNEMONIC }}
GH_COVALENT_API_KEY=${{ secrets.COVALENT_API_KEY }}
GH_NEXT_PUBLIC_NOTIFICATION_APP_ID=BECyoVsDLEgsOj9MvhoetL3YGYZVCE5RzhADmBugpp0hu7QBV_xG8veiT_qAFxF9S8qXKhPvaPiD5oMrdWrFNB0
GH_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=grill-web-push.firebaseapp.com
GH_NEXT_PUBLIC_FIREBASE_PROJECT_ID=grill-web-push
GH_NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyCdu_lvl18590HFoAXTysuKStaJJkaA4h4
GH_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=grill-web-push.appspot.com
GH_NEXT_PUBLIC_FIREBASE_MESSAGING_ID=762898090466
GH_NEXT_PUBLIC_FIREBASE_APP_ID=1:762898090466:web:2a09d26c3bab706b95d1bb
target: runner
tags: |
${{ env.image }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/feature-based.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ jobs:
GH_NEXT_PUBLIC_GA_ID=G-FT28TL1W3M
GH_IPFS_PIN_URL=https://test-pin.crustcloud.io/psa
GH_COVALENT_API_KEY=cqt_rQtDdp9G9DFvqcGjVPDD4FFCyhFQ
GH_NEXT_PUBLIC_NOTIFICATION_APP_ID=BJaKjx7xtiIXtSUT8tR6VDG0WwhFwdqOqp8L5kc6alGBUtndnlV_DUJ6sze_z70VEBOKk4AT_wZTJqE9dC7sbEQ
GH_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=gl-notifications-dev.firebaseapp.com
GH_NEXT_PUBLIC_FIREBASE_PROJECT_ID=gl-notifications-dev
GH_NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyC7pSekdJQ0PpUDCY4eEkEeDGCazVES6QI
GH_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=gl-notifications-dev.appspot.com
GH_NEXT_PUBLIC_FIREBASE_MESSAGING_ID=581626459774
GH_NEXT_PUBLIC_FIREBASE_APP_ID=1:581626459774:web:6b7098eb48c0b142f50a2f
GH_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-ZJBCKJR5F3
target: runner
tags: |
${{ env.image }}
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ next-env.d.ts

/public/sw.js
/public/workbox-*.js
/public/worker-*.js
/public/worker-*.txt

/storybook-static
/public/fallback-*.js

/storybook-static
10 changes: 9 additions & 1 deletion ci.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
NEXT_PUBLIC_CAPTCHA_SITE_KEY='$GH_NEXT_PUBLIC_CAPTCHA_SITE_KEY'
CAPTCHA_SECRET='$GH_CAPTCHA_SECRET'
SERVER_MNEMONIC='$GH_SERVER_MNEMONIC'
GH_SERVER_DISCUSSION_CREATOR_MNEMONIC='$GH_SERVER_DISCUSSION_CREATOR_MNEMONIC'
SERVER_DISCUSSION_CREATOR_MNEMONIC='$GH_SERVER_DISCUSSION_CREATOR_MNEMONIC'
NEXT_PUBLIC_SPACE_IDS='$GH_NEXT_PUBLIC_SPACE_IDS'
MODERATION_URL='$GH_MODERATION_URL'
MODERATION_TOKEN='$GH_MODERATION_TOKEN'
NEXT_PUBLIC_NOTIFICATION_APP_ID='$GH_NEXT_PUBLIC_NOTIFICATION_APP_ID'
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN='$GH_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN'
NEXT_PUBLIC_FIREBASE_PROJECT_ID='$GH_NEXT_PUBLIC_FIREBASE_PROJECT_ID'
NEXT_PUBLIC_FIREBASE_API_KEY='$GH_NEXT_PUBLIC_FIREBASE_API_KEY'
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET='$GH_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET'
NEXT_PUBLIC_FIREBASE_MESSAGING_ID='$GH_NEXT_PUBLIC_FIREBASE_MESSAGING_ID'
NEXT_PUBLIC_FIREBASE_APP_ID='$GH_NEXT_PUBLIC_FIREBASE_APP_ID'
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID='$GH_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID'
NOTIFICATIONS_URL='$GH_NOTIFICATIONS_URL'
NOTIFICATIONS_TOKEN='$GH_NOTIFICATIONS_TOKEN'
NEXT_PUBLIC_AMP_ID='$GH_NEXT_PUBLIC_AMP_ID'
Expand Down
31 changes: 31 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ ARG GH_NEXT_PUBLIC_CAPTCHA_SITE_KEY
ARG GH_NEXT_PUBLIC_SPACE_IDS
ARG GH_MODERATION_URL
ARG GH_MODERATION_TOKEN
ARG GH_NEXT_PUBLIC_NOTIFICATION_APP_ID
ARG GH_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ARG GH_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ARG GH_NEXT_PUBLIC_FIREBASE_API_KEY
ARG GH_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET
ARG GH_NEXT_PUBLIC_FIREBASE_MESSAGING_ID
ARG GH_NEXT_PUBLIC_FIREBASE_APP_ID
ARG GH_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
ARG GH_NOTIFICATIONS_URL
ARG GH_NOTIFICATIONS_TOKEN
ARG GH_NEXT_PUBLIC_AMP_ID
Expand All @@ -23,6 +31,14 @@ ENV NEXT_PUBLIC_CAPTCHA_SITE_KEY=${GH_NEXT_PUBLIC_CAPTCHA_SITE_KEY} \
NEXT_PUBLIC_SPACE_IDS=${GH_NEXT_PUBLIC_SPACE_IDS} \
MODERATION_URL=${GH_MODERATION_URL} \
MODERATION_TOKEN=${GH_MODERATION_TOKEN} \
NEXT_PUBLIC_NOTIFICATION_APP_ID=${GH_NEXT_PUBLIC_NOTIFICATION_APP_ID} \
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${GH_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN} \
NEXT_PUBLIC_FIREBASE_PROJECT_ID=${GH_NEXT_PUBLIC_FIREBASE_PROJECT_ID} \
NEXT_PUBLIC_FIREBASE_API_KEY=${GH_NEXT_PUBLIC_FIREBASE_API_KEY} \
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${GH_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET} \
NEXT_PUBLIC_FIREBASE_MESSAGING_ID=${GH_NEXT_PUBLIC_FIREBASE_MESSAGING_ID} \
NEXT_PUBLIC_FIREBASE_APP_ID=${GH_NEXT_PUBLIC_FIREBASE_APP_ID} \
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=${GH_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID} \
NOTIFICATIONS_URL=${GH_NOTIFICATIONS_URL} \
NOTIFICATIONS_TOKEN=${GH_NOTIFICATIONS_TOKEN} \
NEXT_PUBLIC_AMP_ID=${GH_NEXT_PUBLIC_AMP_ID} \
Expand Down Expand Up @@ -61,6 +77,13 @@ ARG GH_NEXT_PUBLIC_CAPTCHA_SITE_KEY
ARG GH_NEXT_PUBLIC_SPACE_IDS
ARG GH_MODERATION_URL
ARG GH_MODERATION_TOKEN
ARG GH_NEXT_PUBLIC_NOTIFICATION_APP_ID
ARG GH_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ARG GH_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ARG GH_NEXT_PUBLIC_FIREBASE_API_KEY
ARG GH_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET
ARG GH_NEXT_PUBLIC_FIREBASE_MESSAGING_ID
ARG GH_NEXT_PUBLIC_FIREBASE_APP_ID
ARG GH_NOTIFICATIONS_URL
ARG GH_NOTIFICATIONS_TOKEN
ARG GH_NEXT_PUBLIC_AMP_ID
Expand All @@ -75,6 +98,14 @@ ENV NEXT_PUBLIC_CAPTCHA_SITE_KEY=${GH_NEXT_PUBLIC_CAPTCHA_SITE_KEY} \
NEXT_PUBLIC_SPACE_IDS=${GH_NEXT_PUBLIC_SPACE_IDS} \
MODERATION_URL=${GH_MODERATION_URL} \
MODERATION_TOKEN=${GH_MODERATION_TOKEN} \
NEXT_PUBLIC_NOTIFICATION_APP_ID=${GH_NEXT_PUBLIC_NOTIFICATION_APP_ID} \
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${GH_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN} \
NEXT_PUBLIC_FIREBASE_PROJECT_ID=${GH_NEXT_PUBLIC_FIREBASE_PROJECT_ID} \
NEXT_PUBLIC_FIREBASE_API_KEY=${GH_NEXT_PUBLIC_FIREBASE_API_KEY} \
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${GH_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET} \
NEXT_PUBLIC_FIREBASE_MESSAGING_ID=${GH_NEXT_PUBLIC_FIREBASE_MESSAGING_ID} \
NEXT_PUBLIC_FIREBASE_APP_ID=${GH_NEXT_PUBLIC_FIREBASE_APP_ID} \
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=${GH_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID} \
NOTIFICATIONS_URL=${GH_NOTIFICATIONS_URL} \
NOTIFICATIONS_TOKEN=${GH_NOTIFICATIONS_TOKEN} \
NEXT_PUBLIC_AMP_ID=${GH_NEXT_PUBLIC_AMP_ID} \
Expand Down
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({
const withPWA = require('next-pwa')({
dest: 'public',
disable: process.env.NODE_ENV !== 'production',
buildExcludes: [/chunks\/.*$/, /media\/.*$/],
publicExcludes: ['!splashscreens/**/*', '!screenshots/**/*'],
})

/** @type {import('next').NextConfig} */
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"eslint": "8.34.0",
"eslint-config-next": "13.2.1",
"ethers": "^6.3.0",
"firebase": "^10.1.0",
"express": "^4.18.2",
"formidable": "^3.4.0",
"graphql": "^16.6.0",
Expand Down
7 changes: 7 additions & 0 deletions src/components/auth/ProfileModal/ProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import LinkEvmAddressContent from './contents/evm-linking/LinkEvmAddressContent'
import UnlinkEvmConfirmationContent from './contents/evm-linking/UnlinkEvmConfirmationContent'
import LogoutContent from './contents/LogoutContent'
import NotificationContent from './contents/notifications/NotificationContent'
import PushNotificationContent from './contents/notifications/PushNotificationContent'
import TelegramNotificationContent from './contents/notifications/TelegramNotificationContent'
import PrivateKeyContent from './contents/PrivateKeyContent'
import ShareSessionContent from './contents/ShareSessionContent'
Expand All @@ -31,6 +32,7 @@ const modalContents: {
'evm-address-linked': CommonEvmAddressLinked,
notifications: NotificationContent,
'telegram-notifications': TelegramNotificationContent,
'push-notifications': PushNotificationContent,
}

export default function ProfileModal({
Expand Down Expand Up @@ -118,6 +120,11 @@ export default function ProfileModal({
desc: 'Connect your account to our Telegram bot to receive notifications from Grill.',
withBackButton: 'notifications',
},
'push-notifications': {
title: '🔔 Push Notifications',
desc: 'Enable Push Notifications on your browser to receive direct updates from Grill.',
withBackButton: 'notifications',
},
}

const { title, desc, withBackButton, withoutDefaultPadding, withFooter } =
Expand Down
20 changes: 19 additions & 1 deletion src/components/auth/ProfileModal/contents/LogoutContent.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
import Button from '@/components/Button'
import { useLinkFcm } from '@/services/api/notifications/mutation'
import { useSendEvent } from '@/stores/analytics'
import { useMyAccount } from '@/stores/my-account'
import { ContentProps } from '../types'
import { fcmPushNotificationStorage } from './notifications/PushNotificationContent'

function LogoutContent({ setCurrentState }: ContentProps) {
const { address } = useMyAccount()
const logout = useMyAccount((state) => state.logout)
const sendEvent = useSendEvent()

const { mutate: linkFcm, isLoading } = useLinkFcm({
onSuccess: () => fcmPushNotificationStorage.remove(),
})

const onShowPrivateKeyClick = () => {
setCurrentState('private-key')
}
const onLogoutClick = () => {
sendEvent('account_logout')
logout()

const fcmToken = fcmPushNotificationStorage.get()

if (fcmToken && address) {
linkFcm({ address, fcmToken, action: 'unlink' })
}
}

return (
<div className='mt-4 flex flex-col gap-4'>
<Button size='lg' onClick={onShowPrivateKeyClick}>
No, show me my Grill secret key
</Button>
<Button size='lg' onClick={onLogoutClick} variant='primaryOutline'>
<Button
isLoading={isLoading}
size='lg'
onClick={onLogoutClick}
variant='primaryOutline'
>
Yes, log out
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ export default function NotificationContent({
address,
setCurrentState,
}: ContentProps) {
const pwa = useFirstVisitNotification('pwa-notification')
const telegram = useFirstVisitNotification('telegram-notification')
const { data: linkedAccounts } = getLinkedTelegramAccountsQuery.useQuery({
address,
})
const { showNotification, closeNotification } = useFirstVisitNotification(
'telegram-notification'
)

return (
<MenuList
Expand All @@ -30,21 +29,29 @@ export default function NotificationContent({
<span className='flex items-center gap-2'>
<span>Telegram Bot</span>
{!!linkedAccounts?.length && <Notice size='sm'>Enabled</Notice>}
{showNotification && <DotBlinkingNotification />}
{telegram.showNotification && <DotBlinkingNotification />}
</span>
),
iconClassName: cx('text-[#A3ACBE]'),
icon: FaTelegram,
onClick: () => {
closeNotification()
telegram.closeNotification()
setCurrentState('telegram-notifications')
},
},
{
text: <SoonMenu text='Push Notifications' />,
text: (
<span className='flex items-center gap-2'>
<span>Push Notifications</span>
{pwa.showNotification && <DotBlinkingNotification />}
</span>
),
iconClassName: cx('text-[#A3ACBE]'),
icon: BellIcon,
disabled: true,
onClick: () => {
pwa.closeNotification()
setCurrentState('push-notifications')
},
},
{
text: <SoonMenu text='Email Notifications' />,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import Button from '@/components/Button'
import { useLinkFcm } from '@/services/api/notifications/mutation'
import { getMessageToken } from '@/services/firebase/messaging'
import { LocalStorage } from '@/utils/storage'
import { useEffect, useState } from 'react'
import { ContentProps } from '../../types'

const FCM_PUSH_NOTIFICATION_STORAGE_KEY = 'push-notification-fcm-token'
export const fcmPushNotificationStorage = new LocalStorage(
() => FCM_PUSH_NOTIFICATION_STORAGE_KEY
)

export default function PushNotificationContent(props: ContentProps) {
const isNotificationNotSupported = typeof Notification === 'undefined'

const [isRegistered, setIsRegistered] = useState(false)

useEffect(() => {
const storedFcmToken = fcmPushNotificationStorage.get()
setIsRegistered(!!storedFcmToken)
}, [isRegistered])

if (isNotificationNotSupported) {
return (
<Button disabled size='lg'>
Unsupported Browser Notifications
</Button>
)
}

const permission = Notification.permission
if (permission === 'granted' && isRegistered) {
return (
<DisableNotificationButton setIsRegistered={setIsRegistered} {...props} />
)
}

return (
<EnableNotificationButton setIsRegistered={setIsRegistered} {...props} />
)
}

type NotificationButtonProps = ContentProps & {
setIsRegistered: (v: boolean) => void
}

function DisableNotificationButton({
address,
setIsRegistered,
}: NotificationButtonProps) {
const [isGettingToken, setIsGettingToken] = useState(false)

const { mutate: unlinkFcm, isLoading: isUnlinking } = useLinkFcm({
onSuccess: (data) => {
if (!data) throw new Error('Error in disabling notification request')

// FCM Token Disabled.
fcmPushNotificationStorage.remove()
setIsRegistered(false)
},
})

const isLoading = isUnlinking || isGettingToken

const handleClickDisable = async () => {
if (!address) return
setIsGettingToken(true)
const fcmToken = await getMessageToken()
setIsGettingToken(false)
if (!fcmToken) return

unlinkFcm({ address, fcmToken, action: 'unlink' })
}

return (
<Button size='lg' onClick={handleClickDisable} isLoading={isLoading}>
Disable Notifications
</Button>
)
}

function EnableNotificationButton({
address,
setIsRegistered,
}: NotificationButtonProps) {
const [isGettingToken, setIsGettingToken] = useState(false)
const [fcmToken, setFcmToken] = useState<string | undefined>()

const { mutate: linkFcm, isLoading: isLinking } = useLinkFcm({
onSuccess: (data) => {
// FCM Token Enabled.
if (fcmToken) {
fcmPushNotificationStorage.set(fcmToken)
setIsRegistered(true)
}
},
})

const isLoading = isLinking || isGettingToken

const handleClickEnable = async () => {
if (!address) return
setIsGettingToken(true)
const fcmToken = await getMessageToken()
setIsGettingToken(false)
console.log('FCM Token', fcmToken)
if (!fcmToken) return

setFcmToken(fcmToken)
linkFcm({ address, fcmToken, action: 'link' })
}

return (
<Button size='lg' onClick={handleClickEnable} isLoading={isLoading}>
Enable Notifications
</Button>
)
}
Loading

0 comments on commit 5386527

Please sign in to comment.