From de4683605c59257301def804fd462ece7c9066d1 Mon Sep 17 00:00:00 2001 From: hatim boufnichel Date: Wed, 14 Jul 2021 21:15:28 +0200 Subject: [PATCH] fix channels call --- utils/lightningServices/channelRequests.js | 34 ++++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/utils/lightningServices/channelRequests.js b/utils/lightningServices/channelRequests.js index 4598193f..18d3ae1e 100644 --- a/utils/lightningServices/channelRequests.js +++ b/utils/lightningServices/channelRequests.js @@ -5,28 +5,19 @@ const { listPeers, connectPeer,getInfo } = require('./v2') const handlerBaseUrl = "https://channels.shock.network:4444" -/** - * - * @param {string} inviteFromAuth - */ -module.exports = async (inviteFromAuth) => { +module.exports = async () => { /** * @type string | undefined */ - const invite = inviteFromAuth || process.env.HOSTING_INVITE + const invite = process.env.HOSTING_INVITE if(!invite) { return } - try{ - await Storage.getItem('processedInvites') - } catch(e) { - await Storage.setItem('processedInvites',[]) - } try { /** * @type string[] */ - const invites = await Storage.getItem('processedInvites') + const invites = await Storage.getItem('processedInvites') || [] if(invites.includes(invite)){ return } @@ -46,17 +37,22 @@ module.exports = async (inviteFromAuth) => { if(peers.findIndex(peer => peer.pub_key === pub) === -1){ await connectPeer(pub,host) } - + const channelReq = { + userPubKey:identity_pubkey, + invite, + lndTo:pub, + } //@ts-expect-error const res = await fetch(`${handlerBaseUrl}/channel`,{ method:'POST', - body:JSON.stringify({ - userPubKey:identity_pubkey, - invite, - lndTo:pub, - }) + headers: { + 'Content-Type': 'application/json' + }, + body:JSON.stringify(channelReq) }) - + if(res.status !== 200 ){ + return + } invites.push(invite) await Storage.setItem('processedInvites',invites)