diff --git a/src/community/components/TransactionHistory.jsx b/src/community/components/TransactionHistory.jsx new file mode 100644 index 00000000000..917ce9ad222 --- /dev/null +++ b/src/community/components/TransactionHistory.jsx @@ -0,0 +1,194 @@ +import PropTypes from 'prop-types'; +import React, {useEffect, useMemo, useState} from 'react'; +import {Link} from 'react-router-dom'; +import {ChevronLeft, ChevronRight, History} from 'lucide-react'; + +import {useCommunityIntl as useCommunityText} from '../i18n.jsx'; +import {getCommunityLocale} from '../locale.js'; +import Avatar from './Avatar.jsx'; +import {ExploreSearch} from './ExploreHeader.jsx'; +import EmptyState from './ui/EmptyState.jsx'; +import IconButton from './ui/IconButton.jsx'; +import SelectMenu from './ui/SelectMenu.jsx'; +import styles from './TransactionHistory.module.css'; + +const PAGE_SIZE = 25; +const DAY_MS = 24 * 60 * 60 * 1000; + +const dayStart = time => { + const date = new Date(time); + date.setHours(0, 0, 0, 0); + return date.getTime(); +}; + +const amountText = value => Math.abs(value).toLocaleString(getCommunityLocale(), {maximumFractionDigits: 2}); + +const clockText = time => new Date(time).toLocaleTimeString(getCommunityLocale(), {hour: '2-digit', minute: '2-digit'}); + +const TransactionHistory = ({transactions}) => { + const {text: communityText} = useCommunityText(); + const [query, setQuery] = useState(''); + const [filter, setFilter] = useState('all'); + const [page, setPage] = useState(0); + + useEffect(() => { + setPage(0); + }, [query, filter]); + + const filtered = useMemo(() => { + const needle = query.trim().toLowerCase(); + return transactions.filter(transaction => { + if (filter === 'in' && !transaction.incoming) return false; + if (filter === 'out' && transaction.incoming) return false; + if (!needle) return true; + return `${transaction.note} ${transaction.user}`.toLowerCase().includes(needle); + }); + }, [transactions, query, filter]); + + const dayNets = useMemo(() => { + const nets = new Map(); + for (const transaction of filtered) { + const start = dayStart(transaction.time); + const signed = transaction.incoming ? transaction.amount : -transaction.amount; + nets.set(start, (nets.get(start) || 0) + signed); + } + for (const [start, net] of nets) nets.set(start, Math.round(net * 100) / 100); + return nets; + }, [filtered]); + + const totalPages = Math.max(1, Math.ceil(filtered.length / PAGE_SIZE)); + const safePage = Math.min(page, totalPages - 1); + const days = []; + for (const transaction of filtered.slice(safePage * PAGE_SIZE, (safePage + 1) * PAGE_SIZE)) { + const start = dayStart(transaction.time); + let day = days[days.length - 1]; + if (!day || day.start !== start) { + day = {start, net: dayNets.get(start) || 0, items: []}; + days.push(day); + } + day.items.push(transaction); + } + + const today = dayStart(Date.now()); + const yesterday = dayStart(today - (DAY_MS / 2)); + const dayLabel = start => { + if (start === today) return communityText('Today'); + if (start === yesterday) return communityText('Yesterday'); + const sameYear = new Date(start).getFullYear() === new Date(today).getFullYear(); + const options = {weekday: 'long', month: 'long', day: 'numeric'}; + if (!sameYear) options.year = 'numeric'; + return new Date(start).toLocaleDateString(getCommunityLocale(), options); + }; + + return ( +
+
+ + +
+ + {days.length ? ( +
+ {days.map(day => ( +
+

+ {dayLabel(day.start)} + 0 ? styles.income : ''}> + {day.net > 0 ? '+' : day.net < 0 ? '−' : ''}{amountText(day.net)} + +

+
    + {day.items.map(transaction => ( +
  • + + + + + + {transaction.note || (transaction.incoming ? + communityText('Received credits') : + communityText('Sent credits'))} + + + {transaction.user ? ( + + + {`@${transaction.user}`} + + + + ) : null} + + + + + {transaction.incoming ? '+' : '−'}{amountText(transaction.amount)} + +
  • + ))} +
+
+ ))} + {totalPages > 1 ? ( +
+ + {communityText('Page {value1} of {value2}', {value1: safePage + 1, value2: totalPages})} + + + setPage(Math.max(0, safePage - 1))} + > + + + = totalPages - 1} + onClick={() => setPage(Math.min(totalPages - 1, safePage + 1))} + > + + + +
+ ) : null} +
+ ) : ( + + {communityText('Try another search or show all activity.')} + + )} +
+ ); +}; + +TransactionHistory.propTypes = { + transactions: PropTypes.arrayOf(PropTypes.shape({ + id: PropTypes.string.isRequired, + incoming: PropTypes.bool, + amount: PropTypes.number, + user: PropTypes.string, + note: PropTypes.string, + time: PropTypes.number + })).isRequired +}; + +export default TransactionHistory; diff --git a/src/community/components/TransactionHistory.module.css b/src/community/components/TransactionHistory.module.css new file mode 100644 index 00000000000..b794d023e36 --- /dev/null +++ b/src/community/components/TransactionHistory.module.css @@ -0,0 +1,136 @@ +.history { + display: flex; + flex-direction: column; + gap: 12px; +} + +.toolbar { + display: flex; + align-items: center; + gap: 8px; +} + +.filter { + flex-shrink: 0; +} + +.surface { + padding: 4px 18px 8px; + border-radius: var(--radius); + background: var(--bg-card); + box-shadow: var(--card-shadow); +} + +.day + .day { + margin-top: 10px; +} + +.dayHeading { + display: flex; + align-items: baseline; + justify-content: space-between; + gap: 16px; + margin: 0; + padding: 10px 0 6px; + border-bottom: 1px solid var(--border-soft); + font-size: var(--fs-xs); + font-weight: 500; + color: var(--text-dim); +} + +.dayHeading > span:last-child { + font-variant-numeric: tabular-nums; +} + +.rows { + list-style: none; + margin: 0; + padding: 0; +} + +.row { + display: grid; + grid-template-columns: auto minmax(0, 1fr) auto; + align-items: center; + gap: 12px; + min-height: 44px; + padding: 6px 0; + border-bottom: 1px solid var(--border-soft); +} + +.row:last-child { + border-bottom: 0; +} + +.lead { + display: inline-flex; + width: 24px; + height: 24px; +} + +.body { + min-width: 0; +} + +.title { + display: block; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: var(--fs-sm); + font-weight: 500; + color: var(--mw-text); +} + +.meta { + display: block; + margin-top: 1px; + font-size: var(--fs-xs); + color: var(--text-dim); +} + +.meta a { + color: var(--accent-strong); +} + +.meta time { + white-space: nowrap; + font-variant-numeric: tabular-nums; +} + +.amount, +.amountIn { + min-width: 56px; + text-align: end; + font-size: var(--fs-sm); + font-weight: 600; + font-variant-numeric: tabular-nums; + color: var(--mw-text); +} + +.amountIn, +.income { + color: var(--mw-success); +} + +.pagination { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + padding: 10px 0 2px; + border-top: 1px solid var(--border-soft); + font-size: var(--fs-sm); + color: var(--text-dim); +} + +.pageButtons { + display: flex; + gap: 4px; +} + +@media (max-width: 520px) { + .surface { + padding: 2px 12px 6px; + } +} diff --git a/src/community/pages/Wallet.jsx b/src/community/pages/Wallet.jsx index c84e50474ee..e90c462ed9e 100644 --- a/src/community/pages/Wallet.jsx +++ b/src/community/pages/Wallet.jsx @@ -3,7 +3,7 @@ import {useCommunityIntl as useCommunityText} from '../i18n.jsx'; import React, {useEffect, useRef, useState} from 'react'; import {Link, useSearchParams} from 'react-router-dom'; import { - ArrowDownLeft, ArrowUpRight, CalendarCheck, Coins, ExternalLink, History, ShoppingBag, Wallet as WalletIcon + CalendarCheck, Coins, ExternalLink, History, ShoppingBag, Wallet as WalletIcon } from 'lucide-react'; import api, {projectUrl} from '../api'; import {allowWallet, claimDailyCredits, getDailyWait, getWallet} from '../../lib/rotur/wallet.js'; @@ -12,21 +12,19 @@ import Button from '../components/ui/Button.jsx'; import EmptyState, {SignInPrompt} from '../components/ui/EmptyState.jsx'; import PageHeader from '../components/ui/PageHeader.jsx'; import StatusMessage from '../components/ui/StatusMessage.jsx'; +import TransactionHistory from '../components/TransactionHistory.jsx'; import UnderlineTabs from '../components/UnderlineTabs.jsx'; import {tabPanelProps} from '../components/SectionTabs.jsx'; -import {formatDate, safeDate} from '../format'; +import {formatDate} from '../format'; import styles from './Wallet.module.css'; const ROTUR_ACCOUNT = 'https://rotur.dev/me'; +const ROTUR_ACTIVITY = 'https://rotur.dev/me/activity'; const HOUR_MS = 60 * 60 * 1000; const TABS = ['activity', 'purchases']; const fmtCredits = value => Math.round((Number(value) || 0) * 100) / 100; -const transactionDate = value => { - const date = safeDate(value); - return date ? date.toLocaleString(getCommunityLocale(), {dateStyle: 'medium', timeStyle: 'short'}) : ''; -}; const Wallet = () => { const {text: communityText} = useCommunityText(); @@ -149,7 +147,9 @@ const Wallet = () => { }; const waitHours = dailyWait > 0 ? Math.ceil(dailyWait / HOUR_MS) : 0; - const transactions = wallet && wallet.allowed ? wallet.transactions : []; + const transactions = wallet && wallet.allowed ? + wallet.transactions.filter(transaction => transaction.mistwarp) : + []; return (
@@ -222,48 +222,27 @@ const Wallet = () => { {tab === 'activity' ? ( wallet === null && !walletError ? ( - ) : transactions.length ? ( - ) : wallet && wallet.allowed ? ( - - {communityText('Credits you send, receive and spend on Rotur show up here.')} - + +
+ {communityText('Credits you spent and earned on MistWarp.')} + + {communityText('See your full wallet on rotur.dev')} + +
+ {transactions.length ? ( + + ) : ( + + {communityText('Buying projects and game items, donations and sales show up here.')} + + )} +
) : ( {communityText('Show your balance to see them here too.')} diff --git a/src/community/pages/Wallet.module.css b/src/community/pages/Wallet.module.css index 7bd0a6456ce..4f19fb578fd 100644 --- a/src/community/pages/Wallet.module.css +++ b/src/community/pages/Wallet.module.css @@ -78,6 +78,25 @@ margin-inline-start: auto; } +.activityLead { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 6px 16px; + margin-bottom: 12px; + font-size: var(--fs-sm); + color: var(--text-dim); +} + +.activityLead a { + display: inline-flex; + align-items: center; + gap: 5px; + color: var(--accent-strong); + font-weight: 600; +} + .tabs { margin: 8px 0 16px; } @@ -85,23 +104,27 @@ .list { list-style: none; margin: 0; - padding: 0; + padding: 4px 18px; display: flex; flex-direction: column; - gap: 4px; + border-radius: var(--radius); + background: var(--bg-card); + box-shadow: var(--card-shadow); } .row { display: flex; align-items: center; gap: 12px; - padding: 10px 12px; - border-radius: var(--radius-sm); - background: var(--bg-card); - box-shadow: var(--card-shadow); + min-height: 52px; + padding: 8px 0; + border-bottom: 1px solid var(--border-soft); +} + +.row:last-child { + border-bottom: 0; } -.inIcon, .outIcon { display: inline-flex; align-items: center; @@ -110,14 +133,6 @@ height: 32px; border-radius: var(--radius-sm); flex-shrink: 0; -} - -.inIcon { - background: color-mix(in srgb, var(--mw-success) 16%, transparent); - color: var(--mw-success); -} - -.outIcon { background: var(--bg-raised); color: var(--text-dim); } @@ -151,19 +166,11 @@ a.rowTitle:hover { color: var(--text-dim); } -.inAmount, .outAmount { font-weight: 600; font-size: var(--fs-md); white-space: nowrap; flex-shrink: 0; -} - -.inAmount { - color: var(--mw-success); -} - -.outAmount { color: var(--mw-text); } diff --git a/src/community/translations/_sources.json b/src/community/translations/_sources.json index a649f643b41..23d4070442a 100644 --- a/src/community/translations/_sources.json +++ b/src/community/translations/_sources.json @@ -37,7 +37,7 @@ "src/community/pages/ManageProject.jsx:866", "src/community/pages/ManageProject.jsx:901", "src/community/pages/Profile.jsx:928", - "src/community/pages/Wallet.jsx:212", + "src/community/pages/Wallet.jsx:210", "src/community/pages/admin/StatsOverview.jsx:148", "src/community/pages/admin/UserDetailCard.jsx:268" ], @@ -2621,6 +2621,52 @@ "{value1} downloads": [ "src/community/components/ThemeCard.jsx:35" ], + "Today": [ + "src/community/components/TransactionHistory.jsx:75", + "src/community/pages/admin/AnalyticsChart.jsx:61" + ], + "Yesterday": [ + "src/community/components/TransactionHistory.jsx:76" + ], + "Search transactions": [ + "src/community/components/TransactionHistory.jsx:87" + ], + "Search by note or username": [ + "src/community/components/TransactionHistory.jsx:88" + ], + "Transaction type": [ + "src/community/components/TransactionHistory.jsx:93" + ], + "All activity": [ + "src/community/components/TransactionHistory.jsx:99" + ], + "Money in": [ + "src/community/components/TransactionHistory.jsx:100" + ], + "Money out": [ + "src/community/components/TransactionHistory.jsx:101" + ], + "Received credits": [ + "src/community/components/TransactionHistory.jsx:125" + ], + "Sent credits": [ + "src/community/components/TransactionHistory.jsx:126" + ], + "Page {value1} of {value2}": [ + "src/community/components/TransactionHistory.jsx:153" + ], + "Previous page": [ + "src/community/components/TransactionHistory.jsx:157" + ], + "Next page": [ + "src/community/components/TransactionHistory.jsx:164" + ], + "No matching transactions": [ + "src/community/components/TransactionHistory.jsx:175" + ], + "Try another search or show all activity.": [ + "src/community/components/TransactionHistory.jsx:176" + ], "{size} of storage for your projects": [ "src/community/components/UpgradeCelebration.jsx:37" ], @@ -3785,7 +3831,7 @@ ], "credits": [ "src/community/pages/Group.jsx:256", - "src/community/pages/Wallet.jsx:165" + "src/community/pages/Wallet.jsx:163" ], "Request to join": [ "src/community/pages/Group.jsx:259" @@ -3874,7 +3920,7 @@ ], "Explore projects": [ "src/community/pages/Home.jsx:120", - "src/community/pages/Wallet.jsx:304" + "src/community/pages/Wallet.jsx:276" ], "Find a project you like and follow its creator.": [ "src/community/pages/Home.jsx:120" @@ -4773,7 +4819,7 @@ ], "Wallet": [ "src/community/pages/MyStuff.jsx:226", - "src/community/pages/Wallet.jsx:156" + "src/community/pages/Wallet.jsx:154" ], "Credits on Rotur": [ "src/community/pages/MyStuff.jsx:233" @@ -4829,8 +4875,7 @@ "src/community/pages/MyStuff.jsx:303" ], "From {value1}": [ - "src/community/pages/MyStuff.jsx:313", - "src/community/pages/Wallet.jsx:245" + "src/community/pages/MyStuff.jsx:313" ], "Your inventory is empty": [ "src/community/pages/MyStuff.jsx:319" @@ -5574,7 +5619,7 @@ ], "Waiting for Rotur…": [ "src/community/pages/Project.jsx:781", - "src/community/pages/Wallet.jsx:177" + "src/community/pages/Wallet.jsx:175" ], "Buy {value1} for a one-time payment of {value2} credits and support its creator?": [ "src/community/pages/Project.jsx:786" @@ -6890,76 +6935,73 @@ "src/community/pages/UserLibrary.jsx:84" ], "Could not load your balance from Rotur.": [ - "src/community/pages/Wallet.jsx:75" + "src/community/pages/Wallet.jsx:73" ], "Could not load purchase history.": [ - "src/community/pages/Wallet.jsx:92" + "src/community/pages/Wallet.jsx:90" ], "Sign in to see your wallet.": [ - "src/community/pages/Wallet.jsx:104" + "src/community/pages/Wallet.jsx:102" ], "Daily credits claimed.": [ - "src/community/pages/Wallet.jsx:135" + "src/community/pages/Wallet.jsx:133" ], "MistWarp needs your permission on Rotur to claim daily credits.": [ - "src/community/pages/Wallet.jsx:139" + "src/community/pages/Wallet.jsx:137" ], "Could not claim daily credits.": [ - "src/community/pages/Wallet.jsx:145" + "src/community/pages/Wallet.jsx:143" ], "Your balance": [ - "src/community/pages/Wallet.jsx:161" + "src/community/pages/Wallet.jsx:159" ], "Let MistWarp see your balance and transactions on Rotur.": [ - "src/community/pages/Wallet.jsx:170" + "src/community/pages/Wallet.jsx:168" ], "Show my balance": [ - "src/community/pages/Wallet.jsx:179" + "src/community/pages/Wallet.jsx:177" ], "You can claim daily credits again in {value1}h.": [ - "src/community/pages/Wallet.jsx:187" + "src/community/pages/Wallet.jsx:185" ], "Claiming…": [ - "src/community/pages/Wallet.jsx:196" + "src/community/pages/Wallet.jsx:194" ], "Claim daily credits": [ - "src/community/pages/Wallet.jsx:199" + "src/community/pages/Wallet.jsx:197" ], "Open Rotur": [ - "src/community/pages/Wallet.jsx:201" + "src/community/pages/Wallet.jsx:199" ], "Purchases": [ - "src/community/pages/Wallet.jsx:213" + "src/community/pages/Wallet.jsx:211" ], "Wallet sections": [ - "src/community/pages/Wallet.jsx:218" + "src/community/pages/Wallet.jsx:216" ], - "Received credits": [ - "src/community/pages/Wallet.jsx:239" + "Credits you spent and earned on MistWarp.": [ + "src/community/pages/Wallet.jsx:226" ], - "Sent credits": [ - "src/community/pages/Wallet.jsx:240" + "See your full wallet on rotur.dev": [ + "src/community/pages/Wallet.jsx:228" ], - "To {value1}": [ - "src/community/pages/Wallet.jsx:246" + "No MistWarp transactions yet": [ + "src/community/pages/Wallet.jsx:234" ], - "No transactions yet": [ - "src/community/pages/Wallet.jsx:264" - ], - "Credits you send, receive and spend on Rotur show up here.": [ - "src/community/pages/Wallet.jsx:265" + "Buying projects and game items, donations and sales show up here.": [ + "src/community/pages/Wallet.jsx:235" ], "Your transactions are on Rotur": [ - "src/community/pages/Wallet.jsx:268" + "src/community/pages/Wallet.jsx:240" ], "Show your balance to see them here too.": [ - "src/community/pages/Wallet.jsx:269" + "src/community/pages/Wallet.jsx:241" ], "No purchases yet": [ - "src/community/pages/Wallet.jsx:303" + "src/community/pages/Wallet.jsx:275" ], "You have not bought any projects yet.": [ - "src/community/pages/Wallet.jsx:306" + "src/community/pages/Wallet.jsx:278" ], "Add admin": [ "src/community/pages/admin/AdminsSection.jsx:22" @@ -6967,9 +7009,6 @@ "Super admin": [ "src/community/pages/admin/AdminsSection.jsx:37" ], - "Today": [ - "src/community/pages/admin/AnalyticsChart.jsx:61" - ], "Latest": [ "src/community/pages/admin/AnalyticsChart.jsx:61" ], diff --git a/src/community/translations/en.json b/src/community/translations/en.json index 657790599f3..208cd32aa05 100644 --- a/src/community/translations/en.json +++ b/src/community/translations/en.json @@ -2680,9 +2680,6 @@ "Wallet sections": "Wallet sections", "Received credits": "Received credits", "Sent credits": "Sent credits", - "To {value1}": "To {value1}", - "No transactions yet": "No transactions yet", - "Credits you send, receive and spend on Rotur show up here.": "Credits you send, receive and spend on Rotur show up here.", "Your transactions are on Rotur": "Your transactions are on Rotur", "Show your balance to see them here too.": "Show your balance to see them here too.", "View account": "View account", @@ -2756,5 +2753,21 @@ "On bounty {value1}": "On bounty {value1}", "On a roadmap idea": "On a roadmap idea", "On pull request {value1} of project {value2}": "On pull request {value1} of project {value2}", - "Changed from {value1} to {value2}": "Changed from {value1} to {value2}" + "Changed from {value1} to {value2}": "Changed from {value1} to {value2}", + "Yesterday": "Yesterday", + "Search transactions": "Search transactions", + "Search by note or username": "Search by note or username", + "Transaction type": "Transaction type", + "All activity": "All activity", + "Money in": "Money in", + "Money out": "Money out", + "Page {value1} of {value2}": "Page {value1} of {value2}", + "Previous page": "Previous page", + "Next page": "Next page", + "No matching transactions": "No matching transactions", + "Try another search or show all activity.": "Try another search or show all activity.", + "Credits you spent and earned on MistWarp.": "Credits you spent and earned on MistWarp.", + "See your full wallet on rotur.dev": "See your full wallet on rotur.dev", + "No MistWarp transactions yet": "No MistWarp transactions yet", + "Buying projects and game items, donations and sales show up here.": "Buying projects and game items, donations and sales show up here." } diff --git a/src/lib/rotur/wallet.js b/src/lib/rotur/wallet.js index b5f360ca80d..d34c1511c23 100644 --- a/src/lib/rotur/wallet.js +++ b/src/lib/rotur/wallet.js @@ -4,6 +4,8 @@ const VIEW_SCOPE = 'credits:view'; const DAILY_SCOPE = 'credits:daily'; const DAY_MS = 24 * 60 * 60 * 1000; +const MISTWARP_PROVIDERS = /^(app-)?mistwarp$/i; + const roundCredits = value => Math.round((Number(value) || 0) * 100) / 100; const normalizeTransactions = transactions => { @@ -21,6 +23,7 @@ const normalizeTransactions = transactions => { amount: Math.abs(amount), user: String(transaction.user || ''), note: String(transaction.note || ''), + mistwarp: MISTWARP_PROVIDERS.test(String(transaction.provider || '')), time: Number.isFinite(time) ? time : 0, total: Number.isFinite(Number(transaction.new_total)) ? roundCredits(transaction.new_total) : null }); diff --git a/test/unit/community-transaction-history.test.jsx b/test/unit/community-transaction-history.test.jsx new file mode 100644 index 00000000000..1fedd1c8f67 --- /dev/null +++ b/test/unit/community-transaction-history.test.jsx @@ -0,0 +1,76 @@ +import React from 'react'; +import {act} from 'react-dom/test-utils'; +import {mount} from 'enzyme'; +import {MemoryRouter} from 'react-router-dom'; + +import TransactionHistory from '../../src/community/components/TransactionHistory.jsx'; + +const HOUR = 60 * 60 * 1000; + +const transaction = (index, fields = {}) => ({ + id: `t${index}`, + incoming: false, + amount: 0.25, + user: `user${index}`, + note: 'Daily credit', + time: Date.now() - (index * HOUR), + ...fields +}); + +const render = transactions => mount( + + + +); + +const dayHeadings = wrapper => wrapper.find('h3').map(heading => heading.text()); + +describe('TransactionHistory', () => { + test('groups transactions under their day with the day\'s net', () => { + const wrapper = render([ + transaction(0, {incoming: true, amount: 3, note: 'Daily claim', user: 'rotur', time: Date.now()}), + transaction(1, {time: Date.now() - 1000}) + ]); + const headings = dayHeadings(wrapper); + expect(headings).toHaveLength(1); + expect(headings[0]).toContain('Today'); + expect(headings[0]).toContain('+2.75'); + expect(wrapper.find('li')).toHaveLength(2); + expect(wrapper.text()).toContain('@user1'); + expect(wrapper.text()).toContain('−0.25'); + wrapper.unmount(); + }); + + test('shows 25 at a time and pages through the rest', () => { + const many = Array.from({length: 30}, (_, index) => transaction(index, {time: Date.now() - (index * 60000)})); + const wrapper = render(many); + expect(wrapper.find('li')).toHaveLength(25); + expect(wrapper.text()).toContain('Page 1 of 2'); + act(() => { + wrapper.find('button[aria-label="Next page"]').simulate('click'); + }); + wrapper.update(); + expect(wrapper.find('li')).toHaveLength(5); + expect(wrapper.text()).toContain('Page 2 of 2'); + wrapper.unmount(); + }); + + test('searches notes and usernames', () => { + const wrapper = render([ + transaction(1, {note: 'Meowing Simulator', user: 'LucasMcCheese'}), + transaction(2) + ]); + act(() => { + wrapper.find('input[type="search"]').simulate('change', {target: {value: 'meow'}}); + }); + wrapper.update(); + expect(wrapper.find('li')).toHaveLength(1); + expect(wrapper.text()).toContain('Meowing Simulator'); + act(() => { + wrapper.find('input[type="search"]').simulate('change', {target: {value: 'nobody here'}}); + }); + wrapper.update(); + expect(wrapper.text()).toContain('No matching transactions'); + wrapper.unmount(); + }); +}); diff --git a/test/unit/community-wallet.test.jsx b/test/unit/community-wallet.test.jsx index 6aca421a2a2..cf42dfe2ea8 100644 --- a/test/unit/community-wallet.test.jsx +++ b/test/unit/community-wallet.test.jsx @@ -52,23 +52,37 @@ describe('Wallet', () => { allowed: true, balance: 42.5, transactions: [ - {id: 't1', incoming: true, amount: 3, user: 'rotur', note: 'Daily claim', time: 1700000000000}, - {id: 't2', incoming: false, amount: 10, user: 'kit', note: '', time: 1700000100000} + {id: 't1', incoming: true, amount: 3, user: 'rotur', note: 'Daily claim', time: 1700000000000, mistwarp: false}, + {id: 't2', incoming: false, amount: 10, user: 'kit', note: '', time: 1700000100000, mistwarp: true}, + {id: 't3', incoming: true, amount: 9, user: 'lee', note: 'Starfall Racer', time: 1700000200000, mistwarp: true} ] }); getDailyWait.mockResolvedValue(0); api.purchases.mockResolvedValue({purchases: [{projectId: 'p1', title: 'Starfall', amount: 10, at: 1700000000000}]}); }); - test('shows the Rotur balance and transactions', async () => { + test('shows the Rotur balance and only MistWarp transactions, with a link to the full wallet', async () => { const wrapper = await render(); const text = wrapper.text(); expect(text).toContain('Your balance'); expect(text).toContain('42.5'); - expect(text).toContain('Daily claim'); expect(text).toContain('Sent credits'); - expect(text).toContain('To kit'); - expect(text).not.toContain('Starfall'); + expect(text).toContain('@kit'); + expect(text).toContain('Starfall Racer'); + expect(text).not.toContain('Daily claim'); + expect(wrapper.find('a[href="https://rotur.dev/me/activity"]').exists()).toBe(true); + wrapper.unmount(); + }); + + test('says so when nothing was spent or earned on MistWarp', async () => { + getWallet.mockResolvedValueOnce({ + allowed: true, + balance: 3, + transactions: [{id: 't1', incoming: true, amount: 3, user: 'rotur', note: 'Daily claim', time: 1700000000000, mistwarp: false}] + }); + const wrapper = await render(); + expect(wrapper.text()).toContain('No MistWarp transactions yet'); + expect(wrapper.find('a[href="https://rotur.dev/me/activity"]').exists()).toBe(true); wrapper.unmount(); }); diff --git a/test/unit/rotur-wallet.test.js b/test/unit/rotur-wallet.test.js index a26ef102ce0..5cd6a0232bc 100644 --- a/test/unit/rotur-wallet.test.js +++ b/test/unit/rotur-wallet.test.js @@ -27,7 +27,7 @@ describe('Rotur wallet', () => { me.get.mockResolvedValue({ 'sys.currency': 120.456, 'sys.transactions': [ - {type: 'out', user: 'kit', amount: 5, note: 'Starfall', time: 1700000000000, new_total: 120.45}, + {type: 'out', user: 'kit', amount: 5, note: 'Starfall', time: 1700000000000, new_total: 120.45, provider: 'app-mistwarp'}, {type: 'in', user: 'rotur', amount: 3, note: 'Daily claim', time: 1700000100}, {type: 'in', user: 'nobody', amount: 0, time: 1700000200000} ] @@ -38,7 +38,8 @@ describe('Rotur wallet', () => { expect(wallet.balance).toBe(120.46); expect(wallet.transactions.map(transaction => transaction.note)).toEqual(['Daily claim', 'Starfall']); expect(wallet.transactions[0]).toMatchObject({incoming: true, amount: 3, user: 'rotur', time: 1700000100000}); - expect(wallet.transactions[1]).toMatchObject({incoming: false, amount: 5, total: 120.45}); + expect(wallet.transactions[1]).toMatchObject({incoming: false, amount: 5, total: 120.45, mistwarp: true}); + expect(wallet.transactions[0].mistwarp).toBe(false); }); test('says so without asking when this sign-in cannot see credits', async () => { @@ -79,6 +80,16 @@ describe('Rotur wallet', () => { expect(await getDailyWait()).toBe(null); }); + test('knows which transactions came from MistWarp', () => { + const marked = normalizeTransactions([ + {type: 'out', amount: 1, provider: 'app-mistwarp', time: 3}, + {type: 'out', amount: 1, provider: 'mistwarp', time: 2}, + {type: 'out', amount: 1, provider: 'app-mistwarpish', time: 1}, + {type: 'out', amount: 1, time: 0} + ]); + expect(marked.map(transaction => transaction.mistwarp)).toEqual([true, true, false, false]); + }); + test('ignores transactions that are not objects', () => { expect(normalizeTransactions(null)).toEqual([]); expect(normalizeTransactions([null, 'x'])).toEqual([]);