Skip to content

Commit

Permalink
Add basic Bitcoin Lightning wallet via Breez SDK (#59)
Browse files Browse the repository at this point in the history
* bump versions to 0.1.0

* npmrc shh

* add private spark wallet sdk

* initial spark class

* singleton

* pull in breez service

* Enhanced WalletStoreModel with balance tracking and initialization state; added SecureStorageService for improved security.

* Refactor WalletStore.ts to use breezService, add TransactionModel, and remove spark dependency.

* Refactor WalletStore.ts to remove unused imports and streamline transaction model definitions.

* securestorage

* shh

* breezservice fix type errors

* save mnemonic

* extract initialize function from walletstore

* extract setup

* Create file app/models/wallet/actions/types.ts

* Refactor `initialize` to use `IWalletStore` interface for better type safety.

* extract

* Refactor IWalletStore interface: add balance and pending transaction properties, include TransactionModel, and introduce setMnemonic method.

* Refactor setup function to use IWalletStore interface for type consistency.

* Refactor `restoreWallet` to use `IWalletStore` interface for better type safety and reset balance on wallet restoration.

* Added 'types' export and reorganized export order in index.ts for better module structure.

* Refactor WalletStore.ts to remove unused imports and streamline the code base.

* Refactor `IWalletStore` into `IWalletStoreBase` and `IWalletStore` for clearer separation of base properties and extended functionalities in `types.ts`.

* Refactor setup function to use IWalletStoreBase instead of IWalletStore for broader compatibility.

* shh

* Create file app/models/wallet/actions/fetchBalanceInfo.ts

* Create file app/models/wallet/actions/disconnect.ts

* Create file app/models/wallet/actions/fetchTransactions.ts

* Create file app/models/wallet/actions/sendPayment.ts

* Create file app/models/wallet/actions/receivePayment.ts

* Add exports for disconnect, balance, transactions, and payment functions to index.ts for expanded module functionality.

* Refactor WalletStore.ts: remove unused imports, update properties in WalletStoreModel.

* Refactor `types.ts`: Split `IWalletStore` into `IWalletStoreBase` and `IWalletStoreWithTransactions`, add `setError` method, and import `TransactionModel`.

* Refactor fetchTransactions to use IWalletStoreWithTransactions for enhanced type safety.

* Refactor `sendPayment` to use `IWalletStoreWithTransactions` for enhanced transaction handling.

* No changes detected in WalletStore.ts. Commit skipped.

* Create file docs/wallet-store.md

* Refactor `types.ts`: Replace `IWalletStoreWithTransactions` with `IWalletStoreBalance`, enhancing balance management features.

* Refactor fetchBalanceInfo to use IWalletStoreBalance for enhanced type specificity.

* Refactor `sendPayment` to improve readability and maintenance by adding explanatory comments.

* Refactor WalletStore.ts to organize imports and clean up code structure for better readability.

* No changes detected between file revisions.

* Added fetchBalanceInfo import in initialize.ts to enhance wallet initialization.

* Add `fetchBalanceInfo` import and improve wallet state reset in `restoreWallet` function.

* nice

* Create file app/models/wallet/views.ts

* Add 'views' import to WalletStore.ts to enhance model functionality.

* Refactor `views` import to use `createViews` in `WalletStore.ts` for enhanced modularity.

* Refactor views.ts to use MST Instance and renamed functions for clarity and type safety.

* Create file app/models/wallet/types.ts

* Refactor WalletStore.ts by removing unused 'Instance' and 'SnapshotOut' imports to streamline dependencies.

* Refactor `views.ts`: Simplify imports, use `WalletStoreType` for type checking, and modify `self` type for clarity and accuracy.

* Create file app/types.ts

* Refactor `views.ts` to use `WalletStore` from a new path and complete the implementation of `pendingTransactions` view.

* Delete app/models/wallet/types.ts

* Delete app/models/wallet/actions/types.ts

* Create file app/models/wallet/types.ts

* Update import path for `WalletStore` in `views.ts` to use local `types` directory.

* Delete app/types.ts

* testing

* Refactor `types.ts`: added `IArrayType` import and replaced `WalletStoreModel` with `TransactionModel` to align with updated data structures.

* Add `Instance` import and `IWalletStore` interface to `WalletStore.ts` for enhanced type support.

* Refactor fetchTransactions to use IWalletStore and include transaction fee in mapping.

* Refactor `restoreWallet`: Add disconnect check for initialized `breezService` before proceeding.

* Refactor `IArrayType` to `IAnyModelType` in `types.ts` for broader model compatibility.

* Refactor WalletStore.ts: Removed unused 'Instance' import and 'IWalletStore' type, added 'pendingReceiveSat' property to model.

* Refactor sendPayment to use IWalletStore and enhance error handling and balance updates.

* Refactor WalletStore interfaces in types.ts for clarity and modularization.

* Add IWalletStoreProps import to WalletStore.ts for type consistency.

* Refactor fetchTransactions to use IWalletStoreProps for enhanced type accuracy.

* Refactor `sendPayment` to use `IWalletStoreProps` for enhanced type safety and clarity.

* Refactor `IWalletStoreProps` into `IWalletStoreBase` and `IWalletStoreBalance` for clearer separation of concerns.

* Refactor WalletStore.ts: Updated import name from IWalletStoreProps to IWalletStore for consistency.

* Refactor fetchTransactions to use updated IWalletStore interface for improved type consistency.

* Refactor sendPayment to use IWalletStore interface and handle error state by setting it to null.

* Refactor `setup.ts` to retrieve mnemonic from secure storage and handle errors, replacing mnemonic generation with error handling.

* Refactor fetchBalanceInfo to use updated breezService API and IWalletStore interface for balance details.

* Refactor `fetchBalanceInfo` to align property names with `breezService` API changes.

* Refactor WalletStore.ts to use destructuring for `Instance` from mobx-state-tree and change `WalletStoreModel` to a non-exported constant.

* Updated Wallet Store documentation to clarify the modular architecture and roles of core components.

* wallet store hierarchy

* nic

* initialize

* initialize breez sdk store clean

* Refactor WalletStore.ts to improve code organization and maintainability.

* Refactor fetchTransactions to use setTransactions instead of replace for updating store.

* No changes detected in `types.ts`. Commit unnecessary.

* fetch balnace info and transactions

* Added useNavigation hook to ChatDrawerContent for enhanced navigation handling.

* pull in money components etc

* initial wallet screen

* set isinit

* new icon

* icons

* axe walletsdk for now

* Refactor: Import React explicitly in Button.tsx for clarity and consistency.

* Refactor Money.tsx by updating enum and type definitions for clarity and consistency.

* No changes made to MoneySmall.tsx; verify if commit is necessary.

* No changes detected in Money.tsx file; commit unnecessary.

* Refactor MoneySmall.tsx: Remove unused imports and optimize component readability.

* No changes made to Money.tsx; commit unnecessary.

* No changes detected in MoneySmall.tsx. Commit aborted to preserve repository integrity.

* No changes detected in Money.tsx.

* No changes made to Money.tsx, commit aborted.

* Refactor MoneySmall.tsx to remove unused imports and streamline code readability.

* No changes detected in Money.tsx file.

* No changes detected between the old and new content of MoneySmall.tsx.

* Refactor EDenomination enum to type and constant in Money.tsx for improved type safety and flexibility.

* denom types

* ok

* derive nostr keys and save to walletstore

* show npub

* Added StyleSheet import to ChatDrawerContent for custom styling.

* disable send/receive for now

* nice

* Create file app/chat/drawer/styles.ts

* Create file app/chat/drawer/ChatPreview.ts

* Create file app/chat/drawer/NewChatButton.tsx

* Create file app/chat/drawer/WalletButton.tsx

* Create file app/chat/drawer/ChatList.tsx

* Create file app/chat/drawer/index.tsx

* Delete app/chat/ChatDrawerContent.tsx

* Create file app/chat/drawer/ChatDrawerLayout.tsx

* Delete app/chat/ChatDrawerContainer.tsx

* Refactor `ChatDrawerContent` to use proper typing for `drawerInsets` in `index.tsx`.

* chatdrawerlayout

* border button

* Create file app/chat/drawer/README.md

* yarn hierarchy

* Create file app/screens/ProfileScreen/ProfileScreen.tsx

* Create file app/screens/ProfileScreen/index.ts

* Added export for ProfileScreen in index.ts to facilitate module access.

* Refactor AppNavigator.tsx to remove unused imports and streamline navigation setup.

* Create file app/chat/drawer/ProfileButton.tsx

* Add ProfileButton to ChatDrawerContent and update imports in index.tsx.

* Refactor WalletButton to use functional component structure for clarity and maintenance.

* button

* Refactor ProfileButton.tsx to use local styles and MaterialCommunityIcons, improving UI consistency and performance.

* onyx profile

* shh

* hm

* Add useState, Pressable, Clipboard, and MaterialCommunityIcons to ProfileScreen; introduce KeyRow component for handling secret keys.

* Refactor ProfileScreen: Replace Pressable with TouchableOpacity, update Clipboard import for better modularity.

* cool

* Create file app/screens/ProfileScreen/KeyRow.tsx

* Refactor ProfileScreen.tsx: Removed unused imports, extracted KeyRow component, and integrated useStores for state management.

* copied

* profilebutton

* Create file docs/pro.md

* Add authentication section requiring Nostr public key for API requests in `pro.md`.

* Create file app/services/aiur/aiur.types.ts

* Create file app/services/aiur/aiur.ts

* Create file app/services/aiur/index.ts

* Create file docs/aiur.md

* Updated aiur.md to clarify Aiur's role and its decentralized services.

* Add fallback URL to DEFAULT_AIUR_CONFIG in aiur.ts for increased reliability.

* Add AIUR_API_URL to ConfigBaseProps and remove GROQ_API_KEY.

* Added AIUR_API_URL to config.dev.ts for local AI service integration.

* Added AIUR_API_URL to production config for new service integration.

* Update DEFAULT_AIUR_CONFIG URL to use localhost in dev environments for Aiur API.

* hierarchy

* shh

* Create file app/navigators/SettingsNavigator.tsx

* Create file app/screens/SettingsScreen/AutocoderSettings.tsx

* Enhance SettingsScreen with sharing feature, navigation updates, and style adjustments.

* Add SettingsNavigator import to AppNavigator for enhanced settings navigation.

* Delete app/screens/SettingsScreen/coder/RepoSettings.tsx

* Create file app/screens/SettingsScreen/styles.ts

* Refactor SettingsScreen to use local styles import.

* Refactor styles.ts to include typography, update button and container styles, and adjust color scheme for improved UI consistency.

* Refactor SettingsScreen: remove unused 'colors' import and update share message.

* Create file app/screens/ShareScreen/ShareScreen.tsx

* Added ShareScreen to SettingsNavigator and updated SettingsStackParamList.

* Refactor SettingsScreen: remove unused Share import and update UI to navigate to ShareScreen on button press.

* padding

* Added Ionicons and colorsDark to SettingsScreen for enhanced UI elements.

* Refactor ShareScreen to use MobX, add KeyboardAvoidingView, ScrollView, and Button components for enhanced functionality and interactivity.

* hierarchy

* Add TextInput import and extend styles in ShareScreen.tsx for enhanced text input functionality.

* Refactor ShareRequest and Share interfaces to include messages and metadata, replacing previous fields to support enhanced sharing features.

* Refactor ShareScreen.tsx to improve readability and maintainability.

* Refactor AiurApi class to improve code organization and readability.

* hm

* nice

* red

* sharescreen

* android fix fonts

* Create file scripts/deepseek_test_fixer.sh

* pull in wallet screens

* tsc 8

* hm

* update hierarchy

* Refactor: Cleaned up imports and removed unused `useNavigation` in `BackupWalletScreen.tsx`.

* Add TextStyle import in ReceiveScreen.tsx for enhanced styling options.

* Refactor WalletStore.ts to streamline imports and remove unused variables for improved clarity and maintainability.

* Added TextStyle import to RestoreWalletScreen for enhanced text styling.

* Refactor AppNavigator.tsx to use relative imports for better maintainability and consistency.

* Refactor WalletScreen.tsx: Remove unused imports and useEffect, streamline component.

* Create file app/navigators/WalletNavigator.tsx

* Refactor AppNavigator.tsx to improve import efficiency by consolidating navigation utilities.

* Refactor WalletScreen to use typed navigation props from WalletNavigator.

* Refactor SendScreen to use NativeStackScreenProps and simplify imports and components.

* Refactor ReceiveScreen to use NativeStackScreenProps for improved type safety and navigation consistency.

* Refactor BackupWalletScreen to use NativeStackScreenProps for navigation type safety.

* Refactor RestoreWalletScreen to use NativeStackScreenProps for improved type safety and navigation handling.

* Refactor SendScreen.tsx to include useState, additional imports, and useStores hook for enhanced functionality.

* Refactor RestoreWalletScreen to improve readability and maintenance by reorganizing imports and interfaces.

* No changes detected in BackupWalletScreen.tsx.

* Refactor ReceiveScreen.tsx for code clarity and maintainability.

* sendreceive nav

* backup wallet

* backuprestore

* cool

* Refactor BackupWalletScreen to improve code readability and maintainability.

* Create file app/services/notifications/index.ts

* No changes detected in app.tsx; commit unnecessary.

* No changes detected between old and new content of app.config.ts.

* Create file app/hooks/useNotifications.ts

* npx expo install expo-notifications expo-device expo-constants

* axe gemini key shaz

* No changes detected; commit skipped.

* No changes detected in app.config.ts; commit unnecessary.

* Added `sendPushNotification` function to handle sending push notifications in `index.ts`.

* Refactor useNotifications hook to manage state with useState and update listener types for improved handling of Expo notifications.

* hierarchy

* Create file app/screens/SettingsScreen/NotificationsScreen.tsx

* Added NotificationsScreen to SettingsNavigator and updated SettingsStackParamList.

* Refactored SettingsScreen to enhance readability and maintainability.

* ok

* hierarchy

* Create file app/models/user/UserStore.ts

* Added UserStoreModel to RootStore for enhanced user management.

* Added useStores import to NotificationsScreen for state management integration.

* Added KeyRow import to NotificationsScreen for enhanced user settings management.

* invoice only

---------

Co-authored-by: GitHub API <[email protected]>
  • Loading branch information
AtlantisPleb and web-flow authored Jan 3, 2025
1 parent fae453c commit b5d4d20
Show file tree
Hide file tree
Showing 89 changed files with 4,647 additions and 274 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ web-build/

.env
.env.local

.npmrc
3 changes: 2 additions & 1 deletion app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = ({ config }: ConfigContext): Partial<ExpoConfig> => {
...existingPlugins,
'expo-localization',
'expo-sqlite',
'expo-notifications',
],
extra: {
...config.extra,
Expand All @@ -29,4 +30,4 @@ module.exports = ({ config }: ConfigContext): Partial<ExpoConfig> => {
GROQ_API_KEY: process.env.GROQ_API_KEY,
},
}
}
}
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Onyx",
"slug": "onyx",
"scheme": "onyx",
"version": "0.0.6",
"version": "0.1.0",
"orientation": "portrait",
"userInterfaceStyle": "automatic",
"icon": "./assets/images/app-icon-all.png",
Expand Down Expand Up @@ -73,7 +73,7 @@
"expo-splash-screen",
{
"image": "./assets/images/splash.png",
"resizeMode": "cover",
"resizeMode": "contain",
"backgroundColor": "#000000"
}
]
Expand Down
8 changes: 7 additions & 1 deletion app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useInitialRootStore } from "./models"
import { AppNavigator, useNavigationPersistence } from "./navigators"
import { ErrorBoundary } from "./screens/ErrorScreen/ErrorBoundary"
import * as storage from "./utils/storage"
import NotificationService from "./services/notifications"

