Skip to content

Commit

Permalink
Fix own Nostr address, move it to Privacy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
minibits-cash committed Feb 2, 2024
1 parent 461ddf8 commit b953f51
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 35 deletions.
2 changes: 1 addition & 1 deletion 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",
Expand Down
1 change: 1 addition & 0 deletions src/models/ContactsStore.ts
Expand Up @@ -108,6 +108,7 @@ import {
}

const ts2: number = Math.floor(Date.now() / 1000)
self.lastPendingReceivedCheck = ts2
log.trace('[setLastPendingReceivedCheck]', {ts2})
},
addReceivedEventId(id: string) {
Expand Down
6 changes: 4 additions & 2 deletions src/navigation/TabsNavigator.tsx
Expand Up @@ -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<T extends keyof ContactsStackParamList> = StackScreenProps<
Expand Down Expand Up @@ -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<T extends keyof SettingsStackParamList> = StackScreenProps<
Expand Down
23 changes: 15 additions & 8 deletions src/screens/OwnKeysScreen.tsx
Expand Up @@ -215,7 +215,7 @@ export const OwnKeysScreen: FC<OwnKeysScreenProps> = observer(function OwnKeysSc
ContentComponent={
<>
{!ownProfile ? (
<View style={$nip05Container}>
<View style={$nip05Container}>
<ListItem
LeftComponent={<View style={[$numIcon, {backgroundColor: iconNip05}]}><Text text='1'/></View>}
text='Enter your NOSTR address'
Expand Down Expand Up @@ -335,13 +335,20 @@ export const OwnKeysScreen: FC<OwnKeysScreenProps> = observer(function OwnKeysSc
<Card
style={[$card, {marginTop: spacing.medium}]}
ContentComponent={
<ListItem
leftIcon='faCheckCircle'
leftIconColor={colors.palette.success200}
text='Profile change is ready'
subText='Wallet needs to restart to apply this change.'
style={{}}
/>
<>
<ListItem
leftIcon='faTriangleExclamation'
text='Consider before change'
subText={'Using your own Nostr address will disable Lightning address features unique to minibits.cash address.'}
/>
<ListItem
leftIcon='faCheckCircle'
leftIconColor={colors.palette.success200}
text='Profile change is ready'
subText='Wallet needs to restart to apply this change.'
style={{}}
/>
</>
}
/>
<View style={$buttonContainer}>
Expand Down
81 changes: 78 additions & 3 deletions src/screens/PrivacyScreen.tsx
Expand Up @@ -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',
Expand All @@ -35,7 +37,7 @@ export const PrivacyScreen: FC<SettingsStackScreenProps<'Privacy'>> = 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<boolean>(
Expand Down Expand Up @@ -159,6 +161,41 @@ export const PrivacyScreen: FC<SettingsStackScreenProps<'Privacy'>> = 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)
Expand All @@ -168,7 +205,7 @@ export const PrivacyScreen: FC<SettingsStackScreenProps<'Privacy'>> = observer(f
const iconColor = useThemeColor('textDim')

return (
<Screen style={$screen}>
<Screen style={$screen} preset='auto'>
<View style={[$headerContainer, {backgroundColor: headerBg}]}>
<Text preset="heading" text="Privacy" style={{color: 'white'}} />
</View>
Expand Down Expand Up @@ -245,6 +282,44 @@ export const PrivacyScreen: FC<SettingsStackScreenProps<'Privacy'>> = observer(f
</>
}
/>
<Card
style={[$card, {marginTop: spacing.medium}]}
ContentComponent={
<>
<ListItem
text="Use own Nostr profile"
subText={walletProfileStore.isOwnProfile ? walletProfileStore.nip05 : "Import your own NOSTR address and keys. Your wallet stops communicate with minibits.cash Nostr and Lnurl address servers. However this will disable Lightning address features to receive zaps and payments. Only for hard core ecash-ers!"}
leftIcon={'faShareNodes'}
leftIconColor={
walletProfileStore.isOwnProfile
? colors.palette.iconViolet200
: iconColor as string
}
leftIconInverse={true}
RightComponent={
<>
{walletProfileStore.isOwnProfile ? (
<Button
style={{maxHeight: 10, marginTop: spacing.medium}}
preset="secondary"
text="Reset"
onPress={resetProfile}
/>
) : (
<Button
style={{maxHeight: 10, marginTop: spacing.medium}}
preset="secondary"
text="Import"
onPress={gotoOwnKeys}
/>
)}
</>
}
style={$item}
/>
</>
}
/>
<Card
style={[$card, {marginTop: spacing.medium}]}
ContentComponent={
Expand Down
52 changes: 31 additions & 21 deletions src/screens/ProfileScreen.tsx
Expand Up @@ -79,6 +79,12 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
}


const gotoPrivacy = function() {
toggleUpdateModal()
navigation.navigate('SettingsNavigator', {screen: 'Privacy'})
}


const gotoOwnKeys = function() {
toggleUpdateModal()
navigation.navigate('OwnKeys')
Expand Down Expand Up @@ -123,8 +129,9 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
}


const resetProfile = async function() {
/* const resetProfile = async function() {
setIsLoading(true)
toggleUpdateModal()
try {
// overwrite with new keys
Expand All @@ -150,7 +157,7 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
} catch (e: any) {
handleError(e)
}
}
}*/

const handleError = function (e: AppError): void {
setIsLoading(false)
Expand All @@ -174,7 +181,7 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
<>
<ListItem
text='Create wallet address'
subText='Your wallet address allows you to receive encrypted ecash over Nostr. At the same time it serves as your Lightning address, so that you can receive payments from any Lightning wallet or zaps on Nostr social network.'
subText='Your minibits.cash wallet address allows you to receive encrypted ecash over Nostr. At the same time it serves as your Lightning address, so that you can receive payments from any Lightning wallet or zaps on Nostr social network.'
/>
<View style={$buttonContainer}>
<Button
Expand All @@ -187,13 +194,23 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
</>
) : (
<>
<ListItem
text='Your Minibits wallet address'
subText={`Share your wallet address to receive encrypted ecash over Nostr. At the same time it serves as your Lightning address, so that you can receive payments from any Lightning wallet or zaps on Nostr social network.`}
leftIcon='faCircleUser'
bottomSeparator={true}
style={{paddingRight: spacing.small}}
/>
{walletProfileStore.isOwnProfile ? (
<ListItem
text='Your own wallet address'
subText={`You are using your own Nostr address to send and receive ecash. Please note, that such setup does not allow to receive Nostr zaps nor Lightning payments to this address.`}
leftIcon='faCircleUser'
bottomSeparator={true}
style={{paddingRight: spacing.small}}
/>
) : (
<ListItem
text='Your Minibits wallet address'
subText={`Share your wallet address to receive encrypted ecash over Nostr. At the same time it serves as your Lightning address, so that you can receive payments from any Lightning wallet or zaps on Nostr social network.`}
leftIcon='faCircleUser'
bottomSeparator={true}
style={{paddingRight: spacing.small}}
/>
)}
<View style={$buttonContainer}>
<Button
preset='secondary'
Expand Down Expand Up @@ -226,7 +243,7 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
gotoWalletName={gotoWalletName}
/>
)}
{walletProfileStore.isOwnProfile ? (
{walletProfileStore.isOwnProfile && (
<>
<ListItem
text='Sync own profile'
Expand All @@ -237,18 +254,11 @@ export const ProfileScreen: FC<ProfileScreenProps> = observer(
/>
<ListItem
text='Reset own profile'
subText='Stop using your own NOSTR address and re-create Minibits wallet profile with random NOSTR address.'
subText='Stop using your own NOSTR address and re-create Minibits wallet profile.'
leftIcon='faXmark'
onPress={resetProfile}
onPress={gotoPrivacy}
/>
</>
) : (
<ListItem
text='Use own Nostr profile'
subText='Use existing NOSTR address as your wallet address. You can then use Minibits to send and receive ecash using your public identity on NOSTR social network.'
leftIcon='faKey'
onPress={gotoOwnKeys}
/>
)}
</>
}
Expand Down Expand Up @@ -304,7 +314,7 @@ return (
subTx='profileScreen.changeWalletaddressSubtext'
leftIcon='faPencil'
onPress={props.gotoWalletName}
bottomSeparator={true}
// bottomSeparator={true}
/>
</>
)
Expand Down

0 comments on commit b953f51

Please sign in to comment.