-
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.
Merge pull request #1384 from Conflux-Chain/v3
update manifest v3
- Loading branch information
Showing
35 changed files
with
3,907 additions
and
109 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,3 @@ | ||
# shared basic environment variable | ||
# the build tool will load this file with any NODE_ENV | ||
SNOWPACK_PUBLIC_FLUENT_VERSION=2.6.3 | ||
|
||
SNOWPACK_PUBLIC_FLUENT_VERSION=2.6.3 |
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,27 @@ | ||
releases: | ||
"@fluent-wallet/cfx_gas-price": patch | ||
"@fluent-wallet/content-script": patch | ||
"@fluent-wallet/eth_estimate-1559-fee": patch | ||
"@fluent-wallet/extension-runtime": patch | ||
"@fluent-wallet/inner-utils": patch | ||
"@fluent-wallet/sentry": patch | ||
"@fluent-wallet/use-rpc": patch | ||
"@fluent-wallet/wallet_add-pending-user-auth-request": patch | ||
"@fluent-wallet/wallet_add-vault": patch | ||
"@fluent-wallet/wallet_get-current-viewing-app": patch | ||
"@fluent-wallet/wallet_get-fluent-metadata": patch | ||
"@fluent-wallet/wallet_handle-unfinished-cfx-tx": patch | ||
"@fluent-wallet/wallet_handle-unfinished-eth-tx": patch | ||
"@fluent-wallet/wallet_import-all": patch | ||
"@fluent-wallet/wallet_refetch-balance": patch | ||
"@fluent-wallet/wallet_request-unlock-ui": patch | ||
"@fluent-wallet/wallet_set-current-network": patch | ||
"@fluent-wallet/webextension": patch | ||
browser-extension: patch | ||
helios: minor | ||
helios-background: patch | ||
helios-inpage: patch | ||
helios-popup: patch | ||
|
||
declined: | ||
- "@fluent-wallet/db" |
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
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
export const MODE = import.meta.env.NODE_ENV | ||
import browser from 'webextension-polyfill' | ||
import packageJson from '../../package.json' | ||
|
||
export const MODE = import.meta.env | ||
? import.meta.env.NODE_ENV | ||
: process.env.NODE_ENV | ||
export const IS_TEST_MODE = MODE === 'test' | ||
export const IS_DEV_MODE = MODE === 'development' | ||
export const IS_PROD_MODE = MODE === 'production' | ||
export const IS_CI = Boolean(import.meta.env.CI) | ||
export const IS_CI = process.env.CI === 'true' | ||
|
||
export const PACKAGE_VERSION = packageJson.version | ||
|
||
export const isManifestV3 = browser.runtime.getManifest().manifest_version === 3 |
Oops, something went wrong.