interface AppProps {
hideSplashScreen: () => Promise<void>
Expand All @@ -38,6 +39,11 @@ function App(props: AppProps) {
setTimeout(hideSplashScreen, 500)
})

// Initialize notifications
React.useEffect(() => {
NotificationService.init().catch(console.error)
}, [])

if (!loaded || !rehydrated || !isNavigationStateRestored) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
Expand All @@ -62,4 +68,4 @@ function App(props: AppProps) {

AppRegistry.registerComponent("main", () => App)

export default App
export default App
127 changes: 0 additions & 127 deletions app/chat/ChatDrawerContent.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { useState } from "react"
import { Platform } from "react-native"
import { Drawer } from "react-native-drawer-layout"
import { Screen } from "@/components/Screen"
import { $styles } from "@/theme"
import { useSafeAreaInsetsStyle } from "@/utils/useSafeAreaInsetsStyle"
import { Chat } from "./Chat"
import { ChatDrawerContent } from "./ChatDrawerContent"
import { Chat } from "../Chat"
import { ChatDrawerContent } from "./index"

export const ChatDrawerContainer = () => {
export const ChatDrawerLayout = () => {
const [open, setOpen] = useState(false)
const $drawerInsets = useSafeAreaInsetsStyle(["top"])
const $drawerInsets = useSafeAreaInsetsStyle(["top", "bottom"])

return (
<Drawer
Expand All @@ -23,12 +22,11 @@ export const ChatDrawerContainer = () => {
>
<Screen
preset="fixed"
// safeAreaEdges={["bottom"]}
contentContainerStyle={$styles.flex1}
KeyboardAvoidingViewProps={{ behavior: undefined }}
>
<Chat drawerOpen={open} setDrawerOpen={setOpen} />
</Screen>
</Drawer>
)
}
}
43 changes: 43 additions & 0 deletions app/chat/drawer/ChatList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ScrollView, TouchableOpacity, Text } from "react-native"
import { useStores } from "@/models"
import { styles } from "./styles"
import { getChatPreview, sortChats } from "./ChatPreview"

type Props = {
setOpen: (open: boolean) => void
}

export const ChatList = ({ setOpen }: Props) => {
const { chatStore } = useStores()

const handleSelectChat = (chatId: string) => {
chatStore.setCurrentConversationId(chatId)
setOpen(false)
}

const sortedChats = sortChats(chatStore.allChats)

return (
<ScrollView style={styles.scrollView}>
{sortedChats.map((chat) => (
<TouchableOpacity
key={chat.id}
onPress={() => handleSelectChat(chat.id)}
style={[
styles.chatItem,
chatStore.currentConversationId === chat.id && styles.selectedChat,
]}
>
<Text style={styles.chatPreviewText} numberOfLines={1}>
{getChatPreview(chat.messages)}
</Text>
<Text style={styles.dateText}>
{new Date(
chat.messages[0]?.createdAt || parseInt(chat.id.split("_")[1]) || Date.now(),
).toLocaleDateString()}
</Text>
</TouchableOpacity>
))}
</ScrollView>
)
}
22 changes: 22 additions & 0 deletions app/chat/drawer/ChatPreview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const getChatPreview = (messages: any[]) => {
if (!messages || messages.length === 0) {
return "New Chat"
}
const lastUserMessage = messages.filter((msg) => msg.role === "user").pop()
if (!lastUserMessage) {
return "New Chat"
}
const preview = lastUserMessage.content.trim()
if (preview.length <= 30) {
return preview
}
return preview.slice(0, 30) + "..."
}

export const sortChats = (chats: any[]) => {
return [...chats].sort((a, b) => {
const aTime = a.messages[0]?.createdAt || parseInt(a.id.split("_")[1]) || 0
const bTime = b.messages[0]?.createdAt || parseInt(b.id.split("_")[1]) || 0
return bTime - aTime // Reverse chronological order
})
}
26 changes: 26 additions & 0 deletions app/chat/drawer/NewChatButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { TouchableOpacity, Text } from "react-native"
import { MaterialCommunityIcons } from "@expo/vector-icons"
import { useStores } from "@/models"
import { styles } from "./styles"

type Props = {
setOpen: (open: boolean) => void
}

export const NewChatButton = ({ setOpen }: Props) => {
const { chatStore } = useStores()

const handleNewChat = () => {
const newId = `chat_${Date.now()}`
chatStore.setCurrentConversationId(newId)
chatStore.clearMessages()
setOpen(false)
}

return (
<TouchableOpacity onPress={handleNewChat} style={styles.newChatButton}>
<MaterialCommunityIcons name="chat-plus-outline" size={24} color="white" />
<Text style={styles.buttonText}>New chat</Text>
</TouchableOpacity>
)
}
33 changes: 33 additions & 0 deletions app/chat/drawer/ProfileButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { observer } from "mobx-react-lite"
import React from "react"
import { Text, TouchableOpacity } from "react-native"
import { useStores } from "@/models"
import { navigate } from "@/navigators"
import { MaterialCommunityIcons } from "@expo/vector-icons"
import { styles } from "./styles"

interface ProfileButtonProps {
setOpen: (open: boolean) => void
}

export const ProfileButton = observer(({ setOpen }: ProfileButtonProps) => {
const { walletStore } = useStores()
const npub = walletStore.nostrKeys?.npub

const handleProfilePress = () => {
setOpen(false)
navigate("Profile")
}

return (
<TouchableOpacity
onPress={handleProfilePress}
style={[styles.walletButton, { marginBottom: 16, marginTop: 6 }]}
>
<MaterialCommunityIcons name="account-outline" size={24} color="white" />
<Text style={styles.buttonText}>
Profile ({npub ? npub.slice(0, 8) + "..." : "Not connected"})
</Text>
</TouchableOpacity>
)
})
Loading

0 comments on commit b5d4d20

Please sign in to comment.