بلاک‌ها · بانکی و پرداخت
ری‌اکت ۱۹ و Next.js با پیاده‌سازی دسترس‌پذیری داخلی دیگویو ۳ با Composition APISvelte ۵ با runesانگولار با signals و دایرکتیوهای standaloneجتپک کامپوز با KotliniOS — هنوز پورت نشده

انتقال وجه: حساب مبدأ، شماره کارت مقصد، مبلغ با کنترل موجودی، تأیید خلاصه و رمز پویا.

۱. نصب کامپوننت‌ها

این بلاک از ۱۴ آیتم دیگ استفاده می‌کند: alert-dialogavatarbank-logobuttoncontrol-sizedialogiconsinput-otplabelpersianselectseparatortext-fieldtoast

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add https://docs.digdesign.ir/r/alert-dialog.json https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/bank-logo.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/input-otp.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/separator.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.json
pnpm dlx digdesign@latest add https://docs.digdesign.ir/r/alert-dialog.json https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/bank-logo.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/input-otp.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/separator.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.json
yarn dlx digdesign@latest add https://docs.digdesign.ir/r/alert-dialog.json https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/bank-logo.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/input-otp.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/separator.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.json
bunx --bun digdesign@latest add https://docs.digdesign.ir/r/alert-dialog.json https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/bank-logo.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/input-otp.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/separator.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.json
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog input-otp label persian select separator text-field toast --framework vue
pnpm dlx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog input-otp label persian select separator text-field toast --framework vue
yarn dlx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog input-otp label persian select separator text-field toast --framework vue
bunx --bun digdesign@latest add alert-dialog avatar bank-logo button control-size dialog input-otp label persian select separator text-field toast --framework vue
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add button --framework svelte
pnpm dlx digdesign@latest add button --framework svelte
yarn dlx digdesign@latest add button --framework svelte
bunx --bun digdesign@latest add button --framework svelte
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog icons input input-otp label persian select separator text-field toast utils --framework angular
pnpm dlx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog icons input input-otp label persian select separator text-field toast utils --framework angular
yarn dlx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog icons input input-otp label persian select separator text-field toast utils --framework angular
bunx --bun digdesign@latest add alert-dialog avatar bank-logo button control-size dialog icons input input-otp label persian select separator text-field toast utils --framework angular
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog input-otp label persian select separator text-field toast --framework android
pnpm dlx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog input-otp label persian select separator text-field toast --framework android
yarn dlx digdesign@latest add alert-dialog avatar bank-logo button control-size dialog input-otp label persian select separator text-field toast --framework android
bunx --bun digdesign@latest add alert-dialog avatar bank-logo button control-size dialog input-otp label persian select separator text-field toast --framework android

۲. کد صفحه

کد را در صفحهٔ پروژه‌تان بگذارید (React: app/<route>/page.tsx) و متن‌ها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریم‌ورک کدِ همین صفحه در فریم‌ورک دیگر را ببینید.

money-transfer.tsx
"use client";

import * as React from "react";

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { CheckIcon, CopyIcon } from "@/components/icons";
import { Avatar } from "@/components/ui/avatar";
import { BankLogo, getBankByCard } from "@/components/ui/bank-logo";
import { Button } from "@/components/ui/button";
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog";
import { ControlSizeProvider } from "@/components/ui/control-size";
import {
  InputOTP,
  InputOTPGroup,
  InputOTPSlot,
} from "@/components/ui/input-otp";
import { Label } from "@/components/ui/label";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemDescription,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import { TextField } from "@/components/ui/text-field";
import { toast } from "@/components/ui/toast";
import {
  formatCurrency,
  formatJalaliDateTime,
  formatNumber,
  toFaDigits,
} from "@/lib/persian";
import { stockImages, type StockImageName } from "@/lib/stock-images";

const ACCOUNTS = [
  {
    id: "current",
    label: "حساب جاری",
    bank: "mellat",
    number: "0123-4567-89",
    balance: 128_450_000,
  },
  {
    id: "saving",
    label: "حساب پس‌انداز",
    bank: "saman",
    number: "0987-6543-21",
    balance: 42_000_000,
  },
];

const QUICK_AMOUNTS = [500_000, 1_000_000, 5_000_000];
const RECENT: { name: string; card: string; image: StockImageName }[] = [
  { name: "سارا محمدی", card: "6037997512345678", image: "personWoman2" },
  { name: "امیر رضایی", card: "6219861034567812", image: "personMan1" },
  { name: "نگار احمدی", card: "6104337798765432", image: "personWoman3" },
];

type Receipt = {
  amount: number;
  card: string;
  owner: string;
  source: (typeof ACCOUNTS)[number];
  code: string;
  date: Date;
};

/** جای استعلامِ واقعی نامِ دارندهٔ کارت (سرویس بانک یا شاپرک). */
async function lookupCardOwner(card: string) {
  await new Promise((resolve) => setTimeout(resolve, 700));
  if (card.endsWith("0000")) return null;
  return RECENT.find((item) => item.card === card)?.name ?? "آرمیتا رستگار";
}

/** «۶۰۳۷ ۹۹۷۵ ۱۲۳۴ ۵۶۷۸» برای خلاصهٔ تأیید. */
const groupCard = (card: string) =>
  toFaDigits(card.replace(/(\d{4})(?=\d)/g, "$1 "));

/**
 * کارت به کارت: فرم با استعلامِ نامِ دارنده و لوگوی بانک، مبلغ‌های پرکاربرد، ستونِ کنار با
 * موجودی و مقصدهای اخیر (عکس‌دار، با یک کلیک پر می‌شود)؛ تأیید، رمزِ پویا و رسید.
 */
