From 6743843a67f058ec34333c8a0eb01fedd8ede792 Mon Sep 17 00:00:00 2001 From: Kelbie Date: Wed, 2 Jul 2025 13:01:23 +0100 Subject: [PATCH 1/2] feat: add Routstr AI chat client --- app/(drawer)/(tabs)/lifestyle.tsx | 10 +- app/routstr/balance.tsx | 89 ++++++++++ app/routstr/index.tsx | 154 ++++++++++++++++++ components/layout/sheets/registerSheets.tsx | 2 + .../layout/sheets/routstrSession/index.tsx | 21 +++ .../sheets/routstrSession/routes/index.tsx | 25 +++ .../sheets/routstrSession/routes/routeA.tsx | 53 ++++++ helper/redux/routstr/actionTypes.ts | 6 + helper/redux/routstr/actions.ts | 41 +++++ helper/redux/routstr/hooks.ts | 40 +++++ helper/redux/routstr/index.ts | 5 + helper/redux/routstr/reducer.ts | 73 +++++++++ helper/redux/routstr/selectors.ts | 30 ++++ helper/redux/store/index.ts | 2 +- helper/redux/store/reducer.ts | 2 + 15 files changed, 551 insertions(+), 2 deletions(-) create mode 100644 app/routstr/balance.tsx create mode 100644 app/routstr/index.tsx create mode 100644 components/layout/sheets/routstrSession/index.tsx create mode 100644 components/layout/sheets/routstrSession/routes/index.tsx create mode 100644 components/layout/sheets/routstrSession/routes/routeA.tsx create mode 100644 helper/redux/routstr/actionTypes.ts create mode 100644 helper/redux/routstr/actions.ts create mode 100644 helper/redux/routstr/hooks.ts create mode 100644 helper/redux/routstr/index.ts create mode 100644 helper/redux/routstr/reducer.ts create mode 100644 helper/redux/routstr/selectors.ts diff --git a/app/(drawer)/(tabs)/lifestyle.tsx b/app/(drawer)/(tabs)/lifestyle.tsx index bbf4f11a..125f5c87 100644 --- a/app/(drawer)/(tabs)/lifestyle.tsx +++ b/app/(drawer)/(tabs)/lifestyle.tsx @@ -59,6 +59,12 @@ const SERVICE_MENU_ITEMS: MenuItemData[] = [ navigateTo: 'userMessages', params: { pubkey: SUPPORT_PUBKEY }, }, + { + id: 'routstr', + icon: 'mdi:robot', + label: 'AI Chat', + navigateTo: 'routstr', + }, // Empty placeholders to maintain grid layout { id: 'empty1', empty: true }, { id: 'empty2', empty: true }, @@ -126,7 +132,9 @@ const ServicesSection = () => { {SERVICE_MENU_ITEMS.filter((item) => - ['giftcards', 'vpn', 'esims', 'donate'].includes(item.id) ? settings?.experimental : true + ['giftcards', 'vpn', 'esims', 'donate', 'routstr'].includes(item.id) + ? settings?.experimental + : true ).map((item) => ( { + if (!token) return; + const res = await fetch('https://api.routstr.com/v1/wallet/', { + headers: { Authorization: `Bearer ${token}` }, + }); + const data = await res.json(); + if (data?.balance !== undefined) { + setBalance(data.balance); + } + }; + + const handleTopup = async () => { + try { + const tx = await sendEcash({ amount: Number(amount), unit: 'sat' }); + setLastToken(tx.token); + await fetch( + `https://api.routstr.com/v1/wallet/topup?cashu_token=${encodeURIComponent(tx.token)}`, + { + method: 'POST', + headers: { Authorization: `Bearer ${token}` }, + } + ); + await fetchInfo(); + Alert.alert('Topup successful'); + } catch (e) { + Alert.alert('Error', 'Topup failed'); + } + }; + + const handleRefund = async () => { + try { + const res = await fetch('https://api.routstr.com/v1/wallet/refund', { + method: 'POST', + headers: { Authorization: `Bearer ${token}` }, + }); + const data = await res.json(); + if (data?.cashu_token) { + setLastToken(data.cashu_token); + setBalance(data.new_balance || 0); + Alert.alert('Refund token received'); + } + } catch (e) { + Alert.alert('Error', 'Refund failed'); + } + }; + + return ( + + Balance: {balance} sats + + +