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