-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from mintlayer/dev
Dev-26-03-2024-v-1-2-1
- Loading branch information
Showing
18 changed files
with
181 additions
and
47 deletions.
There are no files selected for viewing
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* eslint-disable no-undef */ | ||
let popupWindowId = null | ||
let connectWindowId = null | ||
let isPopupOpening = false | ||
|
||
browser.runtime.onConnect.addListener((port) => { | ||
port.onMessage.addListener((msg) => { | ||
if (msg && msg.myProperty && msg.myProperty.message) { | ||
switch (msg.myProperty.message.message) { | ||
case 'version': | ||
port.postMessage({ version: browser.runtime.getManifest().version }) | ||
break | ||
case 'connect': | ||
handleConnect(msg, port) | ||
break | ||
case 'delegate': | ||
handleDelegate(msg) | ||
break | ||
case 'stake': | ||
handleStake(msg) | ||
break | ||
default: | ||
console.log('Unknown message') | ||
} | ||
} | ||
}) | ||
|
||
async function handleConnect(request, port) { | ||
if (connectWindowId === null) { | ||
await createPopup('index.html', async (win) => { | ||
connectWindowId = win.id | ||
setTimeout(async () => { | ||
const response = await browser.runtime.sendMessage({ | ||
action: 'connect', | ||
}) | ||
port.postMessage(response) | ||
}, 1000) | ||
}) | ||
} else { | ||
await browser.windows.update(connectWindowId, { focused: true }) | ||
} | ||
} | ||
|
||
async function handleDelegate(request) { | ||
if (popupWindowId === null && !isPopupOpening) { | ||
isPopupOpening = true | ||
await createPopup('index.html', async (win) => { | ||
popupWindowId = win.id | ||
isPopupOpening = false | ||
setTimeout(async () => { | ||
await browser.runtime.sendMessage({ | ||
action: 'createDelegate', | ||
data: { pool_id: request.myProperty.message.pool_id }, | ||
}) | ||
}, 1000) | ||
}) | ||
} else if (popupWindowId !== null) { | ||
await browser.windows.update(popupWindowId, { focused: true }) | ||
} | ||
} | ||
|
||
async function handleStake(request) { | ||
if (popupWindowId === null) { | ||
await createPopup('index.html', async (win) => { | ||
popupWindowId = win.id | ||
setTimeout(async () => { | ||
await browser.runtime.sendMessage({ | ||
action: 'addStake', | ||
data: { | ||
delegation_id: request.delegation_id, | ||
amount: request.amount, | ||
}, | ||
}) | ||
}, 1000) | ||
}) | ||
} else { | ||
await browser.windows.update(popupWindowId, { focused: true }) | ||
} | ||
} | ||
|
||
function createPopup(url, callback) { | ||
return new Promise((resolve, reject) => { | ||
browser.windows | ||
.create({ | ||
url: browser.runtime.getURL(url), | ||
type: 'popup', | ||
width: 800, | ||
height: 630, | ||
focused: true, | ||
}) | ||
.then((win) => { | ||
resolve(callback(win)) | ||
}) | ||
.catch((error) => { | ||
reject(error) | ||
}) | ||
}) | ||
} | ||
browser.windows.onRemoved.addListener((winId) => { | ||
if (popupWindowId === winId) { | ||
popupWindowId = null | ||
} | ||
if (connectWindowId === winId) { | ||
connectWindowId = null | ||
} | ||
}) | ||
}) |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.