diff --git a/packages/unlock-js/examples/subgraph.js b/packages/unlock-js/examples/subgraph.js index 8dc7247069a..a7e57be393e 100644 --- a/packages/unlock-js/examples/subgraph.js +++ b/packages/unlock-js/examples/subgraph.js @@ -11,7 +11,6 @@ async function main() { networks: [1, 5], } ) - console.log(locks) const keys = await service.locks( { diff --git a/packages/unlock-js/src/subgraph/index.ts b/packages/unlock-js/src/subgraph/index.ts index 43a32ffe769..a10c79a9643 100644 --- a/packages/unlock-js/src/subgraph/index.ts +++ b/packages/unlock-js/src/subgraph/index.ts @@ -57,22 +57,24 @@ export class SubgraphService { const networks = options?.networks?.map((item) => this.networks[item]) || Object.values(this.networks).filter((item) => item.id !== 31337) - const items = await Promise.all( - networks.map(async (config) => { - try { - const sdk = this.createSdk(config.id) - const results = await sdk.allLocks(variables) - return results.locks.map((item) => ({ + const items = [] + for (let i = 0; i < networks.length; i++) { + const config = networks[i] + try { + const sdk = this.createSdk(config.id) + const results = await sdk.allLocks(variables) + items.push( + ...results.locks.map((item) => ({ ...item, network: config.id, })) - } catch (error) { - console.error(error) - return [] - } - }) - ) - return items.flat() + ) + } catch (error) { + console.error(error) + } + } + + return items } /** @@ -94,22 +96,25 @@ export class SubgraphService { const networks = options?.networks?.map((item) => this.networks[item]) || Object.values(this.networks).filter((item) => item.id !== 31337) - const items = await Promise.all( - networks.map(async (config) => { - try { - const sdk = this.createSdk(config.id) - const results = await sdk.allLocksWithKeys(variables) - return results.locks.map((item) => ({ + + const items = [] + for (let i = 0; i < networks.length; i++) { + const config = networks[i] + try { + const sdk = this.createSdk(config.id) + const results = await sdk.allLocksWithKeys(variables) + items.push( + ...results.locks.map((item) => ({ ...item, network: config.id, })) - } catch (error) { - console.error(error) - return [] - } - }) - ) - return items.flat() + ) + } catch (error) { + console.error(error) + } + } + + return items } /** @@ -139,23 +144,23 @@ export class SubgraphService { options?.networks?.map((item) => this.networks[item]) || Object.values(this.networks).filter((item) => item.id !== 31337) - const items = await Promise.all( - networks.map(async (config) => { - try { - const sdk = this.createSdk(config.id) - const results = await sdk.AllKeys(variables) - return results.keys.map((item) => ({ + const items = [] + for (let i = 0; i < networks.length; i++) { + const network = networks[i] + try { + const sdk = this.createSdk(network.id) + const results = await sdk.AllKeys(variables) + items.push( + ...results.keys.map((item) => ({ ...item, - network: config.id, + network: network.id, })) - } catch (error) { - console.error(error) - return [] - } - }) - ) - - return items.flat() + ) + } catch (error) { + console.error(error) + } + } + return items } /** @@ -175,22 +180,23 @@ export class SubgraphService { options?.networks?.map((item) => this.networks[item]) || Object.values(this.networks).filter((item) => item.id !== 31337) - const items = await Promise.all( - networks.map(async (config) => { - try { - const sdk = this.createSdk(config.id) - const results = await sdk.AllReceipts(variables) - return results.receipts.map((item) => ({ + const items = [] + for (let i = 0; i < networks.length; i++) { + const config = networks[i] + try { + const sdk = this.createSdk(config.id) + const results = await sdk.AllReceipts(variables) + items.push( + results.receipts.map((item) => ({ ...item, network: config.id, })) - } catch (error) { - console.error(error) - return [] - } - }) - ) - return items.flat() + ) + } catch (error) { + console.error(error) + } + } + return items } /** Get a single receipt for a specific network */