|
| 1 | +import type { Meta, StoryObj } from '@storybook/react' |
| 2 | +import { fn, mocked } from 'storybook/test' |
| 3 | +import { useWallet } from '@/hooks/use-wallet' |
| 4 | +import type { StreamData } from '@/types/stream' |
| 5 | +import { StreamCard } from './stream-card' |
| 6 | + |
| 7 | +const NOW = 1_767_225_600 // 2026-01-01T00:00:00Z |
| 8 | +const DAY = 86_400n |
| 9 | +const ME = 'GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI' |
| 10 | +const SENDER = 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG' |
| 11 | +const RECIPIENT = ME |
| 12 | +const USDC = { |
| 13 | + address: 'CBBT7UGKPGP7EOUDJYVWGXQKD4CWPVD54PH43D5F7WAJT3XJVJ2XPMA', |
| 14 | + symbol: 'USDC', |
| 15 | + decimals: 6, |
| 16 | +} |
| 17 | + |
| 18 | +type WalletState = ReturnType<typeof useWallet> |
| 19 | + |
| 20 | +function mockWallet(address: string): WalletState { |
| 21 | + return { |
| 22 | + address, |
| 23 | + walletId: 'freighter', |
| 24 | + connecting: false, |
| 25 | + reconnecting: false, |
| 26 | + isConnected: true, |
| 27 | + networkMismatch: false, |
| 28 | + walletNetwork: 'TESTNET', |
| 29 | + connect: fn(async () => {}), |
| 30 | + disconnect: fn(), |
| 31 | + signTransaction: fn(async (xdr: string) => xdr), |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +function makeStream(id = 'stream-42', overrides: Partial<StreamData> = {}): StreamData { |
| 36 | + const startTime = BigInt(NOW - Number(DAY * 10n)) |
| 37 | + const endTime = BigInt(NOW + Number(DAY * 20n)) |
| 38 | + const depositedAmount = 3_000_000_000n |
| 39 | + return { |
| 40 | + id, |
| 41 | + sender: SENDER, |
| 42 | + recipient: RECIPIENT, |
| 43 | + token: USDC, |
| 44 | + depositedAmount, |
| 45 | + withdrawnAmount: 500_000_000n, |
| 46 | + startTime, |
| 47 | + endTime, |
| 48 | + cliffTime: startTime, |
| 49 | + cliffAmount: 0n, |
| 50 | + amountPerSecond: depositedAmount / (DAY * 30n), |
| 51 | + linearAmount: depositedAmount, |
| 52 | + duration: DAY * 30n, |
| 53 | + cancelled: false, |
| 54 | + metadata: { name: 'Monthly payroll', category: 'payroll', memo: 'January payment' }, |
| 55 | + ...overrides, |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +const meta = { |
| 60 | + title: 'Streams/StreamCard', |
| 61 | + component: StreamCard, |
| 62 | + parameters: { |
| 63 | + layout: 'padded', |
| 64 | + }, |
| 65 | + tags: ['autodocs'], |
| 66 | + decorators: [ |
| 67 | + (Story) => ( |
| 68 | + <div className="w-full max-w-2xl"> |
| 69 | + <Story /> |
| 70 | + </div> |
| 71 | + ), |
| 72 | + ], |
| 73 | + beforeEach: () => { |
| 74 | + mocked(useWallet).mockReturnValue(mockWallet(ME)) |
| 75 | + localStorage.removeItem('flowstar:pinned-streams') |
| 76 | + }, |
| 77 | +} satisfies Meta<typeof StreamCard> |
| 78 | + |
| 79 | +export default meta |
| 80 | +type Story = StoryObj<typeof meta> |
| 81 | + |
| 82 | +/** Incoming stream — the current wallet is the recipient. */ |
| 83 | +export const Incoming: Story = { |
| 84 | + args: { |
| 85 | + stream: makeStream(), |
| 86 | + }, |
| 87 | +} |
| 88 | + |
| 89 | +/** Outgoing stream — the current wallet is the sender. */ |
| 90 | +export const Outgoing: Story = { |
| 91 | + beforeEach: () => { |
| 92 | + mocked(useWallet).mockReturnValue(mockWallet(SENDER)) |
| 93 | + }, |
| 94 | + args: { |
| 95 | + stream: makeStream(), |
| 96 | + }, |
| 97 | +} |
| 98 | + |
| 99 | +/** Dense single-row card for high-volume stream lists. */ |
| 100 | +export const Compact: Story = { |
| 101 | + args: { |
| 102 | + stream: makeStream(), |
| 103 | + compact: true, |
| 104 | + }, |
| 105 | +} |
| 106 | + |
| 107 | +/** Incoming stream with the pinned indicator and highlighted border. */ |
| 108 | +export const Pinned: Story = { |
| 109 | + beforeEach: () => { |
| 110 | + localStorage.setItem('flowstar:pinned-streams', JSON.stringify(['stream-42'])) |
| 111 | + }, |
| 112 | + args: { |
| 113 | + stream: makeStream(), |
| 114 | + }, |
| 115 | +} |
| 116 | + |
| 117 | +/** Selection mode with a checked stream selector. */ |
| 118 | +export const Selectable: Story = { |
| 119 | + args: { |
| 120 | + stream: makeStream(), |
| 121 | + selectable: true, |
| 122 | + selected: true, |
| 123 | + onToggleSelect: fn(), |
| 124 | + }, |
| 125 | +} |
0 commit comments