From 2d73bdc70e5d202826fd0fd0cc0cb78be0c33c8e Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Tue, 23 Apr 2024 12:20:37 +0200 Subject: [PATCH] Filter out duplicate estimates --- src/lib/DataProviderManager.ts | 8 +++----- test/DataProviderManager-merge.test.ts | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/DataProviderManager.ts b/src/lib/DataProviderManager.ts index 802f2e6..a66ca83 100644 --- a/src/lib/DataProviderManager.ts +++ b/src/lib/DataProviderManager.ts @@ -196,12 +196,10 @@ export class DataProviderManager { log.debug({ msg: `Estimates for dataPoint ${providerName}`, estimates }); keys.forEach((key) => { - // Only add the estimate if it has a higher confirmation target and a lower fee + // Only add the estimate if it has a higher confirmation target and a lower fee. if ( - (!mergedEstimates[key] && estimates[key]) || - (mergedEstimates[key] && - key > Math.max(...Object.keys(mergedEstimates).map(Number)) && - estimates[key] < Math.min(...Object.values(mergedEstimates))) + key > Math.max(...Object.keys(mergedEstimates).map(Number)) && + estimates[key] < Math.min(...Object.values(mergedEstimates)) ) { log.debug({ msg: `Adding estimate from ${providerName} with target ${key} and fee ${estimates[key]} to mergedEstimates`, diff --git a/test/DataProviderManager-merge.test.ts b/test/DataProviderManager-merge.test.ts index 696ef10..1454be0 100644 --- a/test/DataProviderManager-merge.test.ts +++ b/test/DataProviderManager-merge.test.ts @@ -69,6 +69,8 @@ class MockProvider3 implements Provider { "2": 15, "3": 5, "5": 3, + "6": 3, + "7": 3, }); getAllData = () => Promise.resolve({ @@ -79,6 +81,8 @@ class MockProvider3 implements Provider { "2": 15, "3": 5, "5": 3, + "6": 3, + "7": 3, }, }); }