From 89301e97f0de1bae278a4d5036bd167bf7250476 Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Thu, 26 Jan 2023 07:28:07 +0100 Subject: [PATCH] Version name an d nip21 test --- android/app/src/main/AndroidManifest.xml | 6 +++ frontend/Contexts/AppContext.tsx | 4 +- frontend/Contexts/UserContext.tsx | 15 ++++++ frontend/Functions/NativeFunctions/index.ts | 9 ++++ frontend/Locales/en.json | 3 +- frontend/Locales/es.json | 3 +- frontend/Locales/ru.json | 3 +- frontend/Pages/AboutPage/index.tsx | 57 ++++++++++++++++----- frontend/Pages/ProfileLoadPage/index.tsx | 10 ++-- package.json | 1 + yarn.lock | 5 ++ 11 files changed, 92 insertions(+), 24 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 187b655..907e7fe 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -17,6 +17,12 @@ android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true"> + + + + + + diff --git a/frontend/Contexts/AppContext.tsx b/frontend/Contexts/AppContext.tsx index a4ef449..88df6e9 100644 --- a/frontend/Contexts/AppContext.tsx +++ b/frontend/Contexts/AppContext.tsx @@ -29,8 +29,10 @@ export const AppContextProvider = ({ children }: AppContextProviderProps): JSX.E setDatabase(db) SInfo.getItem('publicKey', {}).then((value) => { setLoadingDb(false) - // Linking.addEventListener('url', this.handleOpenURL); }) + Linking.addEventListener('url', (event) => { + console.log(event.url) + }); } useEffect(init, []) diff --git a/frontend/Contexts/UserContext.tsx b/frontend/Contexts/UserContext.tsx index b305913..948c42b 100644 --- a/frontend/Contexts/UserContext.tsx +++ b/frontend/Contexts/UserContext.tsx @@ -13,6 +13,8 @@ import { dropTables } from '../Functions/DatabaseFunctions' import { navigate } from '../lib/Navigation' import { nsecEncode } from 'nostr-tools/nip19' import { getNpub } from '../lib/nostr/Nip19' +import Clipboard from '@react-native-clipboard/clipboard' +import { validNip21 } from '../Functions/NativeFunctions' export interface UserContextProps { userState: 'loading' | 'access' | 'ready' @@ -60,6 +62,7 @@ export const UserContextProvider = ({ children }: UserContextProviderProps): JSX const [nSec, setNsec] = useState() const [privateKey, setPrivateKey] = useState() const [user, setUser] = React.useState() + const [clipboardLoads, setClipboardLoads] = React.useState([]) const [contactsCount, setContantsCount] = React.useState(0) const [followersCount, setFollowersCount] = React.useState(0) @@ -73,12 +76,24 @@ export const UserContextProvider = ({ children }: UserContextProviderProps): JSX id: publicKey, }) } + checkClipboard() }) getContactsCount(database).then(setContantsCount) getFollowersCount(database).then(setFollowersCount) } } + const checkClipboard: () => void = () => { + Clipboard.getString().then((clipboardContent) => { + if (validNip21(clipboardContent) && !clipboardLoads.includes(clipboardContent)) { + setClipboardLoads((prev) => [...prev, clipboardContent]) + + } + }) + + + } + const logout: () => void = () => { if (database) { relayPool?.unsubscribeAll() diff --git a/frontend/Functions/NativeFunctions/index.ts b/frontend/Functions/NativeFunctions/index.ts index e5a079e..1e1a6da 100644 --- a/frontend/Functions/NativeFunctions/index.ts +++ b/frontend/Functions/NativeFunctions/index.ts @@ -33,3 +33,12 @@ export const validImageUrl: (url: string | undefined) => boolean = (url) => { return false } } + +export const validNip21: (string: string | undefined) => boolean = (string) => { + if (string) { + const regexp = /^nostr:(npub1|nprofile1|note1|nevent1)S*$/ + return regexp.test(string) + } else { + return false + } +} diff --git a/frontend/Locales/en.json b/frontend/Locales/en.json index afc683a..b25f064 100644 --- a/frontend/Locales/en.json +++ b/frontend/Locales/en.json @@ -122,7 +122,8 @@ "aboutPage": { "gitHub": "GitHub", "nostr": "nostr", - "nips": "NIPs" + "nips": "NIPs", + "version": "Version" }, "homeFeed": { "emptyTitle": "You are not following anyone.", diff --git a/frontend/Locales/es.json b/frontend/Locales/es.json index f8bc734..9493eeb 100644 --- a/frontend/Locales/es.json +++ b/frontend/Locales/es.json @@ -123,7 +123,8 @@ "aboutPage": { "gitHub": "GitHub", "nostr": "nostr", - "nips": "NIPs" + "nips": "NIPs", + "version": "Version" }, "homeFeed": { "emptyTitle": "No sigues a nadie", diff --git a/frontend/Locales/ru.json b/frontend/Locales/ru.json index 6a2d73a..4ea2cbd 100644 --- a/frontend/Locales/ru.json +++ b/frontend/Locales/ru.json @@ -122,7 +122,8 @@ "aboutPage": { "gitHub": "GitHub", "nostr": "nostr", - "nips": "NIPs" + "nips": "NIPs", + "version": "Version" }, "homeFeed": { "emptyTitle": "You are not following anyone.", diff --git a/frontend/Pages/AboutPage/index.tsx b/frontend/Pages/AboutPage/index.tsx index fb67640..6965348 100644 --- a/frontend/Pages/AboutPage/index.tsx +++ b/frontend/Pages/AboutPage/index.tsx @@ -1,13 +1,15 @@ import * as React from 'react' import { useTranslation } from 'react-i18next' import { FlatList, Linking, ListRenderItem, StyleSheet } from 'react-native' -import { Divider, List, useTheme } from 'react-native-paper' +import { Divider, List, Text, useTheme } from 'react-native-paper' import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons' +import DeviceInfo from 'react-native-device-info' interface ItemList { key: number title: string - left?: () => JSX.Element + left?: JSX.Element + right?: JSX.Element onPress: () => void } @@ -20,7 +22,7 @@ export const AboutPage: React.FC = () => { { key: 1, title: t('aboutPage.gitHub'), - left: () => ( + left: ( ( { { key: 2, title: t('aboutPage.nostr'), - left: () => ( + left: ( ( { { key: 3, title: t('aboutPage.nips'), - left: () => ( + left: ( ( { )} /> ), + right: <>, onPress: async () => await Linking.openURL('https://github.com/nostr-protocol/nips'), }, + { + key: 4, + title: t('aboutPage.version'), + left: ( + ( + + )} + /> + ), + right: {DeviceInfo.getVersion()}, + onPress: () => {}, + }, ], [], ) const renderItem: ListRenderItem = ({ item }) => { - return + return ( + item.left} + right={() => item.right} + /> + ) } return ( - - // DeviceInfo.getVersion() + <> + + ) } diff --git a/frontend/Pages/ProfileLoadPage/index.tsx b/frontend/Pages/ProfileLoadPage/index.tsx index 5e46c1e..c107d65 100644 --- a/frontend/Pages/ProfileLoadPage/index.tsx +++ b/frontend/Pages/ProfileLoadPage/index.tsx @@ -23,10 +23,8 @@ export const ProfileLoadPage: React.FC = () => { useFocusEffect( React.useCallback(() => { - if (publicKey && relayPoolReady) { - loadMeta() - loadPets() - } + loadMeta() + loadPets() return () => relayPool?.unsubscribe(['profile-load-notes', 'profile-load-meta-pets']) }, []), @@ -49,7 +47,7 @@ export const ProfileLoadPage: React.FC = () => { }, [user]) const loadMeta: () => void = () => { - if (publicKey) { + if (publicKey && relayPoolReady) { relayPool?.subscribe('profile-load-meta-pets', [ { kinds: [Kind.Contacts], @@ -64,7 +62,7 @@ export const ProfileLoadPage: React.FC = () => { } const loadPets: () => void = () => { - if (database && publicKey) { + if (database && publicKey && relayPoolReady) { getUsers(database, {}).then((results) => { if (results && results.length > 0) { setContactsCount(results.filter((user) => user.contact).length) diff --git a/package.json b/package.json index 97eecbf..b0e746a 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "react-native": "0.70.6", "react-native-action-button": "^2.8.5", "react-native-bidirectional-infinite-scroll": "^0.3.3", + "react-native-device-info": "^10.3.0", "react-native-gesture-handler": "^2.8.0", "react-native-multithreading": "^1.1.1", "react-native-pager-view": "^6.1.2", diff --git a/yarn.lock b/yarn.lock index 50fd17d..9149c2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7225,6 +7225,11 @@ react-native-codegen@^0.70.6: jscodeshift "^0.13.1" nullthrows "^1.1.1" +react-native-device-info@^10.3.0: + version "10.3.0" + resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-10.3.0.tgz#6bab64d84d3415dd00cc446c73ec5e2e61fddbe7" + integrity sha512-/ziZN1sA1REbJTv5mQZ4tXggcTvSbct+u5kCaze8BmN//lbxcTvWsU6NQd4IihLt89VkbX+14IGc9sVApSxd/w== + react-native-gesture-handler@^2.8.0: version "2.8.0" resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.8.0.tgz#ef9857871c10663c95a51546225b6e00cd4740cf"