-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
3,492 additions
and
29 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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
# shared basic environment variable | ||
# the build tool will load this file with any NODE_ENV | ||
SNOWPACK_PUBLIC_FLUENT_VERSION=2.6.3 | ||
|
||
NODE_ENV=production | ||
CI= | ||
SNOWPACK_PUBLIC_SENTRY_DSN= | ||
SNOWPACK_PUBLIC_FLUENT_ENV="production" | ||
SNOWPACK_PUBLIC_FLUENT_VERSION= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import browser from 'webextension-polyfill' | ||
import {stream} from '@thi.ng/rstream' | ||
import {getSiteMetadata} from '@fluent-wallet/site-metadata' | ||
|
||
let INPAGE_INJECTED = false | ||
|
||
function _retry() { | ||
let retryTimeout = 100 | ||
if (CONNECT_RETRY_COUNT >= 10) { | ||
retryTimeout = 1000 | ||
} else if (CONNECT_RETRY_COUNT >= 60) { | ||
retryTimeout = 30000 | ||
} else if (CONNECT_RETRY_COUNT >= 120) { | ||
console.error( | ||
`[Fluent] Failed to connect background with 120 retry. Give up`, | ||
) | ||
return | ||
} | ||
|
||
console.warn( | ||
`[Fluent] Failed to connect background, retry: ${++CONNECT_RETRY_COUNT}`, | ||
) | ||
setTimeout(setup, retryTimeout) | ||
} | ||
|
||
function injectInpage(content) { | ||
try { | ||
const container = document.head || document.documentElement | ||
const scriptTag = document.createElement('script') | ||
scriptTag.setAttribute('async', 'false') | ||
if (content) scriptTag.textContent = content | ||
else scriptTag.src = browser.runtime.getURL('inpage.js') | ||
container.insertBefore(scriptTag, container.children[0]) | ||
container.removeChild(scriptTag) | ||
INPAGE_INJECTED = true | ||
registerSite() | ||
} catch (error) { | ||
console.error('Fluent Wallet: Provider injection failed.', error) | ||
} | ||
} | ||
|
||
let CONNECT_RETRY_COUNT = 0 | ||
let s | ||
|
||
// need to call this after inpage.js is injected | ||
// so that the dapp page can get the connected event | ||
function registerSite() { | ||
if (!s) return | ||
getSiteMetadata() | ||
.then(metadata => { | ||
if (!metadata.icon) delete metadata.icon | ||
s.next.call(s, { | ||
method: 'wallet_registerSiteMetadata', | ||
params: metadata, | ||
_origin: location.host, | ||
}) | ||
}) | ||
.catch(() => null) | ||
} | ||
|
||
function setup() { | ||
s = stream({ | ||
id: 'content-script', | ||
closeIn: false, | ||
closeOut: false, | ||
cache: false, | ||
}) | ||
|
||
let port | ||
try { | ||
port = browser.runtime.connect({name: 'content-script'}) | ||
} catch (err) { | ||
// reload dapp page when ext bg is reloaded | ||
// this only happends in development env | ||
if (err.message.match(/extension.*context.*invalid/i)) | ||
setTimeout(() => window.location.reload(), 500) | ||
else _retry() | ||
} | ||
if (!port) return | ||
const sub = {next: port.postMessage.bind(port)} | ||
|
||
s.subscribe(sub) | ||
|
||
const listenToInpageMessage = e => { | ||
if (e.origin !== location.origin) return | ||
if (e.source !== window) return | ||
if ( | ||
!e.data || | ||
!e.data.__fromFluentInpage || | ||
!e.data.msg || | ||
typeof e.data.msg !== 'object' | ||
) | ||
return | ||
if (!e.data.msg.method) return | ||
if (e.data.msg.jsonrpc !== '2.0') return | ||
if (!Number.isInteger(e.data.msg.id)) return | ||
if (e.data.msg.method === 'wallet_registerSiteMetadata') return | ||
CONNECT_RETRY_COUNT = 0 | ||
s.next.call(s, {...e.data.msg, _origin: location.host}) | ||
} | ||
|
||
window.addEventListener('message', listenToInpageMessage, false) | ||
|
||
port.onDisconnect.addListener(() => { | ||
window.postMessage({ | ||
msg: { | ||
event: 'disconnect', | ||
params: { | ||
code: 4900, | ||
message: | ||
"Can't connect to extension runtime, disconnected from all chain. Please refresh the page or tell user to refresh the page.", | ||
}, | ||
}, | ||
}) | ||
window.removeEventListener('message', listenToInpageMessage) | ||
s.unsubscribe(sub) | ||
s = null | ||
_retry() | ||
}) | ||
|
||
port.onMessage.addListener(e => { | ||
window.postMessage( | ||
{msg: e, __fromFluentContentScript: true}, | ||
location.origin, | ||
) | ||
}) | ||
|
||
if (INPAGE_INJECTED) registerSite() | ||
} | ||
injectInpage() | ||
setup() |
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,94 @@ | ||
{ | ||
"name": "__MSG_extensionNAME__", | ||
"short_name": "__MSG_extensionNAME__", | ||
"version": "", | ||
"version_name": "", | ||
"manifest_version": 2, | ||
"author": "Conflux Network", | ||
"homepage_url": "https://github.com/Conflux-Chain/helios#readme", | ||
"description": "__MSG_extensionDescription__", | ||
"commands": { | ||
"_execute_browser_action": { | ||
"suggested_key": { | ||
"windows": "Alt+Shift+F", | ||
"mac": "Alt+Shift+F", | ||
"chromeos": "Alt+Shift+F", | ||
"linux": "Alt+Shift+F" | ||
}, | ||
"description": "Open the extension popup" | ||
}, | ||
"inner_debug_only": { | ||
"suggested_key": { | ||
"default": "Alt+Shift+3", | ||
"mac": "Ctrl+MacCtrl+3" | ||
}, | ||
"description": "Can only debug internally" | ||
} | ||
}, | ||
"icons": { | ||
"16": "images/icon-16.png", | ||
"19": "images/icon-19.png", | ||
"32": "images/icon-32.png", | ||
"38": "images/icon-38.png", | ||
"64": "images/icon-64.png", | ||
"128": "images/icon-128.png", | ||
"512": "images/icon-512.png" | ||
}, | ||
"browser_specific_settings": { | ||
"gecko": { | ||
"id": "fluent-wallet@confluxnetwork.org", | ||
"strict_min_version": "69.0" | ||
}, | ||
"safari": { | ||
"strict_min_version": "14" | ||
} | ||
}, | ||
"default_locale": "en", | ||
"background": { | ||
"scripts": ["background.js"], | ||
"persistent": true | ||
}, | ||
"browser_action": { | ||
"default_icon": { | ||
"16": "images/icon-16.png", | ||
"19": "images/icon-19.png", | ||
"32": "images/icon-32.png", | ||
"38": "images/icon-38.png", | ||
"64": "images/icon-64.png", | ||
"128": "images/icon-128.png", | ||
"512": "images/icon-512.png" | ||
}, | ||
"default_title": "Fluent", | ||
"default_popup": "popup.html" | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["file://*/*", "http://*/*", "https://*/*"], | ||
"js": ["content-script.js"], | ||
"run_at": "document_start", | ||
"all_frames": true | ||
} | ||
], | ||
"content_security_policy": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'", | ||
"permissions": [ | ||
"storage", | ||
"unlimitedStorage", | ||
"clipboardWrite", | ||
"http://localhost:12537/", | ||
"tabs", | ||
"https://confluxscan.net/*", | ||
"https://*.confluxscan.net/*", | ||
"activeTab", | ||
"notifications" | ||
], | ||
"web_accessible_resources": ["content-script.js", "inpage.js"], | ||
"externally_connectable": { | ||
"matches": [ | ||
"https://confluxscan.net/*", | ||
"https://*.confluxscan.net/*", | ||
"https://confluxnetwork.org/*", | ||
"https://wallet-main.confluxrpc.org/*", | ||
"https://wallet-test.confluxrpc.org/*" | ||
] | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"name": "manifest", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"description": "" | ||
} |
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" class="notranslate" translate="no"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Fluent</title> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="robots" content="Index, Follow" /> | ||
<meta name="description" content="" /> | ||
<meta name="keywords" content="" /> | ||
<meta name="popup-type" content="popup" /> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.