diff --git a/src/main/websockets/client.js b/src/main/websockets/client.js index 9e16a3381..b5eaecd68 100644 --- a/src/main/websockets/client.js +++ b/src/main/websockets/client.js @@ -28,11 +28,11 @@ new Promise((resolve, reject) => { try { const options = url.parse(proxy) const agent = new HttpsProxyAgent(options) - const socket = new WebSocketClient(address, { agent: agent }, { handshakeTimeout: 30000 }) + const socket = new WebSocketClient(address, { agent: agent }, { handshakeTimeout: 80_000 }) const id = setTimeout(() => { // eslint-disable-next-line reject('timeout') - }, 35000) + }, 80_000) socket.on('unexpected-response', err => { console.log(err) }) diff --git a/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.js b/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.js index b45704afb..4253ce570 100644 --- a/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.js +++ b/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.js @@ -141,7 +141,7 @@ const inputStateToMessage = { [INPUT_STATE.LOCKED]: 'All of your funds are locked - please wait for network confirmation or deposit more ZEC to your account', [INPUT_STATE.UNREGISTERED]: - 'You can not reply to this message because you are not registered. Please register your nickname ( button next to your balance )' + 'You can not reply to this message because you are not registered yet, please wait.' } export const ChannelInput = ({ diff --git a/src/renderer/store/handlers/identity.ts b/src/renderer/store/handlers/identity.ts index 7b1b14de0..02ae6bba9 100644 --- a/src/renderer/store/handlers/identity.ts +++ b/src/renderer/store/handlers/identity.ts @@ -410,20 +410,7 @@ export const setIdentityEpic = identityToSet => async (dispatch, getState) => { await dispatch(messagesHandlers.epics.fetchMessages()) if (!useTor) { ipcRenderer.send('killTor') - // await dispatch(appHandlers.epics.initializeUseTor()) } - const usernameStatus = electronStore.get('registrationStatus.status') - const nickname = electronStore.get('registrationStatus.nickname') - console.log(usernameStatus) - if (nickname && usernameStatus !== 'SUCCESS') { - if (usernameStatus === 'IN_PROGRESS') { - dispatch(usersHandlers.epics.checkRegistrationConfirmations({ firstRun: true })) - } else { - await dispatch(usersHandlers.epics.createOrUpdateUser({ nickname, debounce: true })) - console.log('after registration') - } - } - console.log('before coordinator') setTimeout(() => dispatch(coordinatorHandlers.epics.coordinator()), 5000) dispatch(setLoadingMessage('Loading users and messages')) } catch (err) {} diff --git a/src/renderer/store/handlers/users.ts b/src/renderer/store/handlers/users.ts index ed9088753..db7d21e1e 100644 --- a/src/renderer/store/handlers/users.ts +++ b/src/renderer/store/handlers/users.ts @@ -14,7 +14,13 @@ import identitySelector from '../selectors/identity' import { actions as identityActions } from '../handlers/identity' import appSelectors from '../selectors/app' import { getPublicKeysFromSignature } from '../../zbay/messages' -import { messageType, actionTypes, unknownUserId, REQUEST_USER_REGISTRATION_ENDPOINT, FETCH_USERNAMES_ENDPOINT } from '../../../shared/static' +import { + messageType, + actionTypes, + unknownUserId, + REQUEST_USER_REGISTRATION_ENDPOINT, + FETCH_USERNAMES_ENDPOINT +} from '../../../shared/static' import { messages as zbayMessages } from '../../zbay' import staticChannels from '../../zcash/channels' import notificationsHandlers from './notifications' @@ -23,7 +29,7 @@ import electronStore from '../../../shared/electronStore' import { DisplayableMessage } from '../../zbay/messages.types' -import {packMemo} from '../../zbay/transit' +import { packMemo } from '../../zbay/transit' import { ActionsType, PayloadType } from './types' @@ -133,44 +139,6 @@ export const registerAnonUsername = () => async (dispatch, getState) => { await dispatch(createOrUpdateUser({ nickname: `anon${publicKey.substring(0, 10)}` })) } -export const checkRegistrationConfirmations = ({ firstRun }) => async (dispatch, getState) => { - if (firstRun) { - const publicKey = identitySelector.signerPubKey(getState()) - const address = identitySelector.address(getState()) - const nickname = electronStore.get('registrationStatus.nickname') - dispatch( - identityActions.setRegistraionStatus({ - nickname, - status: 'IN_PROGRESS' - }) - ) - dispatch( - mockOwnUser({ - sigPubKey: publicKey, - address, - nickname - }) - ) - } - setTimeout(async () => { - const publicKey = identitySelector.signerPubKey(getState()) - const users = usersSelector.users(getState()) - const usersArray = Array.from(Object.keys(users)) - - if(usersArray.includes(publicKey)){ - electronStore.set('registrationStatus.status', 'SUCCESS') - electronStore.set('registrationStatus.confirmation', 10) - dispatch( - notificationsHandlers.actions.enqueueSnackbar( - successNotification({ - message: `Username registered.` - }) - ) - ) - } - }, 75000) -} - export const createOrUpdateUser = payload => async (dispatch, getState) => { const { nickname, firstName = '', lastName = '', debounce = false, retry = 0 } = payload const publicKey = identitySelector.signerPubKey(getState()) @@ -182,6 +150,7 @@ export const createOrUpdateUser = payload => async (dispatch, getState) => { nickname, address } + const registrationMessage = zbayMessages.createMessage({ messageData: { type: zbayMessages.messageType.USER, @@ -223,39 +192,30 @@ export const createOrUpdateUser = payload => async (dispatch, getState) => { }) ) ) - dispatch( - identityActions.setRegistraionStatus({ - nickname, - status: 'ERROR' - }) - ) + dispatch( + identityActions.setRegistraionStatus({ + nickname, + status: 'ERROR' + }) + ) dispatch(actionCreators.openModal('failedUsernameRegister')()) return } + try { - - dispatch( - identityActions.setRegistraionStatus({ - nickname, - status: 'IN_PROGRESS' - }) - ) - dispatch( - mockOwnUser({ - sigPubKey: publicKey, - address, - nickname - }) - ) - electronStore.set('registrationStatus', { + dispatch( + identityActions.setRegistraionStatus({ nickname, status: 'IN_PROGRESS' }) - - // ipcRenderer.send('spawnTor') - // electronStore.set('useTor', true) - // dispatch(appHandlers.actions.setUseTor(true)) - dispatch(checkRegistrationConfirmations({ firstRun: true })) + ) + dispatch( + mockOwnUser({ + sigPubKey: publicKey, + address, + nickname + }) + ) dispatch( notificationsHandlers.actions.enqueueSnackbar( successNotification({ @@ -273,12 +233,12 @@ export const createOrUpdateUser = payload => async (dispatch, getState) => { dispatch(notificationsHandlers.actions.removeSnackbar('username')) } catch (err) { console.log(err) - dispatch( - identityActions.setRegistraionStatus({ - nickname, - status: 'ERROR' - }) - ) + dispatch( + identityActions.setRegistraionStatus({ + nickname, + status: 'ERROR' + }) + ) dispatch(actionCreators.openModal('failedUsernameRegister')()) } } @@ -319,7 +279,6 @@ export const fetchUsers = (address, messages: DisplayableMessage[]) => async ( let minfee = 0 let users = {} const network = nodeSelectors.network(getState()) - const { status: registrationStatus } = identitySelector.registrationStatus(getState()) const signerPubKey = identitySelector.signerPubKey(getState()) for (const msg of registrationMessages) { if ( @@ -345,29 +304,22 @@ export const fetchUsers = (address, messages: DisplayableMessage[]) => async ( } dispatch(feesHandlers.actions.setUserFee(minfee)) const isRegistrationComplete = users[signerPubKey] - if (!isRegistrationComplete && registrationStatus === 'IN_PROGRESS') { - const publicKey = identitySelector.signerPubKey(getState()) - const address = identitySelector.address(getState()) - const { nickname } = identitySelector.registrationStatus(getState()) - const mockedUser = { - [publicKey]: { - ..._UserData, - address, - nickname, - publicKey - } - } - users = { - ...users, - ...mockedUser + if (isRegistrationComplete) { + if (users[signerPubKey].createdAt !== 0) { + dispatch( + identityActions.setRegistraionStatus({ + nickname: '', + status: 'SUCCESS' + }) + ) + dispatch( + notificationsHandlers.actions.enqueueSnackbar( + successNotification({ + message: `Username registered.` + }) + ) + ) } - } else { - dispatch( - identityActions.setRegistraionStatus({ - nickname: '', - status: 'SUCCESS' - }) - ) } dispatch(setUsers({ users })) } catch (err) { @@ -407,26 +359,28 @@ export const fetchOnionAddresses = (address, messages: DisplayableMessage[]) => } } -let usernames = []; +let usernames = [] if (true) { - (function (){ - try { - axios.get(FETCH_USERNAMES_ENDPOINT).then((res) => { - usernames = res.data.message - } - ).catch((err) => { - console.log('cant fetch usernames') - console.log(err) - }) -} catch (err) { - console.log(err) -} -})(); + (function () { + try { + axios + .get(FETCH_USERNAMES_ENDPOINT) + .then(res => { + usernames = res.data.message + }) + .catch(err => { + console.log('cant fetch usernames') + console.log(err) + }) + } catch (err) { + console.log(err) + } + })() } export const isNicknameTaken = username => (dispatch, getState) => { -return R.includes(username, usernames) + return R.includes(username, usernames) } export const epics = { @@ -435,8 +389,8 @@ export const epics = { createOrUpdateUser, registerAnonUsername, fetchOnionAddresses, - registerOnionAddress, - checkRegistrationConfirmations + registerOnionAddress + // checkRegistrationConfirmations } export const reducer = handleActions>( diff --git a/src/renderer/store/selectors/channel.ts b/src/renderer/store/selectors/channel.ts index f89f3b432..47a6a1243 100644 --- a/src/renderer/store/selectors/channel.ts +++ b/src/renderer/store/selectors/channel.ts @@ -2,6 +2,7 @@ import { createSelector } from "reselect"; import identitySelectors from "./identity"; import messagesQueueSelectors from "./messagesQueue"; import contacts from "./contacts"; +import users from './users' import { networkFee, messageType } from "../../../shared/static"; import { Store } from '../reducers' @@ -182,9 +183,17 @@ export const shareableUri = createSelector(channel, (c) => c.shareableUri); export const inputLocked = createSelector( identitySelectors.balance("zec"), identitySelectors.lockedBalance("zec"), - (available, locked) => { + users.users, + identitySelectors.signerPubKey, + (available, locked, users, signerPubKey) => { if (available.gt(networkFee)) { - return INPUT_STATE.AVAILABLE; + if (users[signerPubKey]) { + if (users[signerPubKey].createdAt) { + return INPUT_STATE.AVAILABLE; + } else { + return INPUT_STATE.UNREGISTERED + } + } } else { if (locked.gt(0)) { return INPUT_STATE.LOCKED;