diff --git a/examples/storybook/src/stories/citizen-claim-widget/CitizenClaimWidgetQA.stories.tsx b/examples/storybook/src/stories/citizen-claim-widget/CitizenClaimWidgetQA.stories.tsx
index dfd38950..c26bbcaf 100644
--- a/examples/storybook/src/stories/citizen-claim-widget/CitizenClaimWidgetQA.stories.tsx
+++ b/examples/storybook/src/stories/citizen-claim-widget/CitizenClaimWidgetQA.stories.tsx
@@ -3,6 +3,7 @@ import { CitizenClaimWidget } from '@goodwidget/citizen-claim-widget'
import {
CustodialClaimExecutionClaimAllStory,
CustodialLocalFixtureStory,
+ MockClaimExecutionWidgetStory,
} from '../helpers/citizenClaimWidgetStories'
import type { NextTaskContent } from '@goodwidget/ui'
import { BRAND_PRESET_OPTIONS, brandPresetOverrides, type BrandPreset } from '../helpers/themeOverridePresets'
@@ -51,7 +52,7 @@ export const CustodialExecutionClaimAllContract: Story = {
const nextTaskContent: NextTaskContent = {
title: 'Stake your G$ and earn',
description: 'Put your claimed G$ to work by staking it for rewards.',
- ctaLabel: 'Open Proposal',
+ ctaLabel: 'Explore staking',
ctaTarget: 'https://gooddollar.org/stake',
imageUrl: 'https://placehold.co/96x96',
contentId: 'stake-prompt',
@@ -82,3 +83,75 @@ export const CustodialLocalFixtureWithNextTask: Story = {
/>
),
}
+
+const mockNextTaskProps = {
+ nextTaskContent,
+ nextTaskResolveNavigation: (ctaTarget: string) => {
+ if (typeof document !== 'undefined') {
+ document.body.dataset.nextTaskNavigated = ctaTarget
+ }
+ console.info('[next-task] host navigates to', ctaTarget)
+ },
+ onNextTaskShown: (payload: { contentId?: string }) => {
+ if (typeof document !== 'undefined') {
+ document.body.dataset.nextTaskLastEvent = `shown:${payload.contentId ?? ''}`
+ }
+ console.info('[next-task] shown', payload)
+ },
+ onNextTaskClicked: (payload: { ctaTarget: string }) => {
+ if (typeof document !== 'undefined') {
+ document.body.dataset.nextTaskLastEvent = `clicked:${payload.ctaTarget}`
+ }
+ console.info('[next-task] clicked', payload)
+ },
+ onNextTaskDismissed: (payload: { reason: string }) => {
+ if (typeof document !== 'undefined') {
+ document.body.dataset.nextTaskLastEvent = `dismissed:${payload.reason}`
+ }
+ console.info('[next-task] dismissed', payload)
+ },
+}
+
+export const MockClaimExecutionWithNextTask: Story = {
+ render: () => ,
+}
+
+export const MockClaimExecutionPartialSuccessWithNextTask: Story = {
+ render: () => ,
+}
+
+export const MockClaimExecutionSingleChainWithNextTask: Story = {
+ render: () => (
+
+ ),
+}
+
+export const MockClaimExecutionSingleClaimFallbackWithNextTask: Story = {
+ render: () => (
+
+ ),
+}
+
+export const MockClaimExecutionAllFailsWithNextTask: Story = {
+ render: () => (
+
+ ),
+}
+
+export const MockClaimExecutionWithoutNextTask: Story = {
+ render: () => ,
+}
diff --git a/examples/storybook/src/stories/design-system/NextTaskModal.stories.tsx b/examples/storybook/src/stories/design-system/NextTaskModal.stories.tsx
index b3888871..379d0d6c 100644
--- a/examples/storybook/src/stories/design-system/NextTaskModal.stories.tsx
+++ b/examples/storybook/src/stories/design-system/NextTaskModal.stories.tsx
@@ -13,7 +13,7 @@
* - A handler that throws or rejects shows an error toast; the modal still closes.
* Error toasts need a mounted ``, which every story here mounts.
*/
-import React, { useState } from 'react'
+import React, { useRef, useState } from 'react'
import type { Meta, StoryObj } from '@storybook/react'
import { expect, within, userEvent, waitFor } from '@storybook/test'
import { NextTaskModal, ToastContainer, Card, Heading, Text, Button, ButtonText } from '@goodwidget/ui'
@@ -29,12 +29,15 @@ const meta: Meta = {
export default meta
type Story = StoryObj
+const SAMPLE_IMAGE_URL =
+ 'data:image/svg+xml;utf8,'
+
const contentWithImage: NextTaskContent = {
title: 'Stake your G$ and earn',
description: 'Put your claimed G$ to work by staking it for rewards.',
- ctaLabel: 'Open Proposal',
+ ctaLabel: 'Explore staking',
ctaTarget: 'https://gooddollar.org/stake',
- imageUrl: 'https://placehold.co/96x96',
+ imageUrl: SAMPLE_IMAGE_URL,
contentId: 'stake-prompt',
}
@@ -67,16 +70,20 @@ function ControlledHarness({
}) {
const [open, setOpen] = useState(false)
const [lastEvent, setLastEvent] = useState('none')
+ const [clickCount, setClickCount] = useState(0)
return (
-
- Next task
- The host controls `open`; the modal reports what the user did.
-
- {lastEvent}
- {open ? 'open' : 'closed'}
+ <>
+
+ Next task
+ The host controls `open`; the modal reports what the user did.
+
+ {lastEvent}
+ {open ? 'open' : 'closed'}
+ {String(clickCount)}
+
setOpen(false)}
resolveNavigation={resolveNavigation}
onShown={(payload) => setLastEvent(`shown:${payload.contentId ?? ''}`)}
- onClicked={(payload) => setLastEvent(`clicked:${payload.ctaTarget}`)}
+ onClicked={(payload) => {
+ setClickCount((count) => count + 1)
+ setLastEvent(`clicked:${payload.ctaTarget}`)
+ }}
onDismissed={(payload) => setLastEvent(`dismissed:${payload.reason}`)}
- statusLabel="Claim completed"
/>
-
+ >
)
}
@@ -198,7 +207,7 @@ export const ExternalLink: Story = {
const restoreNavigation = blockLinkNavigation()
try {
const card = await openAndGetCard(canvasElement, 'NextTaskModal-external-link')
- const cta = await within(document.body).findByRole('link', { name: 'Open Proposal' })
+ const cta = await within(document.body).findByRole('link', { name: 'Explore staking' })
await expect(cta).toHaveAttribute('href', contentWithImage.ctaTarget)
await expect(within(card).queryByRole('link')).not.toBeInTheDocument()
await waitFor(() => userEvent.click(cta))
@@ -233,8 +242,8 @@ export const HostNavigation: Story = {
play: async ({ canvasElement }) => {
delete document.body.dataset.nextTaskNavigated
await openAndGetCard(canvasElement, 'NextTaskModal-host-nav')
- await expect(within(document.body).queryByRole('link', { name: 'Open Proposal' })).not.toBeInTheDocument()
- const cta = await within(document.body).findByRole('button', { name: 'Open Proposal' })
+ await expect(within(document.body).queryByRole('link', { name: 'Explore staking' })).not.toBeInTheDocument()
+ const cta = await within(document.body).findByRole('button', { name: 'Explore staking' })
await waitFor(() => userEvent.click(cta))
await waitFor(() => expect(document.body.dataset.nextTaskNavigated).toBe(contentWithImage.ctaTarget))
await expect(within(canvasElement).getByTestId('NextTaskModal-last-event')).toHaveTextContent(
@@ -244,7 +253,38 @@ export const HostNavigation: Story = {
},
}
-/** A synchronous handler that throws shows an error toast; the sheet still closes. */
+const contentWithCustomCopy: NextTaskContent = {
+ ...contentWithImage,
+ headline: 'Custom Headline Step',
+ supportingCopy: 'Custom supporting message for active community members.',
+ recommendedLabel: 'FEATURED',
+ skipLabel: 'Not now, thanks',
+ statusLabel: 'Verification complete',
+}
+
+const contentWithRealisticLongCopy: NextTaskContent = {
+ title: 'Participate in the GoodDollar Community Expansion & Micro-Grants Initiative',
+ description:
+ 'Read through the extensive proposal detailing the upcoming treasury distribution to regional ambassadors and liquidity pools across multiple EVM ecosystems, cast your vote, and join our active discussion forums.',
+ ctaLabel: 'Read and vote on Snapshot',
+ ctaTarget: 'https://gooddollar.org/governance/proposal-123',
+ imageUrl: 'https://placehold.co/96x96',
+ contentId: 'governance-long-copy',
+ headline: 'Support Community Expansion Proposals',
+ supportingCopy:
+ 'Every citizen vote shapes the next generation of financial inclusion. Review all active proposals before making your choice.',
+ recommendedLabel: 'ACTIVE VOTE',
+ skipLabel: 'Remind me tomorrow',
+ statusLabel: 'Claim successfully processed',
+}
+
+const contentWithRealisticLongCopyWithoutImage: NextTaskContent = {
+ ...contentWithRealisticLongCopy,
+ imageUrl: undefined,
+ contentId: 'governance-long-copy-no-image',
+}
+
+/** A synchronous handler that throws shows an error toast; the sheet stays open so the user can retry or dismiss. */
export const NavigationError: Story = {
render: () => (
{
await openAndGetCard(canvasElement, 'NextTaskModal-nav-error')
- const cta = await within(document.body).findByRole('button', { name: 'Open Proposal' })
+ const cta = await within(document.body).findByRole('button', { name: 'Explore staking' })
await waitFor(() => userEvent.click(cta))
- await expect(
- await within(document.body).findByText('Could not open this link. Please try again.'),
- ).toBeInTheDocument()
- await expect(within(canvasElement).getByTestId('NextTaskModal-open-state')).toHaveTextContent('closed')
+ const toasts = await within(document.body).findAllByText('Could not open this link. Please try again.')
+ await expect(toasts[0]).toBeInTheDocument()
+ await expect(within(canvasElement).getByTestId('NextTaskModal-open-state')).toHaveTextContent('open')
},
}
-/** An async handler that rejects shows the same error toast as a synchronous throw. */
+/** An async handler that rejects shows the same error toast as a synchronous throw, and keeps the drawer open. */
export const NavigationRejected: Story = {
render: () => (
{
await openAndGetCard(canvasElement, 'NextTaskModal-nav-rejected')
- const cta = await within(document.body).findByRole('button', { name: 'Open Proposal' })
+ const cta = await within(document.body).findByRole('button', { name: 'Explore staking' })
await waitFor(() => userEvent.click(cta))
- await expect(
- await within(document.body).findByText('Could not open this link. Please try again.'),
- ).toBeInTheDocument()
- await expect(within(canvasElement).getByTestId('NextTaskModal-open-state')).toHaveTextContent('closed')
+ const toasts = await within(document.body).findAllByText('Could not open this link. Please try again.')
+ await expect(toasts[0]).toBeInTheDocument()
+ await expect(within(canvasElement).getByTestId('NextTaskModal-open-state')).toHaveTextContent('open')
},
}
-/** No handler and a non-http(s) `ctaTarget`: no Anchor is rendered; pressing shows an error toast. */
+/** No handler and a non-http(s) `ctaTarget`: no Anchor is rendered; pressing shows an error toast and keeps the drawer open. */
export const RejectedUrl: Story = {
render: () => ,
play: async ({ canvasElement }) => {
@@ -296,6 +334,183 @@ export const RejectedUrl: Story = {
await waitFor(() => userEvent.click(cta))
await expect(await within(document.body).findByText('This link cannot be opened.')).toBeInTheDocument()
await expect(within(canvasElement).getByTestId('NextTaskModal-last-event')).not.toHaveTextContent('clicked')
- await expect(within(canvasElement).getByTestId('NextTaskModal-open-state')).toHaveTextContent('closed')
+ await expect(within(canvasElement).getByTestId('NextTaskModal-open-state')).toHaveTextContent('open')
},
}
+
+/** Configurable copy overrides: custom headline, supporting copy, labels and status. */
+export const CustomCopy: Story = {
+ render: () => ,
+ play: async ({ canvasElement }) => {
+ await openAndGetCard(canvasElement, 'NextTaskModal-custom-copy')
+ await expect(within(document.body).getByText('Custom Headline Step')).toBeInTheDocument()
+ await expect(within(document.body).getByText('Custom supporting message for active community members.')).toBeInTheDocument()
+ await expect(within(document.body).getByText('FEATURED')).toBeInTheDocument()
+ await expect(within(document.body).getByText('Not now, thanks')).toBeInTheDocument()
+ await expect(within(document.body).getByText('Verification complete')).toBeInTheDocument()
+ },
+}
+
+/** Realistic long copy with inner scrolling for responsive testing. */
+export const RealisticLongCopy: Story = {
+ render: () => ,
+}
+
+/** Realistic long copy without an image slot for responsive testing. */
+export const RealisticLongCopyWithoutImage: Story = {
+ render: () => (
+
+ ),
+}
+
+/** A slow handler that fails first time and succeeds second time, for testing double-press guard and retry. */
+export const NavigationPendingAndRetry: Story = {
+ render: () => {
+ let callCount = 0
+ let shouldFail = true
+ return (
+ {
+ callCount++
+ if (typeof document !== 'undefined') {
+ document.body.dataset.nextTaskCallCount = String(callCount)
+ }
+ if (shouldFail) {
+ shouldFail = false
+ await new Promise((resolve) => setTimeout(resolve, 200))
+ throw new Error('temporary failure')
+ }
+ await new Promise((resolve) => setTimeout(resolve, 200))
+ }}
+ />
+ )
+ },
+}
+
+interface DeferredNavigationAttempt {
+ resolve: () => void
+ reject: (error: Error) => void
+}
+
+function StaleNavigationHarness() {
+ const [mounted, setMounted] = useState(true)
+ const [open, setOpen] = useState(false)
+ const [lastEvent, setLastEvent] = useState('none')
+ const [callCount, setCallCount] = useState(0)
+ const [settledCount, setSettledCount] = useState(0)
+ const [closeCount, setCloseCount] = useState(0)
+ const pendingAttemptsRef = useRef([])
+
+ const settleOldestAttempt = (outcome: 'resolve' | 'reject') => {
+ const oldestAttempt = pendingAttemptsRef.current.shift()
+ if (!oldestAttempt) return
+ if (outcome === 'resolve') {
+ oldestAttempt.resolve()
+ } else {
+ oldestAttempt.reject(new Error('stale failure'))
+ }
+ // Schedule state update on the next macrotask so all async continuations in NextTaskModal settle first.
+ setTimeout(() => setSettledCount((count) => count + 1), 0)
+ }
+
+ return (
+
+ Stale navigation harness
+
+
+
+
+
+ {lastEvent}
+ {open ? 'open' : 'closed'}
+ {String(callCount)}
+ {String(settledCount)}
+ {String(closeCount)}
+ {mounted ? (
+ {
+ setCloseCount((count) => count + 1)
+ setOpen(false)
+ }}
+ resolveNavigation={() => {
+ setCallCount((count) => count + 1)
+ return new Promise((resolve, reject) => {
+ pendingAttemptsRef.current.push({ resolve, reject })
+ })
+ }}
+ onShown={(payload) => setLastEvent(`shown:${payload.contentId ?? ''}`)}
+ onClicked={(payload) => setLastEvent(`clicked:${payload.ctaTarget}`)}
+ onDismissed={(payload) => setLastEvent(`dismissed:${payload.reason}`)}
+ />
+ ) : null}
+
+
+ )
+}
+
+/** Controlled close/reopen while an earlier navigation promise is still pending ignores stale outcomes. */
+export const StaleNavigationIgnoredAcrossReopen: Story = {
+ render: () => ,
+}
+
+function ThrowingOnCloseHarness() {
+ const [open, setOpen] = useState(false)
+ const [callCount, setCallCount] = useState(0)
+ const [closeAttempts, setCloseAttempts] = useState(0)
+
+ return (
+
+ Throwing onClose harness
+
+ {open ? 'open' : 'closed'}
+ {String(callCount)}
+ {String(closeAttempts)}
+ {
+ setCloseAttempts((count) => count + 1)
+ throw new Error('host onClose failure')
+ }}
+ resolveNavigation={async () => {
+ setCallCount((count) => count + 1)
+ }}
+ />
+
+
+ )
+}
+
+/** A host onClose failure after navigation succeeds does not trigger the navigation error toast or reset the guard. */
+export const OnCloseThrowAfterNavigationSuccess: Story = {
+ render: () => ,
+}
diff --git a/examples/storybook/src/stories/helpers/citizenClaimWidgetStories.tsx b/examples/storybook/src/stories/helpers/citizenClaimWidgetStories.tsx
index e0a34427..ef402556 100644
--- a/examples/storybook/src/stories/helpers/citizenClaimWidgetStories.tsx
+++ b/examples/storybook/src/stories/helpers/citizenClaimWidgetStories.tsx
@@ -15,14 +15,48 @@ import { createCustodialEip1193Provider } from '../../fixtures/custodialEip1193'
const MOCK_CLAIM_ALL_ACCOUNT = '0x329377cbeeF39f01b0Ea04B80465c9eB47D3ED1'
-function createMockClaimExecutionClientBundle(chainId: number, shouldFail: boolean) {
+export function createMockClaimExecutionClientBundle(
+ chainId: number,
+ shouldFail: boolean,
+ options: { emptyClaimables?: boolean } = {},
+) {
+ const { emptyClaimables = false } = options
+ // Distinguish loadClaimablesByChain()'s checkEntitlement read (preceded by a connected
+ // getWhitelistedRoot call synchronously before getDailyStats) from getWalletClaimStatus()
+ // and ClaimSDK.claim(), so claimablesByChain stays empty while single-chain claim() can succeed.
+ let hasConnectedRootBeforeStats = false
+ let pendingEmptyClaimableChecks = 0
+
return {
publicClient: {
- readContract: async ({ functionName }: { functionName: string }) => {
+ readContract: async ({
+ functionName,
+ args,
+ }: {
+ functionName: string
+ args?: unknown[]
+ }) => {
if (functionName === 'getWhitelistedRoot') {
+ hasConnectedRootBeforeStats = true
return '0x0000000000000000000000000000000000000001'
}
+ if (functionName === 'getDailyStats') {
+ if (hasConnectedRootBeforeStats) {
+ hasConnectedRootBeforeStats = false
+ pendingEmptyClaimableChecks += 1
+ }
+ return 0n
+ }
if (functionName === 'checkEntitlement') {
+ if (emptyClaimables) {
+ if (!args || args.length === 0) {
+ return 0n
+ }
+ if (pendingEmptyClaimableChecks > 0) {
+ pendingEmptyClaimableChecks -= 1
+ return 0n
+ }
+ }
return 1_000000000000000000n
}
if (functionName === 'canTop') {
@@ -269,3 +303,51 @@ export function CustodialClaimExecutionClaimAllStory() {
)
}
+
+export function MockClaimExecutionWidgetStory({
+ nextTaskProps,
+ singleChain = false,
+ allFail = false,
+ partialSuccess = false,
+ emptyClaimables = false,
+}: {
+ nextTaskProps?: CitizenClaimNextTaskProps
+ singleChain?: boolean
+ allFail?: boolean
+ partialSuccess?: boolean
+ emptyClaimables?: boolean
+} = {}) {
+ const claimExecution = useMemo(() => {
+ if (singleChain) {
+ return createCitizenClaimWidgetCustodialExecution({
+ 42220: createMockClaimExecutionClientBundle(42220, allFail, { emptyClaimables }),
+ })
+ }
+ if (partialSuccess) {
+ return createCitizenClaimWidgetCustodialExecution({
+ 42220: createMockClaimExecutionClientBundle(42220, false),
+ 122: createMockClaimExecutionClientBundle(122, true),
+ })
+ }
+ return createCitizenClaimWidgetCustodialExecution({
+ 42220: createMockClaimExecutionClientBundle(42220, allFail, { emptyClaimables }),
+ 122: createMockClaimExecutionClientBundle(122, allFail, { emptyClaimables }),
+ })
+ }, [singleChain, allFail, partialSuccess, emptyClaimables])
+
+ const provider = useMemo(() => {
+ return createCustodialEip1193Provider()
+ }, [])
+
+ return (
+
+ )
+}
diff --git a/packages/citizen-claim-widget/src/CitizenClaimWidget.tsx b/packages/citizen-claim-widget/src/CitizenClaimWidget.tsx
index e3631edd..82f1bac7 100644
--- a/packages/citizen-claim-widget/src/CitizenClaimWidget.tsx
+++ b/packages/citizen-claim-widget/src/CitizenClaimWidget.tsx
@@ -15,6 +15,7 @@ import {
Spinner,
Separator,
NextTaskModal,
+ NEXT_TASK_STATUS_LABEL,
ToastContainer,
createToast,
updateToast,
@@ -608,7 +609,7 @@ function CitizenClaimInner({
onShown={onNextTaskShown}
onClicked={onNextTaskClicked}
onDismissed={onNextTaskDismissed}
- statusLabel="Claim completed"
+ statusLabel={NEXT_TASK_STATUS_LABEL}
/>
)
diff --git a/packages/ui/src/components/Drawer.tsx b/packages/ui/src/components/Drawer.tsx
index f8832e5e..9a5eebdb 100644
--- a/packages/ui/src/components/Drawer.tsx
+++ b/packages/ui/src/components/Drawer.tsx
@@ -72,7 +72,7 @@ interface DrawerProps {
open: boolean
onClose: () => void
children?: ReactNode
- height?: 'half' | 'full'
+ height?: 'half' | 'full' | 'fit'
/**
* Hides the corner close button. Only for a drawer whose content already
* renders its own — dismissing by pressing outside is a thin target on a
@@ -90,7 +90,8 @@ export function Drawer({
hideCloseButton = false,
}: DrawerProps) {
const theme = useTheme()
- const snapPoints = height === 'half' ? [50] : [80]
+ const snapPoints = height === 'fit' ? undefined : height === 'half' ? [50] : [80]
+ const snapPointsMode = height === 'fit' ? 'fit' : 'percent'
return (
-
-
+
+ {height !== 'fit' && }
{!hideCloseButton && (
`.
*/
resolveNavigation?: (ctaTarget: string) => void | Promise
onShown?: (payload: { contentId?: string }) => void
onClicked?: (payload: { ctaTarget: string }) => void
onDismissed?: (payload: { reason: NextTaskDismissReason }) => void
- /** Pill shown at the top of the sheet, e.g. "Claim completed". Hidden when omitted. */
+ /**
+ * Pill shown at the top of the sheet, e.g. "Claim completed".
+ * If `content.statusLabel` is also set, `content.statusLabel` takes precedence over this prop.
+ * If both are omitted, defaults to `NEXT_TASK_STATUS_LABEL`.
+ */
statusLabel?: string
/** Applied to the rendered card root, for Storybook/Playwright targeting. */
testID?: string
@@ -83,17 +99,33 @@ export function NextTaskModal({
testID,
}: NextTaskModalProps) {
const isVisible = open && Boolean(content)
- // Guards so exactly one `onShown` fires per open and one terminal action (CTA or dismiss) per open.
+ // Guards so exactly one `onShown` fires per open and one `onClicked` per open intent.
const hasReportedShownRef = useRef(false)
- const hasResolvedRef = useRef(false)
+ const hasReportedClickedRef = useRef(false)
+ const isNavigatingRef = useRef(false)
+ const hasClosedRef = useRef(false)
+ // Tracks the active visibility/navigation session so stale async completions after close or unmount are ignored.
+ const navigationGenerationRef = useRef(0)
useEffect(() => {
if (!isVisible) {
+ navigationGenerationRef.current += 1
hasReportedShownRef.current = false
- hasResolvedRef.current = false
- return
+ hasReportedClickedRef.current = false
+ isNavigatingRef.current = false
+ hasClosedRef.current = false
}
- if (hasReportedShownRef.current) return
+ }, [isVisible])
+
+ useEffect(
+ () => () => {
+ navigationGenerationRef.current += 1
+ },
+ [],
+ )
+
+ useEffect(() => {
+ if (!isVisible || hasReportedShownRef.current) return
hasReportedShownRef.current = true
invokeHostCallbackSafely('onShown', onShown, { contentId: content?.contentId })
}, [isVisible, onShown, content?.contentId])
@@ -105,8 +137,10 @@ export function NextTaskModal({
const dismissWithReason = useCallback(
(reason: NextTaskDismissReason) => {
- if (hasResolvedRef.current) return
- hasResolvedRef.current = true
+ if (hasClosedRef.current) return
+ hasClosedRef.current = true
+ isNavigatingRef.current = false
+ navigationGenerationRef.current += 1
invokeHostCallbackSafely('onDismissed', onDismissed, { reason })
onClose()
},
@@ -114,90 +148,160 @@ export function NextTaskModal({
)
// Host navigation: the host owns the destination; a throw or rejection is shown, never swallowed.
+ // The drawer stays open so the user can retry or dismiss. Dismissal remains unblocked during pending navigation.
const handleHostNavigationPress = useCallback(async () => {
- if (!content || !resolveNavigation || hasResolvedRef.current) return
- hasResolvedRef.current = true
- invokeHostCallbackSafely('onClicked', onClicked, { ctaTarget: content.ctaTarget })
+ if (!content || !resolveNavigation || hasClosedRef.current || isNavigatingRef.current) return
+ isNavigatingRef.current = true
+ const attemptGeneration = ++navigationGenerationRef.current
+
+ if (!hasReportedClickedRef.current) {
+ hasReportedClickedRef.current = true
+ invokeHostCallbackSafely('onClicked', onClicked, { ctaTarget: content.ctaTarget })
+ }
+
try {
await resolveNavigation(content.ctaTarget)
} catch {
+ if (attemptGeneration !== navigationGenerationRef.current) return
+ isNavigatingRef.current = false
createToast({ message: NAVIGATION_FAILED_TOAST_MESSAGE, status: 'error' })
+ return
}
+
+ if (attemptGeneration !== navigationGenerationRef.current) return
+ isNavigatingRef.current = false
+ hasClosedRef.current = true
onClose()
}, [content, resolveNavigation, onClicked, onClose])
// The Anchor opens the link itself; this only reports the click and closes the sheet.
const handleAnchorPress = useCallback(() => {
- if (!content || hasResolvedRef.current) return
- hasResolvedRef.current = true
- invokeHostCallbackSafely('onClicked', onClicked, { ctaTarget: content.ctaTarget })
+ if (!content || hasClosedRef.current) return
+ hasClosedRef.current = true
+ if (!hasReportedClickedRef.current) {
+ hasReportedClickedRef.current = true
+ invokeHostCallbackSafely('onClicked', onClicked, { ctaTarget: content.ctaTarget })
+ }
onClose()
}, [content, onClicked, onClose])
// A URL that failed the http(s) check is never rendered as an Anchor, so nothing navigates.
+ // The drawer stays open on error so the user can inspect or dismiss.
const handleRejectedUrlPress = useCallback(() => {
- if (hasResolvedRef.current) return
- hasResolvedRef.current = true
createToast({ message: REJECTED_URL_TOAST_MESSAGE, status: 'error' })
- onClose()
- }, [onClose])
+ }, [])
if (!content) return null
const isCtaTargetOpenableAsLink = !resolveNavigation && isAllowedExternalCtaUrl(content.ctaTarget)
const handleButtonCtaPress = resolveNavigation ? handleHostNavigationPress : handleRejectedUrlPress
- // `height="full"` (80% snap point): the half-height drawer clips the CTA on a 375x667 phone.
+ const effectiveStatusLabel = content.statusLabel ?? statusLabel ?? NEXT_TASK_STATUS_LABEL
+ const effectiveHeadline = content.headline ?? NEXT_TASK_HEADLINE
+ const effectiveSupportingCopy = content.supportingCopy ?? NEXT_TASK_SUPPORTING_COPY
+ const effectiveRecommendedLabel = content.recommendedLabel ?? NEXT_TASK_RECOMMENDED_LABEL
+ const effectiveSkipLabel = content.skipLabel ?? NEXT_TASK_SKIP_LABEL
+
+ // `height="fit"`: the sheet height follows its content up to the viewport cap, with inner scrolling for long copy or landscape.
+ // Sheet.ScrollView ensures long copy scrolls smoothly on native platforms as well as web.
return (
- dismissWithReason('overlay')}>
-
- {statusLabel ? (
-
-
- {statusLabel}
-
- ) : null}
-
- {NEXT_TASK_HEADLINE}
-
-
- {NEXT_TASK_SUPPORTING_COPY}
-
-
- {content.imageUrl ? (
-
-
-
- ) : null}
-
-
- {NEXT_TASK_RECOMMENDED_LABEL}
-
- {content.title}
-
- {content.description}
+ dismissWithReason('overlay')}>
+
+
+
+ {effectiveStatusLabel ? (
+
+
+ {effectiveStatusLabel}
+
+ ) : null}
+
+ {effectiveHeadline}
+
+
+ {effectiveSupportingCopy}
-
- {isCtaTargetOpenableAsLink ? (
-
- {content.ctaLabel}
-
- ) : (
-
- )}
-
-
+
+ {content.imageUrl ? (
+
+
+
+ ) : null}
+
+
+ {effectiveRecommendedLabel}
+
+ {content.title}
+
+ {content.description}
+
+
+
+
+ {/*
+ * Note: Anchor wraps Tamagui's Anchor directly rather than through `createComponent`
+ * (so native `onPress` propagates to `Linking.openURL`), and therefore does not
+ * participate in the theme-manifest override chain. The wrapped Button provides
+ * standard themeable styling.
+ */}
+ {isCtaTargetOpenableAsLink ? (
+
+
+
+ ) : (
+
+ )}
+
+
+
+
)
}
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index 6d8027e1..66e4f636 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -72,7 +72,16 @@ export type { ToastStatus, ToastConfig, ToastItem } from './components/Toast'
export { Alert } from './components-test/Alert'
export { Badge, BadgeText } from './components-test/Badge'
export { Drawer } from './components/Drawer'
-export { NextTaskModal } from './components/NextTaskModal'
+export {
+ NextTaskModal,
+ NEXT_TASK_HEADLINE,
+ NEXT_TASK_SUPPORTING_COPY,
+ NEXT_TASK_RECOMMENDED_LABEL,
+ NEXT_TASK_SKIP_LABEL,
+ NEXT_TASK_STATUS_LABEL,
+ NAVIGATION_FAILED_TOAST_MESSAGE,
+ REJECTED_URL_TOAST_MESSAGE,
+} from './components/NextTaskModal'
export type { NextTaskModalProps, NextTaskContent, NextTaskDismissReason } from './components/NextTaskModal'
export { NextTaskCtaCard } from './components/NextTaskCtaCard'
export { PageWizardProvider, PageWizardShell, usePageWizard } from './components/PageWizard'
diff --git a/tests/design-system/smoke.spec.ts b/tests/design-system/smoke.spec.ts
index c26e7522..50527dfa 100644
--- a/tests/design-system/smoke.spec.ts
+++ b/tests/design-system/smoke.spec.ts
@@ -582,16 +582,34 @@ test('NextTaskModal/ShownWithoutImage story renders the sheet without the image
await screenshotStory(page, 'tests/design-system/test-results/story-nexttaskmodal-no-image.png')
})
-// Mobile and desktop viewports: the iframe document is loaded directly so the viewport size is
-// the story's own viewport (the Storybook manager switches layout at small widths).
+test('NextTaskModal renders default fallbacks when optional copy fields are omitted', async ({ page }) => {
+ await gotoStory(page, 'design-system-primitives-nexttaskmodal--shown-without-image')
+ const frame = getStoryFrame(page)
+ const card = frame.getByTestId('NextTaskModal-no-image')
+ await expect(card).toBeVisible()
+
+ // Proves that when headline, supportingCopy, recommendedLabel, skipLabel, and statusLabel
+ // are omitted from content and props, all five fall back to their default constants.
+ await expect(frame.getByText('One good next step')).toBeVisible()
+ await expect(
+ frame.getByText(
+ 'Small actions today create a bigger impact tomorrow. Thanks for being part of GoodDollar.',
+ ),
+ ).toBeVisible()
+ await expect(frame.getByText('RECOMMENDED')).toBeVisible()
+ await expect(frame.getByRole('button', { name: 'Skip for now' })).toBeVisible()
+ await expect(frame.getByText('Claim completed')).toBeVisible()
+})
+
+// Mobile, landscape, and desktop viewports: inner scrolling ensures actions stay reachable across all viewports.
const NEXT_TASK_VIEWPORTS = [
{ label: 'desktop', width: 1280, height: 800 },
- // 375x667 (iPhone SE) is the smallest common phone, so it stresses clipping the most.
{ label: 'mobile', width: 375, height: 667 },
+ { label: 'landscape', width: 667, height: 375 },
]
for (const viewport of NEXT_TASK_VIEWPORTS) {
- test(`NextTaskModal keeps its CTA, skip link and close button fully on screen at ${viewport.width}x${viewport.height} (${viewport.label})`, async ({
+ test(`NextTaskModal keeps its CTA, skip link and close button accessible at ${viewport.width}x${viewport.height} (${viewport.label})`, async ({
page,
}) => {
await page.setViewportSize({ width: viewport.width, height: viewport.height })
@@ -599,14 +617,15 @@ for (const viewport of NEXT_TASK_VIEWPORTS) {
await page.waitForLoadState('networkidle')
const card = page.getByTestId('NextTaskModal-shown')
- const cta = page.getByRole('link', { name: 'Open Proposal' })
+ const cta = page.getByRole('link', { name: 'Explore staking' })
const skipLink = page.getByRole('button', { name: 'Skip for now' })
const closeButton = page.getByRole('button', { name: 'Close' })
for (const control of [cta, skipLink, closeButton]) {
+ await control.scrollIntoViewIfNeeded()
+ await expect(control).toBeInViewport({ ratio: 1 })
await expect(control).toBeVisible()
await expect(control).toBeEnabled()
- await expect(control).toBeInViewport({ ratio: 1 })
}
// The card's own content must not be wider than the viewport.
const cardWidth = await card.evaluate((element) => element.scrollWidth)
@@ -624,8 +643,10 @@ test('NextTaskModal Anchor mode: the CTA is a link to ctaTarget and pressing it
await gotoStory(page, 'design-system-primitives-nexttaskmodal--closed')
const frame = getStoryFrame(page)
await frame.getByTestId('NextTaskModal-open').click()
- const cta = frame.getByRole('link', { name: 'Open Proposal' })
+ const cta = frame.getByRole('link', { name: 'Explore staking' })
await expect(cta).toHaveAttribute('href', NEXT_TASK_CTA_TARGET)
+ await expect(cta.locator('button')).toHaveCount(0)
+ await expect(frame.getByRole('button', { name: 'Explore staking' })).toHaveCount(0)
// Navigation is blocked at the document level (after React's handler) so the test stays on the page.
await frame.locator('body').evaluate((body) => {
body.ownerDocument.addEventListener('click', (event) => {
@@ -644,7 +665,7 @@ test('NextTaskModal host mode: the handler is called with ctaTarget, the sheet c
const frame = getStoryFrame(page)
await expect(frame.getByTestId('NextTaskModal-last-event')).toHaveText(`clicked:${NEXT_TASK_CTA_TARGET}`)
await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
- await expect(frame.getByRole('link', { name: 'Open Proposal' })).toHaveCount(0)
+ await expect(frame.getByRole('link', { name: 'Explore staking' })).toHaveCount(0)
})
const NEXT_TASK_ERROR_TOASTS = [
@@ -666,10 +687,268 @@ const NEXT_TASK_ERROR_TOASTS = [
]
for (const errorCase of NEXT_TASK_ERROR_TOASTS) {
- test(`NextTaskModal shows an error toast and still closes for ${errorCase.description}`, async ({ page }) => {
+ test(`NextTaskModal shows an error toast and keeps drawer open for ${errorCase.description}`, async ({ page }) => {
await gotoStory(page, errorCase.storyId)
const frame = getStoryFrame(page)
await expect(frame.getByText(errorCase.message)).toBeVisible()
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+
+ // Dismiss still works while error is displayed
+ const skipButton = frame.getByRole('button', { name: 'Skip for now' })
+ await skipButton.scrollIntoViewIfNeeded()
+ await skipButton.click()
await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
})
}
+
+test('NextTaskModal CustomCopy story renders configurable copy overrides', async ({ page }) => {
+ await gotoStory(page, 'design-system-primitives-nexttaskmodal--custom-copy')
+ const frame = getStoryFrame(page)
+ await expect(frame.getByText('Custom Headline Step')).toBeVisible()
+ await expect(frame.getByText('Custom supporting message for active community members.')).toBeVisible()
+ await expect(frame.getByText('FEATURED')).toBeVisible()
+ await expect(frame.getByText('Not now, thanks')).toBeVisible()
+ await expect(frame.getByText('Verification complete')).toBeVisible()
+})
+
+const NEXT_TASK_LONG_COPY_VARIANTS = [
+ {
+ label: 'with-image',
+ storyId: 'design-system-primitives-nexttaskmodal--realistic-long-copy',
+ testId: 'NextTaskModal-long-copy',
+ hasImage: true,
+ },
+ {
+ label: 'without-image',
+ storyId: 'design-system-primitives-nexttaskmodal--realistic-long-copy-without-image',
+ testId: 'NextTaskModal-long-copy-no-image',
+ hasImage: false,
+ },
+]
+
+for (const variant of NEXT_TASK_LONG_COPY_VARIANTS) {
+ for (const viewport of NEXT_TASK_VIEWPORTS) {
+ test(`NextTaskModal RealisticLongCopy (${variant.label}) keeps headline, CTA and skip accessible at ${viewport.width}x${viewport.height} (${viewport.label})`, async ({
+ page,
+ }) => {
+ await page.setViewportSize({ width: viewport.width, height: viewport.height })
+ await page.goto(`/iframe.html?id=${variant.storyId}&viewMode=story`)
+ await page.waitForLoadState('domcontentloaded')
+
+ const openButton = page.getByTestId('NextTaskModal-open')
+ await expect(openButton).toBeVisible()
+ await openButton.click()
+
+ const card = page.getByTestId(variant.testId)
+ await expect(card).toBeVisible()
+ if (!variant.hasImage) {
+ await expect(card.getByRole('img')).toHaveCount(0)
+ }
+
+ const headline = page.getByText('Support Community Expansion Proposals', { exact: true })
+ const cta = page.getByRole('link', { name: 'Read and vote on Snapshot' })
+ const skip = page.getByRole('button', { name: 'Remind me tomorrow' })
+ const closeButton = page.getByRole('button', { name: 'Close' })
+
+ for (const control of [headline, cta, skip, closeButton]) {
+ await control.scrollIntoViewIfNeeded()
+ await expect(control).toBeInViewport({ ratio: 1 })
+ await expect(control).toBeVisible()
+ }
+ await expect(cta).toBeEnabled()
+ await expect(skip).toBeEnabled()
+ await expect(closeButton).toBeEnabled()
+
+ const cardWidth = await card.evaluate((element) => element.scrollWidth)
+ expect(cardWidth).toBeLessThanOrEqual(viewport.width)
+
+ await page.screenshot({
+ path: `tests/design-system/test-results/story-nexttaskmodal-long-copy-${variant.label}-${viewport.label}.png`,
+ })
+ })
+ }
+}
+
+test('NextTaskModal host mode: double-press during pending navigation calls handler once, and retrying after failure succeeds', async ({
+ page,
+}) => {
+ await gotoStory(page, 'design-system-primitives-nexttaskmodal--navigation-pending-and-retry')
+ const frame = getStoryFrame(page)
+ await frame.getByTestId('NextTaskModal-open').click()
+ const cta = frame.getByRole('button', { name: 'Explore staking' })
+ await cta.scrollIntoViewIfNeeded()
+ await expect(cta).toBeInViewport({ ratio: 1 })
+ await expect(cta).toBeVisible()
+ await expect(cta).toBeEnabled()
+
+ // Dispatch both presses in a single browser execution so slow runners cannot
+ // settle and reset the guard between sequential Playwright clicks.
+ await cta.evaluate((button) => {
+ ;(button as HTMLElement).click()
+ ;(button as HTMLElement).click()
+ })
+
+ // Error toast appears after delay, drawer remains open
+ await expect(frame.getByText('Could not open this link. Please try again.')).toBeVisible()
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+
+ // resolveNavigation was only called once despite double press
+ const callCountAfterFirstAttempt = await frame.locator('body').evaluate((body) => body.dataset.nextTaskCallCount)
+ expect(callCountAfterFirstAttempt).toBe('1')
+
+ // onClicked was only called once for the first attempt
+ await expect(frame.getByTestId('NextTaskModal-click-count')).toHaveText('1')
+
+ // Retry after failure: second press succeeds
+ await cta.click()
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
+ const callCountAfterRetry = await frame.locator('body').evaluate((body) => body.dataset.nextTaskCallCount)
+ expect(callCountAfterRetry).toBe('2')
+
+ // Item C: onClicked still has count 1 (one intent counted once despite retry)
+ await expect(frame.getByTestId('NextTaskModal-click-count')).toHaveText('1')
+})
+
+test('NextTaskModal host mode: stale pending navigation from a closed session does not reset guard, toast, or close reopened modal', async ({
+ page,
+}) => {
+ await gotoStory(page, 'design-system-primitives-nexttaskmodal--stale-navigation-ignored-across-reopen')
+ const frame = getStoryFrame(page)
+
+ // Session 1: open and start navigation attempt 1 (left pending)
+ await frame.getByTestId('NextTaskModal-open').click()
+ const cta = frame.getByRole('button', { name: 'Explore staking' })
+ await cta.scrollIntoViewIfNeeded()
+ await expect(cta).toBeVisible()
+ await cta.click()
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('1')
+
+ // Host closes and reopens modal before attempt 1 settles (session 2)
+ await frame.getByTestId('NextTaskModal-host-close').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
+ await frame.getByTestId('NextTaskModal-open').click()
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+
+ // Session 2: start navigation attempt 2 (also pending)
+ await cta.scrollIntoViewIfNeeded()
+ await expect(cta).toBeVisible()
+ await cta.click()
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('2')
+
+ // Reject stale attempt 1: must NOT show error toast or unlock CTA for a 3rd call while attempt 2 is pending
+ await frame.getByTestId('NextTaskModal-reject-oldest').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-settled-count')).toHaveText('1')
+ await expect(frame.getByText('Could not open this link. Please try again.')).toHaveCount(0)
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+ await cta.evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('2')
+
+ // Resolve attempt 2: current session closes cleanly
+ await frame.getByTestId('NextTaskModal-resolve-oldest').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-settled-count')).toHaveText('2')
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
+
+ // Verify stale fulfillment as well: open session 3, leave attempt 3 pending, close + reopen into session 4,
+ // then resolve stale attempt 3 -> session 4 stays open without being closed by attempt 3.
+ await frame.getByTestId('NextTaskModal-open').click()
+ await cta.scrollIntoViewIfNeeded()
+ await expect(cta).toBeVisible()
+ await cta.click()
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('3')
+
+ await frame.getByTestId('NextTaskModal-host-close').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
+ await frame.getByTestId('NextTaskModal-open').click()
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+
+ await frame.getByTestId('NextTaskModal-resolve-oldest').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-settled-count')).toHaveText('3')
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+
+ // Session 4 CTA still works normally once resolved
+ await cta.scrollIntoViewIfNeeded()
+ await expect(cta).toBeVisible()
+ await cta.click()
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('4')
+ await frame.getByTestId('NextTaskModal-resolve-oldest').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-settled-count')).toHaveText('4')
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
+ await expect(frame.getByTestId('NextTaskModal-close-count')).toHaveText('2')
+
+ // Verify unmount invalidation: unmount while attempts 5 & 6 are pending, then settle both -> no toast or onClose call
+ await frame.getByTestId('NextTaskModal-open').click()
+ await cta.scrollIntoViewIfNeeded()
+ await expect(cta).toBeVisible()
+ await cta.click()
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('5')
+
+ await frame.getByTestId('NextTaskModal-toggle-mount').evaluate((button) => (button as HTMLElement).click())
+ await frame.getByTestId('NextTaskModal-resolve-oldest').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-settled-count')).toHaveText('5')
+ await expect(frame.getByTestId('NextTaskModal-close-count')).toHaveText('2')
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+
+ await frame.getByTestId('NextTaskModal-toggle-mount').evaluate((button) => (button as HTMLElement).click())
+ await expect(cta).toBeVisible()
+ await cta.click()
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('6')
+ await frame.getByTestId('NextTaskModal-toggle-mount').evaluate((button) => (button as HTMLElement).click())
+ await frame.getByTestId('NextTaskModal-reject-oldest').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-settled-count')).toHaveText('6')
+ await expect(frame.getByText('Could not open this link. Please try again.')).toHaveCount(0)
+})
+
+test('NextTaskModal host mode: onClose throwing after successful navigation does not show navigation error toast or reset guard', async ({
+ page,
+}) => {
+ await gotoStory(page, 'design-system-primitives-nexttaskmodal--on-close-throw-after-navigation-success')
+ const frame = getStoryFrame(page)
+
+ await frame.getByTestId('NextTaskModal-open').click()
+ const cta = frame.getByRole('button', { name: 'Explore staking' })
+ await cta.scrollIntoViewIfNeeded()
+ await expect(cta).toBeVisible()
+
+ const [pageError] = await Promise.all([page.waitForEvent('pageerror'), cta.click()])
+ expect(pageError.message).toContain('host onClose failure')
+
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('1')
+ await expect(frame.getByTestId('NextTaskModal-close-count')).toHaveText('1')
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+ await expect(frame.getByText('Could not open this link. Please try again.')).toHaveCount(0)
+
+ // Guard stays latched after successful navigation so pressing CTA again does not re-run resolveNavigation
+ await cta.evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('1')
+ await expect(frame.getByTestId('NextTaskModal-close-count')).toHaveText('1')
+})
+
+test('NextTaskModal dismissal via Skip link works during pending navigation and late completion is ignored', async ({
+ page,
+}) => {
+ await gotoStory(page, 'design-system-primitives-nexttaskmodal--stale-navigation-ignored-across-reopen')
+ const frame = getStoryFrame(page)
+
+ await frame.getByTestId('NextTaskModal-open').click()
+ const cta = frame.getByRole('button', { name: 'Explore staking' })
+ await cta.scrollIntoViewIfNeeded()
+ await expect(cta).toBeVisible()
+ await cta.click()
+ await expect(frame.getByTestId('NextTaskModal-call-count')).toHaveText('1')
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('open')
+
+ // Dismissal via Skip link must proceed immediately despite pending navigation (Item B)
+ const skip = frame.getByRole('button', { name: 'Skip for now' })
+ await skip.scrollIntoViewIfNeeded()
+ await skip.click()
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
+ await expect(frame.getByTestId('NextTaskModal-close-count')).toHaveText('1')
+ await expect(frame.getByTestId('NextTaskModal-last-event')).toHaveText('dismissed:skip-link')
+
+ // Late resolution of attempt 1 does not reopen the modal or call onClose again
+ await frame.getByTestId('NextTaskModal-resolve-oldest').evaluate((button) => (button as HTMLElement).click())
+ await expect(frame.getByTestId('NextTaskModal-settled-count')).toHaveText('1')
+ await expect(frame.getByTestId('NextTaskModal-open-state')).toHaveText('closed')
+ await expect(frame.getByTestId('NextTaskModal-close-count')).toHaveText('1')
+ await expect(frame.getByText('Could not open this link. Please try again.')).toHaveCount(0)
+})
diff --git a/tests/design-system/test-results/qa-evidence/01-cta-primary-button.jpg b/tests/design-system/test-results/qa-evidence/01-cta-primary-button.jpg
new file mode 100644
index 00000000..69ae0de9
Binary files /dev/null and b/tests/design-system/test-results/qa-evidence/01-cta-primary-button.jpg differ
diff --git a/tests/design-system/test-results/qa-evidence/02-navigation-error-retained.jpg b/tests/design-system/test-results/qa-evidence/02-navigation-error-retained.jpg
new file mode 100644
index 00000000..d2bc8e74
Binary files /dev/null and b/tests/design-system/test-results/qa-evidence/02-navigation-error-retained.jpg differ
diff --git a/tests/design-system/test-results/qa-evidence/03-small-mobile-320x568.png b/tests/design-system/test-results/qa-evidence/03-small-mobile-320x568.png
new file mode 100644
index 00000000..2d590c2d
Binary files /dev/null and b/tests/design-system/test-results/qa-evidence/03-small-mobile-320x568.png differ
diff --git a/tests/design-system/test-results/qa-evidence/04-iphone-se-top.jpg b/tests/design-system/test-results/qa-evidence/04-iphone-se-top.jpg
new file mode 100644
index 00000000..15ee5956
Binary files /dev/null and b/tests/design-system/test-results/qa-evidence/04-iphone-se-top.jpg differ
diff --git a/tests/design-system/test-results/qa-evidence/05-iphone-se-bottom.jpg b/tests/design-system/test-results/qa-evidence/05-iphone-se-bottom.jpg
new file mode 100644
index 00000000..15ee5956
Binary files /dev/null and b/tests/design-system/test-results/qa-evidence/05-iphone-se-bottom.jpg differ
diff --git a/tests/design-system/test-results/qa-evidence/06-claim-in-progress.jpg b/tests/design-system/test-results/qa-evidence/06-claim-in-progress.jpg
new file mode 100644
index 00000000..5e4decd7
Binary files /dev/null and b/tests/design-system/test-results/qa-evidence/06-claim-in-progress.jpg differ
diff --git a/tests/design-system/test-results/qa-evidence/07-claim-drawer-opened.jpg b/tests/design-system/test-results/qa-evidence/07-claim-drawer-opened.jpg
new file mode 100644
index 00000000..5e4decd7
Binary files /dev/null and b/tests/design-system/test-results/qa-evidence/07-claim-drawer-opened.jpg differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-closed.png b/tests/design-system/test-results/story-nexttaskmodal-closed.png
index ec5227f7..d686a831 100644
Binary files a/tests/design-system/test-results/story-nexttaskmodal-closed.png and b/tests/design-system/test-results/story-nexttaskmodal-closed.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-desktop.png b/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-desktop.png
new file mode 100644
index 00000000..b455b00a
Binary files /dev/null and b/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-desktop.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-landscape.png b/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-landscape.png
new file mode 100644
index 00000000..aff6c510
Binary files /dev/null and b/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-landscape.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-mobile.png b/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-mobile.png
new file mode 100644
index 00000000..07c8a0ed
Binary files /dev/null and b/tests/design-system/test-results/story-nexttaskmodal-long-copy-with-image-mobile.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-desktop.png b/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-desktop.png
new file mode 100644
index 00000000..63a2cdce
Binary files /dev/null and b/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-desktop.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-landscape.png b/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-landscape.png
new file mode 100644
index 00000000..5dbcf3a1
Binary files /dev/null and b/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-landscape.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-mobile.png b/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-mobile.png
new file mode 100644
index 00000000..50cc65c6
Binary files /dev/null and b/tests/design-system/test-results/story-nexttaskmodal-long-copy-without-image-mobile.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-no-image.png b/tests/design-system/test-results/story-nexttaskmodal-no-image.png
index 828c751f..0f9569d4 100644
Binary files a/tests/design-system/test-results/story-nexttaskmodal-no-image.png and b/tests/design-system/test-results/story-nexttaskmodal-no-image.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-shown-desktop.png b/tests/design-system/test-results/story-nexttaskmodal-shown-desktop.png
index 0a20b6d8..f914a783 100644
Binary files a/tests/design-system/test-results/story-nexttaskmodal-shown-desktop.png and b/tests/design-system/test-results/story-nexttaskmodal-shown-desktop.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-shown-landscape.png b/tests/design-system/test-results/story-nexttaskmodal-shown-landscape.png
new file mode 100644
index 00000000..d6004ff6
Binary files /dev/null and b/tests/design-system/test-results/story-nexttaskmodal-shown-landscape.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-shown-mobile.png b/tests/design-system/test-results/story-nexttaskmodal-shown-mobile.png
index e7774dba..12abd31c 100644
Binary files a/tests/design-system/test-results/story-nexttaskmodal-shown-mobile.png and b/tests/design-system/test-results/story-nexttaskmodal-shown-mobile.png differ
diff --git a/tests/design-system/test-results/story-nexttaskmodal-shown.png b/tests/design-system/test-results/story-nexttaskmodal-shown.png
index 0d6d5ff6..700a9593 100644
Binary files a/tests/design-system/test-results/story-nexttaskmodal-shown.png and b/tests/design-system/test-results/story-nexttaskmodal-shown.png differ
diff --git a/tests/widgets/citizen-claim-widget/states.spec.ts b/tests/widgets/citizen-claim-widget/states.spec.ts
index 251c9a07..9b13be63 100644
--- a/tests/widgets/citizen-claim-widget/states.spec.ts
+++ b/tests/widgets/citizen-claim-widget/states.spec.ts
@@ -199,3 +199,198 @@ test('CitizenClaimWidget claimExecution claimAll reports per-chain success and f
fullPage: true,
})
})
+
+const MOCK_WIDGET_WITH_NEXT_TASK_STORY =
+ '/iframe.html?id=qa-citizenclaimwidget-runtime-fixtures--mock-claim-execution-with-next-task&viewMode=story'
+const MOCK_WIDGET_PARTIAL_SUCCESS_STORY =
+ '/iframe.html?id=qa-citizenclaimwidget-runtime-fixtures--mock-claim-execution-partial-success-with-next-task&viewMode=story'
+const MOCK_WIDGET_SINGLE_CHAIN_STORY =
+ '/iframe.html?id=qa-citizenclaimwidget-runtime-fixtures--mock-claim-execution-single-chain-with-next-task&viewMode=story'
+const MOCK_WIDGET_SINGLE_CLAIM_FALLBACK_STORY =
+ '/iframe.html?id=qa-citizenclaimwidget-runtime-fixtures--mock-claim-execution-single-claim-fallback-with-next-task&viewMode=story'
+const MOCK_WIDGET_ALL_FAILS_STORY =
+ '/iframe.html?id=qa-citizenclaimwidget-runtime-fixtures--mock-claim-execution-all-fails-with-next-task&viewMode=story'
+const MOCK_WIDGET_WITHOUT_NEXT_TASK_STORY =
+ '/iframe.html?id=qa-citizenclaimwidget-runtime-fixtures--mock-claim-execution-without-next-task&viewMode=story'
+
+test('CitizenClaimWidget real flow: drawer opens after multi-chain claim with all chains succeeding, CTA navigates and closes drawer', async ({
+ page,
+}) => {
+ await page.goto(MOCK_WIDGET_WITH_NEXT_TASK_STORY)
+ await page.waitForLoadState('domcontentloaded')
+
+ // Find and click the Claim button in the widget
+ const claimButton = page.getByRole('button', { name: /Claim/i })
+ await expect(claimButton).toBeVisible({ timeout: 15_000 })
+ await claimButton.click()
+
+ // Verify the NextTaskModal drawer opens after claim
+ const drawerHeadline = page.getByText('One good next step')
+ await expect(drawerHeadline).toBeVisible({ timeout: 20_000 })
+ await expect(page.getByText('Stake your G$ and earn')).toBeVisible()
+ await page.waitForTimeout(600)
+
+ await page.screenshot({
+ path: 'tests/widgets/citizen-claim-widget/test-results/ccw-06-next-task-drawer-open.png',
+ })
+
+ // Press the CTA and verify the host-side callback receives the target and drawer closes
+ const cta = page.getByRole('button', { name: 'Explore staking' })
+ await expect(cta).toBeVisible()
+ await cta.scrollIntoViewIfNeeded()
+ await cta.click()
+
+ await expect(page.locator('body')).toHaveAttribute('data-next-task-navigated', 'https://gooddollar.org/stake')
+ await expect(page.locator('body')).toHaveAttribute('data-next-task-last-event', 'clicked:https://gooddollar.org/stake')
+ await expect(drawerHeadline).not.toBeInViewport()
+})
+
+test('CitizenClaimWidget real flow: drawer opens after multi-chain claim with partial success (at least one success)', async ({
+ page,
+}) => {
+ await page.goto(MOCK_WIDGET_PARTIAL_SUCCESS_STORY)
+ await page.waitForLoadState('domcontentloaded')
+
+ const claimButton = page.getByRole('button', { name: /Claim/i })
+ await expect(claimButton).toBeVisible({ timeout: 15_000 })
+ await claimButton.click()
+
+ // In partial success (Celo succeeds, Fuse fails), drawer must still open
+ const drawerHeadline = page.getByText('One good next step')
+ await expect(drawerHeadline).toBeVisible({ timeout: 20_000 })
+ await expect(page.getByText('Stake your G$ and earn')).toBeVisible()
+
+ // Press the CTA and verify the host-side callback receives the target and drawer closes
+ const cta = page.getByRole('button', { name: 'Explore staking' })
+ await expect(cta).toBeVisible()
+ await cta.scrollIntoViewIfNeeded()
+ await cta.click()
+
+ await expect(page.locator('body')).toHaveAttribute('data-next-task-navigated', 'https://gooddollar.org/stake')
+ await expect(drawerHeadline).not.toBeInViewport()
+})
+
+test('CitizenClaimWidget real flow: drawer dismiss via Skip link closes drawer without navigating', async ({
+ page,
+}) => {
+ await page.goto(MOCK_WIDGET_WITH_NEXT_TASK_STORY)
+ await page.waitForLoadState('domcontentloaded')
+
+ const claimButton = page.getByRole('button', { name: /Claim/i })
+ await expect(claimButton).toBeVisible({ timeout: 15_000 })
+ await claimButton.click()
+
+ const drawerHeadline = page.getByText('One good next step')
+ await expect(drawerHeadline).toBeVisible({ timeout: 20_000 })
+
+ const skipButton = page.getByRole('button', { name: 'Skip for now' })
+ await expect(skipButton).toBeVisible()
+ await skipButton.scrollIntoViewIfNeeded()
+ await skipButton.click()
+
+ await expect(drawerHeadline).not.toBeInViewport()
+ const navigated = await page.evaluate(() => document.body.dataset.nextTaskNavigated)
+ expect(navigated).toBeUndefined()
+ await expect(page.locator('body')).toHaveAttribute('data-next-task-last-event', 'dismissed:skip-link')
+})
+
+test('CitizenClaimWidget real flow: drawer opens after single-chain claim success', async ({
+ page,
+}) => {
+ await page.goto(MOCK_WIDGET_SINGLE_CHAIN_STORY)
+ await page.waitForLoadState('domcontentloaded')
+
+ const claimButton = page.getByRole('button', { name: /Claim/i })
+ await expect(claimButton).toBeVisible({ timeout: 15_000 })
+ await claimButton.click()
+
+ const drawerHeadline = page.getByText('One good next step')
+ await expect(drawerHeadline).toBeVisible({ timeout: 15_000 })
+
+ const closeButton = page.getByRole('button', { name: 'Close' })
+ await closeButton.click()
+ await expect(drawerHeadline).not.toBeInViewport()
+})
+
+test('CitizenClaimWidget real flow: single-claim fallback runs and opens drawer when claimablesByChain is empty', async ({
+ page,
+}) => {
+ // Abort fallback RPCs so findAltEntitlement settles immediately with no alt-chain claimables.
+ await page.route('https://forno.celo.org/**', (route) => route.abort())
+ await page.route('https://rpc.fuse.io/**', (route) => route.abort())
+ await page.route('https://fuse-rpc.gateway.pokt.network/**', (route) => route.abort())
+ await page.route('https://rpc.ankr.com/**', (route) => route.abort())
+
+ await page.goto(MOCK_WIDGET_SINGLE_CLAIM_FALLBACK_STORY)
+ await page.waitForLoadState('domcontentloaded')
+
+ await expect(page.getByText('Ready to claim')).toBeVisible({ timeout: 15_000 })
+ const claimButton = page.getByRole('button', { name: /Claim/i })
+ await expect(claimButton).toBeVisible()
+ await expect(claimButton).toBeEnabled()
+
+ // claimablesByChain is empty, so ClaimChainBreakdown ("Celo" inside the card) is absent:
+ // only the WidgetTabs network badge renders exact "Celo", proving claimPlan.length === 0.
+ await expect(page.getByText('Celo', { exact: true })).toHaveCount(1)
+ await expect(page.getByTestId('CitizenClaimWidget-custodial-claim-all-42220')).toHaveCount(0)
+ await expect(page.getByTestId('CitizenClaimWidget-custodial-claim-all-122')).toHaveCount(0)
+
+ await claimButton.click()
+
+ // Single-claim fallback emits single-chain success toast and opens NextTaskModal.
+ await expect(page.getByText('Claim succeeded on Celo')).toBeVisible({ timeout: 20_000 })
+ const drawerHeadline = page.getByText('One good next step')
+ await expect(drawerHeadline).toBeVisible({ timeout: 20_000 })
+ await expect(page.getByText('Stake your G$ and earn')).toBeVisible()
+
+ // ClaimChainBreakdown stays absent after claim completion as well.
+ await expect(page.getByText('Celo', { exact: true })).toHaveCount(1)
+ await expect(page.getByTestId('CitizenClaimWidget-custodial-claim-all-42220')).toHaveCount(0)
+
+ const cta = page.getByRole('button', { name: 'Explore staking' })
+ await expect(cta).toBeVisible()
+ await cta.scrollIntoViewIfNeeded()
+ await cta.click()
+
+ await expect(page.locator('body')).toHaveAttribute('data-next-task-navigated', 'https://gooddollar.org/stake')
+ await expect(drawerHeadline).not.toBeInViewport()
+})
+
+test('CitizenClaimWidget real flow: drawer does NOT open when every claim fails', async ({
+ page,
+}) => {
+ await page.goto(MOCK_WIDGET_ALL_FAILS_STORY)
+ await page.waitForLoadState('domcontentloaded')
+
+ const claimButton = page.getByRole('button', { name: /Claim/i })
+ await expect(claimButton).toBeVisible({ timeout: 15_000 })
+ await claimButton.click()
+
+ // Wait for claim failure outcome to be reported and execution to settle
+ await expect(page.getByText('Claim failed on Celo')).toBeVisible({ timeout: 20_000 })
+ await expect(page.getByText('Claim failed on Fuse')).toBeVisible({ timeout: 20_000 })
+ await expect(claimButton).toBeEnabled({ timeout: 20_000 })
+
+ // Assert the drawer headline did not open
+ const drawerHeadline = page.getByText('One good next step')
+ await expect(drawerHeadline).not.toBeInViewport()
+})
+
+test('CitizenClaimWidget real flow: drawer does NOT open when nextTaskContent is absent', async ({
+ page,
+}) => {
+ await page.goto(MOCK_WIDGET_WITHOUT_NEXT_TASK_STORY)
+ await page.waitForLoadState('domcontentloaded')
+
+ const claimButton = page.getByRole('button', { name: /Claim/i })
+ await expect(claimButton).toBeVisible({ timeout: 15_000 })
+ await claimButton.click()
+
+ // Wait for claim success outcome to be reported, proving the claim succeeded
+ await expect(page.getByText('Claim succeeded on Celo')).toBeVisible({ timeout: 20_000 })
+ await expect(page.getByText('Claim succeeded on Fuse')).toBeVisible({ timeout: 20_000 })
+
+ // Assert the drawer was not opened despite success
+ const drawerHeadline = page.getByText('One good next step')
+ await expect(drawerHeadline).toHaveCount(0)
+})
diff --git a/tests/widgets/citizen-claim-widget/test-results/ccw-01-loading.png b/tests/widgets/citizen-claim-widget/test-results/ccw-01-loading.png
index 8fc965dd..5afa070a 100644
Binary files a/tests/widgets/citizen-claim-widget/test-results/ccw-01-loading.png and b/tests/widgets/citizen-claim-widget/test-results/ccw-01-loading.png differ
diff --git a/tests/widgets/citizen-claim-widget/test-results/ccw-02-not-whitelisted.png b/tests/widgets/citizen-claim-widget/test-results/ccw-02-not-whitelisted.png
index 2bde29ad..a263c28a 100644
Binary files a/tests/widgets/citizen-claim-widget/test-results/ccw-02-not-whitelisted.png and b/tests/widgets/citizen-claim-widget/test-results/ccw-02-not-whitelisted.png differ
diff --git a/tests/widgets/citizen-claim-widget/test-results/ccw-03-error.png b/tests/widgets/citizen-claim-widget/test-results/ccw-03-error.png
index d8cf8497..943c1679 100644
Binary files a/tests/widgets/citizen-claim-widget/test-results/ccw-03-error.png and b/tests/widgets/citizen-claim-widget/test-results/ccw-03-error.png differ
diff --git a/tests/widgets/citizen-claim-widget/test-results/ccw-04-retry-clicked.png b/tests/widgets/citizen-claim-widget/test-results/ccw-04-retry-clicked.png
index 8fc965dd..5afa070a 100644
Binary files a/tests/widgets/citizen-claim-widget/test-results/ccw-04-retry-clicked.png and b/tests/widgets/citizen-claim-widget/test-results/ccw-04-retry-clicked.png differ
diff --git a/tests/widgets/citizen-claim-widget/test-results/ccw-05-custodial-claim-all-contract.png b/tests/widgets/citizen-claim-widget/test-results/ccw-05-custodial-claim-all-contract.png
index 8ed534c9..90b7a9b0 100644
Binary files a/tests/widgets/citizen-claim-widget/test-results/ccw-05-custodial-claim-all-contract.png and b/tests/widgets/citizen-claim-widget/test-results/ccw-05-custodial-claim-all-contract.png differ
diff --git a/tests/widgets/citizen-claim-widget/test-results/ccw-06-next-task-drawer-open.png b/tests/widgets/citizen-claim-widget/test-results/ccw-06-next-task-drawer-open.png
new file mode 100644
index 00000000..599985a7
Binary files /dev/null and b/tests/widgets/citizen-claim-widget/test-results/ccw-06-next-task-drawer-open.png differ