Skip to content

Commit

Permalink
Merge pull request #1384 from Conflux-Chain/v3
Browse files Browse the repository at this point in the history
update manifest v3
  • Loading branch information
iosh authored Aug 13, 2024
2 parents d485772 + b95a35d commit df1f65b
Show file tree
Hide file tree
Showing 35 changed files with 3,907 additions and 109 deletions.
3 changes: 1 addition & 2 deletions .env
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
1 change: 0 additions & 1 deletion .env.development.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
# the build tool will load this file when NODE_ENV is development
# NOTE: don't commit .env.development.local into git
# NOTE: this file will override .env.development
SNOWPACK_PUBLIC_IS_LOCAL_ENV=true
18 changes: 12 additions & 6 deletions .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: "yarn"
cache: 'yarn'
node-version: ${{ matrix.node-version }}
- uses: actions/setup-java@v3
with:
distribution: "adopt"
java-version: "11"
distribution: 'adopt'
java-version: '11'
- name: Install clojure tools
uses: DeLaGuardo/setup-clojure@7.0
with:
Expand Down Expand Up @@ -104,11 +104,17 @@ jobs:
- name: build and release
env:
SNOWPACK_PUBLIC_SENTRY_DSN: ${{ secrets.SNOWPACK_PUBLIC_SENTRY_DSN }}
SNOWPACK_PUBLIC_FLUENT_ENV: "debug-release"
SNOWPACK_PUBLIC_FLUENT_ENV: 'debug-release'
SNOWPACK_PUBLIC_FLUENT_VERSION: ${{ fromJSON(steps.get-release-version-and-tag.outputs.result).version }}
run: yarn prod:release
run: yarn build

