From c2fcbfeca89437d985aa025350ed2091b83aeed5 Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Tue, 12 Dec 2023 00:26:27 +0100 Subject: [PATCH] Offline and Contacts fixes --- .github/workflows/release.yml | 15 +++++- frontend/Components/MenuItems/index.tsx | 2 +- frontend/Components/NoteCard/index.tsx | 4 +- frontend/Contexts/AppContext.tsx | 5 -- frontend/Functions/DatabaseFunctions/index.ts | 1 + frontend/Pages/ContactsPage/index.tsx | 14 ++---- frontend/Pages/ConversationPage/index.tsx | 13 +++--- frontend/Pages/GroupPage/index.tsx | 11 +++-- .../HomePage/ConversationsFeed/index.tsx | 20 ++++---- frontend/Pages/HomePage/GroupsFeed/index.tsx | 22 +++++---- frontend/Pages/HomePage/HomeFeed/index.tsx | 4 +- frontend/Pages/NotePage/index.tsx | 2 +- frontend/Pages/ProfileCreatePage/index.tsx | 12 ++--- .../Pages/ProfileLoadPage/ThirdStep/index.tsx | 3 +- frontend/Pages/RelaysPage/index.tsx | 46 ++++++++++--------- frontend/Pages/WalletPage/index.tsx | 6 +-- frontend/Pages/ZapPage/index.tsx | 8 ++-- 17 files changed, 102 insertions(+), 86 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e4c632..13720ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,6 +26,10 @@ jobs: https://github.com/KoalaSat/nostros/releases/download/${{ github.ref_name }}/nostros-${{ github.ref_name }}-universal.apk + **Torrent** + + https://github.com/KoalaSat/nostros/releases/download/${{ github.ref_name }}/nostros-${{ github.ref_name }}-universal.torrent + **Changelog** https://github.com/KoalaSat/nostros/releases/${{ github.ref_name }} @@ -75,4 +79,13 @@ jobs: upload_url: ${{ steps.create-release.outputs.upload_url }} asset_path: app-armeabi-v7a-release.apk asset_name: nostros-${{ github.ref_name }}-armeabi-v7a.apk - asset_content_type: application/apk + asset_content_type: application/apk + - name: Install torf-cli + run: sudo pip3 install torf-cli + - name: Create torrent using torf-cli + run: torf "nostros-${{ github.ref_name }}-universal.apk" -o "nostros-${{ github.ref_name }}-universal.torrent" -w "https://github.com/KoalaSat/nostros/releases/download/${{ github.ref_name }}/nostros-${{ github.ref_name }}-universal.apk" -s "torrent-webseed-creator" + - name: Upload torrent file + uses: actions/upload-artifact@v3 + with: + name: Torrent + path: nostros-${{ github.ref_name }}-universal.torrent diff --git a/frontend/Components/MenuItems/index.tsx b/frontend/Components/MenuItems/index.tsx index 3f17439..316454f 100644 --- a/frontend/Components/MenuItems/index.tsx +++ b/frontend/Components/MenuItems/index.tsx @@ -132,7 +132,7 @@ export const MenuItems: React.FC = () => { /> - {privateKey && ( + {privateKey && online && ( = ({ )} - bottomSheetCreateRef.current?.open()} - animateFrom='right' - iconMode='static' - extended={false} - /> + {privateKey && online && ( + bottomSheetCreateRef.current?.open()} + animateFrom='right' + iconMode='static' + extended={false} + /> + )} { const { t } = useTranslation('common') const theme = useTheme() const { database, qrReader, setQrReader, refreshBottomBarAt, online } = useContext(AppContext) - const { publicKey } = useContext(UserContext) + const { publicKey, privateKey } = useContext(UserContext) const { relayPool, lastEventId, lastConfirmationtId, sendEvent, setNewGroupMessages, newGroupMessages } = useContext(RelayPoolContext) const bottomSheetSearchRef = React.useRef(null) const bottomSheetCreateRef = React.useRef(null) @@ -297,15 +297,17 @@ export const GroupsFeed: React.FC = () => { horizontal={false} estimatedItemSize={76} /> - bottomSheetFabActionRef.current?.open()} - animateFrom='right' - iconMode='static' - extended={false} - /> + {privateKey && online && ( + bottomSheetFabActionRef.current?.open()} + animateFrom='right' + iconMode='static' + extended={false} + /> + )} diff --git a/frontend/Pages/HomePage/HomeFeed/index.tsx b/frontend/Pages/HomePage/HomeFeed/index.tsx index 256f310..23c68db 100644 --- a/frontend/Pages/HomePage/HomeFeed/index.tsx +++ b/frontend/Pages/HomePage/HomeFeed/index.tsx @@ -9,12 +9,14 @@ import Tabs from '../../../Components/Tabs' import ZapsFeed from './ZapsFeed' import BookmarksFeed from './BookmarksFeed' import { RelayPoolContext } from '../../../Contexts/RelayPoolContext' +import { AppContext } from '../../../Contexts/AppContext' interface HomeFeedProps { navigation: any } export const HomeFeed: React.FC = ({ navigation }) => { + const { online } = useContext(AppContext) const { privateKey, publicKey } = useContext(UserContext) const { relayPool } = useContext(RelayPoolContext) const [activeTab, setActiveTab] = React.useState('myFeed') @@ -80,7 +82,7 @@ export const HomeFeed: React.FC = ({ navigation }) => { defaultTab='myFeed' /> {renderScene[activeTab]} - {privateKey && ( + {privateKey && online && ( = ({ route }) => { /> - {privateKey && ( + {privateKey && online && ( = ({ navigation }) => { const { t } = useTranslation('common') const { setPrivateKey, setUserState, publicKey } = useContext(UserContext) - const { createRandomRelays, sendEvent, relays } = useContext(RelayPoolContext) - const [key, setKey] = useState() + const { createRandomRelays, sendEvent, relays, relayPoolReady } = useContext(RelayPoolContext) const [inputValue, setInputValue] = useState() const [keyboardShow, setKeyboardShow] = useState(false) const [step, setStep] = useState(0) @@ -35,13 +34,16 @@ export const ProfileCreatePage: React.FC = ({ navigation generateRandomMnemonic().then((words) => { setMnemonicWords(words) const privateKey = nip06.privateKeyFromSeedWords(Object.values(words).join(' ')) - setKey(privateKey) + setPrivateKey(privateKey) const nsec = nip19.nsecEncode(privateKey) setInputValue(nsec) }) - createRandomRelays() }, []) + React.useEffect(() => { + if (relayPoolReady) createRandomRelays() + }, [relayPoolReady]) + useEffect(() => { if (inputValue) setLoading(false) }, [inputValue]) @@ -92,7 +94,6 @@ export const ProfileCreatePage: React.FC = ({ navigation sendEvent(event) } if (validConfirmation()) { - setPrivateKey(key) publishRelays() setUserState('ready') } else { @@ -104,7 +105,6 @@ export const ProfileCreatePage: React.FC = ({ navigation } const onPressSkip: () => void = () => { - setPrivateKey(key) publishRelays() setUserState('ready') } diff --git a/frontend/Pages/ProfileLoadPage/ThirdStep/index.tsx b/frontend/Pages/ProfileLoadPage/ThirdStep/index.tsx index efd2164..0c2387b 100644 --- a/frontend/Pages/ProfileLoadPage/ThirdStep/index.tsx +++ b/frontend/Pages/ProfileLoadPage/ThirdStep/index.tsx @@ -1,7 +1,7 @@ import React, { useContext, useState } from 'react' import { useTranslation } from 'react-i18next' import { type ListRenderItem, StyleSheet, View, FlatList } from 'react-native' -import { Button, Card, Divider, List, Text, useTheme } from 'react-native-paper' +import { ActivityIndicator, Button, Card, Divider, List, Text, useTheme } from 'react-native-paper' import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons' import { AppContext } from '../../../Contexts/AppContext' import { RelayPoolContext } from '../../../Contexts/RelayPoolContext' @@ -121,6 +121,7 @@ export const ThirdStep: React.FC = ({ nextStep, skip }) => { {t('profileLoadPage.contatcsRelays')} + {t('profileLoadPage.contatcsRelaysCount', { activeRelays: contactsRelays.length })} diff --git a/frontend/Pages/RelaysPage/index.tsx b/frontend/Pages/RelaysPage/index.tsx index eb6347a..f953bb0 100644 --- a/frontend/Pages/RelaysPage/index.tsx +++ b/frontend/Pages/RelaysPage/index.tsx @@ -350,27 +350,31 @@ export const RelaysPage: React.FC = () => { ItemSeparatorComponent={Divider} /> - { - calculateContactsRelays() - bottomSheetContactsRef.current?.open() - }} - animateFrom='right' - iconMode='static' - extended={false} - /> - bottomSheetPushRef.current?.open()} - animateFrom='right' - iconMode='static' - extended={false} - /> + {online && ( + <> + { + calculateContactsRelays() + bottomSheetContactsRef.current?.open() + }} + animateFrom='right' + iconMode='static' + extended={false} + /> + bottomSheetPushRef.current?.open()} + animateFrom='right' + iconMode='static' + extended={false} + /> + + )} { const theme = useTheme() - const { getSatoshiSymbol, database, setDisplayUserDrawer, online } = React.useContext(AppContext) + const { getSatoshiSymbol, database, online } = React.useContext(AppContext) const { publicKey } = React.useContext(UserContext) const { relayPool, lastEventId } = React.useContext(RelayPoolContext) const { refreshWallet, updateWallet, type, balance, transactions, invoices, updatedAt } = @@ -171,7 +171,7 @@ export const WalletPage: React.FC = () => { if (zap.zapped_event_id) { navigate('Note', { noteId: zap.zapped_event_id }) } else if (zap.zapper_user_id) { - setDisplayUserDrawer(zap.zapper_user_id) + push('ProfileActions', { userId: zap.zapper_user_id, title: zap.name }) } } }} diff --git a/frontend/Pages/ZapPage/index.tsx b/frontend/Pages/ZapPage/index.tsx index acc46dc..23b50e6 100644 --- a/frontend/Pages/ZapPage/index.tsx +++ b/frontend/Pages/ZapPage/index.tsx @@ -18,7 +18,7 @@ import { Kind } from 'nostr-tools' import { getUsers, type User } from '../../Functions/DatabaseFunctions/Users' import LnPreview from '../../Components/LnPreview' import { FlatList, type ListRenderItem, ScrollView, StyleSheet, View, Dimensions } from 'react-native' -import { goBack } from '../../lib/Navigation' +import { goBack, push } from '../../lib/Navigation' import { getZapTag } from '../../Functions/RelayFunctions/Events' interface ZapPageProps { @@ -33,7 +33,7 @@ export const ZapPage: React.FC = ({ route: { params: { note, user const userId = user?.id ?? note?.pubkey const zapPubkey = user?.zap_pubkey ?? note?.zap_pubkey const zapSplitTags = getZapTag(note) - const { getSatoshiSymbol, database, setDisplayUserDrawer, online } = React.useContext(AppContext) + const { getSatoshiSymbol, database, online } = React.useContext(AppContext) const { relayPool, lastEventId } = React.useContext(RelayPoolContext) const { publicKey, privateKey } = React.useContext(UserContext) const bottomSheetLnPaymentRef = React.useRef(null) @@ -135,7 +135,7 @@ export const ZapPage: React.FC = ({ route: { params: { note, user const zapDescription = item.tags?.find((tag) => tag[0] === 'description') const content = zapDescription ? JSON.parse(zapDescription[1])?.content : undefined return ( - setDisplayUserDrawer(item.user_id)}> + push('ProfileActions', { userId: item?.user_id, title: item?.name })}> = ({ route: { params: { note, user const totalWeight = zapSplitTags.reduce((acc, tag) => acc + parseInt(tag[3] ?? '0', 10), 0) const weightedAllocation = allocationTag ? (parseInt(allocationTag[3] ?? '0', 10) * 100) / totalWeight : 0 return ( - setDisplayUserDrawer(item)}> + push('ProfileActions', { userId: user?.id, title: user?.name })}>