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

مدیریت کارت‌ها

پیش‌نمایش تمام‌صفحه

کارت‌های بانکی با شمارهٔ پوشیده، کارت اصلی، مسدودسازی موقت و حذف با تأیید.

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

این بلاک از ۱۴ آیتم دیگ استفاده می‌کند: alert-dialogbadgebank-logobuttoncardcontrol-sizedialogdropdown-menuiconslabelpersianswitchtext-fieldtoast

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add https://docs.digdesign.ir/r/alert-dialog.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/bank-logo.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/switch.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/badge.json https://docs.digdesign.ir/r/bank-logo.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/switch.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/badge.json https://docs.digdesign.ir/r/bank-logo.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/switch.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/badge.json https://docs.digdesign.ir/r/bank-logo.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/switch.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 badge bank-logo button card control-size dialog dropdown-menu label persian switch text-field toast --framework vue
pnpm dlx digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu label persian switch text-field toast --framework vue
yarn dlx digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu label persian switch text-field toast --framework vue
bunx --bun digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu label persian switch 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 badge bank-logo button card control-size dialog dropdown-menu icons input label persian switch text-field toast --framework angular
pnpm dlx digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu icons input label persian switch text-field toast --framework angular
yarn dlx digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu icons input label persian switch text-field toast --framework angular
bunx --bun digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu icons input label persian switch text-field toast --framework angular
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu label persian switch text-field toast --framework android
pnpm dlx digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu label persian switch text-field toast --framework android
yarn dlx digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu label persian switch text-field toast --framework android
bunx --bun digdesign@latest add alert-dialog badge bank-logo button card control-size dialog dropdown-menu label persian switch text-field toast --framework android

۲. کد صفحه

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

card-management.tsx
"use client"

import * as React from "react"

import { EditIcon, StarIcon, MoreHorizontalIcon, TrashIcon } from "@/components/icons"
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { Badge } from "@/components/ui/badge"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { BankLogo, getBankByCard } from "@/components/ui/bank-logo"
import { Button } from "@/components/ui/button"
import { Card, CardAction, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
import { TextField } from "@/components/ui/text-field"
import { toast } from "@/components/ui/toast"
import { toFaDigits } from "@/lib/persian"

type BankCard = { id: string; number: string; expiry: string; blocked: boolean; main: boolean }

const INITIAL: BankCard[] = [
  { id: "c1", number: "6104337812345678", expiry: "07/08", blocked: false, main: true },
  { id: "c2", number: "6219861098765432", expiry: "04/05", blocked: false, main: false },
  { id: "c3", number: "5022291011223344", expiry: "02/11", blocked: true, main: false },
]

/** شمارهٔ کارت: فقط ۶ رقمِ اول و ۴ رقمِ آخر؛ ارقام همیشه چپ‌به‌راست. */
function maskCard(number: string) {
  return toFaDigits(`${number.slice(0, 4)} ${number.slice(4, 6)}** **** ${number.slice(-4)}`)
}

const bankName = (number: string) => getBankByCard(number)?.name ?? "کارت بانکی"

export default function CardManagementBlock() {
  const [cards, setCards] = React.useState(INITIAL)
  const [removing, setRemoving] = React.useState<BankCard | null>(null)
  const [pinFor, setPinFor] = React.useState<BankCard | null>(null)
  const [adding, setAdding] = React.useState(false)

  const update = (id: string, patch: Partial<BankCard>) =>
    setCards((list) => list.map((card) => (card.id === id ? { ...card, ...patch } : card)))

  function setBlocked(card: BankCard, blocked: boolean) {
    update(card.id, { blocked })
    // مسدودکردن کارِ حساسی است: هشدار با امکانِ برگرداندن، نه یک «موفق شد» هم‌شکلِ فعال‌کردن.
    if (blocked) {
      toast.warning("کارت مسدود شد.", {
        description: `${bankName(card.number)} تا رفع مسدودی قابل استفاده نیست.`,
        action: { label: "لغو", onClick: () => update(card.id, { blocked: false }) },
      })
    } else {
      toast.success("کارت دوباره فعال شد.", { description: `${bankName(card.number)} آمادهٔ استفاده است.` })
    }
  }

  return (
    <ControlSizeProvider size="xl" asChild>
    <main className="mx-auto flex w-full max-w-2xl flex-col gap-4 p-4 sm:p-6">
      <header className="mb-2 flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
        <div className="flex flex-col gap-1">
          <h1 className="text-2xl font-bold">کارت‌های من</h1>
          <p className="text-sm text-muted-foreground">کارت اصلی، مسدودی و رمز کارت‌هایتان را این‌جا مدیریت کنید.</p>
        </div>
        <Button variant="outline" onClick={() => setAdding(true)}>
          افزودن کارت
        </Button>
      </header>

      {cards.map((card) => (
        <Card key={card.id}>
          <CardHeader className="flex items-center gap-3">
            <BankLogo cardNumber={card.number} size="lg" />
            <div className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
              <CardTitle>{bankName(card.number)}</CardTitle>
              {card.main && (
                <Badge variant="soft" color="primary">
                  کارت اصلی
                </Badge>
              )}
              {card.blocked && (
                <Badge variant="soft" color="destructive">
                  مسدود
                </Badge>
              )}
            </div>
            <CardAction>
              <DropdownMenu>
                <DropdownMenuTrigger asChild>
                  <Button variant="ghost" size="icon" aria-label={`عملیات ${bankName(card.number)}`}>
                    <MoreHorizontalIcon />
                  </Button>
                </DropdownMenuTrigger>
                <DropdownMenuContent align="end">
                  <DropdownMenuItem
                    disabled={card.main}
                    onSelect={() => {
                      setCards((list) => list.map((item) => ({ ...item, main: item.id === card.id })))
                      toast.success("کارت اصلی عوض شد.", { description: bankName(card.number) })
                    }}
                  >
                    <StarIcon />
                    انتخاب به‌عنوان کارت اصلی
                  </DropdownMenuItem>
                  <DropdownMenuItem disabled={card.blocked} onSelect={() => setPinFor(card)}>
                    <EditIcon />
                    تغییر رمز دوم
                  </DropdownMenuItem>
                  <DropdownMenuSeparator />
                  <DropdownMenuItem variant="destructive" onSelect={() => setRemoving(card)}>
                    <TrashIcon />
                    حذف کارت
                  </DropdownMenuItem>
                </DropdownMenuContent>
              </DropdownMenu>
            </CardAction>
          </CardHeader>
          <CardContent className="flex flex-col gap-2">
            <bdi dir="ltr" className="self-start text-lg font-semibold">
              {maskCard(card.number)}
            </bdi>
            {/* تاریخِ انقضا و مسدودسازی در یک ردیف: دو مشخصهٔ کوتاهِ همان کارت، کنارِ هم. */}
            <div className="flex items-center justify-between gap-3">
              <span className="text-sm text-muted-foreground">
                انقضا <bdi dir="ltr">{toFaDigits(card.expiry)}</bdi>
              </span>
              <div className="flex items-center gap-2">
                <Label htmlFor={`block-${card.id}`}>مسدودسازی موقت</Label>
                <Switch
                  id={`block-${card.id}`}
                  checked={card.blocked}
                  onCheckedChange={(blocked) => setBlocked(card, blocked)}
                />
              </div>
            </div>
          </CardContent>
        </Card>
      ))}

      <AddCardDialog
        open={adding}
        onOpenChange={setAdding}
        existing={cards.map((card) => card.number)}
        onAdd={(number, expiry) => {
          setCards((list) => [...list, { id: number, number, expiry, blocked: false, main: list.length === 0 }])
          toast.success("کارت اضافه شد.", { description: bankName(number) })
        }}
      />

      <ChangePinDialog card={pinFor} onClose={() => setPinFor(null)} />

      <AlertDialog open={removing !== null} onOpenChange={(open) => !open && setRemoving(null)}>
        <ControlSizeProvider size="xl" asChild>
          <AlertDialogContent>
            <AlertDialogHeader>
              <AlertDialogTitle>{removing && bankName(removing.number)} حذف شود؟</AlertDialogTitle>
              <AlertDialogDescription>تا چند ثانیه بعد از حذف می‌توانید برش گردانید؛ بعد از آن باید کارت را از نو اضافه کنید.</AlertDialogDescription>
            </AlertDialogHeader>
            <AlertDialogFooter>
              <AlertDialogCancel>انصراف</AlertDialogCancel>
              <AlertDialogAction
                variant="destructive"
                onClick={() => {
                  if (!removing) return
                  // بعد از تأیید هم تا وقتی توست باز است برگشت‌پذیر است: نوارِ زمان و «برگردان» سرِ جای قبلی.
                  const card = removing
                  const index = cards.findIndex((item) => item.id === card.id)
                  setCards((list) => list.filter((item) => item.id !== card.id))
                  toast.success("کارت حذف شد.", {
                    description: `${bankName(card.number)} از فهرست برداشته شد.`,
                    duration: 6000,
                    action: { label: "برگردان", onClick: () => setCards((list) => (list.some((item) => item.id === card.id) ? list : [...list.slice(0, index), card, ...list.slice(index)])) },
                  })
                }}
              >
                حذف کارت
              </AlertDialogAction>
            </AlertDialogFooter>
          </AlertDialogContent>
        </ControlSizeProvider>
      </AlertDialog>
    </main>
    </ControlSizeProvider>
  )
}

function AddCardDialog({
  open,
  onOpenChange,
  existing,
  onAdd,
}: {
  open: boolean
  onOpenChange: (open: boolean) => void
  existing: string[]
  onAdd: (number: string, expiry: string) => void
}) {
  const [number, setNumber] = React.useState("")
  const [month, setMonth] = React.useState("")
  const [year, setYear] = React.useState("")
  const bank = getBankByCard(number)
  const duplicate = existing.includes(number)
  const monthValid = Number(month) >= 1 && Number(month) <= 12
  const ready = number.length === 16 && Boolean(bank) && !duplicate && monthValid && year.length === 2

  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <ControlSizeProvider size="xl" asChild>
        <DialogContent>
          <DialogHeader>
            <DialogTitle>افزودن کارت</DialogTitle>
            <DialogDescription>بانک از ۶ رقمِ اولِ کارت شناخته می‌شود.</DialogDescription>
          </DialogHeader>
          <form
            className="flex flex-col gap-4"
            onSubmit={(event) => {
              event.preventDefault()
              if (!ready) return
              onAdd(number, `${year}/${month.padStart(2, "0")}`)
              setNumber("")
              setMonth("")
              setYear("")
              onOpenChange(false)
            }}
          >
            <TextField
              label="شماره کارت"
              inputMode="numeric"
              dir="ltr"
              digitGroups={[4, 4, 4, 4]}
              autoComplete="cc-number"
              value={number}
              onValueChange={setNumber}
              endContent={<BankLogo cardNumber={number} size="sm" showName />}
              invalid={(number.length >= 6 && !bank) || duplicate}
              errorMessage={duplicate ? "این کارت قبلاً اضافه شده است." : "این شماره کارت به هیچ بانکی تعلق ندارد."}
              required
            />
            <div className="grid grid-cols-2 gap-3">
              <TextField
                label="ماه انقضا"
                inputMode="numeric"
                dir="ltr"
                maxLength={2}
                placeholder="۰۸"
                autoComplete="cc-exp-month"
                value={month}
                onValueChange={setMonth}
                invalid={month.length === 2 && !monthValid}
                errorMessage="بین ۱ تا ۱۲"
                required
              />
              <TextField
                label="سال انقضا"
                inputMode="numeric"
                dir="ltr"
                maxLength={2}
                placeholder="۰۶"
                autoComplete="cc-exp-year"
                value={year}
                onValueChange={setYear}
                required
              />
            </div>
            <DialogFooter>
              <Button type="submit" fullWidth disabled={!ready}>
                افزودن
              </Button>
            </DialogFooter>
          </form>
        </DialogContent>
      </ControlSizeProvider>
    </Dialog>
  )
}

