From 7ddf7c82f3bc1641d1ee1dbd1873729fbf2cc2cd Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 28 Feb 2020 16:52:51 -0400 Subject: [PATCH] use on() --- services/gunDB/contact-api/actions.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index 821c44e9..9664be05 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -958,19 +958,19 @@ const sendPayment = async (to, amount, memo) => { let timeoutID const invoice = await Promise.race([ - Utils.tryAndWait( - gun => - gun - .user(to) - .get(Key.ORDER_TO_RESPONSE) - .get(orderID) - .then() - .then(v => { + new Promise(res => { + require('../Mediator') + .getGun() + .user(to) + .get(Key.ORDER_TO_RESPONSE) + .get(orderID) + .on(inv => { + if (typeof inv === 'string') { clearTimeout(timeoutID) - return v - }), - v => typeof v !== 'string' - ), + res(inv) + } + }) + }), new Promise((_, rej) => { setTimeout(() => { rej(new Error(ErrorCode.ORDER_NOT_ANSWERED_IN_TIME))