diff --git a/packages/server/src/helpers.ts b/packages/server/src/helpers.ts index cdf6174c..bd4d98bc 100644 --- a/packages/server/src/helpers.ts +++ b/packages/server/src/helpers.ts @@ -5,26 +5,13 @@ export function matchCurrencies( currencies: Currency[], patterns: string[], ): Currency[] { - const matchedCurrencies: Currency[] = []; - const patternCount = patterns.length; - const currencyCount = currencies.length; + const matchers = patterns + .filter((pattern) => pattern) + .map((pattern) => picomatch(pattern)); - for (let i = 0; i < patternCount; i += 1) { - const currentPattern = patterns[i]; - if (currentPattern) { - const isMatch = picomatch(currentPattern); - - for (let j = 0; j < currencyCount; j += 1) { - const currentCurrency = currencies[j]; - if (currentCurrency) { - if (isMatch(currentCurrency.id)) { - matchedCurrencies.push(currentCurrency); - } - } - } - } - } - return matchedCurrencies; + return currencies.filter((currency) => + matchers.some((matcher) => matcher(currency.id)), + ); } export function filterAccountsForCurrencies( diff --git a/packages/simulator/tests/simulator.spec.ts b/packages/simulator/tests/simulator.spec.ts index 65256155..0b0dcd1d 100644 --- a/packages/simulator/tests/simulator.spec.ts +++ b/packages/simulator/tests/simulator.spec.ts @@ -181,9 +181,9 @@ describe("Simulator", () => { // THEN expect(currencies).toBeDefined(); expect(currencies.length).toBe(currencyIds.length); - expect(currencies[0]?.id).toBe(currencyIds[1]); - expect(currencies[1]?.id).toBe(currencyIds[0]); - // Notice that the order of the list isn't defined by the order of the arguments in the query + expect(currencies.map(({ id }) => id)).toEqual( + expect.arrayContaining(currencyIds), + ); }); it("should throw an error if permission not granted", async () => {