- name: zip files
run: |
zip -r ./dist/chrome.zip ./dist/chrome
zip -r ./dist/firefox.zip ./dist/firefox
zip -r ./dist/edge.zip ./dist/edge
- uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: releases/*
asset_path: dist/*.zip
10 changes: 8 additions & 2 deletions .github/workflows/prod-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ jobs:
SNOWPACK_PUBLIC_SENTRY_DSN: ${{ secrets.SNOWPACK_PUBLIC_SENTRY_DSN }}
SNOWPACK_PUBLIC_FLUENT_ENV: "production"
SNOWPACK_PUBLIC_FLUENT_VERSION: ${{ steps.dotenv.outputs.SNOWPACK_PUBLIC_FLUENT_VERSION }}
run: yarn prod:release
run: yarn build

- name: zip files
run: |
zip -r ./dist/chrome.zip ./dist/chrome
zip -r ./dist/firefox.zip ./dist/firefox
zip -r ./dist/edge.zip ./dist/edge
- uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: releases/*
asset_path: dist/*.zip

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4.0.4
Expand Down
27 changes: 27 additions & 0 deletions .yarn/versions/ed98fc34.yml
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"
4 changes: 3 additions & 1 deletion examples/basic-dapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// more info about js-conflux-sdk
// https://github.com/Conflux-Chain/js-conflux-sdk#readme
// eslint-disable-next-line import/no-unresolved
import {Conflux, format} from 'https://cdn.skypack.dev/js-conflux-sdk'
import * as SDK from 'https://cdn.skypack.dev/js-conflux-sdk'

const {Conflux, format} = SDK.default

const exampleContract = new Conflux().Contract({
abi: [
Expand Down
34 changes: 31 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "helios",
"private": true,
"version": "2.6.3",
"workspaces": [
"websites/*",
"packages/doc-ui/*",
Expand Down Expand Up @@ -56,7 +57,14 @@
"test:unit": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest --no-cache --testPathIgnorePatterns '.*\\.integration\\.test\\.jsx?'",
"test:integration": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test node ./scripts/integration-test.js --no-cache --config='./integration.jest.config.js'",
"contract:compile": "bash ./scripts/solc.sh",
"contract:watch": "watchexec --restart --on-busy-update queue -w ./contracts/ --debounce 500 yarn run contract:compile"
"contract:watch": "watchexec --restart --on-busy-update queue -w ./contracts/ --debounce 500 yarn run contract:compile",
"dev:chrome": "cross-env NODE_ENV=development cross-env TARGET_BROWSER=chrome webpack --config ./scripts/webpack.config.dev.mjs",
"dev:firefox": "cross-env NODE_ENV=development cross-env TARGET_BROWSER=firefox webpack --config ./scripts/webpack.config.dev.mjs",
"dev:edge": "cross-env NODE_ENV=development cross-env TARGET_BROWSER=edge webpack --config ./scripts/webpack.config.dev.mjs",
"build:chrome": "cross-env NODE_ENV=production cross-env TARGET_BROWSER=chrome webpack --config ./scripts/webpack.config.prod.mjs",
"build:firefox": "cross-env NODE_ENV=production cross-env TARGET_BROWSER=firefox webpack --config ./scripts/webpack.config.prod.mjs",
"build:edge": "cross-env NODE_ENV=production cross-env TARGET_BROWSER=edge webpack --config ./scripts/webpack.config.prod.mjs",
"build": "yarn build:chrome && yarn build:firefox && yarn build:edge"
},
"devDependencies": {
"@babel/core": "7.17.9",
Expand All @@ -81,17 +89,23 @@
"@types/finalhandler": "^1",
"@types/js-string-escape": "^1",
"@types/serve-static": "^1",
"@types/webpack-bundle-analyzer": "^4",
"@yarnpkg/esbuild-plugin-pnp": "3.0.0-rc.2",
"@yqrashawn/snowpack": "3.8.6-fix-6",
"autoprefixer": "^10.4.7",
"autoprefixer": "10.4.20",
"babel-loader": "8.2.4",
"browserslist": "^4.20.4",
"buffer": "6.0.3",
"concurrently": "^7.2.1",
"copy-webpack-plugin": "12.0.2",
"cross-env": "^7.0.3",
"css-loader": "7.1.2",
"cssnano": "5.1.11",
"dot-env": "^0.0.1",
"dotenv-expand": "^8.0.3",
"dotenv-webpack": "8.1.0",
"esbuild": "0.14.43",
"esbuild-loader": "4.2.2",
"esbuild-plugin-alias": "0.2.1",
"esbuild-plugin-browserslist": "0.4.10",
"esbuild-style-plugin": "1.6.0",
Expand All @@ -107,16 +121,19 @@
"finalhandler": "1.2.0",
"fs-extra": "^10.1.0",
"highlight.js": "9.18.5",
"html-webpack-plugin": "5.6.0",
"husky": "^8.0.1",
"identity-obj-proxy": "3.0.0",
"jest": "^27.5.1",
"jest-webextension-mock": "^3.7.22",
"js-string-escape": "1.0.1",
"lint-staged": "^13.0.1",
"mini-css-extract-plugin": "2.9.0",
"mustache": "^4.2.0",
"nock": "13.2.6",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.14",
"postcss-loader": "8.1.1",
"prettier": "^2.6.2",
"prettier-plugin-solidity": "1.0.0-beta.18",
"ramda": "^0.28.0",
Expand All @@ -127,12 +144,20 @@
"rimraf": "^3.0.2",
"serve-static": "1.15.0",
"shadow-cljs": "^2.19.4",
"stream-browserify": "3.0.0",
"style-loader": "4.0.0",
"stylelint": "^14.9.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-standard": "^26.0.0",
"tailwindcss": "^3.1.1",
"wait-for-expect": "3.0.2",
"web-ext": "7.0.0",
"webpack": "5.93.0",
"webpack-bundle-analyzer": "4.10.2",
"webpack-cli": "5.1.4",
"webpack-merge": "6.0.1",
"wext-manifest-loader": "2.4.2",
"wext-manifest-webpack-plugin": "1.4.1",
"zip-a-folder": "1.1.3"
},
"nohoist": [
Expand Down Expand Up @@ -203,5 +228,8 @@
"no-descending-specificity": null
}
},
"packageManager": "yarn@3.2.0"
"packageManager": "yarn@3.2.0",
"dependencies": {
"@svgr/webpack": "8.1.0"
}
}
2 changes: 0 additions & 2 deletions packages/background/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// # imports
import 'regenerator-runtime/runtime'

import {IS_PROD_MODE, IS_TEST_MODE} from '@fluent-wallet/inner-utils'
import {EXT_STORAGE} from '@fluent-wallet/consts'

Expand Down
131 changes: 131 additions & 0 deletions packages/content-script/indexTemplate.js
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()
4 changes: 2 additions & 2 deletions packages/db/src/main/cfxjs/db/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
(cfxjs.spec.cljs/js->clj v :keywordize-keys true))

;; debug
(set! (.-jtc js/window) j->c)
(set! (.-jtc js/globalThis) j->c)

(declare conn t q p e fdb)

Expand Down Expand Up @@ -353,7 +353,7 @@
[(?gid ?g)]
[?g :accountGroup/account ?e]]
#(= % 24))
(create-db (.-schema js/window))
(create-db (.-schema js/globalThis))
(:schema @conn)
(js/console.log (clj->js (t [{:db/id "a" :hdPath/name "a"}
{:db/id "a" :hdPath/value "b"}])))
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/main/cfxjs/db/datascript/impl/entity.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,4 @@
:vault/data "b"
:vault/type "a"
:db/id 1}
(.get (goog.object.get js/window.a "vault") "data"))
(.get (goog.object.get js/globalThis.a "vault") "data"))
2 changes: 1 addition & 1 deletion packages/db/src/main/cfxjs/db/queries.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@

(def queries {:batchTx
(fn [txs]
(let [txs (-> txs js/window.JSON.parse j->c)
(let [txs (-> txs js/globalThis.JSON.parse j->c)
txs (map (fn [[e a v]] [:db/add e (keyword a) v]) txs)
rst (t txs)]
(clj->js rst)))
Expand Down
13 changes: 11 additions & 2 deletions packages/inner-utils/env.js
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
Loading

0 comments on commit df1f65b

Please sign in to comment.