feat(driver-pwa): top-up fetches commission rate from backend (no hardcoded rate)
Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { useState } from "react";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Delete } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { topup } from "@/api/driver";
|
||||
import { topup, getCommission } from "@/api/driver";
|
||||
import { keypadReduce, withCommission } from "@/lib/amount";
|
||||
import { formatMoney } from "@/lib/format";
|
||||
import { Segment } from "@/components/Segment";
|
||||
import { Spinner } from "@/components/Spinner";
|
||||
|
||||
const RATE = 0.052;
|
||||
const QUICK = ["500", "1000", "2000"];
|
||||
const KEYS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "·", "0", "back"];
|
||||
|
||||
@@ -19,9 +19,11 @@ export function TopupPage() {
|
||||
const [raw, setRaw] = useState("");
|
||||
const [method, setMethod] = useState("qr");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const { data: commission } = useQuery({ queryKey: ["commission"], queryFn: getCommission });
|
||||
const rate = commission?.rate ?? 0.052; // fallback only while loading
|
||||
|
||||
const base = raw ? parseInt(raw, 10) : 0;
|
||||
const { commission, total } = withCommission(base, RATE);
|
||||
const { commission: fee, total } = withCommission(base, rate);
|
||||
|
||||
function press(k: string) {
|
||||
if (k === "·") return;
|
||||
@@ -46,7 +48,7 @@ export function TopupPage() {
|
||||
<button className="text-muted text-xs mb-3" onClick={() => nav(-1)}>‹ {bucket}</button>
|
||||
<p data-testid="amount" className="text-3xl font-extrabold text-center mt-2">{formatMoney(base)}</p>
|
||||
<p data-testid="total" className="text-muted text-xs text-center mb-3">
|
||||
к оплате {formatMoney(total)} (комиссия {formatMoney(commission)})
|
||||
к оплате {formatMoney(total)} (комиссия {formatMoney(fee)})
|
||||
</p>
|
||||
|
||||
<div className="flex gap-1.5 mb-3">
|
||||
|
||||
Reference in New Issue
Block a user