Pārlūkot izejas kodu

buy: make CX configurable

raylu 3 nedēļas atpakaļ
vecāks
revīzija
398b56e960
2 mainītis faili ar 7 papildinājumiem un 6 dzēšanām
  1. 6 5
      ts/buy.ts
  2. 1 1
      www/buy.html

+ 6 - 5
ts/buy.ts

@@ -12,16 +12,17 @@ const apiKey = document.querySelector('#api-key') as HTMLInputElement;
 }
 document.querySelector('#fetch')!.addEventListener('click', async () => {
 	const supplyForDays = parseInt((document.querySelector('#days') as HTMLInputElement).value, 10);
-	const output = await calculate(username.value, apiKey.value, supplyForDays);
+	const cx = (document.querySelector('#cx') as HTMLInputElement).value;
+	const output = await calculate(username.value, apiKey.value, supplyForDays, cx);
 	console.log(output);
 	localStorage.setItem('fio-username', username.value);
 	localStorage.setItem('fio-api-key', apiKey.value);
 });
 setupPopover();
 
-async function calculate(username: string, apiKey: string, supplyForDays: number): Promise<void> {
+async function calculate(username: string, apiKey: string, supplyForDays: number, cx: string): Promise<void> {
 	const [prices, planets, avail, {bids, orders}] = await Promise.all([
-		getPrices(),
+		getPrices(cx),
 		getPlanets(username, apiKey),
 		warehouseInventory(username, apiKey),
 		getBids(username, apiKey)
@@ -86,11 +87,11 @@ async function calculate(username: string, apiKey: string, supplyForDays: number
 	}
 }
 
-async function getPrices() {
+async function getPrices(cx: string) {
 	const rawPrices= await fetch('https://refined-prun.github.io/refined-prices/all.json').then(r => r.json());
 	const prices = new Map<string, RawPrice>();
 	for (const p of rawPrices)
-		if (p.ExchangeCode === 'IC1')
+		if (p.ExchangeCode === cx)
 			prices.set(p.MaterialTicker, p);
 	return prices;
 }

+ 1 - 1
www/buy.html

@@ -15,7 +15,7 @@
 			<label>FIO username: <input type="text" id="username"></label>
 			<label>FIO API key: <input type="password" size="30" id="api-key"></label>
 			<label>supply for <input type="number" size="2" value="7" id="days"> days</label>
-			<label>CX <input type="text" id="cx" value="IC1" size="3" disabled></label>
+			<label>CX <input type="text" id="cx" value="IC1" size="3"></label>
 			<input type="button" value="fetch" id="fetch">
 		</form>
 		<table class="buy">