function ChangePinDialog({ card, onClose }: { card: BankCard | null; onClose: () => void }) {
  const [current, setCurrent] = React.useState("")
  const [next, setNext] = React.useState("")
  const [repeat, setRepeat] = React.useState("")
  const [saving, setSaving] = React.useState(false)
  const mismatch = repeat.length > 0 && repeat !== next
  const ready = current.length >= 5 && next.length >= 5 && next === repeat

  function reset() {
    setCurrent("")
    setNext("")
    setRepeat("")
    onClose()
  }

  return (
    <Dialog open={card !== null} onOpenChange={(open) => !open && reset()}>
      <ControlSizeProvider size="xl" asChild>
        <DialogContent>
          <DialogHeader>
            <DialogTitle>تغییر رمز دوم</DialogTitle>
            <DialogDescription>
              {card && bankName(card.number)} · <bdi dir="ltr">{card && maskCard(card.number)}</bdi>
            </DialogDescription>
          </DialogHeader>
          <form
            className="flex flex-col gap-4"
            onSubmit={async (event) => {
              event.preventDefault()
              if (!ready) return
              setSaving(true)
              await new Promise((resolve) => setTimeout(resolve, 800))
              setSaving(false)
              toast.success("رمز دوم عوض شد.", { description: "از تراکنشِ بعد رمز تازه را وارد کنید." })
              reset()
            }}
          >
            <TextField
              label="رمز دوم فعلی"
              type="password"
              inputMode="numeric"
              dir="ltr"
              maxLength={12}
              autoComplete="off"
              value={current}
              onValueChange={setCurrent}
              required
            />
            <TextField
              label="رمز دوم تازه"
              type="password"
              inputMode="numeric"
              dir="ltr"
              maxLength={12}
              autoComplete="off"
              description="۵ تا ۱۲ رقم"
              value={next}
              onValueChange={setNext}
              required
            />
            <TextField
              label="تکرار رمز تازه"
              type="password"
              inputMode="numeric"
              dir="ltr"
              maxLength={12}
              autoComplete="off"
              value={repeat}
              onValueChange={setRepeat}
              invalid={mismatch}
              errorMessage="با رمز تازه یکی نیست."
              required
            />
            <DialogFooter>
              <Button type="submit" fullWidth loading={saving} disabled={!ready}>
                ذخیره
              </Button>
            </DialogFooter>
          </form>
        </DialogContent>
      </ControlSizeProvider>
    </Dialog>
  )
}
card-management.vue
<script setup lang="ts">
import { computed, ref } 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 Badge from "@/components/ui/Badge.vue"
import BankLogo from "@/components/ui/BankLogo.vue"
import Button from "@/components/ui/Button.vue"
import Card from "@/components/ui/Card.vue"
import CardAction from "@/components/ui/CardAction.vue"
import CardContent from "@/components/ui/CardContent.vue"
import CardHeader from "@/components/ui/CardHeader.vue"
import CardTitle from "@/components/ui/CardTitle.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 DropdownMenu from "@/components/ui/DropdownMenu.vue"
import DropdownMenuContent from "@/components/ui/DropdownMenuContent.vue"
import DropdownMenuItem from "@/components/ui/DropdownMenuItem.vue"
import DropdownMenuSeparator from "@/components/ui/DropdownMenuSeparator.vue"
import DropdownMenuTrigger from "@/components/ui/DropdownMenuTrigger.vue"
import Label from "@/components/ui/Label.vue"
import Switch from "@/components/ui/Switch.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 { toFaDigits } from "@/lib/persian"

type BankCard = { id: string; number: string; expiry: string; blocked: boolean; main: boolean }

const INITIAL: BankCard[] = [
  { id: "c1", number: "6104337812345678", expiry: "07/08", blocked: false, main: true },
  { id: "c2", number: "6219861098765432", expiry: "04/05", blocked: false, main: false },
  { id: "c3", number: "5022291011223344", expiry: "02/11", blocked: true, main: false },
]

