()
| 22 | const [isPaymentRequestOpen, setIsPaymentRequestOpen] = useState(false); |
| 23 | |
| 24 | const handleTopUp = async () => { |
| 25 | if (isToppingUp) return; |
| 26 | |
| 27 | setIsToppingUp(true); |
| 28 | setTopUpError(null); |
| 29 | setTopUpSuccess(false); |
| 30 | |
| 31 | try { |
| 32 | // Self-mint test tokens to this wallet (v2; no faucet, no nametag). |
| 33 | const results = await topUp(); |
| 34 | const failed = results.filter((r) => !r.success); |
| 35 | |
| 36 | // One toast per minted coin — outlives the modal's 1.5s auto-close. |
| 37 | for (const r of results) { |
| 38 | if (r.success) showMintToast(r); |
| 39 | } |
| 40 | |
| 41 | if (failed.length === results.length) { |
| 42 | // All failed — surface the reason(s). |
| 43 | const uniqueReasons = [...new Set(failed.map((r) => r.error || 'Unknown error'))]; |
| 44 | setTopUpError( |
| 45 | uniqueReasons.length === 1 |
| 46 | ? uniqueReasons[0] |
| 47 | : failed.map((r) => `${r.symbol}: ${r.error || 'Unknown error'}`).join('\n'), |
| 48 | ); |
| 49 | } else if (failed.length > 0) { |
| 50 | // Partial success — minted some; note which failed but treat as success. |
| 51 | setTopUpSuccess(true); |
| 52 | showToast(`Some coins failed: ${failed.map((r) => r.symbol).join(', ')}`, 'info', 4000); |
| 53 | setTimeout(handleClose, 1500); |
| 54 | } else { |
| 55 | setTopUpSuccess(true); |
| 56 | setTimeout(handleClose, 1500); |
| 57 | } |
| 58 | } catch (error) { |
| 59 | setTopUpError(getErrorMessage(error)); |
| 60 | } finally { |
| 61 | setIsToppingUp(false); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | const handleClose = () => { |
| 66 | setTopUpError(null); |
nothing calls this directly
no test coverage detected