diff --git a/app/components/notifications/bulletins.tsx b/app/components/notifications/bulletins.tsx index 55cb9f6122..c12c9ba2bc 100644 --- a/app/components/notifications/bulletins.tsx +++ b/app/components/notifications/bulletins.tsx @@ -1,65 +1,26 @@ import { Linking } from "react-native" -import { gql } from "@apollo/client" import { useNotifications } from "." import { NotificationCardUI } from "./notification-card-ui" import { BulletinsDocument, - useBulletinsQuery, + BulletinsQuery, useStatefulNotificationAcknowledgeMutation, } from "@app/graphql/generated" import { BLINK_DEEP_LINK_PREFIX } from "@app/config" -gql` - query Bulletins($first: Int!, $after: String) { - me { - unacknowledgedStatefulNotificationsWithBulletinEnabled( - first: $first - after: $after - ) { - pageInfo { - endCursor - hasNextPage - hasPreviousPage - startCursor - } - edges { - node { - id - title - body - createdAt - acknowledgedAt - bulletinEnabled - action { - ... on OpenDeepLinkAction { - deepLink - } - ... on OpenExternalLinkAction { - url - } - } - } - cursor - } - } - } - } -` +type Props = { + loading: boolean + bulletins: BulletinsQuery | undefined +} -export const BulletinsCard: React.FC = () => { +export const BulletinsCard: React.FC = ({ loading, bulletins }) => { const { cardInfo } = useNotifications() const [ack, { loading: ackLoading }] = useStatefulNotificationAcknowledgeMutation({ refetchQueries: [BulletinsDocument], }) - const { data: bulletins, loading } = useBulletinsQuery({ - fetchPolicy: "cache-and-network", - variables: { first: 1 }, - pollInterval: 30000, - }) - if (loading) return null if ( diff --git a/app/screens/home-screen/home-screen.tsx b/app/screens/home-screen/home-screen.tsx index ac83dbacb5..7b93b3f1df 100644 --- a/app/screens/home-screen/home-screen.tsx +++ b/app/screens/home-screen/home-screen.tsx @@ -25,6 +25,7 @@ import { TransactionFragment, TxDirection, TxStatus, + useBulletinsQuery, useHasPromptedSetDefaultAccountQuery, useHomeAuthedQuery, useHomeUnauthedQuery, @@ -92,6 +93,41 @@ gql` fractionDigits } } + + query Bulletins($first: Int!, $after: String) { + me { + unacknowledgedStatefulNotificationsWithBulletinEnabled( + first: $first + after: $after + ) { + pageInfo { + endCursor + hasNextPage + hasPreviousPage + startCursor + } + edges { + node { + id + title + body + createdAt + acknowledgedAt + bulletinEnabled + action { + ... on OpenDeepLinkAction { + deepLink + } + ... on OpenExternalLinkAction { + url + } + } + } + cursor + } + } + } + } ` export const HomeScreen: React.FC = () => { @@ -161,6 +197,17 @@ export const HomeScreen: React.FC = () => { nextFetchPolicy: "cache-and-network", }) + // load bulletins on home screen + const { + data: bulletins, + loading: bulletinsLoading, + refetch: refetchBulletins, + } = useBulletinsQuery({ + skip: !isAuthed, + fetchPolicy: "cache-and-network", + variables: { first: 1 }, + }) + const loading = loadingAuthed || loadingPrice || loadingUnauthed || loadingSettings const refetch = React.useCallback(() => { @@ -168,8 +215,9 @@ export const HomeScreen: React.FC = () => { refetchRealtimePrice() refetchAuthed() refetchUnauthed() + refetchBulletins() } - }, [isAuthed, refetchAuthed, refetchRealtimePrice, refetchUnauthed]) + }, [isAuthed, refetchAuthed, refetchBulletins, refetchRealtimePrice, refetchUnauthed]) const pendingIncomingTransactions = dataAuthed?.me?.defaultAccount?.pendingIncomingTransactions @@ -382,7 +430,7 @@ export const HomeScreen: React.FC = () => { ))} - + {recentTransactionsData && ( <>