export default function MoneyTransferBlock() {
  const [account, setAccount] = React.useState("current");
  const [card, setCard] = React.useState("");
  const [amount, setAmount] = React.useState("");
  const [confirming, setConfirming] = React.useState(false);
  const [otpStep, setOtpStep] = React.useState(false);
  const [sending, setSending] = React.useState(false);
  const [receipt, setReceipt] = React.useState<Receipt | null>(null);
  const [copied, setCopied] = React.useState(false);
  const [owner, setOwner] = React.useState<{
    card: string;
    name: string | null;
  } | null>(null);

  const source = ACCOUNTS.find((item) => item.id === account)!;
  const value = Number(amount || 0);
  const overBalance = value > source.balance;
  const destinationBank = getBankByCard(card);
  const complete = card.length === 16 && Boolean(destinationBank);
  // نتیجهٔ استعلام فقط برای همان کارتی معتبر است که استعلام شده.
  const ownerName = owner?.card === card ? owner.name : undefined;
  const lookingUp = complete && owner?.card !== card;
  const ready = complete && Boolean(ownerName) && value > 0 && !overBalance;

  React.useEffect(() => {
    if (!complete) return;
    let current = true;
    lookupCardOwner(card).then((name) => current && setOwner({ card, name }));
    return () => {
      current = false;
    };
  }, [card, complete]);

  async function send(code: string) {
    setSending(true);
    // جای درخواستِ واقعی انتقال با کدِ رمزِ پویا.
    await new Promise((resolve) => setTimeout(resolve, 900));
    setSending(false);
    setOtpStep(false);
    // انتقالِ پول رسید می‌خواهد، نه یک اعلانِ چندثانیه‌ای: کاربر باید بتواند کد پیگیری را بردارد.
    setReceipt({
      amount: value,
      card,
      owner: ownerName ?? "",
      source,
      code: `${code}8821`,
      date: new Date(),
    });
    setCard("");
    setAmount("");
  }

  async function copyCode(code: string) {
    try {
      await navigator.clipboard.writeText(code);
      setCopied(true);
      setTimeout(() => setCopied(false), 2000);
    } catch {
      toast.error("کپی نشد؛ کد را دستی بردارید.");
    }
  }

  return (
    <ControlSizeProvider size="xl" asChild>
      <main className="mx-auto grid grid-cols-1 w-full max-w-5xl items-start gap-8 p-4 sm:p-6 lg:grid-cols-[minmax(0,1fr)_20rem]">
        <form
          className="flex flex-col gap-8 rounded-xl border border-border bg-card p-6 sm:p-8"
          onSubmit={(event) => {
            event.preventDefault();
            if (ready) setConfirming(true);
          }}
        >
          <div className="flex flex-col gap-1">
            <h1 className="text-2xl font-bold">کارت به کارت</h1>
            <p className="text-muted-foreground">
              انتقال وجه به هر کارتِ عضو شتاب.
            </p>
          </div>
          <div className="flex flex-col gap-5">
            <div className="flex flex-col gap-2">
              <Label id="source-label">از حساب</Label>
              <Select
                name="source"
                value={account}
                onValueChange={(next) => setAccount(next as string)}
              >
                <SelectTrigger
                  aria-labelledby="source-label"
                  className="w-full"
                >
                  <SelectValue />
                </SelectTrigger>
                <SelectContent>
                  {ACCOUNTS.map((item) => (
                    // موجودی فقط در فهرست دیده می‌شود؛ دکمه فقط لوگو و نامِ حساب را نشان می‌دهد تا در موبایل بریده نشود.
                    <SelectItem key={item.id} value={item.id}>
                      <BankLogo bank={item.bank} size="sm" />
                      <span className="flex flex-col">
                        {item.label}
                        <SelectItemDescription>
                          موجودی {formatCurrency(item.balance)}
                        </SelectItemDescription>
                      </span>
                    </SelectItem>
                  ))}
                </SelectContent>
              </Select>
            </div>
            <TextField
              label="شماره کارت مقصد"
              name="card"
              inputMode="numeric"
              dir="ltr"
              digitGroups={[4, 4, 4, 4]}
              // کارتِ مقصد مالِ کسِ دیگری است؛ پرکردنش از کارت‌های ذخیره‌شدهٔ مرورگر اشتباه است.
              autoComplete="off"
              value={card}
              onValueChange={setCard}
              // لوگوی بانک با تایپِ ۶ رقمِ اول خودش ظاهر می‌شود.
              endContent={<BankLogo cardNumber={card} size="sm" showName />}
              invalid={
                (card.length >= 6 && !destinationBank) || ownerName === null
              }
              errorMessage={
                ownerName === null
                  ? "این کارت فعال نیست یا استعلام نشد."
                  : "این شماره کارت به هیچ بانکی تعلق ندارد."
              }
              description={
                lookingUp ? (
                  "در حال استعلام نام دارنده…"
                ) : ownerName ? (
                  <>
                    به نام{" "}
                    <span className="font-semibold text-foreground">
                      {ownerName}
                    </span>
                  </>
                ) : undefined
              }
              required
            />
            {/* مبلغ‌های پرکاربرد زیرِ خودِ فیلد، چون مالِ همان‌اند. */}
            <div className="flex flex-col gap-3">
              <TextField
                label="مبلغ"
                name="amount"
                inputMode="numeric"
                dir="rtl"
                groupDigits
                endContent="تومان"
                value={amount}
                onValueChange={setAmount}
                invalid={overBalance}
                errorMessage="مبلغ از موجودی حساب بیشتر است."
                description={`موجودی: ${formatCurrency(source.balance)}`}
                required
              />
              <div className="grid grid-cols-3 gap-2" role="group" aria-label="مبلغ‌های پرکاربرد (تومان)">
                {QUICK_AMOUNTS.map((quick) => (
                  <Button key={quick} type="button" variant="outline" className="px-2 tabular-nums" onClick={() => setAmount(String(quick))}>
                    {formatNumber(quick)}
                  </Button>
                ))}
              </div>
            </div>
            <TextField label="توضیحات" name="note" optional maxLength={60} />
          </div>
          <div className="border-t border-border pt-8">
            <Button type="submit" fullWidth disabled={!ready}>
              ادامه
            </Button>
          </div>
        </form>

        <aside className="flex flex-col gap-6">
          <div className="flex flex-col gap-1 rounded-xl bg-inverse p-6 text-[var(--dig-white)] [--muted-foreground:var(--dig-neutral-400)]">
            <span className="text-sm text-muted-foreground">
              موجودی {source.label}
            </span>
            <span className="text-2xl font-black tabular-nums">
              {formatCurrency(source.balance)}
            </span>
            <span className="mt-3 text-xs text-muted-foreground">
              سقفِ انتقالِ امروز: {formatCurrency(50_000_000)}
            </span>
          </div>
          <section
            aria-labelledby="recent-title"
            className="flex flex-col gap-3"
          >
            <h2 id="recent-title" className="font-semibold">
              مقصدهای اخیر
            </h2>
            <ul className="flex flex-col gap-2">
              {RECENT.map((item) => (
                <li key={item.card}>
                  <Button
                    type="button"
                    variant="outline"
                    onClick={() => {
                      setCard(item.card);
                      // مقصدهای ذخیره‌شده از قبل استعلام شده‌اند؛ نام باید همان لحظه با شماره هماهنگ شود.
                      setOwner({ card: item.card, name: item.name });
                    }}
                    className={`h-auto w-full justify-start gap-3 py-3 font-normal ${card === item.card ? "border-primary bg-primary-subtle" : ""}`}
                  >
                    <Avatar alt={item.name} src={stockImages[item.image].src} />
                    <span className="flex flex-1 flex-col items-start">
                      <span className="font-medium">{item.name}</span>
                      <bdi dir="ltr" className="text-xs text-muted-foreground">
                        {toFaDigits(
                          `${item.card.slice(0, 4)} •••• ${item.card.slice(-4)}`,
                        )}
                      </bdi>
                    </span>
                    <BankLogo cardNumber={item.card} size="sm" />
                  </Button>
                </li>
              ))}
            </ul>
          </section>
        </aside>

        <AlertDialog open={confirming} onOpenChange={setConfirming}>
          <ControlSizeProvider size="xl" asChild>
            <AlertDialogContent>
              <AlertDialogHeader>
                <AlertDialogTitle>انتقال را تأیید می‌کنید؟</AlertDialogTitle>
                <AlertDialogDescription>
                  این انتقال بعد از انجام قابل بازگشت نیست.
                </AlertDialogDescription>
              </AlertDialogHeader>
              <TransferParties
                source={source}
                card={card}
                owner={ownerName ?? ""}
              />
              <Separator />
              <div className="flex justify-between gap-2 text-sm font-semibold">
                <span>مبلغ</span>
                <span>{formatCurrency(value)}</span>
              </div>
              <AlertDialogFooter>
                <AlertDialogCancel>انصراف</AlertDialogCancel>
                <AlertDialogAction
                  onClick={() => {
                    setConfirming(false);
                    setOtpStep(true);
                  }}
                >
                  تأیید و دریافت رمز پویا
                </AlertDialogAction>
              </AlertDialogFooter>
            </AlertDialogContent>
          </ControlSizeProvider>
        </AlertDialog>

        <AlertDialog open={otpStep} onOpenChange={setOtpStep}>
          <ControlSizeProvider size="xl" asChild>
            <AlertDialogContent>
              <AlertDialogHeader>
                <AlertDialogTitle>رمز پویا</AlertDialogTitle>
                <AlertDialogDescription>
                  کد ۶ رقمی پیامک‌شده را وارد کنید.
                </AlertDialogDescription>
              </AlertDialogHeader>
              <InputOTP
                aria-label="رمز پویا"
                onComplete={send}
                disabled={sending}
                className="mx-auto"
              >
                <InputOTPGroup>
                  {[0, 1, 2, 3, 4, 5].map((index) => (
                    <InputOTPSlot key={index} index={index} />
                  ))}
                </InputOTPGroup>
              </InputOTP>
              <AlertDialogFooter>
                <AlertDialogCancel disabled={sending}>انصراف</AlertDialogCancel>
              </AlertDialogFooter>
            </AlertDialogContent>
          </ControlSizeProvider>
        </AlertDialog>

        <Dialog
          open={receipt !== null}
          onOpenChange={(open) => !open && setReceipt(null)}
        >
          {receipt && (
            <ControlSizeProvider size="xl" asChild>
              <DialogContent>
                <DialogHeader className="items-center text-center">
                  <span
                    aria-hidden
                    className="mb-1 flex size-12 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-6"
                  >
                    <CheckIcon />
                  </span>
                  <DialogTitle>انتقال انجام شد</DialogTitle>
                  <DialogDescription>
                    {formatJalaliDateTime(receipt.date)}
                  </DialogDescription>
                </DialogHeader>
                <p className="text-center text-2xl font-bold">
                  {formatCurrency(receipt.amount)}
                </p>
                <TransferParties
                  source={receipt.source}
                  card={receipt.card}
                  owner={receipt.owner}
                />
                <Separator />
                <div className="flex items-center justify-between gap-2 text-sm">
                  <span className="text-muted-foreground">کد پیگیری</span>
                  <span className="flex items-center gap-1">
                    <bdi dir="ltr" className="font-semibold tracking-wider">
                      {toFaDigits(receipt.code)}
                    </bdi>
                    <Button
                      variant="ghost"
                      size="icon"
                      aria-label={copied ? "کد پیگیری کپی شد" : "کپی کد پیگیری"}
                      onClick={() => copyCode(receipt.code)}
                    >
                      {copied ? (
                        <CheckIcon className="text-success-subtle-foreground" />
                      ) : (
                        <CopyIcon />
                      )}
                    </Button>
                  </span>
                </div>
                <DialogFooter>
                  <Button fullWidth onClick={() => setReceipt(null)}>
                    بازگشت
                  </Button>
                </DialogFooter>
              </DialogContent>
            </ControlSizeProvider>
          )}
        </Dialog>
      </main>
    </ControlSizeProvider>
  );
}

