Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8e5c8d8
Show gas estimate in confirmation window
germanviescas Oct 12, 2022
73935b8
Merge pull request #77 from pointnetwork/PN-257-gas-estimate
tankakatan Oct 13, 2022
5cb1394
Add user-friendly explanation to confirmation window
germanviescas Oct 13, 2022
d2129d7
Provide gas estimate of token transfers
germanviescas Oct 14, 2022
c835e94
Update .nvmrc
yurivin Oct 13, 2022
91b5bd0
Merge pull request #79 from pointnetwork/PN-258-explain-tx
tankakatan Oct 17, 2022
1e41382
Merge pull request #80 from pointnetwork/PN-260
tankakatan Oct 17, 2022
e4776f8
Enrich tx input information
germanviescas Oct 17, 2022
ba37fdd
Show identities in confirmation window
germanviescas Oct 18, 2022
70a826e
Show beneficiary of token transfer
germanviescas Oct 18, 2022
1a3676d
Merge pull request #81 from pointnetwork/PN-262
tankakatan Oct 19, 2022
09d4097
Merge pull request #82 from pointnetwork/PN-265
tankakatan Oct 19, 2022
1b1a18b
Reconcile code style with Point Engine
germanviescas Oct 20, 2022
f377ee0
Apply ESLint and Prettier
germanviescas Oct 20, 2022
2aff2b8
Add "lint" github workflow
germanviescas Oct 20, 2022
089e1ee
Merge pull request #83 from pointnetwork/PN-268
tankakatan Oct 21, 2022
dfe4303
Update confirmation window styling
germanviescas Oct 25, 2022
538d693
Show address of identities
germanviescas Oct 25, 2022
229ed47
Merge pull request #84 from pointnetwork/PN-274
tankakatan Oct 27, 2022
f31fc7e
add hoststorage functionality
sergevar Apr 24, 2023
54150aa
Update manifest version
sergevar Apr 24, 2023
7c497e5
0.1.1
sergevar Apr 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 62 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'plugin:prettier/recommended' // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
ignorePatterns: ['.eslintrc.js'],
env: {
Expand All @@ -19,45 +19,63 @@ module.exports = {
sourceType: 'module', // Allows for the use of imports
// project: 'tsconfig.json',
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
jsx: true // Allows for the parsing of JSX
},
project: './tsconfig.json'
},
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
version: 'detect' // Tells eslint-plugin-react to automatically detect the version of React to use
}
},
rules: {
// 'react/prop-types': 0, // no requiring of prop types
'react/display-name': 0, // allow anonymous components
'strict': [2, 'safe'],
'no-debugger': 2,
'brace-style': [2, '1tbs', { 'allowSingleLine': true }],
'no-trailing-spaces': [2, { 'skipBlankLines': true }],
'keyword-spacing': 2,
strict: [2, 'safe'],
'no-debugger': 'error',
'brace-style': ['error', '1tbs', {allowSingleLine: true}],
'keyword-spacing': ['error'],
'comma-spacing': 'error',
'object-curly-spacing': ['error', 'never'],
'object-curly-newline': ['error', {multiline: true}],
'array-bracket-spacing': ['error', 'never'],
'spaced-comment': [2, 'always'],
'vars-on-top': 0, // Disable: all 'var' declarations must be at the top of the function scope
'no-undef': 0,
'no-undefined': 0,
'comma-dangle': [0, 'never'],
'quotes': [2, 'double'],
'semi': 1,
'comma-dangle': ['error', 'never'],
quotes: ['error', 'single', {allowTemplateLiterals: true}],
semi: ['error', 'always'],
'guard-for-in': 0, // allow iterating with for..in without checking for Object.hasOwnProperty
'no-eval': 2,
'no-with': 2,
'valid-typeof': 2,
'no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
'@typescript-eslint/no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{argsIgnorePattern: '^_', varsIgnorePattern: '^_'}
],
'no-continue': 1,
'no-unreachable': 1,
'no-unused-expressions': 1,
'no-unreachable': 'error',
'no-unused-expressions': 'error',
'no-duplicate-imports': 'error',
'no-magic-numbers': 0,
'no-inner-declarations': 0,
'no-constant-condition': 0,
'no-empty-function': 0,
'max-len': [1, 120, 4],
'arrow-body-style': ['error', 'as-needed'],
'max-len': [
'warn',
{
code: 100,
ignoreStrings: true,
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
tabWidth: 4,
ignoreComments: true
}
],
'react/prefer-es6-class': 1,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-use-before-define': 0,
Expand All @@ -68,5 +86,31 @@ module.exports = {
'@typescript-eslint/no-extra-semi': 0,
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/ban-ts-comment': 0,
},
semi: ['error', 'always'],
'linebreak-style': ['error', 'unix'],
curly: ['error', 'multi-line'],
indent: [
'error',
4,
{
SwitchCase: 1,
MemberExpression: 1,
ArrayExpression: 1,
ObjectExpression: 1,
VariableDeclarator: 1,
CallExpression: {arguments: 1},
offsetTernaryExpressions: true
}
],
'space-in-parens': ['error', 'never'],
'no-case-declarations': 'warn',
eqeqeq: ['error', 'always', {null: 'ignore'}],
'prefer-const': ['error', {destructuring: 'all', ignoreReadBeforeAssign: false}],
'no-multiple-empty-lines': ['warn', {max: 1, maxEOF: 0}],
'@typescript-eslint/no-unsafe-call': 'warn', // TODO: fix and delete rule
'@typescript-eslint/no-unsafe-assignment': 'warn', // TODO: fix and delete rule
'@typescript-eslint/no-unsafe-member-access': 'warn', // TODO: fix and delete rule
'@typescript-eslint/restrict-template-expressions': 'warn', // TODO: fix and delete rule
'@typescript-eslint/no-unsafe-return': 'warn' // TODO: fix and delete rule
}
};
20 changes: 20 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This workflow will run a lint check
name: Run ESLint

