Skip to content

Commit

Permalink
Merge pull request #2 from AmolDerickSoans/feature/stateManagement
Browse files Browse the repository at this point in the history
Feature/state management
  • Loading branch information
AmolDerickSoans authored Dec 24, 2024
2 parents 2c0f07b + 4bf466c commit 684148c
Show file tree
Hide file tree
Showing 25 changed files with 14,730 additions and 846 deletions.
2,473 changes: 2,473 additions & 0 deletions EQUITY_L.csv

Large diffs are not rendered by default.

41 changes: 19 additions & 22 deletions background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@ const CACHE_CONFIG = {
maxItems: 500 // Limit cache size
};
const supabase = createClient(
'YOUR_SUPABASE_URL',
'YOUR_SUPABASE_ANON_KEY'


)
// Initialize extension
chrome.runtime.onInstalled.addListener(async () => {
console.log('Trade Call Widget installed/updated');
await initializeCache();
await cacheAllStockSymbols(); // Cache stock symbols on installation
await checkAuth();
//await initializeCache();
//await cacheAllStockSymbols(); // Cache stock symbols on installation
//await checkAuth();
await chrome.sidePanel.setOptions({
enabled: true,
path: 'popup.html'
});
});

// Check auth state when extension opens
chrome.runtime.onStartup.addListener(async() => {
await checkAuth();
// await checkAuth();
console.log('on startup checked auth')
});

async function checkAuth() {
const { data: { session }, error } = await supabase.auth.getSession();

console.log('checking auth')
if (error || !session) {
// If not authenticated, open auth popup
chrome.windows.create({
Expand Down Expand Up @@ -69,21 +74,13 @@ async function cacheAllStockSymbols() {

// Listen for extension icon clicks
chrome.action.onClicked.addListener(async (tab) => {
// Open the side panel in the current window
await chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true })
.catch((error) => console.error(error));
});


chrome.sidePanel
.setPanelBehavior({ openPanelOnActionClick: true })
.catch((error) => console.error(error));
// Initialize side panel options when extension is installed or updated
chrome.runtime.onInstalled.addListener(async () => {
await chrome.sidePanel.setOptions({
enabled: true,
path: 'popup.html'
});
console.log('Extension icon clicked'); // Log when the icon is clicked
try {
await chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true });
console.log('Side panel behavior set successfully');
} catch (error) {
console.error('Error setting side panel behavior:', error);
}
});

// Handle messages from popup
Expand Down
51 changes: 51 additions & 0 deletions csv2db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const fs = require('fs');
const csv = require('csv-parser');

function csvToJson(csvFilePath, jsonFilePath) {
return new Promise((resolve, reject) => {
const results = { stocks: [] };
let lineCount = 0;

fs.createReadStream(csvFilePath)
.pipe(csv())
.on('data', (row) => {
lineCount++;
const symbol = row['SYMBOL'] ? String(row['SYMBOL']).trim() : null;
const companyName = row['NAME OF COMPANY'] ? String(row['NAME OF COMPANY']).trim() : null;

if (symbol && companyName) {
results.stocks.push({
ticker: symbol,
name: companyName,
});
console.log(`Converted: ${symbol} - ${companyName}`);
}
})
.on('end', () => {
console.log(`Total number of lines: ${lineCount}`);
fs.writeFile(jsonFilePath, JSON.stringify(results, null, 4), (err) => {
if (err) {
reject(`Error writing to JSON file: ${err}`);
} else {
console.log(`Successfully converted '${csvFilePath}' to '${jsonFilePath}'`);
resolve();
}
});
})
.on('error', (err) => {
reject(`Error reading or parsing CSV file: ${err}`);
});
});
}

// Example Usage:
const csvFile = 'EQUITY_L.csv';
const jsonFile = 'db.json';

csvToJson(csvFile, jsonFile)
.then(() => {
console.log("Conversion Complete");
})
.catch((error) => {
console.error("Error during conversion:", error);
});
Loading

0 comments on commit 684148c

Please sign in to comment.