/** دو طرفِ انتقال با لوگوی بانک؛ هم در تأیید و هم در رسید. */
function TransferParties({
  source,
  card,
  owner,
}: {
  source: (typeof ACCOUNTS)[number];
  card: string;
  owner: string;
}) {
  const bank = getBankByCard(card);
  return (
    <dl className="flex flex-col gap-3 text-sm">
      <div className="flex items-center justify-between gap-3">
        <dt className="text-muted-foreground">از</dt>
        <dd className="flex items-center gap-2">
          <span className="flex flex-col items-end">
            <span>{source.label}</span>
            <bdi dir="ltr" className="text-xs text-muted-foreground">
              {toFaDigits(source.number)}
            </bdi>
          </span>
          <BankLogo bank={source.bank} />
        </dd>
      </div>
      <div className="flex items-center justify-between gap-3">
        <dt className="text-muted-foreground">به</dt>
        <dd className="flex items-center gap-2">
          <span className="flex flex-col items-end">
            <span className="font-medium">{owner}</span>
            <span className="text-xs text-muted-foreground">
              {bank?.name} · <bdi dir="ltr">{groupCard(card)}</bdi>
            </span>
          </span>
          <BankLogo cardNumber={card} />
        </dd>
      </div>
    </dl>
  );
}
money-transfer.vue
<script setup lang="ts">
import { computed, ref, watch } from "vue"

import AlertDialog from "@/components/ui/AlertDialog.vue"
import AlertDialogAction from "@/components/ui/AlertDialogAction.vue"
import AlertDialogCancel from "@/components/ui/AlertDialogCancel.vue"
import AlertDialogContent from "@/components/ui/AlertDialogContent.vue"
import AlertDialogDescription from "@/components/ui/AlertDialogDescription.vue"
import AlertDialogFooter from "@/components/ui/AlertDialogFooter.vue"
import AlertDialogHeader from "@/components/ui/AlertDialogHeader.vue"
import AlertDialogTitle from "@/components/ui/AlertDialogTitle.vue"
import Avatar from "@/components/ui/Avatar.vue"
import BankLogo from "@/components/ui/BankLogo.vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Dialog from "@/components/ui/Dialog.vue"
import DialogContent from "@/components/ui/DialogContent.vue"
import DialogDescription from "@/components/ui/DialogDescription.vue"
import DialogFooter from "@/components/ui/DialogFooter.vue"
import DialogHeader from "@/components/ui/DialogHeader.vue"
import DialogTitle from "@/components/ui/DialogTitle.vue"
import InputOTP from "@/components/ui/InputOTP.vue"
import InputOTPGroup from "@/components/ui/InputOTPGroup.vue"
import InputOTPSlot from "@/components/ui/InputOTPSlot.vue"
import Label from "@/components/ui/Label.vue"
import Select from "@/components/ui/Select.vue"
import SelectContent from "@/components/ui/SelectContent.vue"
import SelectItem from "@/components/ui/SelectItem.vue"
import SelectItemDescription from "@/components/ui/SelectItemDescription.vue"
import SelectTrigger from "@/components/ui/SelectTrigger.vue"
import SelectValue from "@/components/ui/SelectValue.vue"
import Separator from "@/components/ui/Separator.vue"
import TextField from "@/components/ui/TextField.vue"
import { toast } from "@/components/ui/Toast.vue"
import { DigIcon } from "@/lib/icons"
import { getBankByCard } from "@/lib/iran-banks"
import { formatCurrency, formatJalaliDateTime, formatNumber, toFaDigits } from "@/lib/persian"