on:
pull_request:
branches: [ develop ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ npm-debug.log
/.parcel-cache
.DS_Store
web-ext-artifacts

/.idea
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.8.0
v16
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/*
*.snap
*.snap
8 changes: 6 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = {
semi: true,
trailingComma: "all",
singleQuote: false,
trailingComma: "none",
singleQuote: true,
printWidth: 100,
tabWidth: 4,
useTabs: false,
bracketSpacing: false,
arrowParens: "avoid",
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pointnetwork-browser-extension",
"version": "0.0.41",
"version": "0.1.1",
"description": "Point Browser Extension",
"alias": {
"pointsdk": "./src"
Expand Down Expand Up @@ -83,6 +83,7 @@
"scripts": {
"start": "npm run cleanup && parcel src/manifest.json --host localhost --target dev",
"build": "npm run cleanup && parcel build src/manifest.json --target prod --no-source-maps",
"watch": "npm run cleanup && parcel watch src/manifest.json --target prod",
"build:sdk": "npx parcel@2.4.1 build src/pointsdk/browser.ts --target sdk",
"cleanup": "rm -rf dist .cache .parcel-cache",
"test": "jest --config=jest.config.js",
Expand Down
22 changes: 11 additions & 11 deletions src/background/confirmationWindowApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import browser from "webextension-polyfill";
import browser from 'webextension-polyfill';

let windowId: number | null = null;
export const displayConfirmationWindow = async (
Expand All @@ -7,21 +7,21 @@ export const displayConfirmationWindow = async (
host: string,
network: string,
params = {},
decodedTxData = {},
decodedTxData = {}
) => {
const query = new URLSearchParams();
query.append("reqId", reqId);
query.append("pointId", pointId);
query.append("host", host);
query.append("network", network);
query.append("params", JSON.stringify(params));
query.append("decodedTxData", JSON.stringify(decodedTxData));
query.append('reqId', reqId);
query.append('pointId', pointId);
query.append('host', host);
query.append('network', network);
query.append('params', JSON.stringify(params));
query.append('decodedTxData', JSON.stringify(decodedTxData));

const win = await browser.windows.create({
type: "detached_panel",
width: 400,
type: 'detached_panel',
width: 512,
height: 600,
url: `./confirmation-window/index.html?${query.toString()}`,
url: `./confirmation-window/index.html?${query.toString()}`
});
windowId = win.id!;
};
Expand Down
65 changes: 22 additions & 43 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,67 @@
import browser from "webextension-polyfill";
import browser from 'webextension-polyfill';
import {
rpcListener,
confirmationWindowListener,
registerHandlerListener,
setAuthTokenHandler,
getAuthToken,
} from "pointsdk/background/messaging";
getAuthToken
} from 'pointsdk/background/messaging';

const setChainIds = async () => {
try {
const token = (await getAuthToken()).token;
const networksRes = await fetch(
"https://point/v1/api/blockchain/networks",
{
headers: {
"X-Point-Token": `Bearer ${token}`,
},
},
);
const oldDefaultNetwork = await browser.storage.local.get(
"default_network",
);
const { networks, default_network } = await networksRes.json();
const opts = {headers: {'X-Point-Token': `Bearer ${token}`}};
const networksRes = await fetch('https://point/v1/api/blockchain/networks', opts);
const oldDefaultNetwork = await browser.storage.local.get('default_network');
const {networks, default_network} = await networksRes.json();
// TODO: if the default network changed we need to update it everywhere
// therefore we need to clear the prevoius setting, but this is not polite
// need to think of a better solution...
if (oldDefaultNetwork && oldDefaultNetwork !== default_network) {
await browser.storage.local.remove("chainIdGlobal"); // it will be set up below
await browser.storage.local.remove('chainIdGlobal'); // it will be set up below
const storage = await browser.storage.local.get(null);
for (const key in storage) {
if (key.startsWith("chainId")) {
await browser.storage.local.set({
[key]: default_network as string,
});
if (key.startsWith('chainId')) {
await browser.storage.local.set({[key]: default_network as string});
}
}
}
await browser.storage.local.set({
networks: JSON.stringify(networks),
default_network,
default_network
});
const { chainIdGlobal } = await browser.storage.local.get(
"chainIdGlobal",
);
const {chainIdGlobal} = await browser.storage.local.get('chainIdGlobal');
if (!chainIdGlobal || !(chainIdGlobal in networks)) {
await browser.storage.local.set({
chainIdGlobal: default_network,
});
await browser.storage.local.set({chainIdGlobal: default_network});
}
} catch (e) {
console.error("Failed to fetch networks info from the node: ", e);
console.error('Failed to fetch networks info from the node: ', e);
setTimeout(() => {
void setChainIds();
}, 1000);
}
};

setChainIds();
void setChainIds();

browser.runtime.onMessage.addListener(async (message, sender) => {
switch (message.__message_type) {
case "rpc":
case 'rpc':
return rpcListener(message);
case "registerHandler":
case 'registerHandler':
return registerHandlerListener(message);
case "setAuthToken":
case 'setAuthToken':
if (!sender.url?.match(/^https:\/\/point/)) {
console.error(
"Attempt to set auth token from unauthorized host",
);
console.error('Attempt to set auth token from unauthorized host');
break;
}
return setAuthTokenHandler(message);
case "getAuthToken":
case 'getAuthToken':
return getAuthToken();
default:
if (sender.url?.match("confirmation-window")) {
if (sender.url?.match('confirmation-window')) {
return confirmationWindowListener(message);
}
console.error(
"Unexpected runtime message: ",
message,
" from sender: ",
sender,
);
console.error('Unexpected runtime message: ', message, ' from sender: ', sender);
}
});
Loading