This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Background service worker | |
function backgroundServiceHandshake() { | |
chrome.runtime.onMessage.addListener((message: any, _: any, sendResponse: (response: 'ack') => void) => { | |
if (message === 'syn') { | |
if (!isInitialized) { | |
initializeService(); | |
isInitialized = true; | |
} | |
sendResponse('ack'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const globalKey = 'FORDEFI_data'; | |
const divider = '--'; | |
async function storeComplexData (complexData: Record<string, string[]>) { | |
// Flatten the complex object to avoid it being overwritten | |
for (const [itemKey, itemValue] of Object.entries(complexData)) { | |
const newKey = `${globalKey}${divider}${itemKey}`; | |
await chrome.storage.local.set({[newKey]: itemValue}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* data = { | |
* balance: 100, | |
*. addresses: ['0x1', '0x2'] | |
* } | |
*/ | |
// Alice (1) | |
const aliceData = await getComplexData(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const key = 'FORDEFI_data'; | |
async function storeComplexData (complexData: Record<string, string[]>) { | |
await chrome.storage.local.set({[key]: complexData}); | |
} | |
async function getComplexData () { | |
return (await chrome.storage.local.get([key]))?.[key]; | |
} |