use tryAndWait()

This commit is contained in:
Daniel Lugo 2020-02-24 15:11:17 -04:00
parent 438c5d09c7
commit 6c8c7c27ed

View file

@ -206,12 +206,18 @@ const recipientToOutgoingID = async recipientPub => {
* @returns {Promise<string|null>}
*/
const currHandshakeAddress = async userPub => {
const maybeAddr = await tryAndWait(gun =>
gun
const maybeAddr = await tryAndWait(async gun => {
const addr = await gun
.user(userPub)
.get(Key.CURRENT_HANDSHAKE_ADDRESS)
.then()
)
if (typeof addr !== 'string' && addr !== null) {
throw new TypeError('Expected handshake address to be string or null')
}
return addr
})
return typeof maybeAddr === 'string' ? maybeAddr : null
}