Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: v1.27.0 #347

Merged
merged 13 commits into from
Sep 15, 2023
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
"devDependencies": {
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@swc/core": "^1.3.80",
"concurrently": "^7.6.0",
"@swc/core": "^1.3.84",
"concurrently": "^8.2.1",
"devmoji": "^2.3.0",
"husky": "^8.0.3",
"node-notifier": "^10.0.1",
"nodemon": "^2.0.22",
"nodemon": "^3.0.1",
"ultra-runner": "^3.10.5"
},
"resolutions": {
"@ledgerhq/compressjs": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.2.1.tgz"
}
}
7 changes: 3 additions & 4 deletions packages/extension-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@
"webextension-polyfill": "^0.10.0"
},
"devDependencies": {
"@antfu/eslint-config": "^0.27.0",
"@types/chai": "^4.3.5",
"@types/chai": "^4.3.6",
"@types/mocha": "^10.0.1",
"@types/node": "^20.5.7",
"@types/node": "^20.6.0",
"@types/webextension-polyfill": "^0.10.2",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"bumpp": "^8.2.1",
"eslint": "^8.48.0",
"eslint": "^8.49.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.10.0",
"eslint-import-resolver-alias": "^1.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import { uglify } from "rollup-plugin-uglify";
import inject from "@rollup/plugin-inject";
import json from "@rollup/plugin-json";
import replace from "@rollup/plugin-replace";
import packageJson from "../package.json" assert { type: "json" };

const enableMinification = process.env.minify === "on";
const base = {
Expand All @@ -14,9 +15,12 @@ const base = {
sourcemap: process.env.minify !== "on",
},
plugins: [
replace({
preventAssignment: true,
__VERSION__: JSON.stringify(packageJson.version),
}),
typescript(),
commonjs(),
json(),
inject({
Buffer: ["buffer", "Buffer"],
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Base from "./rollup.config.base";
import Base from "./rollup.config.base.mjs";
Base.input.push("src/scripts/contentscript.ts");
export default Base;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Base from "./rollup.config.base";
import Base from "./rollup.config.base.mjs";
Base.input.push("src/scripts/inject.ts");
export default Base;
2 changes: 1 addition & 1 deletion packages/extension/configs/testNullCompiler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const noop = () => 1;

global.__VERSION__ = "test";
require.extensions[".css"] = noop;
require.extensions[".scss"] = noop;
require.extensions[".png"] = noop;
Expand Down
48 changes: 24 additions & 24 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "@enkryptcom/extension",
"version": "1.26.0",
"version": "1.27.0",
"private": true,
"scripts": {
"zip": "cd dist; zip -r release.zip *;",
"build:chrome": "cross-env BROWSER='chrome' vue-cli-service build && yarn build:rollup",
"build:firefox": "cross-env BROWSER='firefox' vue-cli-service build && yarn build:rollup && node configs/get-system-info.js",
"lint": "vue-cli-service lint --fix",
"build:rollup": "cross-env minify=on rollup --config configs/rollup.config.contentscript.js && cross-env minify=on rollup --config configs/rollup.config.inject.js",
"build:rollup": "cross-env minify=on rollup --config configs/rollup.config.contentscript.mjs && cross-env minify=on rollup --config configs/rollup.config.inject.mjs",
"inspectWebpack": "vue-cli-service inspect > webpack.log",
"test": "ts-mocha --require ./configs/testNullCompiler.js --paths -p configs/tsconfig.test.json ./**/*.mocha.ts",
"watch": "rimraf dist && concurrently 'npm:watch-*(!firefox)'",
"watch:firefox": "concurrently 'npm:watch-*(!chrome)'",
"watch-contentscript": "rollup --watch --config configs/rollup.config.contentscript.js",
"watch-inject": "rollup --watch --config configs/rollup.config.inject.js",
"watch-contentscript": "rollup --watch --config configs/rollup.config.contentscript.mjs",
"watch-inject": "rollup --watch --config configs/rollup.config.inject.mjs",
"watch-vue-chrome": "cross-env BROWSER='chrome' vue-cli-service build --watch --no-clean",
"watch-vue-firefox": "cross-env BROWSER='firefox' vue-cli-service build --watch --no-clean"
},
"dependencies": {
"@babel/runtime": "^7.22.10",
"@babel/runtime": "^7.22.15",
"@enkryptcom/extension-bridge": "workspace:^",
"@enkryptcom/hw-wallets": "workspace:^",
"@enkryptcom/keyring": "workspace:^",
Expand All @@ -30,11 +30,12 @@
"@ethereumjs/common": "^3.2.0",
"@ethereumjs/tx": "^4.2.0",
"@ledgerhq/hw-transport-webusb": "^6.27.19",
"@metamask/eth-sig-util": "^6.0.0",
"@types/chrome": "^0.0.244",
"@metamask/eth-sig-util": "^6.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@types/chrome": "^0.0.245",
"@types/events": "^3.0.0",
"@types/less": "^3.0.3",
"@types/lodash": "^4.14.197",
"@types/less": "^3.0.4",
"@types/lodash": "^4.14.198",
"@types/utf-8-validate": "^5.0.0",
"@vueuse/core": "^9.13.0",
"add": "^2.0.6",
Expand All @@ -43,8 +44,8 @@
"bitcoinjs-lib": "^6.1.3",
"bitcoinjs-message": "^2.2.0",
"chai": "^4.3.8",
"concurrently": "^7.6.0",
"core-js": "^3.32.1",
"concurrently": "^8.2.1",
"core-js": "^3.32.2",
"echarts": "^5.4.3",
"ethereumjs-abi": "^0.6.8",
"ethereumjs-util": "^7.1.5",
Expand Down Expand Up @@ -79,17 +80,16 @@
"@polkadot/ui-shared": "^3.6.2",
"@polkadot/util": "^12.4.2",
"@polkadot/wasm-crypto": "^7.2.2",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-inject": "^4.0.4",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^14.1.0",
"@rollup/plugin-typescript": "^8.5.0",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-inject": "^5.0.3",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.3",
"@types/ethereumjs-abi": "^0.6.3",
"@types/mocha": "^10.0.1",
"@types/url-parse": "^1.4.8",
"@types/uuid": "^9.0.2",
"@types/url-parse": "^1.4.9",
"@types/uuid": "^9.0.3",
"@types/wif": "^2.0.2",
"@types/zxcvbn": "^4.4.1",
"@types/zxcvbn": "^4.4.2",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@vue/cli-plugin-babel": "~5.0.8",
Expand All @@ -100,7 +100,7 @@
"buffer": "^6.0.3",
"cross-env": "^7.0.3",
"crypto-browserify": "^3.12.0",
"eslint": "^8.48.0",
"eslint": "^8.49.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^8.7.1",
Expand All @@ -110,16 +110,16 @@
"mocha": "^10.2.0",
"path-browserify": "^1.0.1",
"prettier": "^2.8.8",
"rimraf": "^4.4.1",
"rollup": "^2.79.1",
"rimraf": "^5.0.1",
"rollup": "^3.29.1",
"rollup-plugin-uglify": "^6.0.4",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"systeminformation": "^5.21.1",
"systeminformation": "^5.21.4",
"ts-mocha": "^10.0.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^4.9.5",
"url": "^0.11.1",
"url": "^0.11.2",
"webextension-polyfill": "^0.10.0"
},
"installConfig": {
Expand Down
2 changes: 0 additions & 2 deletions packages/extension/src/configs/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import packagejson from "@/../package.json";
export const EXTENSION_VERSION = packagejson.version;
export const EXTENSION_NAMESPACE =
"dfc62431af1c3c1258035e5ab4058b6440e507238cf0fe429ea39827a7ee43fc"; //keccak256("enkrypt")
151 changes: 39 additions & 112 deletions packages/extension/src/libs/networks-state/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BrowserStorage from "../common/browser-storage";
import { getAllNetworks, POPULAR_NAMES } from "../utils/networks";
import { POPULAR_NAMES } from "../utils/networks";
import { InternalStorageNamespace } from "@/types/provider";
import { IState, StorageKeys, NetworkStorageElement } from "./types";

Expand All @@ -11,136 +11,63 @@ class NetworksState {
}

private async setInitialActiveNetworks(): Promise<void> {
const networks: NetworkStorageElement[] = (await getAllNetworks()).map(
({ name }) => {
if (POPULAR_NAMES.includes(name)) {
return { name, isActive: true };
} else {
return { name, isActive: false };
}
}
);

networks
.filter((network) => network.isActive)
.forEach((network, index) => (network.order = index));

await this.storage.set(StorageKeys.networkInfo, { networks });
const networks: NetworkStorageElement[] = POPULAR_NAMES.map((name) => ({
name,
}));
await this.setState({ networks });
}

async setNetworkStatus(
targetNetworkName: string,
isActive: boolean
): Promise<void> {
const state: IState = await this.storage.get(StorageKeys.networkInfo);

if (state.networks) {
let targetNetwork: NetworkStorageElement | undefined =
state.networks.find((network) => network.name === targetNetworkName);
if (!targetNetwork) {
targetNetwork = {
name: targetNetworkName,
isActive: true,
};

state.networks.push(targetNetwork as NetworkStorageElement);
}
if (targetNetwork !== undefined) {
targetNetwork.isActive = isActive;

if (isActive) {
const numActive = state.networks.filter(
(network) => network.isActive
).length;

targetNetwork.order = numActive - 1;
} else {
targetNetwork.order = undefined;
const activeNetworks = state.networks.filter(
(network) => network.isActive
);

activeNetworks.sort((a, b) => {
if (a.order! < b.order!) return -1;
return 1;
});

activeNetworks.forEach((network, index) => {
network.order = index;
});
}
}

await this.storage.set(StorageKeys.networkInfo, state);
const state: IState = await this.getState();
const targetNetwork: NetworkStorageElement = {
name: targetNetworkName,
};
if (
isActive &&
state.networks.findIndex((n) => n.name === targetNetworkName) === -1
) {
state.networks.push(targetNetwork as NetworkStorageElement);
} else if (!isActive) {
const idxArr = state.networks.map((_, i) => i);
const filteredIdx = idxArr
.filter((i) => state.networks[i].name !== targetNetwork!.name)
.sort((a, b) => a - b);
const activeNetworks: NetworkStorageElement[] = [];
filteredIdx.forEach((i) => activeNetworks.push(state.networks[i]));
state.networks = activeNetworks;
}
await this.setState(state);
}

async getActiveNetworkNames(): Promise<string[]> {
const state: IState | undefined = await this.storage.get(
StorageKeys.networkInfo
);
const state: IState | undefined = await this.getState();
if (state && state.networks) {
return state.networks
.filter((network) => network.isActive)
.sort((a, b) => {
if (a.order! < b.order!) return -1;
return 1;
})
.map(({ name }) => name);
const validNetworks = state.networks.filter((net) => {
if ((net as any).isActive === undefined || (net as any).isActive) {
return true;
}
});
state.networks = validNetworks;
await this.setState(state);
return validNetworks.map(({ name }) => name);
} else {
await this.setInitialActiveNetworks();
return POPULAR_NAMES;
}
}

async reorderNetwork(
targetNetworkName: string,
beforeNetworkName: string | undefined
): Promise<void> {
const state: IState | undefined = await this.storage.get(
StorageKeys.networkInfo
async reorderNetwork(networkNames: string[]): Promise<void> {
const activeNetworks: NetworkStorageElement[] = networkNames.map(
(name) => ({ name })
);
await this.setState({ networks: activeNetworks });
}

if (state && state.networks) {
const activeNetworks = state.networks
.filter((network) => network.isActive)
.sort((a, b) => {
if (a.order! < b.order!) return -1;
return 1;
});

const targetNetwork = activeNetworks.find(
(network) => network.name === targetNetworkName
);

const beforeNetwork = activeNetworks.find(
(network) => network.name === beforeNetworkName
);

if (targetNetwork !== undefined) {
if (beforeNetwork === undefined) {
targetNetwork.order = 0;
} else {
targetNetwork.order = beforeNetwork.order! + 1;
}
}

activeNetworks.sort((a, b) => {
if (a.order! < b.order!) {
return -1;
} else if (a.order === b.order && a.name === targetNetworkName) {
return -1;
}

return 1;
});

activeNetworks.forEach((network, index) => {
network.order = index;
});

await this.storage.set(StorageKeys.networkInfo, state);
}
async setState(state: IState): Promise<void> {
return this.storage.set(StorageKeys.networkInfo, state);
}

async getState(): Promise<IState> {
Expand Down
4 changes: 1 addition & 3 deletions packages/extension/src/libs/networks-state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ export enum StorageKeys {

export interface NetworkStorageElement {
name: string;
isActive: boolean;
order?: number;
}

export interface IState {
networks?: Array<{ name: string; isActive: boolean; order?: number }>;
networks: NetworkStorageElement[];
}
Loading