/** شمارهٔ کارت: فقط ۶ رقمِ اول و ۴ رقمِ آخر؛ ارقام همیشه چپ‌به‌راست. */
function maskCard(number: string) {
  return toFaDigits(`${number.slice(0, 4)} ${number.slice(4, 6)}** **** ${number.slice(-4)}`)
}

const bankName = (number: string) => getBankByCard(number)?.name ?? "کارت بانکی"

const cards = ref<BankCard[]>(INITIAL)
const removing = ref<BankCard | null>(null)
const pinFor = ref<BankCard | null>(null)
const adding = ref(false)

const update = (id: string, patch: Partial<BankCard>) => {
  cards.value = cards.value.map((card) => (card.id === id ? { ...card, ...patch } : card))
}

function setBlocked(card: BankCard, blocked: boolean) {
  update(card.id, { blocked })
  // مسدودکردن کارِ حساسی است: هشدار با امکانِ برگرداندن، نه یک «موفق شد» هم‌شکلِ فعال‌کردن.
  if (blocked) {
    toast.warning("کارت مسدود شد.", {
      description: `${bankName(card.number)} تا رفع مسدودی قابل استفاده نیست.`,
      action: { label: "لغو", onClick: () => update(card.id, { blocked: false }) },
    })
  } else {
    toast.success("کارت دوباره فعال شد.", { description: `${bankName(card.number)} آمادهٔ استفاده است.` })
  }
}

function makeMain(card: BankCard) {
  cards.value = cards.value.map((item) => ({ ...item, main: item.id === card.id }))
  toast.success("کارت اصلی عوض شد.", { description: bankName(card.number) })
}

function confirmRemove() {
  if (!removing.value) return
  // بعد از تأیید هم تا وقتی توست باز است برگشت‌پذیر است: نوارِ زمان و «برگردان» سرِ جای قبلی.
  const card = removing.value
  const index = cards.value.findIndex((item) => item.id === card.id)
  cards.value = cards.value.filter((item) => item.id !== card.id)
  toast.success("کارت حذف شد.", {
    description: `${bankName(card.number)} از فهرست برداشته شد.`,
    duration: 6000,
    action: {
      label: "برگردان",
      onClick: () => {
        if (cards.value.some((item) => item.id === card.id)) return
        cards.value = [...cards.value.slice(0, index), card, ...cards.value.slice(index)]
      },
    },
  })
}

// دیالوگ افزودن کارت
const number = ref("")
const month = ref("")
const year = ref("")
const bank = computed(() => getBankByCard(number.value))
const duplicate = computed(() => cards.value.map((card) => card.number).includes(number.value))
const monthValid = computed(() => Number(month.value) >= 1 && Number(month.value) <= 12)
const ready = computed(() => number.value.length === 16 && Boolean(bank.value) && !duplicate.value && monthValid.value && year.value.length === 2)

function addCard() {
  if (!ready.value) return
  const expiry = `${year.value}/${month.value.padStart(2, "0")}`
  const added = number.value
  cards.value = [...cards.value, { id: added, number: added, expiry, blocked: false, main: cards.value.length === 0 }]
  toast.success("کارت اضافه شد.", { description: bankName(added) })
  number.value = ""
  month.value = ""
  year.value = ""
  adding.value = false
}

// دیالوگ تغییر رمز دوم
const current = ref("")
const next = ref("")
const repeat = ref("")
const saving = ref(false)
const mismatch = computed(() => repeat.value.length > 0 && repeat.value !== next.value)
const pinReady = computed(() => current.value.length >= 5 && next.value.length >= 5 && next.value === repeat.value)

function resetPin() {
  current.value = ""
  next.value = ""
  repeat.value = ""
  pinFor.value = null
}

