1- import React , { useContext , useEffect , useState } from 'react'
1+ import React , { useContext , useState } from 'react'
22import { Button , Input , Layout , useTheme } from '@ui-kitten/components'
33import { Clipboard , StyleSheet } from 'react-native'
44import { RelayPoolContext } from '../../../Contexts/RelayPoolContext'
55import { useTranslation } from 'react-i18next'
6- import { EventKind } from '../../../lib/nostr/Events'
7- import { AppContext } from '../../../Contexts/AppContext'
8- import SInfo from 'react-native-sensitive-info'
96import Icon from 'react-native-vector-icons/FontAwesome5'
10- import { generateRandomKey , getPublickey } from '../../../lib/nostr/Bip'
7+ import { generateRandomKey } from '../../../lib/nostr/Bip'
118import { showMessage } from 'react-native-flash-message'
12- import { getUsers , User } from '../../../Functions/DatabaseFunctions/Users'
139
1410export const Logger : React . FC = ( ) => {
15- const { goToPage, loadingDb, database } = useContext ( AppContext )
16- const { privateKey, publicKey, relayPool, loadingRelayPool, setPrivateKey, setPublicKey } =
17- useContext ( RelayPoolContext )
11+ const { publicKey, setPrivateKey, setPublicKey } = useContext ( RelayPoolContext )
1812 const { t } = useTranslation ( 'common' )
1913 const theme = useTheme ( )
20- const [ loading , setLoading ] = useState < boolean > ( false )
21- const [ status , setStatus ] = useState < number > ( 0 )
2214 const [ isPrivate , setIsPrivate ] = useState < boolean > ( true )
2315 const [ inputValue , setInputValue ] = useState < string > ( '' )
2416
25- useEffect ( ( ) => {
26- if ( loading ) {
27- setStatus ( 1 )
17+ const onPress : ( ) => void = ( ) => {
18+ if ( inputValue && inputValue !== '' ) {
2819 if ( isPrivate ) {
2920 setPrivateKey ( inputValue )
30- const publicKey : string = getPublickey ( inputValue )
31- setPublicKey ( publicKey )
32- SInfo . setItem ( 'privateKey' , inputValue , { } )
33- SInfo . setItem ( 'publicKey' , publicKey , { } )
3421 } else {
3522 setPublicKey ( inputValue )
36- SInfo . setItem ( 'publicKey' , inputValue , { } )
3723 }
3824 }
39- } , [ loading ] )
40-
41- useEffect ( ( ) => {
42- if ( ! loadingRelayPool && ! loadingDb && publicKey ) {
43- relayPool ?. subscribe ( 'main-channel' , {
44- kinds : [ EventKind . petNames , EventKind . meta ] ,
45- authors : [ publicKey ] ,
46- } )
47- setTimeout ( loadPets , 4000 )
48- }
49- } , [ loadingRelayPool , publicKey , loadingDb ] )
50-
51- const onPress : ( ) => void = ( ) => {
52- if ( inputValue && inputValue !== '' ) {
53- setLoading ( true )
54- }
55- }
56-
57- const loadPets : ( ) => void = ( ) => {
58- if ( database ) {
59- getUsers ( database , { contacts : true } ) . then ( ( results ) => {
60- if ( results && results . length > 0 ) {
61- relayPool ?. subscribe ( 'main-channel' , {
62- kinds : [ EventKind . textNote , EventKind . recommendServer , EventKind . meta ] ,
63- authors : results . map ( ( user : User ) => user . id ) ,
64- } )
65- }
66- setTimeout ( ( ) => goToPage ( 'home' , true ) , 5000 )
67- } )
68- }
6925 }
7026
7127 const randomKeyGenerator : ( ) => JSX . Element = ( ) => {
@@ -95,11 +51,6 @@ export const Logger: React.FC = () => {
9551 )
9652 }
9753
98- const statusName : { [ status : number ] : string } = {
99- 0 : t ( 'landing.connect' ) ,
100- 1 : t ( 'landing.connecting' ) ,
101- 2 : t ( 'landing.ready' ) ,
102- }
10354 const styles = StyleSheet . create ( {
10455 inputsContainer : {
10556 flexDirection : 'row' ,
@@ -130,7 +81,7 @@ export const Logger: React.FC = () => {
13081
13182 const label : string = isPrivate ? t ( 'landing.privateKey' ) : t ( 'landing.publicKey' )
13283
133- return ! privateKey || ! publicKey || status !== 0 ? (
84+ return (
13485 < >
13586 < Layout style = { styles . inputsContainer } >
13687 < Layout style = { styles . input } >
@@ -139,7 +90,7 @@ export const Logger: React.FC = () => {
13990 label = { label }
14091 onChangeText = { setInputValue }
14192 value = { inputValue }
142- disabled = { loading }
93+ disabled = { publicKey !== undefined }
14394 accessoryRight = { randomKeyGenerator }
14495 />
14596 </ Layout >
@@ -151,20 +102,18 @@ export const Logger: React.FC = () => {
151102 setIsPrivate ( ! isPrivate )
152103 setInputValue ( '' )
153104 } }
154- disabled = { loading }
105+ disabled = { publicKey !== undefined }
155106 accessoryLeft = { keyButton }
156107 status = { isPrivate ? 'warning' : 'default' }
157108 />
158109 </ Layout >
159110 < Layout style = { styles . buttonRight } >
160- < Button onPress = { onPress } disabled = { loading } >
161- { statusName [ status ] }
111+ < Button onPress = { onPress } disabled = { publicKey !== undefined } >
112+ { t ( 'landing.connect' ) }
162113 </ Button >
163114 </ Layout >
164115 </ Layout >
165116 </ >
166- ) : (
167- < > </ >
168117 )
169118}
170119
0 commit comments