const IMAGE_BASE = "https://docs.digdesign.ir/images"

const ACCOUNTS = [
  { id: "current", label: "حساب جاری", bank: "mellat", number: "0123-4567-89", balance: 128_450_000 },
  { id: "saving", label: "حساب پس‌انداز", bank: "saman", number: "0987-6543-21", balance: 42_000_000 },
]

const QUICK_AMOUNTS = [500_000, 1_000_000, 5_000_000]
const RECENT = [
  { name: "سارا محمدی", card: "6037997512345678", image: `${IMAGE_BASE}/person-woman-2.webp` },
  { name: "امیر رضایی", card: "6219861034567812", image: `${IMAGE_BASE}/person-man-1.webp` },
  { name: "نگار احمدی", card: "6104337798765432", image: `${IMAGE_BASE}/person-woman-3.webp` },
]

type Account = (typeof ACCOUNTS)[number]
type Receipt = {
  amount: number
  card: string
  owner: string
  source: Account
  code: string
  date: Date
}

/** جای استعلامِ واقعی نامِ دارندهٔ کارت (سرویس بانک یا شاپرک). */
async function lookupCardOwner(card: string) {
  await new Promise((resolve) => setTimeout(resolve, 700))
  if (card.endsWith("0000")) return null
  return RECENT.find((item) => item.card === card)?.name ?? "آرمیتا رستگار"
}

/** «۶۰۳۷ ۹۹۷۵ ۱۲۳۴ ۵۶۷۸» برای خلاصهٔ تأیید. */
const groupCard = (card: string) => toFaDigits(card.replace(/(\d{4})(?=\d)/g, "$1 "))

/**
 * کارت به کارت: فرم با استعلامِ نامِ دارنده و لوگوی بانک، مبلغ‌های پرکاربرد، ستونِ کنار با
 * موجودی و مقصدهای اخیر (عکس‌دار، با یک کلیک پر می‌شود)؛ تأیید، رمزِ پویا و رسید.
 */
const account = ref("current")
const card = ref("")
const amount = ref("")
const confirming = ref(false)
const otpStep = ref(false)
const sending = ref(false)
const receipt = ref<Receipt | null>(null)
const copied = ref(false)
const owner = ref<{ card: string; name: string | null } | null>(null)

const source = computed(() => ACCOUNTS.find((item) => item.id === account.value)!)
const value = computed(() => Number(amount.value || 0))
const overBalance = computed(() => value.value > source.value.balance)
const destinationBank = computed(() => getBankByCard(card.value))
const complete = computed(() => card.value.length === 16 && Boolean(destinationBank.value))
// نتیجهٔ استعلام فقط برای همان کارتی معتبر است که استعلام شده.
const ownerName = computed(() => (owner.value?.card === card.value ? owner.value.name : undefined))
const lookingUp = computed(() => complete.value && owner.value?.card !== card.value)
const ready = computed(() => complete.value && Boolean(ownerName.value) && value.value > 0 && !overBalance.value)

watch(
  [card, complete],
  ([currentCard, isComplete], _old, onCleanup) => {
    if (!isComplete) return
    let current = true
    lookupCardOwner(currentCard).then((name) => {
      if (current) owner.value = { card: currentCard, name }
    })
    onCleanup(() => {
      current = false
    })
  },
  { immediate: true }
)

async function send(code: string) {
  sending.value = true
  // جای درخواستِ واقعی انتقال با کدِ رمزِ پویا.
  await new Promise((resolve) => setTimeout(resolve, 900))
  sending.value = false
  otpStep.value = false
  // انتقالِ پول رسید می‌خواهد، نه یک اعلانِ چندثانیه‌ای: کاربر باید بتواند کد پیگیری را بردارد.
  receipt.value = {
    amount: value.value,
    card: card.value,
    owner: ownerName.value ?? "",
    source: source.value,
    code: `${code}8821`,
    date: new Date(),
  }
  card.value = ""
  amount.value = ""
}

async function copyCode(code: string) {
  try {
    await navigator.clipboard.writeText(code)
    copied.value = true
    setTimeout(() => {
      copied.value = false
    }, 2000)
  } catch {
    toast.error("کپی نشد؛ کد را دستی بردارید.")
  }
}

function onSubmit() {
  if (ready.value) confirming.value = true
}

function pickRecent(item: (typeof RECENT)[number]) {
  card.value = item.card
  // مقصدهای ذخیره‌شده از قبل استعلام شده‌اند؛ نام باید همان لحظه با شماره هماهنگ شود.
  owner.value = { card: item.card, name: item.name }
}

function goToOtp() {
  confirming.value = false
  otpStep.value = true
}