async function savePin() {
  if (!pinReady.value) return
  saving.value = true
  await new Promise((resolve) => setTimeout(resolve, 800))
  saving.value = false
  toast.success("رمز دوم عوض شد.", { description: "از تراکنشِ بعد رمز تازه را وارد کنید." })
  resetPin()
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="mx-auto flex w-full max-w-2xl flex-col gap-4 p-4 sm:p-6">
      <header class="mb-2 flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
        <div class="flex flex-col gap-1">
          <h1 class="text-2xl font-bold">کارت‌های من</h1>
          <p class="text-sm text-muted-foreground">کارت اصلی، مسدودی و رمز کارت‌هایتان را این‌جا مدیریت کنید.</p>
        </div>
        <Button variant="outline" @click="adding = true">افزودن کارت</Button>
      </header>

      <Card v-for="card in cards" :key="card.id">
        <CardHeader class="flex items-center gap-3">
          <BankLogo :card-number="card.number" size="lg" />
          <div class="flex min-w-0 flex-1 flex-wrap items-center gap-2">
            <CardTitle>{{ bankName(card.number) }}</CardTitle>
            <Badge v-if="card.main" variant="soft" color="primary">کارت اصلی</Badge>
            <Badge v-if="card.blocked" variant="soft" color="destructive">مسدود</Badge>
          </div>
          <CardAction>
            <DropdownMenu>
              <DropdownMenuTrigger as-child>
                <Button variant="ghost" size="icon" :aria-label="`عملیات ${bankName(card.number)}`">
                  <DigIcon name="more-horizontal" />
                </Button>
              </DropdownMenuTrigger>
              <DropdownMenuContent align="end">
                <DropdownMenuItem :disabled="card.main" @select="makeMain(card)">
                  <DigIcon name="star" />
                  انتخاب به‌عنوان کارت اصلی
                </DropdownMenuItem>
                <DropdownMenuItem :disabled="card.blocked" @select="pinFor = card">
                  <DigIcon name="edit" />
                  تغییر رمز دوم
                </DropdownMenuItem>
                <DropdownMenuSeparator />
                <DropdownMenuItem variant="destructive" @select="removing = card">
                  <DigIcon name="trash" />
                  حذف کارت
                </DropdownMenuItem>
              </DropdownMenuContent>
            </DropdownMenu>
          </CardAction>
        </CardHeader>
        <CardContent class="flex flex-col gap-2">
          <bdi dir="ltr" class="self-start text-lg font-semibold">{{ maskCard(card.number) }}</bdi>
          <!-- تاریخِ انقضا و مسدودسازی در یک ردیف: دو مشخصهٔ کوتاهِ همان کارت، کنارِ هم. -->
          <div class="flex items-center justify-between gap-3">
            <span class="text-sm text-muted-foreground">
              انقضا <bdi dir="ltr">{{ toFaDigits(card.expiry) }}</bdi>
            </span>
            <div class="flex items-center gap-2">
              <Label :for="`block-${card.id}`">مسدودسازی موقت</Label>
              <Switch :id="`block-${card.id}`" :checked="card.blocked" @update:checked="(blocked) => setBlocked(card, blocked)" />
            </div>
          </div>
        </CardContent>
      </Card>

      <Dialog :open="adding" @update:open="adding = $event">
        <ControlSize size="xl" as-child>
          <DialogContent>
            <DialogHeader>
              <DialogTitle>افزودن کارت</DialogTitle>
              <DialogDescription>بانک از ۶ رقمِ اولِ کارت شناخته می‌شود.</DialogDescription>
            </DialogHeader>
            <form class="flex flex-col gap-4" @submit.prevent="addCard">
              <TextField
                v-model="number"
                label="شماره کارت"
                inputmode="numeric"
                dir="ltr"
                :digit-groups="[4, 4, 4, 4]"
                autocomplete="cc-number"
                :invalid="(number.length >= 6 && !bank) || duplicate"
                :error-message="duplicate ? 'این کارت قبلاً اضافه شده است.' : 'این شماره کارت به هیچ بانکی تعلق ندارد.'"
                required
              >
                <template #endContent>
                  <BankLogo :card-number="number" size="sm" show-name />
                </template>
              </TextField>
              <div class="grid grid-cols-2 gap-3">
                <TextField
                  v-model="month"
                  label="ماه انقضا"
                  inputmode="numeric"
                  dir="ltr"
                  maxlength="2"
                  placeholder="۰۸"
                  autocomplete="cc-exp-month"
                  :invalid="month.length === 2 && !monthValid"
                  error-message="بین ۱ تا ۱۲"
                  required
                />
                <TextField v-model="year" label="سال انقضا" inputmode="numeric" dir="ltr" maxlength="2" placeholder="۰۶" autocomplete="cc-exp-year" required />
              </div>
              <DialogFooter>
                <Button type="submit" full-width :disabled="!ready">افزودن</Button>
              </DialogFooter>
            </form>
          </DialogContent>
        </ControlSize>
      </Dialog>

      <Dialog :open="pinFor !== null" @update:open="(open) => !open && resetPin()">
        <ControlSize size="xl" as-child>
          <DialogContent>
            <DialogHeader>
              <DialogTitle>تغییر رمز دوم</DialogTitle>
              <DialogDescription>
                {{ pinFor && bankName(pinFor.number) }} · <bdi dir="ltr">{{ pinFor && maskCard(pinFor.number) }}</bdi>
              </DialogDescription>
            </DialogHeader>
            <form class="flex flex-col gap-4" @submit.prevent="savePin">
              <TextField v-model="current" label="رمز دوم فعلی" type="password" inputmode="numeric" dir="ltr" maxlength="12" autocomplete="off" required />
              <TextField v-model="next" label="رمز دوم تازه" type="password" inputmode="numeric" dir="ltr" maxlength="12" autocomplete="off" description="۵ تا ۱۲ رقم" required />
              <TextField
                v-model="repeat"
                label="تکرار رمز تازه"
                type="password"
                inputmode="numeric"
                dir="ltr"
                maxlength="12"
                autocomplete="off"
                :invalid="mismatch"
                error-message="با رمز تازه یکی نیست."
                required
              />
              <DialogFooter>
                <Button type="submit" full-width :loading="saving" :disabled="!pinReady">ذخیره</Button>
              </DialogFooter>
            </form>
          </DialogContent>
        </ControlSize>
      </Dialog>

      <AlertDialog :open="removing !== null" @update:open="(open) => !open && (removing = null)">
        <ControlSize size="xl" as-child>
          <AlertDialogContent>
            <AlertDialogHeader>
              <AlertDialogTitle>{{ removing && bankName(removing.number) }} حذف شود؟</AlertDialogTitle>
              <AlertDialogDescription>تا چند ثانیه بعد از حذف می‌توانید برش گردانید؛ بعد از آن باید کارت را از نو اضافه کنید.</AlertDialogDescription>
            </AlertDialogHeader>
            <AlertDialogFooter>
              <AlertDialogCancel>انصراف</AlertDialogCancel>
              <AlertDialogAction variant="destructive" @click="confirmRemove">حذف کارت</AlertDialogAction>
            </AlertDialogFooter>
          </AlertDialogContent>
        </ControlSize>
      </AlertDialog>
    </main>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: alert-dialogbadgebank-logocardcontrol-sizedialogdropdown-menulabelpersianswitchtext-fieldtoastآیکون editآیکون more-horizontalآیکون starآیکون trash

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

card-management.ts
import { Component, ChangeDetectionStrategy, signal, computed } from "@angular/core"

import { DigControlSize } from "@/components/ui/control-size"
import { DigButton } from "@/components/ui/button"
import { DigCard, DigCardHeader, DigCardTitle, DigCardAction, DigCardContent } from "@/components/ui/card"
import { DigBankLogo } from "@/components/ui/bank-logo"
import { DigBadge } from "@/components/ui/badge"
import {
  DigDropdownMenu,
  DigDropdownMenuTrigger,
  DigDropdownMenuContent,
  DigDropdownMenuItem,
  DigDropdownMenuSeparator,
} from "@/components/ui/dropdown-menu"
import { DigIcon } from "@/lib/icons"
import { DigLabel } from "@/components/ui/label"
import { DigSwitch } from "@/components/ui/switch"
import {
  DigDialog,
  DigDialogContent,
  DigDialogHeader,
  DigDialogTitle,
  DigDialogDescription,
  DigDialogFooter,
} from "@/components/ui/dialog"
import { DigTextField } from "@/components/ui/text-field"
import { DigInputEnd, DigInput, DigInputField } from "@/components/ui/input"
import {
  DigAlertDialog,
  DigAlertDialogContent,
  DigAlertDialogHeader,
  DigAlertDialogTitle,
  DigAlertDialogDescription,
  DigAlertDialogFooter,
  DigAlertDialogCancel,
  DigAlertDialogAction,
} from "@/components/ui/alert-dialog"
import { FormsModule } from "@angular/forms"
import { toast } from "@/components/ui/toast"
import { getBankByCard } from "@/lib/iran-banks"
import { toFaDigits } from "@/lib/persian"

type BankCard = { id: string; number: string; expiry: string; blocked: boolean; main: boolean }

const INITIAL: BankCard[] = [
  { id: "c1", number: "6104337812345678", expiry: "07/08", blocked: false, main: true },
  { id: "c2", number: "6219861098765432", expiry: "04/05", blocked: false, main: false },
  { id: "c3", number: "5022291011223344", expiry: "02/11", blocked: true, main: false },
]

@Component({
  selector: "dig-block-card-management",
  imports: [
    DigControlSize,
    DigButton,
    DigCard,
    DigCardHeader,
    DigCardTitle,
    DigCardAction,
    DigCardContent,
    DigBankLogo,
    DigBadge,
    DigDropdownMenu,
    DigDropdownMenuTrigger,
    DigDropdownMenuContent,
    DigDropdownMenuItem,
    DigDropdownMenuSeparator,
    DigIcon,
    DigLabel,
    DigSwitch,
    DigDialog,
    DigDialogContent,
    DigDialogHeader,
    DigDialogTitle,
    DigDialogDescription,
    DigDialogFooter,
    DigTextField,
    DigInputEnd,
    DigInput,
    DigInputField,
    DigAlertDialog,
    DigAlertDialogContent,
    DigAlertDialogHeader,
    DigAlertDialogTitle,
    DigAlertDialogDescription,
    DigAlertDialogFooter,
    DigAlertDialogCancel,
    DigAlertDialogAction,
    FormsModule,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <main digControlSize="xl" class="mx-auto flex w-full max-w-2xl flex-col gap-4 p-4 sm:p-6">
      <header class="mb-2 flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
        <div class="flex flex-col gap-1">
          <h1 class="text-2xl font-bold">کارت‌های من</h1>
          <p class="text-sm text-muted-foreground">کارت اصلی، مسدودی و رمز کارت‌هایتان را این‌جا مدیریت کنید.</p>
        </div>
        <button digButton type="button" variant="outline" (click)="adding.set(true)">افزودن کارت</button>
      </header>

      @for (card of cards(); track card.id) {
        <div digCard>
          <div digCardHeader class="flex items-center gap-3">
            <span digBankLogo [cardNumber]="card.number" size="lg"></span>
            <div class="flex min-w-0 flex-1 flex-wrap items-center gap-2">
              <div digCardTitle>{{ bankName(card.number) }}</div>
              @if (card.main) {
                <span digBadge variant="soft" color="primary">کارت اصلی</span>
              }
              @if (card.blocked) {
                <span digBadge variant="soft" color="destructive">مسدود</span>
              }
            </div>
            <div digCardAction>
              <ng-container digDropdownMenu
                ><button
                  digDropdownMenuTrigger
                  digButton
                  type="button"
                  variant="ghost"
                  size="icon"
                  [attr.aria-label]="\`عملیات \${bankName(card.number)}\`"
                >
                  <svg digIcon="more-horizontal"></svg>
                </button>
                <div digDropdownMenuContent align="end">
                  <div digDropdownMenuItem [disabled]="card.main" (select)="makeMain(card)">
                    <svg digIcon="star"></svg>
                    انتخاب به‌عنوان کارت اصلی
                  </div>
                  <div digDropdownMenuItem [disabled]="card.blocked" (select)="pinFor.set(card)">
                    <svg digIcon="edit"></svg>
                    تغییر رمز دوم
                  </div>
                  <div digDropdownMenuSeparator></div>
                  <div digDropdownMenuItem variant="destructive" (select)="removing.set(card)">
                    <svg digIcon="trash"></svg>
                    حذف کارت
                  </div>
                </div></ng-container
              >
            </div>
          </div>
          <div digCardContent class="flex flex-col gap-2">
            <bdi dir="ltr" class="self-start text-lg font-semibold">{{ maskCard(card.number) }}</bdi>
            <!-- تاریخِ انقضا و مسدودسازی در یک ردیف: دو مشخصهٔ کوتاهِ همان کارت، کنارِ هم. -->
            <div class="flex items-center justify-between gap-3">
              <span class="text-sm text-muted-foreground">
                انقضا <bdi dir="ltr">{{ toFaDigits(card.expiry) }}</bdi></span
              >
              <div class="flex items-center gap-2">
                <label digLabel [htmlFor]="\`block-\${card.id}\`">مسدودسازی موقت</label>
                <button
                  digSwitch
                  [id]="\`block-\${card.id}\`"
                  [checked]="card.blocked"
                  (checkedChange)="setBlocked(card, $event)"
                ></button>
              </div>
            </div>
          </div>
        </div>
      }

      <ng-container digDialog [open]="adding()" (openChange)="adding.set($event)"
        ><div digControlSize="xl" digDialogContent>
          <div digDialogHeader>
            <h2 digDialogTitle>افزودن کارت</h2>
            <p digDialogDescription>بانک از ۶ رقمِ اولِ کارت شناخته می‌شود.</p>
          </div>
          <form class="flex flex-col gap-4" (submit)="$event.preventDefault(); addCard()">
            <div
              digTextField
              label="شماره کارت"
              [invalid]="(number().length >= 6 && !bank()) || duplicate()"
              [errorMessage]="duplicate() ? 'این کارت قبلاً اضافه شده است.' : 'این شماره کارت به هیچ بانکی تعلق ندارد.'"
              required
            >
              <dig-input
                ><input
                  digInput
                  [ngModel]="number()"
                  [ngModelOptions]="{ standalone: true }"
                  (ngModelChange)="number.set($event)"
                  inputmode="numeric"
                  dir="ltr"
                  [digitGroups]="[4, 4, 4, 4]"
                  autocomplete="cc-number" /><span digInputEnd
                  ><span digBankLogo [cardNumber]="number()" size="sm" showName></span></span
              ></dig-input>
            </div>
            <div class="grid grid-cols-2 gap-3">
              <div
                digTextField
                label="ماه انقضا"
                [invalid]="month().length === 2 && !monthValid()"
                errorMessage="بین ۱ تا ۱۲"
                required
              >
                <dig-input
                  ><input
                    digInput
                    [ngModel]="month()"
                    [ngModelOptions]="{ standalone: true }"
                    (ngModelChange)="month.set($event)"
                    inputmode="numeric"
                    dir="ltr"
                    maxlength="2"
                    placeholder="۰۸"
                    autocomplete="cc-exp-month"
                /></dig-input>
              </div>
              <div digTextField label="سال انقضا" required>
                <dig-input
                  ><input
                    digInput
                    [ngModel]="year()"
                    [ngModelOptions]="{ standalone: true }"
                    (ngModelChange)="year.set($event)"
                    inputmode="numeric"
                    dir="ltr"
                    maxlength="2"
                    placeholder="۰۶"
                    autocomplete="cc-exp-year"
                /></dig-input>
              </div>
            </div>
            <div digDialogFooter><button digButton type="submit" fullWidth [disabled]="!ready()">افزودن</button></div>
          </form>
        </div></ng-container
      >

      <ng-container digDialog [open]="pinFor() !== null" (openChange)="!$event && resetPin()"
        ><div digControlSize="xl" digDialogContent>
          <div digDialogHeader>
            <h2 digDialogTitle>تغییر رمز دوم</h2>
            <p digDialogDescription>
              {{ pinFor() && bankName(pinFor()?.number ?? "") }} ·
              <bdi dir="ltr">{{ pinFor() && maskCard(pinFor()?.number ?? "") }}</bdi>
            </p>
          </div>
          <form class="flex flex-col gap-4" (submit)="$event.preventDefault(); savePin()">
            <div digTextField label="رمز دوم فعلی" required>
              <dig-input
                ><input
                  digInput
                  [ngModel]="current()"
                  [ngModelOptions]="{ standalone: true }"
                  (ngModelChange)="current.set($event)"
                  type="password"
                  inputmode="numeric"
                  dir="ltr"
                  maxlength="12"
                  autocomplete="off"
              /></dig-input>
            </div>
            <div digTextField label="رمز دوم تازه" description="۵ تا ۱۲ رقم" required>
              <dig-input
                ><input
                  digInput
                  [ngModel]="next()"
                  [ngModelOptions]="{ standalone: true }"
                  (ngModelChange)="next.set($event)"
                  type="password"
                  inputmode="numeric"
                  dir="ltr"
                  maxlength="12"
                  autocomplete="off"
              /></dig-input>
            </div>
            <div
              digTextField
              label="تکرار رمز تازه"
              [invalid]="mismatch()"
              errorMessage="با رمز تازه یکی نیست."
              required
            >
              <dig-input
                ><input
                  digInput
                  [ngModel]="repeat()"
                  [ngModelOptions]="{ standalone: true }"
                  (ngModelChange)="repeat.set($event)"
                  type="password"
                  inputmode="numeric"
                  dir="ltr"
                  maxlength="12"
                  autocomplete="off"
              /></dig-input>
            </div>
            <div digDialogFooter>
              <button digButton type="submit" fullWidth [loading]="saving()" [disabled]="!pinReady()">ذخیره</button>
            </div>
          </form>
        </div></ng-container
      >

      <ng-container digAlertDialog [open]="removing() !== null" (openChange)="!$event && removing.set(null)"
        ><div digControlSize="xl">
          <div digAlertDialogContent>
            <div digAlertDialogHeader>
              <h2 digAlertDialogTitle>{{ removing() && bankName(removing()?.number ?? "") }} حذف شود؟</h2>
              <p digAlertDialogDescription>
                تا چند ثانیه بعد از حذف می‌توانید برش گردانید؛ بعد از آن باید کارت را از نو اضافه کنید.
              </p>
            </div>
            <div digAlertDialogFooter>
              <button digAlertDialogCancel>انصراف</button>
              <button digAlertDialogAction variant="destructive" (click)="confirmRemove()">حذف کارت</button>
            </div>
          </div>
        </div></ng-container
      >
    </main>
  `,
})
export class CardManagementBlock {
  readonly toFaDigits = toFaDigits

  maskCard(number: string) {
    return toFaDigits(`${number.slice(0, 4)} ${number.slice(4, 6)}** **** ${number.slice(-4)}`)
  }

  readonly bankName = (number: string) => getBankByCard(number)?.name ?? "کارت بانکی"

  readonly cards = signal<BankCard[]>(INITIAL)

  readonly removing = signal<BankCard | null>(null)

  readonly pinFor = signal<BankCard | null>(null)

  readonly adding = signal(false)

  readonly update = (id: string, patch: Partial<BankCard>) => {
    this.cards.set(this.cards().map((card) => (card.id === id ? { ...card, ...patch } : card)))
  }

  setBlocked(card: BankCard, blocked: boolean) {
    this.update(card.id, { blocked })
    // مسدودکردن کارِ حساسی است: هشدار با امکانِ برگرداندن، نه یک «موفق شد» هم‌شکلِ فعال‌کردن.
    if (blocked) {
      toast.warning("کارت مسدود شد.", {
        description: `${this.bankName(card.number)} تا رفع مسدودی قابل استفاده نیست.`,
        action: { label: "لغو", onClick: () => this.update(card.id, { blocked: false }) },
      })
    } else {
      toast.success("کارت دوباره فعال شد.", { description: `${this.bankName(card.number)} آمادهٔ استفاده است.` })
    }
  }

  makeMain(card: BankCard) {
    this.cards.set(this.cards().map((item) => ({ ...item, main: item.id === card.id })))
    toast.success("کارت اصلی عوض شد.", { description: this.bankName(card.number) })
  }

  confirmRemove() {
    const card = this.removing()
    if (!card) return
    // بعد از تأیید هم تا وقتی توست باز است برگشت‌پذیر است: نوارِ زمان و «برگردان» سرِ جای قبلی.

    const index = this.cards().findIndex((item) => item.id === card.id)
    this.cards.set(this.cards().filter((item) => item.id !== card.id))
    toast.success("کارت حذف شد.", {
      description: `${this.bankName(card.number)} از فهرست برداشته شد.`,
      duration: 6000,
      action: {
        label: "برگردان",
        onClick: () => {
          if (this.cards().some((item) => item.id === card.id)) return
          this.cards.set([...this.cards().slice(0, index), card, ...this.cards().slice(index)])
        },
      },
    })
  }

  readonly number = signal("")

  readonly month = signal("")

  readonly year = signal("")

  readonly bank = computed(() => getBankByCard(this.number()))

  readonly duplicate = computed(() =>
    this.cards()
      .map((card) => card.number)
      .includes(this.number())
  )

  readonly monthValid = computed(() => Number(this.month()) >= 1 && Number(this.month()) <= 12)

  readonly ready = computed(
    () =>
      this.number().length === 16 &&
      Boolean(this.bank()) &&
      !this.duplicate() &&
      this.monthValid() &&
      this.year().length === 2
  )

  addCard() {
    if (!this.ready()) return
    const expiry = `${this.year()}/${this.month().padStart(2, "0")}`
    const added = this.number()
    this.cards.set([
      ...this.cards(),
      { id: added, number: added, expiry, blocked: false, main: this.cards().length === 0 },
    ])
    toast.success("کارت اضافه شد.", { description: this.bankName(added) })
    this.number.set("")
    this.month.set("")
    this.year.set("")
    this.adding.set(false)
  }

  readonly current = signal("")

  readonly next = signal("")

  readonly repeat = signal("")

  readonly saving = signal(false)

  readonly mismatch = computed(() => this.repeat().length > 0 && this.repeat() !== this.next())

  readonly pinReady = computed(
    () => this.current().length >= 5 && this.next().length >= 5 && this.next() === this.repeat()
  )

  resetPin() {
    this.current.set("")
    this.next.set("")
    this.repeat.set("")
    this.pinFor.set(null)
  }

  async savePin() {
    if (!this.pinReady()) return
    this.saving.set(true)
    await new Promise((resolve) => setTimeout(resolve, 800))
    this.saving.set(false)
    toast.success("رمز دوم عوض شد.", { description: "از تراکنشِ بعد رمز تازه را وارد کنید." })
    this.resetPin()
  }
}

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

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

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