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 Sep 20, 2024
1 parent 9fda79c commit 01913b0
Show file tree
Hide file tree
Showing 9 changed files with 1,023 additions and 102 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
11 changes: 11 additions & 0 deletions src/components/composed/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const Navigation = ({ customNavigation }) => {
toggleSliderMenu()
}

const goCustomOutput = () => {
navigate('/wallet/Mintlayer/custom-output')
toggleSliderMenu()
}

const goDashboard = () => {
navigate('/dashboard')
toggleSliderMenu()
Expand Down Expand Up @@ -84,6 +89,12 @@ const Navigation = ({ customNavigation }) => {
icon: <SettingsImg />,
onClick: goSettings,
},
{
id: 2,
label: 'Custom Output',
icon: <SettingsImg />,
onClick: goCustomOutput,
},
]

const navigationList = [
Expand Down
26 changes: 26 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
DelegationStakePage,
DelegationWithdrawPage,
LockedBalancePage,
SendCustomOutput,
} from '@Pages'

import {
Expand Down Expand Up @@ -129,6 +130,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 @@ -219,6 +241,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 01913b0

Please sign in to comment.