function onReceiptOpen(open: boolean) {
  if (!open) receipt.value = null
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="mx-auto grid grid-cols-1 w-full max-w-5xl items-start gap-8 p-4 sm:p-6 lg:grid-cols-[minmax(0,1fr)_20rem]">
      <form class="flex flex-col gap-8 rounded-xl border border-border bg-card p-6 sm:p-8" @submit.prevent="onSubmit">
        <div class="flex flex-col gap-1">
          <h1 class="text-2xl font-bold">کارت به کارت</h1>
          <p class="text-muted-foreground">انتقال وجه به هر کارتِ عضو شتاب.</p>
        </div>
        <div class="flex flex-col gap-5">
          <div class="flex flex-col gap-2">
            <Label id="source-label">از حساب</Label>
            <Select name="source" :value="account" @update:value="account = $event as string">
              <SelectTrigger aria-labelledby="source-label" class="w-full">
                <SelectValue />
              </SelectTrigger>
              <SelectContent>
                <!-- موجودی فقط در فهرست دیده می‌شود؛ دکمه فقط لوگو و نامِ حساب را نشان می‌دهد تا در موبایل بریده نشود. -->
                <SelectItem v-for="item in ACCOUNTS" :key="item.id" :value="item.id">
                  <BankLogo :bank="item.bank" size="sm" />
                  <span class="flex flex-col">
                    {{ item.label }}
                    <SelectItemDescription>موجودی {{ formatCurrency(item.balance) }}</SelectItemDescription>
                  </span>
                </SelectItem>
              </SelectContent>
            </Select>
          </div>
          <TextField
            v-model="card"
            label="شماره کارت مقصد"
            name="card"
            inputmode="numeric"
            dir="ltr"
            :digit-groups="[4, 4, 4, 4]"
            autocomplete="off"
            :invalid="(card.length >= 6 && !destinationBank) || ownerName === null"
            :error-message="ownerName === null ? 'این کارت فعال نیست یا استعلام نشد.' : 'این شماره کارت به هیچ بانکی تعلق ندارد.'"
            required
          >
            <!-- لوگوی بانک با تایپِ ۶ رقمِ اول خودش ظاهر می‌شود. -->
            <template #endContent>
              <BankLogo :card-number="card" size="sm" show-name />
            </template>
            <template v-if="lookingUp || ownerName" #description>
              <template v-if="lookingUp">در حال استعلام نام دارنده…</template>
              <template v-else>
                به نام <span class="font-semibold text-foreground">{{ ownerName }}</span>
              </template>
            </template>
          </TextField>
          <!-- مبلغ‌های پرکاربرد زیرِ خودِ فیلد، چون مالِ همان‌اند. -->
          <div class="flex flex-col gap-3">
            <TextField
              v-model="amount"
              label="مبلغ"
              name="amount"
              inputmode="numeric"
              dir="rtl"
              group-digits
              :invalid="overBalance"
              error-message="مبلغ از موجودی حساب بیشتر است."
              :description="`موجودی: ${formatCurrency(source.balance)}`"
              required
            >
              <template #endContent>تومان</template>
            </TextField>
            <div class="grid grid-cols-3 gap-2" role="group" aria-label="مبلغ‌های پرکاربرد (تومان)">
              <Button v-for="quick in QUICK_AMOUNTS" :key="quick" type="button" variant="outline" class="px-2 tabular-nums" @click="amount = String(quick)">
                {{ formatNumber(quick) }}
              </Button>
            </div>
          </div>
          <TextField label="توضیحات" name="note" optional maxlength="60" />
        </div>
        <div class="border-t border-border pt-8">
          <Button type="submit" full-width :disabled="!ready">ادامه</Button>
        </div>
      </form>

      <aside class="flex flex-col gap-6">
        <div class="flex flex-col gap-1 rounded-xl bg-inverse p-6 text-[var(--dig-white)] [--muted-foreground:var(--dig-neutral-400)]">
          <span class="text-sm text-muted-foreground">موجودی {{ source.label }}</span>
          <span class="text-2xl font-black tabular-nums">{{ formatCurrency(source.balance) }}</span>
          <span class="mt-3 text-xs text-muted-foreground">سقفِ انتقالِ امروز: {{ formatCurrency(50_000_000) }}</span>
        </div>
        <section aria-labelledby="recent-title" class="flex flex-col gap-3">
          <h2 id="recent-title" class="font-semibold">مقصدهای اخیر</h2>
          <ul class="flex flex-col gap-2">
            <li v-for="item in RECENT" :key="item.card">
              <Button
                type="button"
                variant="outline"
                :class="['h-auto w-full justify-start gap-3 py-3 font-normal', card === item.card ? 'border-primary bg-primary-subtle' : '']"
                @click="pickRecent(item)"
              >
                <Avatar :alt="item.name" :src="item.image" />
                <span class="flex flex-1 flex-col items-start">
                  <span class="font-medium">{{ item.name }}</span>
                  <bdi dir="ltr" class="text-xs text-muted-foreground">
                    {{ toFaDigits(`${item.card.slice(0, 4)} •••• ${item.card.slice(-4)}`) }}
                  </bdi>
                </span>
                <BankLogo :card-number="item.card" size="sm" />
              </Button>
            </li>
          </ul>
        </section>
      </aside>

      <AlertDialog :open="confirming" @update:open="confirming = $event">
        <ControlSize size="xl" as-child>
          <AlertDialogContent>
            <AlertDialogHeader>
              <AlertDialogTitle>انتقال را تأیید می‌کنید؟</AlertDialogTitle>
              <AlertDialogDescription>این انتقال بعد از انجام قابل بازگشت نیست.</AlertDialogDescription>
            </AlertDialogHeader>
            <!-- دو طرفِ انتقال با لوگوی بانک. -->
            <dl class="flex flex-col gap-3 text-sm">
              <div class="flex items-center justify-between gap-3">
                <dt class="text-muted-foreground">از</dt>
                <dd class="flex items-center gap-2">
                  <span class="flex flex-col items-end">
                    <span>{{ source.label }}</span>
                    <bdi dir="ltr" class="text-xs text-muted-foreground">{{ toFaDigits(source.number) }}</bdi>
                  </span>
                  <BankLogo :bank="source.bank" />
                </dd>
              </div>
              <div class="flex items-center justify-between gap-3">
                <dt class="text-muted-foreground">به</dt>
                <dd class="flex items-center gap-2">
                  <span class="flex flex-col items-end">
                    <span class="font-medium">{{ ownerName ?? "" }}</span>
                    <span class="text-xs text-muted-foreground">
                      {{ destinationBank?.name }} · <bdi dir="ltr">{{ groupCard(card) }}</bdi>
                    </span>
                  </span>
                  <BankLogo :card-number="card" />
                </dd>
              </div>
            </dl>
            <Separator />
            <div class="flex justify-between gap-2 text-sm font-semibold">
              <span>مبلغ</span>
              <span>{{ formatCurrency(value) }}</span>
            </div>
            <AlertDialogFooter>
              <AlertDialogCancel>انصراف</AlertDialogCancel>
              <AlertDialogAction @click="goToOtp">تأیید و دریافت رمز پویا</AlertDialogAction>
            </AlertDialogFooter>
          </AlertDialogContent>
        </ControlSize>
      </AlertDialog>

      <AlertDialog :open="otpStep" @update:open="otpStep = $event">
        <ControlSize size="xl" as-child>
          <AlertDialogContent>
            <AlertDialogHeader>
              <AlertDialogTitle>رمز پویا</AlertDialogTitle>
              <AlertDialogDescription>کد ۶ رقمی پیامک‌شده را وارد کنید.</AlertDialogDescription>
            </AlertDialogHeader>
            <InputOTP aria-label="رمز پویا" :disabled="sending" class="mx-auto" @complete="send">
              <InputOTPGroup>
                <InputOTPSlot v-for="index in [0, 1, 2, 3, 4, 5]" :key="index" :index="index" />
              </InputOTPGroup>
            </InputOTP>
            <AlertDialogFooter>
              <AlertDialogCancel :disabled="sending">انصراف</AlertDialogCancel>
            </AlertDialogFooter>
          </AlertDialogContent>
        </ControlSize>
      </AlertDialog>

      <Dialog :open="receipt !== null" @update:open="onReceiptOpen">
        <ControlSize v-if="receipt" size="xl" as-child>
          <DialogContent>
            <DialogHeader class="items-center text-center">
              <span aria-hidden="true" class="mb-1 flex size-12 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-6">
                <DigIcon name="check" />
              </span>
              <DialogTitle>انتقال انجام شد</DialogTitle>
              <DialogDescription>{{ formatJalaliDateTime(receipt.date) }}</DialogDescription>
            </DialogHeader>
            <p class="text-center text-2xl font-bold">{{ formatCurrency(receipt.amount) }}</p>
            <dl class="flex flex-col gap-3 text-sm">
              <div class="flex items-center justify-between gap-3">
                <dt class="text-muted-foreground">از</dt>
                <dd class="flex items-center gap-2">
                  <span class="flex flex-col items-end">
                    <span>{{ receipt.source.label }}</span>
                    <bdi dir="ltr" class="text-xs text-muted-foreground">{{ toFaDigits(receipt.source.number) }}</bdi>
                  </span>
                  <BankLogo :bank="receipt.source.bank" />
                </dd>
              </div>
              <div class="flex items-center justify-between gap-3">
                <dt class="text-muted-foreground">به</dt>
                <dd class="flex items-center gap-2">
                  <span class="flex flex-col items-end">
                    <span class="font-medium">{{ receipt.owner }}</span>
                    <span class="text-xs text-muted-foreground">
                      {{ getBankByCard(receipt.card)?.name }} · <bdi dir="ltr">{{ groupCard(receipt.card) }}</bdi>
                    </span>
                  </span>
                  <BankLogo :card-number="receipt.card" />
                </dd>
              </div>
            </dl>
            <Separator />
            <div class="flex items-center justify-between gap-2 text-sm">
              <span class="text-muted-foreground">کد پیگیری</span>
              <span class="flex items-center gap-1">
                <bdi dir="ltr" class="font-semibold tracking-wider">{{ toFaDigits(receipt.code) }}</bdi>
                <Button variant="ghost" size="icon" :aria-label="copied ? 'کد پیگیری کپی شد' : 'کپی کد پیگیری'" @click="copyCode(receipt.code)">
                  <DigIcon v-if="copied" name="check" class="text-success-subtle-foreground" />
                  <DigIcon v-else name="copy" />
                </Button>
              </span>
            </div>
            <DialogFooter>
              <Button full-width @click="receipt = null">بازگشت</Button>
            </DialogFooter>
          </DialogContent>
        </ControlSize>
      </Dialog>
    </main>
  </ControlSize>
</template>

کدِ این بلاک هنوز برای Svelte نوشته نشده است.

این موارد هنوز برای Svelte آماده نیستند: alert-dialogavatarbank-logocontrol-sizedialoginput-otplabelpersianselectseparatortext-fieldtoastآیکون checkآیکون copy

کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننت‌های Svelte می‌سازد.

money-transfer.ts
import { Component, ChangeDetectionStrategy, signal, computed, effect, untracked } from "@angular/core"

import { DigControlSize } from "@/components/ui/control-size"
import { DigLabel } from "@/components/ui/label"
import {
  DigSelect,
  DigSelectTrigger,
  DigSelectValue,
  DigSelectContent,
  DigSelectItem,
  DigSelectItemDescription,
} from "@/components/ui/select"
import { DigBankLogo } from "@/components/ui/bank-logo"
import { DigTextField } from "@/components/ui/text-field"
import { DigInputEnd, DigInput, DigInputField } from "@/components/ui/input"
import { DigButton } from "@/components/ui/button"
import { cn } from "@/lib/utils"
import { DigAvatar } from "@/components/ui/avatar"
import {
  DigAlertDialog,
  DigAlertDialogContent,
  DigAlertDialogHeader,
  DigAlertDialogTitle,
  DigAlertDialogDescription,
  DigAlertDialogFooter,
  DigAlertDialogCancel,
  DigAlertDialogAction,
} from "@/components/ui/alert-dialog"
import { DigSeparator } from "@/components/ui/separator"
import { DigInputOtp, DigInputOtpGroup, DigInputOtpSlot } from "@/components/ui/input-otp"
import {
  DigDialog,
  DigDialogContent,
  DigDialogHeader,
  DigDialogTitle,
  DigDialogDescription,
  DigDialogFooter,
} from "@/components/ui/dialog"
import { DigIcon } from "@/lib/icons"
import { FormsModule } from "@angular/forms"
import { toast } from "@/components/ui/toast"
import { getBankByCard } from "@/lib/iran-banks"
import { formatCurrency, formatJalaliDateTime, formatNumber, toFaDigits } from "@/lib/persian"

const IMAGE_BASE = "https://docs.digdesign.ir/images"

const ACCOUNTS = [
  { id: "current", label: "حساب جاری", bank: "mellat", number: "0123-4567-89", balance: 128_450_000 },
  { id: "saving", label: "حساب پس‌انداز", bank: "saman", number: "0987-6543-21", balance: 42_000_000 },
]

const QUICK_AMOUNTS = [500_000, 1_000_000, 5_000_000]

const RECENT = [
  { name: "سارا محمدی", card: "6037997512345678", image: `${IMAGE_BASE}/person-woman-2.webp` },
  { name: "امیر رضایی", card: "6219861034567812", image: `${IMAGE_BASE}/person-man-1.webp` },
  { name: "نگار احمدی", card: "6104337798765432", image: `${IMAGE_BASE}/person-woman-3.webp` },
]

type Account = (typeof ACCOUNTS)[number]

type Receipt = {
  amount: number
  card: string
  owner: string
  source: Account
  code: string
  date: Date
}

@Component({
  selector: "dig-block-money-transfer",
  imports: [
    DigControlSize,
    DigLabel,
    DigSelect,
    DigSelectTrigger,
    DigSelectValue,
    DigSelectContent,
    DigSelectItem,
    DigSelectItemDescription,
    DigBankLogo,
    DigTextField,
    DigInputEnd,
    DigInput,
    DigInputField,
    DigButton,
    DigAvatar,
    DigAlertDialog,
    DigAlertDialogContent,
    DigAlertDialogHeader,
    DigAlertDialogTitle,
    DigAlertDialogDescription,
    DigAlertDialogFooter,
    DigAlertDialogCancel,
    DigAlertDialogAction,
    DigSeparator,
    DigInputOtp,
    DigInputOtpGroup,
    DigInputOtpSlot,
    DigDialog,
    DigDialogContent,
    DigDialogHeader,
    DigDialogTitle,
    DigDialogDescription,
    DigDialogFooter,
    DigIcon,
    FormsModule,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <main
      digControlSize="xl"
      class="mx-auto grid grid-cols-1 w-full max-w-5xl items-start gap-8 p-4 sm:p-6 lg:grid-cols-[minmax(0,1fr)_20rem]"
    >
      <form
        class="flex flex-col gap-8 rounded-xl border border-border bg-card p-6 sm:p-8"
        (submit)="$event.preventDefault(); onSubmit()"
      >
        <div class="flex flex-col gap-1">
          <h1 class="text-2xl font-bold">کارت به کارت</h1>
          <p class="text-muted-foreground">انتقال وجه به هر کارتِ عضو شتاب.</p>
        </div>
        <div class="flex flex-col gap-5">
          <div class="flex flex-col gap-2">
            <label digLabel id="source-label">از حساب</label>
            <ng-container
              digSelect
              name="source"
              [value]="account()"
              (valueChange)="typeof $event === 'string' && account.set($event)"
              ><button digSelectTrigger aria-labelledby="source-label" class="w-full">
                <span digSelectValue></span>
              </button>
              <div digSelectContent>
                <!-- موجودی فقط در فهرست دیده می‌شود؛ دکمه فقط لوگو و نامِ حساب را نشان می‌دهد تا در موبایل بریده نشود. -->
                @for (item of ACCOUNTS; track item.id) {
                  <div digSelectItem [value]="item.id">
                    <span digBankLogo [bank]="item.bank" size="sm"></span>
                    <span class="flex flex-col"
                      >{{ item.label }}
                      <span digSelectItemDescription>موجودی {{ formatCurrency(item.balance) }}</span></span
                    >
                  </div>
                }
              </div></ng-container
            >
          </div>
          <div
            digTextField
            label="شماره کارت مقصد"
            [invalid]="(card().length >= 6 && !destinationBank()) || ownerName() === null"
            [errorMessage]="
              ownerName() === null ? 'این کارت فعال نیست یا استعلام نشد.' : 'این شماره کارت به هیچ بانکی تعلق ندارد.'
            "
            required
          >
            <dig-input
              ><input
                digInput
                [ngModel]="card()"
                [ngModelOptions]="{ standalone: true }"
                (ngModelChange)="card.set($event)"
                name="card"
                inputmode="numeric"
                dir="ltr"
                [digitGroups]="[4, 4, 4, 4]"
                autocomplete="off"
              /><span digInputEnd><span digBankLogo [cardNumber]="card()" size="sm" showName></span></span
              ><!-- لوگوی بانک با تایپِ ۶ رقمِ اول خودش ظاهر می‌شود. -->
            </dig-input>
          </div>
          <!-- مبلغ‌های پرکاربرد زیرِ خودِ فیلد، چون مالِ همان‌اند. -->
          <div class="flex flex-col gap-3">
            <div
              digTextField
              label="مبلغ"
              [invalid]="overBalance()"
              errorMessage="مبلغ از موجودی حساب بیشتر است."
              [description]="\`موجودی: \${formatCurrency(source().balance)}\`"
              required
            >
              <dig-input
                ><input
                  digInput
                  [ngModel]="amount()"
                  [ngModelOptions]="{ standalone: true }"
                  (ngModelChange)="amount.set($event)"
                  name="amount"
                  inputmode="numeric"
                  dir="rtl"
                  groupDigits
                /><span digInputEnd>تومان</span></dig-input
              >
            </div>
            <div class="grid grid-cols-3 gap-2" role="group" aria-label="مبلغ‌های پرکاربرد (تومان)">
              @for (quick of QUICK_AMOUNTS; track quick) {
                <button
                  digButton
                  type="button"
                  variant="outline"
                  class="px-2 tabular-nums"
                  (click)="amount.set(string(quick))"
                >
                  {{ formatNumber(quick) }}
                </button>
              }
            </div>
          </div>
          <div digTextField label="توضیحات" optional>
            <dig-input><input digInput name="note" maxlength="60" /></dig-input>
          </div>
        </div>
        <div class="border-t border-border pt-8">
          <button digButton type="submit" fullWidth [disabled]="!ready()">ادامه</button>
        </div>
      </form>

      <aside class="flex flex-col gap-6">
        <div
          class="flex flex-col gap-1 rounded-xl bg-inverse p-6 text-[var(--dig-white)] [--muted-foreground:var(--dig-neutral-400)]"
        >
          <span class="text-sm text-muted-foreground">موجودی {{ source().label }}</span>
          <span class="text-2xl font-black tabular-nums">{{ formatCurrency(source().balance) }}</span>
          <span class="mt-3 text-xs text-muted-foreground">سقفِ انتقالِ امروز: {{ formatCurrency(50_000_000) }}</span>
        </div>
        <section aria-labelledby="recent-title" class="flex flex-col gap-3">
          <h2 id="recent-title" class="font-semibold">مقصدهای اخیر</h2>
          <ul class="flex flex-col gap-2">
            @for (item of RECENT; track item.card) {
              <li>
                <button
                  digButton
                  type="button"
                  variant="outline"
                  [class]="
                    cn(
                      'h-auto w-full justify-start gap-3 py-3 font-normal',
                      card() === item.card ? 'border-primary bg-primary-subtle' : ''
                    )
                  "
                  (click)="pickRecent(item)"
                >
                  <span digAvatar [alt]="item.name" [src]="item.image"></span>
                  <span class="flex flex-1 flex-col items-start"
                    ><span class="font-medium">{{ item.name }}</span>
                    <bdi dir="ltr" class="text-xs text-muted-foreground">{{
                      toFaDigits(\`\${item.card.slice(0, 4)} •••• \${item.card.slice(-4)}\`)
                    }}</bdi></span
                  >
                  <span digBankLogo [cardNumber]="item.card" size="sm"></span>
                </button>
              </li>
            }
          </ul>
        </section>
      </aside>

      <ng-container digAlertDialog [open]="confirming()" (openChange)="confirming.set($event)"
        ><div digControlSize="xl">
          <div digAlertDialogContent>
            <div digAlertDialogHeader>
              <h2 digAlertDialogTitle>انتقال را تأیید می‌کنید؟</h2>
              <p digAlertDialogDescription>این انتقال بعد از انجام قابل بازگشت نیست.</p>
            </div>
            <!-- دو طرفِ انتقال با لوگوی بانک. -->
            <dl class="flex flex-col gap-3 text-sm">
              <div class="flex items-center justify-between gap-3">
                <dt class="text-muted-foreground">از</dt>
                <dd class="flex items-center gap-2">
                  <span class="flex flex-col items-end"
                    ><span>{{ source().label }}</span>
                    <bdi dir="ltr" class="text-xs text-muted-foreground">{{ toFaDigits(source().number) }}</bdi></span
                  >
                  <span digBankLogo [bank]="source().bank"></span>
                </dd>
              </div>
              <div class="flex items-center justify-between gap-3">
                <dt class="text-muted-foreground">به</dt>
                <dd class="flex items-center gap-2">
                  <span class="flex flex-col items-end"
                    ><span class="font-medium">{{ ownerName() ?? "" }}</span>
                    <span class="text-xs text-muted-foreground"
                      >{{ destinationBank()?.name }} · <bdi dir="ltr">{{ groupCard(card()) }}</bdi></span
                    ></span
                  >
                  <span digBankLogo [cardNumber]="card()"></span>
                </dd>
              </div>
            </dl>
            <div digSeparator></div>
            <div class="flex justify-between gap-2 text-sm font-semibold">
              <span>مبلغ</span> <span>{{ formatCurrency(value()) }}</span>
            </div>
            <div digAlertDialogFooter>
              <button digAlertDialogCancel>انصراف</button>
              <button digAlertDialogAction (click)="goToOtp()">تأیید و دریافت رمز پویا</button>
            </div>
          </div>
        </div></ng-container
      >

      <ng-container digAlertDialog [open]="otpStep()" (openChange)="otpStep.set($event)"
        ><div digControlSize="xl">
          <div digAlertDialogContent>
            <div digAlertDialogHeader>
              <h2 digAlertDialogTitle>رمز پویا</h2>
              <p digAlertDialogDescription>کد ۶ رقمی پیامک‌شده را وارد کنید.</p>
            </div>
            <div digInputOtp aria-label="رمز پویا" [disabled]="sending()" class="mx-auto" (complete)="send($event)">
              <div digInputOtpGroup>
                @for (index of [0, 1, 2, 3, 4, 5]; track index) {
                  <input digInputOtpSlot [index]="index" />
                }
              </div>
            </div>
            <div digAlertDialogFooter><button digAlertDialogCancel [disabled]="sending()">انصراف</button></div>
          </div>
        </div></ng-container
      >

      <ng-container digDialog [open]="receipt() !== null" (openChange)="onReceiptOpen($event)">
        @if (receipt(); as receipt) {
          <div digControlSize="xl" digDialogContent>
            <div digDialogHeader class="items-center text-center">
              <span
                aria-hidden="true"
                class="mb-1 flex size-12 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-6"
                ><svg digIcon="check"></svg
              ></span>
              <h2 digDialogTitle>انتقال انجام شد</h2>
              <p digDialogDescription>{{ formatJalaliDateTime(receipt.date) }}</p>
            </div>
            <p class="text-center text-2xl font-bold">{{ formatCurrency(receipt.amount) }}</p>
            <dl class="flex flex-col gap-3 text-sm">
              <div class="flex items-center justify-between gap-3">
                <dt class="text-muted-foreground">از</dt>
                <dd class="flex items-center gap-2">
                  <span class="flex flex-col items-end"
                    ><span>{{ receipt.source.label }}</span>
                    <bdi dir="ltr" class="text-xs text-muted-foreground">{{
                      toFaDigits(receipt.source.number)
                    }}</bdi></span
                  >
                  <span digBankLogo [bank]="receipt.source.bank"></span>
                </dd>
              </div>
              <div class="flex items-center justify-between gap-3">
                <dt class="text-muted-foreground">به</dt>
                <dd class="flex items-center gap-2">
                  <span class="flex flex-col items-end"
                    ><span class="font-medium">{{ receipt.owner }}</span>
                    <span class="text-xs text-muted-foreground"
                      >{{ getBankByCard(receipt.card)?.name }} ·
                      <bdi dir="ltr">{{ groupCard(receipt.card) }}</bdi></span
                    ></span
                  >
                  <span digBankLogo [cardNumber]="receipt.card"></span>
                </dd>
              </div>
            </dl>
            <div digSeparator></div>
            <div class="flex items-center justify-between gap-2 text-sm">
              <span class="text-muted-foreground">کد پیگیری</span>
              <span class="flex items-center gap-1"
                ><bdi dir="ltr" class="font-semibold tracking-wider">{{ toFaDigits(receipt.code) }}</bdi>
                <button
                  digButton
                  type="button"
                  variant="ghost"
                  size="icon"
                  [attr.aria-label]="copied() ? 'کد پیگیری کپی شد' : 'کپی کد پیگیری'"
                  (click)="copyCode(receipt.code)"
                >
                  @if (copied()) {
                    <svg digIcon="check" class="text-success-subtle-foreground"></svg>
                  } @else {
                    <svg digIcon="copy"></svg>
                  }</button
              ></span>
            </div>
            <div digDialogFooter>
              <button digButton type="button" fullWidth (click)="closeReceipt()">بازگشت</button>
            </div>
          </div>
        }
      </ng-container>
    </main>
  `,
})
export class MoneyTransferBlock {
  readonly string = String

  readonly cn = cn

  readonly toFaDigits = toFaDigits

  readonly formatNumber = formatNumber

  readonly formatJalaliDateTime = formatJalaliDateTime

  readonly formatCurrency = formatCurrency

  readonly getBankByCard = getBankByCard

  readonly RECENT = RECENT

  readonly QUICK_AMOUNTS = QUICK_AMOUNTS

  readonly ACCOUNTS = ACCOUNTS

  async lookupCardOwner(card: string) {
    await new Promise((resolve) => setTimeout(resolve, 700))
    if (card.endsWith("0000")) return null
    return RECENT.find((item) => item.card === card)?.name ?? "آرمیتا رستگار"
  }

  readonly groupCard = (card: string) => toFaDigits(card.replace(/(\d{4})(?=\d)/g, "$1 "))

  readonly account = signal("current")

  readonly card = signal("")

  readonly amount = signal("")

  readonly confirming = signal(false)

  readonly otpStep = signal(false)

  readonly sending = signal(false)

  readonly receipt = signal<Receipt | null>(null)

  readonly copied = signal(false)

  readonly owner = signal<{ card: string; name: string | null } | null>(null)

  readonly source = computed(() => ACCOUNTS.find((item) => item.id === this.account())!)

  readonly value = computed(() => Number(this.amount() || 0))

  readonly overBalance = computed(() => this.value() > this.source().balance)

  readonly destinationBank = computed(() => getBankByCard(this.card()))

  readonly complete = computed(() => this.card().length === 16 && Boolean(this.destinationBank()))

  readonly ownerName = computed(() => (this.owner()?.card === this.card() ? this.owner()?.name : undefined))

  readonly lookingUp = computed(() => this.complete() && this.owner()?.card !== this.card())

  readonly ready = computed(
    () => this.complete() && Boolean(this.ownerName()) && this.value() > 0 && !this.overBalance()
  )

  async send(code: string) {
    this.sending.set(true)
    // جای درخواستِ واقعی انتقال با کدِ رمزِ پویا.
    await new Promise((resolve) => setTimeout(resolve, 900))
    this.sending.set(false)
    this.otpStep.set(false)
    // انتقالِ پول رسید می‌خواهد، نه یک اعلانِ چندثانیه‌ای: کاربر باید بتواند کد پیگیری را بردارد.
    this.receipt.set({
      amount: this.value(),
      card: this.card(),
      owner: this.ownerName() ?? "",
      source: this.source(),
      code: `${code}8821`,
      date: new Date(),
    })
    this.card.set("")
    this.amount.set("")
  }

  async copyCode(code: string) {
    try {
      await navigator.clipboard.writeText(code)
      this.copied.set(true)
      setTimeout(() => {
        this.copied.set(false)
      }, 2000)
    } catch {
      toast.error("کپی نشد؛ کد را دستی بردارید.")
    }
  }

  onSubmit() {
    if (this.ready()) this.confirming.set(true)
  }

  pickRecent(item: (typeof RECENT)[number]) {
    this.card.set(item.card)
    // مقصدهای ذخیره‌شده از قبل استعلام شده‌اند؛ نام باید همان لحظه با شماره هماهنگ شود.
    this.owner.set({ card: item.card, name: item.name })
  }

  goToOtp() {
    this.confirming.set(false)
    this.otpStep.set(true)
  }

  onReceiptOpen(open: boolean) {
    if (!open) this.receipt.set(null)
  }

  constructor() {
    {
      let previous: readonly unknown[] | undefined
      effect((onCleanup) => {
        const snapshot = [this.card(), this.complete()] as const
        const changed = previous ? snapshot.some((value, index) => !Object.is(value, previous?.[index])) : true
        previous = snapshot
        if (!changed) return
        untracked(() => {
          const [currentCard, isComplete] = snapshot

          if (!isComplete) return
          let current = true
          this.lookupCardOwner(currentCard).then((name) => {
            if (current) this.owner.set({ card: currentCard, name })
          })
          onCleanup(() => {
            current = false
          })
        })
      })
    }
  }

  closeReceipt() {
    this.receipt.set(null)
  }
}

کدِ این بلاک هنوز برای Android نوشته نشده است.

همهٔ کامپوننت‌های لازم برای Android آماده‌اند؛ با MCP می‌توانید همین صفحه را از روی نسخهٔ React بسازید.

کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننت‌های Android می‌سازد.