From 8616e1fdefa2571a81511b7184ae10cb2446f299 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Wed, 26 Aug 2020 20:30:27 -0400 Subject: [PATCH] use usual retry routine --- services/gunDB/contact-api/actions.js | 40 +++++++++++---------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index fec3fa62..176b855e 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -979,30 +979,22 @@ const sendSpontaneousPayment = async (to, amount, memo, feeLimit) => { throw new Error(msg) } - /** @type {ReturnType} */ - // eslint-disable-next-line init-declarations - let timeoutID - - /** - * @type {import('shock-common').Schema.OrderResponse} - */ - const encryptedOrderRes = await new Promise((res, rej) => { - require('../Mediator') - .getGun() - .user(to) - .get(Key.ORDER_TO_RESPONSE) - .get(orderID) - .on(orderResponse => { - if (Schema.isOrderResponse(orderResponse)) { - clearTimeout(timeoutID) - res(orderResponse) - } - }) - - timeoutID = setTimeout(() => { - rej(new Error(ErrorCode.ORDER_NOT_ANSWERED_IN_TIME)) - }, 20000) - }) + /** @type {import('shock-common').Schema.OrderResponse} */ + const encryptedOrderRes = await Utils.tryAndWait( + gun => + new Promise(res => { + gun + .user(to) + .get(Key.ORDER_TO_RESPONSE) + .get(orderID) + .on(orderResponse => { + if (Schema.isOrderResponse(orderResponse)) { + res(orderResponse) + } + }) + }), + v => !Schema.isOrderResponse(v) + ) /** @type {import('shock-common').Schema.OrderResponse} */ const orderResponse = {