From b953f513c61545a306711a2a784a377d64560156 Mon Sep 17 00:00:00 2001 From: minibits-cash Date: Fri, 2 Feb 2024 15:49:04 +0100 Subject: [PATCH] Fix own Nostr address, move it to Privacy settings --- package.json | 2 +- src/models/ContactsStore.ts | 1 + src/navigation/TabsNavigator.tsx | 6 ++- src/screens/OwnKeysScreen.tsx | 23 +++++---- src/screens/PrivacyScreen.tsx | 81 ++++++++++++++++++++++++++++++-- src/screens/ProfileScreen.tsx | 52 +++++++++++--------- 6 files changed, 130 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index d4e177b..bad942b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minibits_wallet", - "version": "0.1.5-beta.31", + "version": "0.1.5-beta.32", "private": true, "scripts": { "android:clean": "cd android && ./gradlew clean", diff --git a/src/models/ContactsStore.ts b/src/models/ContactsStore.ts index cf407cd..7e5ac4b 100644 --- a/src/models/ContactsStore.ts +++ b/src/models/ContactsStore.ts @@ -108,6 +108,7 @@ import { } const ts2: number = Math.floor(Date.now() / 1000) + self.lastPendingReceivedCheck = ts2 log.trace('[setLastPendingReceivedCheck]', {ts2}) }, addReceivedEventId(id: string) { diff --git a/src/navigation/TabsNavigator.tsx b/src/navigation/TabsNavigator.tsx index 74b32b2..dbb68dc 100644 --- a/src/navigation/TabsNavigator.tsx +++ b/src/navigation/TabsNavigator.tsx @@ -173,7 +173,8 @@ export type ContactsStackParamList = { OwnName: {navigation: any} ContactDetail: {contact: Contact, relays: string[]} OwnKeys: undefined - WalletNavigator: {screen: string, params: any} + WalletNavigator: {screen: string, params: any} + SettingsNavigator: {screen: string} } export type ContactsStackScreenProps = StackScreenProps< @@ -219,7 +220,8 @@ export type SettingsStackParamList = { LocalRecovery: undefined Developer: undefined Relays: undefined - WalletNavigator: {screen: string} + WalletNavigator: {screen: string} + ContactsNavigator: {screen: string} } export type SettingsStackScreenProps = StackScreenProps< diff --git a/src/screens/OwnKeysScreen.tsx b/src/screens/OwnKeysScreen.tsx index 70b7518..508f286 100644 --- a/src/screens/OwnKeysScreen.tsx +++ b/src/screens/OwnKeysScreen.tsx @@ -215,7 +215,7 @@ export const OwnKeysScreen: FC = observer(function OwnKeysSc ContentComponent={ <> {!ownProfile ? ( - + } text='Enter your NOSTR address' @@ -335,13 +335,20 @@ export const OwnKeysScreen: FC = observer(function OwnKeysSc + <> + + + } /> diff --git a/src/screens/PrivacyScreen.tsx b/src/screens/PrivacyScreen.tsx index 5d748f1..d17f758 100644 --- a/src/screens/PrivacyScreen.tsx +++ b/src/screens/PrivacyScreen.tsx @@ -19,8 +19,10 @@ import {useHeader} from '../utils/useHeader' import {useStores} from '../models' import AppError from '../utils/AppError' import {ResultModalInfo} from './Wallet/ResultModalInfo' -import { TorDaemon } from '../services' +import { KeyChain, MinibitsClient, TorDaemon } from '../services' import { log } from '../services/logService' +import { OwnKeysScreen } from './OwnKeysScreen' +import { MINIBITS_NIP05_DOMAIN } from '@env' enum TorStatus { NOTINIT = 'NOTINIT', @@ -35,7 +37,7 @@ export const PrivacyScreen: FC> = observer(f onLeftPress: () => navigation.goBack(), }) - const {userSettingsStore} = useStores() + const {userSettingsStore, walletProfileStore} = useStores() const [info, setInfo] = useState('') const [isLoading, setIsLoading] = useState(false) const [isTorDaemonOn, setIsTorDaemonOn] = useState( @@ -159,6 +161,41 @@ export const PrivacyScreen: FC> = observer(f } } + const gotoOwnKeys = function() { + navigation.navigate('ContactsNavigator', {screen: 'OwnKeys'}) + } + + const resetProfile = async function() { + setIsLoading(true) + + try { + // overwrite with new keys + const keyPair = KeyChain.generateNostrKeyPair() + await KeyChain.saveNostrKeyPair(keyPair) + + // set name to defualt walletId + const name = userSettingsStore.walletId as string + + // get random image + const pictures = await MinibitsClient.getRandomPictures() // TODO PERF + + // update wallet profile + await walletProfileStore.updateNip05( + keyPair.publicKey, + name + MINIBITS_NIP05_DOMAIN, + name, + pictures[0], + false // isOwnProfile + ) + + + navigation.navigate('ContactsNavigator', {screen: 'Profile'}) + setIsLoading(false) + } catch (e: any) { + handleError(e) + } + } + const handleError = function (e: AppError): void { setIsLoading(false) setError(e) @@ -168,7 +205,7 @@ export const PrivacyScreen: FC> = observer(f const iconColor = useThemeColor('textDim') return ( - + @@ -245,6 +282,44 @@ export const PrivacyScreen: FC> = observer(f } /> + + + {walletProfileStore.isOwnProfile ? ( +