-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * ui changes * injection * upd * adding connections page * upd extension * merge * prettier * fix * fix * fix
- Loading branch information
Showing
26 changed files
with
944 additions
and
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,6 @@ yarn-error.log* | |
|
||
.idea | ||
.eslintcache | ||
|
||
# generate with `build:extension` script | ||
extension/build/* |
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,70 @@ | ||
const responseHandlers = new Map(); | ||
|
||
function launchPopup(message, sender, sendResponse) { | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set('origin', sender.origin); | ||
searchParams.set('network', message.data.params.network); | ||
searchParams.set('request', JSON.stringify(message.data)); | ||
|
||
// TODO consolidate popup dimensions | ||
chrome.windows.getLastFocused((focusedWindow) => { | ||
chrome.windows.create({ | ||
url: 'index.html/#' + searchParams.toString(), | ||
type: 'popup', | ||
width: 375, | ||
height: 600, | ||
top: focusedWindow.top, | ||
left: focusedWindow.left + (focusedWindow.width - 375), | ||
setSelfAsOpener: true, | ||
focused: true, | ||
}); | ||
}); | ||
|
||
responseHandlers.set(message.data.id, sendResponse); | ||
} | ||
|
||
function handleConnect(message, sender, sendResponse) { | ||
chrome.storage.local.get('connectedWallets', (result) => { | ||
const connectedWallet = (result.connectedWallets || {})[sender.origin]; | ||
if (!connectedWallet) { | ||
launchPopup(message, sender, sendResponse); | ||
} else { | ||
sendResponse({ | ||
method: 'connected', | ||
params: { | ||
publicKey: connectedWallet.publicKey, | ||
autoApprove: connectedWallet.autoApprove, | ||
}, | ||
id: message.data.id, | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function handleDisconnect(message, sender, sendResponse) { | ||
chrome.storage.local.get('connectedWallets', (result) => { | ||
delete result.connectedWallets[sender.origin]; | ||
chrome.storage.local.set( | ||
{ connectedWallets: result.connectedWallets }, | ||
() => sendResponse({ method: 'disconnected', id: message.data.id }), | ||
); | ||
}); | ||
} | ||
|
||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||
if (message.channel === 'sollet_contentscript_background_channel') { | ||
if (message.data.method === 'connect') { | ||
handleConnect(message, sender, sendResponse); | ||
} else if (message.data.method === 'disconnect') { | ||
handleDisconnect(message, sender, sendResponse); | ||
} else { | ||
launchPopup(message, sender, sendResponse); | ||
} | ||
// keeps response channel open | ||
return true; | ||
} else if (message.channel === 'sollet_extension_background_channel') { | ||
const responseHandler = responseHandlers.get(message.data.id); | ||
responseHandlers.delete(message.data.id); | ||
responseHandler(message.data); | ||
} | ||
}); |
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,24 @@ | ||
const container = document.head || document.documentElement; | ||
const scriptTag = document.createElement('script'); | ||
scriptTag.setAttribute('async', 'false'); | ||
scriptTag.src = chrome.runtime.getURL('script.js'); | ||
container.insertBefore(scriptTag, container.children[0]); | ||
container.removeChild(scriptTag); | ||
|
||
window.addEventListener('sollet_injected_script_message', (event) => { | ||
chrome.runtime.sendMessage( | ||
{ | ||
channel: 'sollet_contentscript_background_channel', | ||
data: event.detail, | ||
}, | ||
(response) => { | ||
// Can return null response if window is killed | ||
if (!response) { | ||
return; | ||
} | ||
window.dispatchEvent( | ||
new CustomEvent('sollet_contentscript_message', { detail: response }), | ||
); | ||
}, | ||
); | ||
}); |
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,35 @@ | ||
{ | ||
"name": "Sollet", | ||
"description": "Solana SPL Token Wallet", | ||
"version": "0.1", | ||
"browser_action": { | ||
"default_popup": "index.html", | ||
"default_title": "Open the popup" | ||
}, | ||
"manifest_version": 2, | ||
"icons": { | ||
"16": "favicon.ico", | ||
"192": "logo192.png", | ||
"512": "logo512.png" | ||
}, | ||
"background": { | ||
"persistent": false, | ||
"scripts": ["background.js"] | ||
}, | ||
"permissions": [ | ||
"storage" | ||
], | ||
"content_scripts": [ | ||
{ | ||
"matches": ["file://*/*", "http://*/*", "https://*/*"], | ||
"js": [ | ||
"contentscript.js" | ||
], | ||
"run_at": "document_start", | ||
"all_frames": true | ||
} | ||
], | ||
"web_accessible_resources": ["script.js"], | ||
"content_security_policy": "script-src 'self' 'sha256-ek+jXksbUr00x+EdLLqiv69t8hATh5rPjHVvVVGA9ms='; object-src 'self'" | ||
} | ||
|
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,15 @@ | ||
window.sollet = { | ||
postMessage: (message) => { | ||
const listener = (event) => { | ||
if (event.detail.id === message.id) { | ||
window.removeEventListener('sollet_contentscript_message', listener); | ||
window.postMessage(event.detail); | ||
} | ||
}; | ||
window.addEventListener('sollet_contentscript_message', listener); | ||
|
||
window.dispatchEvent( | ||
new CustomEvent('sollet_injected_script_message', { detail: message }), | ||
); | ||
}, | ||
}; |
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.