From c2fe81e8ab8c085d89ee1a76d6e1aadfd8f22475 Mon Sep 17 00:00:00 2001 From: Tim Stone Date: Mon, 18 Mar 2024 11:51:10 +1000 Subject: [PATCH] wip(app): implement core functionality in wtfdyp.ts - Began work on `wtfdyp.ts`, the main TypeScript file responsible for orchestrating the extension's core functionality. This file aims to integrate various components of the project, such as fetching invoice data, calculating combinations, and updating the UI based on user input. - Imported `getInvoiceCombinations` and `sortCombinations` functions to utilize the algorithm for finding optimal invoice combinations given a payment amount. - Temporarily commented out the Chrome message listener intended to react to popup actions. This listener will ultimately handle receiving the payment amount from the popup, initiating the combination finding and sorting process, and updating the DOM to reflect the selected invoices. - Included a test scenario with hardcoded invoice amounts and a payment amount to demonstrate the output of the sorting algorithm. This test will be replaced with dynamic data extraction from the page and interaction with the popup. This work-in-progress represents a significant step towards achieving the extension's goal of automating invoice selection. The next steps include finalizing the message listener to interact with the popup, extracting actual invoice data from the page, and implementing DOM manipulation to visually indicate the chosen invoices. --- src/wtfdyp.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/wtfdyp.ts diff --git a/src/wtfdyp.ts b/src/wtfdyp.ts new file mode 100644 index 0000000..8e136fa --- /dev/null +++ b/src/wtfdyp.ts @@ -0,0 +1,35 @@ +/** + * @license + * tsdevau + * License: BSD-3-Clause + * Licence Copywright: This software is licensed under the BSD-3-Clause License. See LICENCE file. + * + * Copyright (c) 2020-2024 tpsTech, TPS Contractors Pty Ltd and its affiliates. All rights reserved. + */ + +import { getInvoiceCombinations } from "./getInvoiceCombinations" +import { sortCombinations } from "./sortCombinations" +import type { Combo, WeightedCombo } from "./types" + +// chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { +// const paymentAmount = request.paymentAmount +// Logic to read the table and extract invoice amounts +// Your algorithm to find the best combination +// Update the page DOM to check off the selected invoices +// }) + +// Test output of sorting algorithm +const invAmounts: number[] = [ + 20.99, 80.1, 11.55, 57.6, 31.85, 278.5, 59.3, 14.8, 25, 112.16, 23, 58.4, 35, 246.32, 21.8, 56.63, + 25.8, +] +const paymentAmount: number = 379.39 + +// Get the valid combinations +const validCombos: Combo[][] = getInvoiceCombinations(invAmounts, paymentAmount) + +// Sort the valid combinations +const rankedCombos: WeightedCombo[] = sortCombinations(validCombos) + +// Log the sorted combinations +console.log(rankedCombos)