From 5b13c3e45c32e4fd91b514a0d75c6507c9b7967f Mon Sep 17 00:00:00 2001 From: reya Date: Mon, 11 Mar 2024 15:38:54 +0700 Subject: [PATCH] feat: auto close window if zapp successfully --- apps/desktop2/src/routes/zap.$id.lazy.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/desktop2/src/routes/zap.$id.lazy.tsx b/apps/desktop2/src/routes/zap.$id.lazy.tsx index c86fb900..b84a4c72 100644 --- a/apps/desktop2/src/routes/zap.$id.lazy.tsx +++ b/apps/desktop2/src/routes/zap.$id.lazy.tsx @@ -4,6 +4,8 @@ import { Box, Container, User } from "@lume/ui"; import { createLazyFileRoute } from "@tanstack/react-router"; import { useState } from "react"; import { useTranslation } from "react-i18next"; +import { getCurrent } from "@tauri-apps/api/webviewWindow"; +import { toast } from "sonner"; import CurrencyInput from "react-currency-input-field"; const DEFAULT_VALUES = [69, 100, 200, 500]; @@ -26,8 +28,22 @@ function Screen() { const ark = useArk(); const submit = async () => { - const val = await ark.zap_event(id, amount, message); - console.log(val); + try { + // start loading + setIsLoading(true); + + const val = await ark.zap_event(id, amount, message); + + if (val) { + setIsCompleted(true); + const window = getCurrent(); + // close current window + window.close(); + } + } catch (e) { + setIsLoading(false); + toast.error(e); + } }; return (