avoid commonjs require race conditions
This commit is contained in:
parent
e0fe2e96ba
commit
29680618ff
4 changed files with 14 additions and 11 deletions
|
|
@ -1053,7 +1053,7 @@ const saveSeedBackup = async (mnemonicPhrase, user, SEA) => {
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
const disconnect = async pub => {
|
const disconnect = async pub => {
|
||||||
const user = p(getUser())
|
const user = p(require('../Mediator').getUser())
|
||||||
if (!(await Utils.successfulHandshakeAlreadyExists(pub))) {
|
if (!(await Utils.successfulHandshakeAlreadyExists(pub))) {
|
||||||
throw new Error('No handshake exists for this pub')
|
throw new Error('No handshake exists for this pub')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
*/
|
*/
|
||||||
const debounce = require('lodash/debounce')
|
const debounce = require('lodash/debounce')
|
||||||
|
|
||||||
const { getGun } = require('../Mediator/index')
|
|
||||||
|
|
||||||
const Actions = require('./actions')
|
const Actions = require('./actions')
|
||||||
const ErrorCode = require('./errorCode')
|
const ErrorCode = require('./errorCode')
|
||||||
const Getters = require('./getters')
|
const Getters = require('./getters')
|
||||||
|
|
@ -636,7 +634,8 @@ const onChats = (cb, gun, user, SEA) => {
|
||||||
if (!userWithDisconnectionListeners.has(recipientPK)) {
|
if (!userWithDisconnectionListeners.has(recipientPK)) {
|
||||||
userWithDisconnectionListeners.add(recipientPK)
|
userWithDisconnectionListeners.add(recipientPK)
|
||||||
|
|
||||||
getGun()
|
require('../Mediator')
|
||||||
|
.getGun()
|
||||||
.user(recipientPK)
|
.user(recipientPK)
|
||||||
.get(Key.OUTGOINGS)
|
.get(Key.OUTGOINGS)
|
||||||
.get(incomingFeedID)
|
.get(incomingFeedID)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ exports.currentOrderAddress = async (pub) => {
|
||||||
* @returns {Promise<string|null>}
|
* @returns {Promise<string|null>}
|
||||||
*/
|
*/
|
||||||
exports.userToIncomingID = async (pub) => {
|
exports.userToIncomingID = async (pub) => {
|
||||||
const incomingID = await getUser().get(Key.USER_TO_INCOMING).get(pub).then()
|
const incomingID = await require('../Mediator').getUser().get(Key.USER_TO_INCOMING).get(pub).then()
|
||||||
|
|
||||||
if (typeof incomingID === 'string') return incomingID
|
if (typeof incomingID === 'string') return incomingID
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
const { getUser, mySEA: SEA, getGun } = require('../../Mediator')
|
|
||||||
const ErrorCode = require('../errorCode')
|
const ErrorCode = require('../errorCode')
|
||||||
const Key = require('../key')
|
const Key = require('../key')
|
||||||
|
|
||||||
|
|
@ -21,8 +20,11 @@ const delay = ms => new Promise(res => setTimeout(res, ms))
|
||||||
* @returns {Promise<string>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
const mySecret = () => {
|
const mySecret = () => {
|
||||||
const user = getUser()
|
const user = require('../../Mediator/index').getUser()
|
||||||
return SEA.secret(user._.sea.epub, user._.sea)
|
return require('../../Mediator/index').mySEA.secret(
|
||||||
|
user._.sea.epub,
|
||||||
|
user._.sea
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -159,13 +161,14 @@ const successfulHandshakeAlreadyExists = async recipientPub => {
|
||||||
* @returns {Promise<string|null>}
|
* @returns {Promise<string|null>}
|
||||||
*/
|
*/
|
||||||
const recipientToOutgoingID = async recipientPub => {
|
const recipientToOutgoingID = async recipientPub => {
|
||||||
const maybeEncryptedOutgoingID = await getUser()
|
const maybeEncryptedOutgoingID = await require('../../Mediator/index')
|
||||||
|
.getUser()
|
||||||
.get(Key.RECIPIENT_TO_OUTGOING)
|
.get(Key.RECIPIENT_TO_OUTGOING)
|
||||||
.get(recipientPub)
|
.get(recipientPub)
|
||||||
.then()
|
.then()
|
||||||
|
|
||||||
if (typeof maybeEncryptedOutgoingID === 'string') {
|
if (typeof maybeEncryptedOutgoingID === 'string') {
|
||||||
const outgoingID = await SEA.decrypt(
|
const outgoingID = await require('../../Mediator/index').mySEA.decrypt(
|
||||||
maybeEncryptedOutgoingID,
|
maybeEncryptedOutgoingID,
|
||||||
await mySecret()
|
await mySecret()
|
||||||
)
|
)
|
||||||
|
|
@ -306,7 +309,8 @@ const defaultName = pub => 'anon' + pub.slice(0, 8)
|
||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
const didDisconnect = async (pub, incomingID) => {
|
const didDisconnect = async (pub, incomingID) => {
|
||||||
const feed = await getGun()
|
const feed = await require('../../Mediator/index')
|
||||||
|
.getGun()
|
||||||
.user(pub)
|
.user(pub)
|
||||||
.get(Key.OUTGOINGS)
|
.get(Key.OUTGOINGS)
|
||||||
.get(incomingID)
|
.get(incomingID)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue