Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug PM-710: The interface sometimes forgets that the wallet is registered until you refresh the page #442

Merged
merged 1 commit into from
Jul 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/api/gnosis.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ const addOlympiaContracts = async (gnosisJsInstance) => {
})
}

const waitForGnosisConnection = instance => new Promise((resolve, reject) => {
let stillRunning = true
const instanceCheck = setInterval(() => {
if (instance) {
stillRunning = false
clearInterval(instanceCheck)
return resolve(instance)
}
}, 50)

setTimeout(() => {
if (stillRunning) {
clearInterval(instanceCheck)
reject(new Error('Connection to RO Gnosis.js timed out'))
}
}, NETWORK_TIMEOUT)
})

/**
* Initializes connection to GnosisJS
* @param {*dictionary} GNOSIS_OPTIONS
Expand Down Expand Up @@ -74,25 +92,15 @@ export const getGnosisConnection = async () => {
return gnosisInstance
}

return new Promise((resolve, reject) => {
let stillRunning = true
const instanceCheck = setInterval(() => {
if (gnosisInstance) {
stillRunning = false
clearInterval(instanceCheck)
return resolve(gnosisInstance)
}
}, 50)

setTimeout(() => {
if (stillRunning) {
clearInterval(instanceCheck)
reject(new Error('Connection to Gnosis.js timed out'))
}
}, NETWORK_TIMEOUT)
})
return waitForGnosisConnection(gnosisInstance)
}

export const getROGnosisConnection = async () => gnosisROInstance || undefined
export const getROGnosisConnection = async () => {
if (gnosisROInstance) {
return gnosisROInstance
}

return waitForGnosisConnection(gnosisROInstance)
}

export default Gnosis