Recipes
Wallet page
A wallet screen: hero, health, ledger, payout window and a top-up flow.
A wallet page shows how much money the brand has, whether that is healthy, where it went, and lets the brand add more. Every figure is a 2-decimal string; the "?" notes come from one dictionary.
The whole recipe
A wallet page is figures, health, the ledger and one action. The hero and the health card take the same numbers; the ledger groups entries by challenge; "Top up" opens a modal with TopUpAmountPicker, and the result comes back as TopUpResultBanner. All money is 2-decimal strings, and the "?" notes come from one dictionary.
Pinned to TRNDR preset
Code
import { useState } from 'react';
import { Banner, Button, HeroCard, Modal, MoneyNotesProvider, PageGrid, PageHeader, PayoutWindowCard, TopUpAmountPicker, TopUpResultBanner, WalletHealthCard, WalletLedger, useLanguage, type LedgerView, type TopUpResult } from '@ergasti/bricks';
import { blocksData, moneyNotes } from './sample-data';
function Page() {
const language = useLanguage();
const [view, setView] = useState<LedgerView>('grouped');
const [topUp, setTopUp] = useState(false);
const [result, setResult] = useState<TopUpResult | null>(null);
const w = blocksData.WALLET;
return (
<MoneyNotesProvider notes={moneyNotes(language)}>
<PageGrid>
<PageHeader title="Payments" subtitle="Your wallet, commissions and payouts to creators" actions={<Button size="sm" variant="rasp" onClick={() => setTopUp(true)}>Top up by card</Button>} />
<TopUpResultBanner result={result} onDismiss={() => setResult(null)} onRetry={() => { setResult(null); setTopUp(true); }} />
{w.low && <Banner tone="warn" icon="⚠️" action={<Button size="sm" onClick={() => setTopUp(true)}>Top up</Button>}>Your wallet is low. Top up so coupons keep working.</Banner>}
<PageGrid cols={2}>
<HeroCard figures={w} actions={<Button variant="white" onClick={() => setTopUp(true)}>Top up</Button>} />
<WalletHealthCard lowPercent={20} pauseDays={7} leftPercent={w.leftPercent} lastTopup={w.lastTopup} onOpenSettings={() => {}} />
</PageGrid>
<PayoutWindowCard title="November payouts" status="pending" day={4} windowDays={11} paid={38} creators={112} />
<WalletLedger groups={blocksData.LEDGER(language, () => {})} balance={w.balance} view={view} onViewChange={setView} onExport={() => {}} />
</PageGrid>
<Modal open={topUp} onClose={() => setTopUp(false)} title="Top up by card" hint="You are taken to the card page to pay.">
<TopUpAmountPicker suggested={[5000, 10000, 25000, 50000]} min={1000} max={500000} available={w.available} defaultValue="10000" onSubmit={() => { setTopUp(false); setResult('pending'); }} onCancel={() => setTopUp(false)} />
</Modal>
</MoneyNotesProvider>
);
}How it fits together
- One
MoneyNotesProvider(orBricksProvider moneyNotes) above the page gives every "?" its text. The hero, the health card and the ledger all draw notes without you wiring them. HeroCardtakes the wallet figures (available,balance,held,toppedUp,lastTopup,leftPercent,low) and your action buttons.WalletHealthCardtakes the same percentage and last top-up, works out ok or low (low at or under thelowPercentyou pass), and lets the server saynegativeorpaused. A PageGrid withcols={2}puts them side by side (one column at 1180px and under), and a plainPageGridstacks the page's cards 16px apart.WalletLedgertakes groups (a challenge, always-on, top-ups) each with entries and a total; the brand can flip between grouped and flat (view,onViewChange) and export.- The top-up flow is a
ModalaroundTopUpAmountPicker. When the card page returns, pass the result (ok,pending,failed) toTopUpResultBanner;failedoffers "Try again". - Loading and errors: the ledger takes
status="loading"andstatus="error"withonRetry; the health and hero cards are plain data, so wrap their load inAsyncBlock.
Related: HeroCard, WalletHealthCard, WalletLedger, TopUpAmountPicker, Money.