Skip to content

Commit

Permalink
feat: add page for adding custom outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
anyxem committed Nov 4, 2024
1 parent a7310d5 commit 76b1402
Show file tree
Hide file tree
Showing 13 changed files with 1,281 additions and 175 deletions.
228 changes: 128 additions & 100 deletions public/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,114 +4,142 @@
var popupWindowId = false
var connectWindowId = false

chrome.runtime.onMessageExternal.addListener(function (
request,
sender,
sendResponse,
) {
if (request) {
if (request.message) {
if (request.message === 'version') {
sendResponse({ version: chrome.runtime.getManifest().version })
}
chrome.runtime.onMessageExternal.addListener(
function (request, sender, sendResponse) {
if (request) {
if (request.message) {
if (request.message === 'version') {
sendResponse({ version: chrome.runtime.getManifest().version })
}

if (request.message === 'connect') {
if (connectWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('popup.html'),
type: 'popup',
width: 800,
height: 600,
focused: true,
},
function (win) {
connectWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage(
{
action: 'connect',
},
function (response) {
sendResponse(response)
},
)
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
if (request.message === 'connect') {
if (connectWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('popup.html'),
type: 'popup',
width: 800,
height: 600,
focused: true,
},
function (win) {
connectWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage(
{
action: 'connect',
},
function (response) {
sendResponse(response)
},
)
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
}
}
}

if (request.message === 'delegate') {
if (popupWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('popup.html'),
type: 'popup',
width: 800,
height: 600,
focused: true,
},
function (win) {
popupWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage({
action: 'createDelegate',
data: {
pool_id: request.pool_id,
referral_code: request.referral_code || '',
},
})
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
if (request.message === 'delegate') {
if (popupWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('popup.html'),
type: 'popup',
width: 800,
height: 600,
focused: true,
},
function (win) {
popupWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage({
action: 'createDelegate',
data: {
pool_id: request.pool_id,
referral_code: request.referral_code || '',
},
})
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
}
}
}

if (request.message === 'stake') {
if (popupWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('popup.html'),
type: 'popup',
width: 800,
height: 630,
focused: true,
},
function (win) {
popupWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage({
action: 'addStake',
data: {
delegation_id: request.delegation_id,
amount: request.amount,
},
})
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
if (request.message === 'output') {
if (popupWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('popup.html'),
type: 'popup',
width: 800,
height: 600,
focused: true,
},
function (win) {
popupWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage({
action: 'customOutput',
data: {
output: request.output,
},
})
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
}
}

if (request.message === 'stake') {
if (popupWindowId === false) {
popupWindowId = true
chrome.windows.create(
{
url: chrome.runtime.getURL('popup.html'),
type: 'popup',
width: 800,
height: 630,
focused: true,
},
function (win) {
popupWindowId = win.id
setTimeout(function () {
chrome.runtime.sendMessage({
action: 'addStake',
data: {
delegation_id: request.delegation_id,
amount: request.amount,
},
})
}, 1000)
},
)
} else if (typeof popupWindowId === 'number') {
//The window is open, and the user clicked the button.
// Focus the window.
chrome.windows.update(popupWindowId, { focused: true })
}
}
}
}
}
return true
})
return true
},
)

chrome.windows.onRemoved.addListener(function (winId) {
if (popupWindowId === winId) {
Expand Down
26 changes: 26 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
DelegationWithdrawPage,
LockedBalancePage,
MessagePage,
SendCustomOutput,
} from '@Pages'

import {
Expand Down Expand Up @@ -130,6 +131,27 @@ const App = () => {
})
}

if (request.action === 'customOutput') {
if (!unlocked) {
setNextAfterUnlock({
route: '/wallet/Mintlayer/custom-output',
state: {
action: 'customOutput',
output: request.data.output,
},
})
return
}
// change route to staking page
navigate('/wallet/Mintlayer/staking/create-delegation', {
state: {
action: 'createDelegate',
pool_id: request.data.pool_id,
referral_code: request.data.referral_code || '',
},
})
}

if (request.action === 'getAddresses') {
// respond with addresses
sendResponse({
Expand Down Expand Up @@ -220,6 +242,10 @@ const App = () => {
path="/wallet/:coinType/send-transaction"
element={<SendTransactionPage />}
/>
<Route
path="/wallet/:coinType/custom-output"
element={<SendCustomOutput />}
/>
<Route
path="/wallet/:coinType/staking"
element={<StakingPage />}
Expand Down
Loading

0 comments on commit 76b1402

Please sign in to comment.