From d8b88c18f9f1439e3818bec1c8f8a5c124acbcf5 Mon Sep 17 00:00:00 2001 From: Pulyak Viktor Date: Mon, 5 Aug 2019 12:12:23 +0300 Subject: [PATCH 01/21] [ECHO-1113] Preparation for publication (#2) --- .gitlab-ci.yml | 82 ++++---------------------------------------- .travis.yml | 34 ++++++++++++++++++ CONTRIBUTING.md | 50 +++++++++++++++++++++++++++ README.md | 58 ++++++++++++++++--------------- SECURITY.md | 18 ++++++++++ config/manifest.json | 6 ++-- package.json | 7 ++-- 7 files changed, 145 insertions(+), 110 deletions(-) create mode 100644 .travis.yml create mode 100644 CONTRIBUTING.md create mode 100644 SECURITY.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c87fd53d..353af18b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,88 +1,18 @@ stages: - - lint - build - - artifacts - -cache: - key: $CI_COMMIT_REF_NAME - paths: - - node_modules/ - -lint.test: - image: node:10.15 - stage: lint - script: - - node -v - - if [ -d node_modules/echojs-lib ]; then rm -rf node_modules/echojs-lib; fi - - npm config set unsafe-perm true - - npm i - - npm run lint - tags: - - docker - -build.develop: - stage: build - script: - - cd /home/devuser/DevProjects/649.bridge/extension - - git pull origin develop - - npm i - - npm run build-dev - only: - - develop - environment: - name: development - tags: - - pp-projects - -artifacts.build: - stage: artifacts - script: - - npm i - - npm run build-ext - artifacts: - paths: - - build/zip/echo_bridge.zip - only: - - develop - - master - tags: - - pp-projects - -build.master: - stage: build - script: - - cd /home/devuser/Projects/649.bridge/extension - - git pull origin master - - npm install - - npm run build-stage - only: - - master - environment: - name: stage - tags: - - pp-projects build.publish: - image: node:10.15 + image: node:10.16 stage: build - cache: - key: $CI_COMMIT_REF_NAME - paths: - - node_modules - script: + before_script: - apt-get update -y && apt-get -y --allow-unauthenticated install curl jq - - if [ -d node_modules/echojs-lib ]; then rm -rf node_modules/echojs-lib; fi - - npm config set unsafe-perm true + script: - npm i - npm run build-ext - - cd build/zip - - ls - - ACCESS_TOKEN=$(curl "https://accounts.google.com/o/oauth2/token" -d "client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&refresh_token=${REFRESH_TOKEN}&grant_type=refresh_token&redirect_uri=urn:ietf:wg:oauth:2.0:oob" | jq -r .access_token) - - 'curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -X PUT -T echo_bridge.zip -v "https://www.googleapis.com/upload/chromewebstore/v1.1/items/${APP_ID}"' - - 'curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -H "Content-Length: 0" -X POST -v "https://www.googleapis.com/chromewebstore/v1.1/items/${APP_ID}/publish?publishTarget=default"' + - ACCESS_TOKEN=$(curl "https://accounts.google.com/o/oauth2/token" -d "client_id=${CHROME_CLIENT_ID}&client_secret=${CHROME_CLIENT_SECRET}&refresh_token=${CHROME_REFRESH_TOKEN}&grant_type=refresh_token&redirect_uri=urn:ietf:wg:oauth:2.0:oob" | jq -r .access_token) + - 'curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -X PUT -T build/zip/echo_bridge.zip -v "https://www.googleapis.com/upload/chromewebstore/v1.1/items/${CHROME_APP_ID}"' + - 'curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -H "Content-Length: 0" -X POST -v "https://www.googleapis.com/chromewebstore/v1.1/items/${CHROME_APP_ID}/publish?publishTarget=default"' only: - tags tags: - docker - environment: - name: development \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ccb5143b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,34 @@ +language: node_js +node_js: + - "10" + +stages: + - lint + - test + - build + +jobs: + include: + + - stage: lint + name: "Lint" + if: type = push + script: + - npm run lint + + - stage: test + name: "Tests" + if: branch IN (develop, master) AND type = pull_request + script: npm run test + + - stage: build + name: "Build Artifacts" + if: (branch = master OR tag IS present) AND type = push + addons: + artifacts: + working_dir: build/zip/ + paths: + - echo_bridge.zip + script: + - npm run build-ext + - "echo \"Download URL: https://${ARTIFACTS_BUCKET}.s3.amazonaws.com/echoprotocol/bridge-extension/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/echo_bridge.zip\"" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..79fa38bb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,50 @@ +# Contributing + +We greatly appreciate your contribution to the development of this +project and are very grateful to any of your help that you can offer, be +it assistance in developing a codebase, auditing existing code, creating +bugs and issues in the issue list, or commenting on already created +issues. + +But before you spend your time developing code, please make sure that +you take into account the points described below: + +1. If the problem you are trying to solve is related to security, we + will be very grateful if before creating issue or Pull Request you + follow the steps described here - [SECURITY.md](SECURITY.md). +2. See a list of known issues. Perhaps the problem you are trying to + solve has already been discussed and, as an option, work is already + underway to fix it. +3. If there is no issue in the list, we will be grateful if you create + an appropriate Issue, which we can discuss and come to the option + together, how best to solve it. In addition, our team is constantly + working on improving the project, and therefore there is a high + probability that the task you are planning to solve is already + planned by our team and has a plan for solving it. In any case, + having Issue, we always have the opportunity to help you. + +If you already have code that you would like to merge into the main +development branch, you will come in handy a few recommendations, which +we described below. + +## Pull Request Process + +1. Make sure your branch is based on the `develop` branch and includes + the latest state. We are developing in the `develop` branch, so your + request should be directed to it. If your fix is a critical bugfix, + then you can create a request to the `master`. Such requests will be + reviewed more closely, so please provide as much information as + possible about what you are correcting and why your request should be + sent to the `master`. +2. Make sure your code does not violate the lint rules. +3. Make sure the CI processes are successful +4. If your request is associated with a bug or issue from the issues + list, add the line `Fixes #$ISSUE_NUMBER` or `Resolves + #$ISSUE_NUMBER`. Ex. For closing issue `418`, include the line `Fixes + #418`. If it doesn't close the issue but addresses it partially, just + include a reference to the issue number, like `#418`. +5. You can merge the request after you have at least one approval of + core contributor, or, if you do not have permission to do so, you may + request the second reviewer to merge it for you. + +Thank you for helping to make this project better! diff --git a/README.md b/README.md index 1116128d..d9258a7c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Echo Bridge Browser Extension +[![Build Status](https://travis-ci.com/echoprotocol/bridge-extension.svg?token=FbPpGfasAys9FvssGPyt&branch=master)](https://travis-ci.com/echoprotocol/bridge-extension) + Bridge is a tool designed to make running Echo dApps for people as easy as possible. As an extension for browser, Bridge can act as a dedicated Echo wallet, @@ -46,33 +48,33 @@ There is an example of connecting to the node and subscribe to switch network ```javascript window.onload = async () => { - // you do not need to use the isEchoBridge flag, - // but you can be sure that you did not override - // the variable above - if (echojslib && echojslib.isEchoBridge) { - - /** - * Get access - */ - await echojslib.extension.getAccess(); - - /** - * Subscribe to current Echo network selected in Bridge - */ - await echojslib.extension.subscribeSwitchNetwork(async () => { - - if (echojslib.echo.isConnected) { - await window.echojslib.echo.disconnect(); - } - - /** - * Connect to current Echo network selected in Bridge - */ - await echojslib.echo.connect(); - - }); - - } + // you do not need to use the isEchoBridge flag, + // but you can be sure that you did not override + // the variable above + if (echojslib && echojslib.isEchoBridge) { + + /** + * Get access + */ + await echojslib.extension.getAccess(); + + /** + * Subscribe to current Echo network selected in Bridge + */ + await echojslib.extension.subscribeSwitchNetwork(async () => { + + if (echojslib.echo.isConnected) { + await window.echojslib.echo.disconnect(); + } + + /** + * Connect to current Echo network selected in Bridge + */ + await echojslib.echo.connect(); + + }); + + } }; ``` @@ -123,7 +125,7 @@ const sendTransaction = async () => { See the [examples](./examples/examples.md) for more different transactions. -#### Payload Signing +### Payload Signing In order for the user to confirm ownership of the account's private key, the extension suggests using the proofOfAuthority method. The method provides an opportunity to sign payload by account private key. Because the raw signing can potentially sign transactions or even leak its private key we have to add an extra layer of encryption. So the extension will sign payload instead of raw data. ```javascript diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..a7a59ecc --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,18 @@ +# Reporting Security Issues + +The Echo team takes security errors at Echo Bridge seriously. We +appreciate your efforts and will make every effort to recognize your +contribution. + +To report a security issue, write +[security@echo-dev.io](mailto:security@echo-dev.io) and include the word +"SECURITY" in the subject. + +We will send you a response with the following steps. After the initial +response to your report, the our team will inform you of the progress +towards the correction and the full announcement and may request +additional information or recommendations. + +Report security errors in third-party modules to an employee or team +serving the module. You can also report a vulnerability through +[this page](https://www.npmjs.com/advisories/report). diff --git a/config/manifest.json b/config/manifest.json index 090cfbef..7aec3b52 100644 --- a/config/manifest.json +++ b/config/manifest.json @@ -12,13 +12,13 @@ } }, "icons": { - "16": "images/16.png", - "32": "images/32.png", + "16": "images/16.png", + "32": "images/32.png", "48": "images/48.png", "96": "images/96.png", "128": "images/128.png" }, - "version": "1.9.3", + "version": "1.9.4", "background": { "scripts": [ "background.js" diff --git a/package.json b/package.json index bfbc0a61..18c57c9e 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,18 @@ { "name": "echo-bridge", "description": "The bridge between your web site and the Echo", - "version": "1.9.3", + "version": "1.9.4", "scripts": { "start": "cross-env NODE_ENV=local webpack-dev-server --mode development --progress --colors --history-api-fallback --hot --inline --port 8081", "build": "cross-env NODE_ENV=production webpack --progress --display-error-details --colors --mode production", - "build-ext": "cross-env EXTENSION=TRUE NODE_ENV=production webpack --progress --display-error-details --colors --mode production", + "build-ext": "cross-env EXTENSION=TRUE NODE_ENV=production webpack --display-error-details --colors --mode production", "build-ext-dev": "cross-env EXTENSION=TRUE NODE_ENV=development webpack --progress --display-error-details --colors --mode development", "build-dev": "cross-env NODE_ENV=development webpack --progress --display-error-details --colors --mode production", "build-stage": "cross-env NODE_ENV=stage webpack --progress --display-error-details --colors --mode production", "lint": "$(npm bin)/eslint 'src/**/*.jsx' 'src/**/*.js'", "lint-win": "cross-env eslint 'src/**/*.jsx' 'src/**/*.js' --fix", - "copy-manifest": "copyfiles -f config/manifest.json build/src" + "copy-manifest": "copyfiles -f config/manifest.json build/src", + "test": "echo \"should run tests\"" }, "dependencies": { "EventEmitter": "^1.0.0", From 170336b6218d35272a8423d88039903dc334c25c Mon Sep 17 00:00:00 2001 From: Echo Protocol <43003270+echoprotocol@users.noreply.github.com> Date: Mon, 5 Aug 2019 12:23:53 +0300 Subject: [PATCH 02/21] [ECHO-1113] Add badges (#3) --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d9258a7c..d0d4fa11 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Echo Bridge Browser Extension -[![Build Status](https://travis-ci.com/echoprotocol/bridge-extension.svg?token=FbPpGfasAys9FvssGPyt&branch=master)](https://travis-ci.com/echoprotocol/bridge-extension) +![Travis (.com) branch](https://img.shields.io/travis/com/echoprotocol/bridge-extension/master?label=build%20master) +![Travis (.com) branch](https://img.shields.io/travis/com/echoprotocol/bridge-extension/develop?label=build%20develop) Bridge is a tool designed to make running Echo dApps for people as easy as possible. From c627788b43d0186066fc121c7eb364d5331a6f56 Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Wed, 7 Aug 2019 15:55:45 +0300 Subject: [PATCH 03/21] [BRG-440] after call subscribeSwitchNetwork return current network (#5) --- extension/inpage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/inpage.js b/extension/inpage.js index d2bd5eee..d63d4802 100644 --- a/extension/inpage.js +++ b/extension/inpage.js @@ -100,7 +100,7 @@ const subscribeSwitchNetwork = (subscriberCb) => { return; } - resolve(); + resolve(data.res); if (!networkSubscribers.length) { networkSubscription(); From b6f4e3fdd40e818960cff92b673cf89ff268006d Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Wed, 7 Aug 2019 16:32:36 +0300 Subject: [PATCH 04/21] [BRG-434] getNetwork return chain id (#6) --- extension/background.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extension/background.js b/extension/background.js index 803b871b..c8c8bcc5 100644 --- a/extension/background.js +++ b/extension/background.js @@ -90,7 +90,8 @@ const connectSubscribe = (status) => { */ const getNetwork = async () => { const network = await storage.get('current_network') || NETWORKS[0]; - return network; + const chainId = await echoService.getChainLib().api.getChainId(); + return { ...network, chainId }; }; /** From d1dc10c4bfd591f54197fe9d08880dca028abc68 Mon Sep 17 00:00:00 2001 From: Anastasia Rudenko Date: Wed, 7 Aug 2019 18:01:45 +0300 Subject: [PATCH 05/21] [BRG-436] make required network name parameter (#9) --- src/actions/BalanceActions.js | 4 ++-- src/actions/CryptoActions.js | 29 ++++++++++++++++------------- src/actions/GlobalActions.js | 21 +++++++++------------ src/containers/Backup/index.jsx | 24 +++++++++++++++--------- src/containers/Welcome/index.jsx | 15 +++++++++++---- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/actions/BalanceActions.js b/src/actions/BalanceActions.js index f89e4c81..1bac908e 100644 --- a/src/actions/BalanceActions.js +++ b/src/actions/BalanceActions.js @@ -661,7 +661,7 @@ export const watchToken = (contractId) => async (dispatch, getState) => { tokens[accountId].push(contractId.split('.')[2]); - dispatch(setCryptoInfo('tokens', tokens)); + dispatch(setCryptoInfo('tokens', tokens, networkName)); let stateTokens = getState().balance.get('tokens'); @@ -828,7 +828,7 @@ export const removeToken = (contractId) => async (dispatch, getState) => { tokens[accountId] = tokens[accountId].filter((id) => contractId.split('.')[2] !== id); - dispatch(setCryptoInfo('tokens', tokens)); + dispatch(setCryptoInfo('tokens', tokens, networkName)); const stateTokens = getState().balance.get('tokens'); diff --git a/src/actions/CryptoActions.js b/src/actions/CryptoActions.js index 09b90d4e..14969e79 100644 --- a/src/actions/CryptoActions.js +++ b/src/actions/CryptoActions.js @@ -206,13 +206,13 @@ export const initCrypto = () => async (dispatch) => { * * @param {String} field * @param {*} value - * @param {String?} networkName + * @param {String} networkName */ -export const setCryptoInfo = (field, value, networkName) => async (dispatch, getState) => { +export const setCryptoInfo = (field, value, networkName) => async (dispatch) => { const crypto = echoService.getCrypto(); try { if (!networkName) { - networkName = getState().global.getIn(['network', 'name']); + throw new Error('Network is required'); } await crypto.setInByNetwork(networkName, field, value); @@ -229,12 +229,12 @@ export const setCryptoInfo = (field, value, networkName) => async (dispatch, get * @param {String} field * @param {String} networkName */ -export const getCryptoInfo = (field, networkName) => async (dispatch, getState) => { +export const getCryptoInfo = (field, networkName) => async (dispatch) => { const crypto = echoService.getCrypto(); try { if (!networkName) { - networkName = getState().global.getIn(['network', 'name']); + throw new Error('Network is required'); } const value = await crypto.getInByNetwork(networkName, field); @@ -250,20 +250,22 @@ export const getCryptoInfo = (field, networkName) => async (dispatch, getState) /** * @method transitPublicKey * + * @param {String} accountId + * @param {String} networkName */ -export const transitPublicKey = () => async (dispatch, getState) => { +export const transitPublicKey = (accountId, networkName) => async (dispatch) => { try { const keys = []; let wifs = []; - const networkName = getState().global.getIn(['network', 'name']); - const account = getState().global.get('account'); - if (!account) { - return null; + if (!accountId) { + throw new Error('Account is required'); } - const accountId = getState().global.getIn(['account', 'id']); + if (!networkName) { + throw new Error('Network is required'); + } const accountChain = []; try { @@ -303,14 +305,15 @@ export const transitPublicKey = () => async (dispatch, getState) => { * Remove value by field in network storage * * @param {String} field + * @param {String} networkName */ -export const removeCryptoInfo = (field, networkName) => async (dispatch, getState) => { +export const removeCryptoInfo = (field, networkName) => async (dispatch) => { const crypto = echoService.getCrypto(); try { if (!networkName) { - networkName = getState().global.getIn(['network', 'name']); + throw new Error('Network is required'); } await crypto.removeInByNetwork(networkName, field); diff --git a/src/actions/GlobalActions.js b/src/actions/GlobalActions.js index 929ff628..432452b0 100644 --- a/src/actions/GlobalActions.js +++ b/src/actions/GlobalActions.js @@ -287,7 +287,7 @@ export const addAccount = (name, keys, networkName, path) => async (dispatch, ge id: account.id, active: true, icon, iconColor, name, keys, })); - await dispatch(setCryptoInfo('accounts', accounts.get(networkName))); + await dispatch(setCryptoInfo('accounts', accounts.get(networkName), networkName)); dispatch(set('accounts', accounts)); await dispatch(initAccount({ name, icon, iconColor })); @@ -350,14 +350,10 @@ export const onLogout = (name) => async (dispatch, getState) => { dispatch(removeBalances(id)); - /* eslint-disable no-await-in-loop, no-plusplus */ - for (let i = 0; i < keys.length; i++) { - await dispatch(removeCryptoInfo(keys[i])); - } - /* eslint-enable no-await-in-loop, no-plusplus */ + await Promise.all(keys.map((k) => dispatch(removeCryptoInfo(k, networkName)))); accounts = accounts.set(networkName, accounts.get(networkName).filter((i) => i.name !== name)); - await dispatch(setCryptoInfo('accounts', accounts.get(networkName))); + await dispatch(setCryptoInfo('accounts', accounts.get(networkName), networkName)); dispatch(set('accounts', accounts)); if (accountName !== name) { return false; @@ -374,7 +370,7 @@ export const onLogout = (name) => async (dispatch, getState) => { accounts.get(networkName).set(0, { ...accounts.getIn([networkName, 0]), active: true }), ); - await dispatch(setCryptoInfo('accounts', accounts.get(networkName))); + await dispatch(setCryptoInfo('accounts', accounts.get(networkName), networkName)); dispatch(set('accounts', accounts)); await dispatch(initAccount(accounts.getIn([networkName, 0]))); @@ -405,7 +401,7 @@ export const switchAccount = (name) => async (dispatch, getState) => { ); try { - await dispatch(setCryptoInfo('accounts', accounts.get(networkName))); + await dispatch(setCryptoInfo('accounts', accounts.get(networkName), networkName)); dispatch(set('accounts', accounts)); const account = accounts.get(networkName).find((i) => i.active); @@ -428,6 +424,7 @@ export const loadInfo = () => async (dispatch, getState) => { try { const networks = getState().global.get('networks'); + const currentNetworkName = getState().global.getIn(['network', 'name']); let accountsNetworks = new Map(); const resultPromises = networks.concat(NETWORKS).map(async (network) => { @@ -483,7 +480,7 @@ export const loadInfo = () => async (dispatch, getState) => { }); - const accounts = await dispatch(getCryptoInfo('accounts')); + const accounts = await dispatch(getCryptoInfo('accounts', currentNetworkName)); if (accounts && accounts.length) { await dispatch(initAccount(accounts.find((account) => account.active))); @@ -722,7 +719,7 @@ export const changeAccountIcon = (icon, iconColor) => async (dispatch, getState) account = account.set('icon', icon).set('iconColor', iconColor); try { - dispatch(setCryptoInfo('accounts', accounts.get(networkName))); + dispatch(setCryptoInfo('accounts', accounts.get(networkName), networkName)); dispatch(batchActions([ GlobalReducer.actions.set({ field: 'accounts', value: accounts }), @@ -786,7 +783,7 @@ export const addKeyToAccount = (accountId, active) => async (dispatch, getState) })); - await dispatch(setCryptoInfo('accounts', accounts.get(networkName).toJS())); + await dispatch(setCryptoInfo('accounts', accounts.get(networkName).toJS(), networkName)); dispatch(set('accounts', accounts)); }; diff --git a/src/containers/Backup/index.jsx b/src/containers/Backup/index.jsx index 8588ec94..4e899657 100644 --- a/src/containers/Backup/index.jsx +++ b/src/containers/Backup/index.jsx @@ -21,18 +21,17 @@ class Backup extends React.Component { } componentWillReceiveProps(nextProps) { - if (nextProps.accountName !== this.props.accountName) { + if (nextProps.accountId !== this.props.accountId) { this.getKeys(); } } - getKeys() { - const keys = this.props.transitPublicKey(); + async getKeys() { + const { accountId, networkName } = this.props; + const keys = await this.props.transitPublicKey(accountId, networkName); - keys.then((value) => { - this.setState({ keys: value }); - }); + this.setState({ keys }); } render() { @@ -85,13 +84,20 @@ class Backup extends React.Component { } Backup.propTypes = { + accountId: PropTypes.string.isRequired, + networkName: PropTypes.string.isRequired, transitPublicKey: PropTypes.func.isRequired, - accountName: PropTypes.string.isRequired, }; export default connect( - (state) => ({ accountName: state.global.getIn(['account', 'name']) }), + (state) => ({ + accountId: state.global.getIn(['account', 'id']), + networkName: state.global.getIn(['network', 'name']), + }), (dispatch) => ({ - transitPublicKey: () => dispatch(transitPublicKey()), + transitPublicKey: (accountId, networkName) => dispatch(transitPublicKey( + accountId, + networkName, + )), }), )(Backup); diff --git a/src/containers/Welcome/index.jsx b/src/containers/Welcome/index.jsx index 5950f643..96fe4131 100644 --- a/src/containers/Welcome/index.jsx +++ b/src/containers/Welcome/index.jsx @@ -41,7 +41,9 @@ class Welcome extends React.Component { } getKeys() { - const keys = this.props.transitPublicKey(); + const { account, networkName } = this.props; + + const keys = this.props.transitPublicKey(account.get('id'), networkName); keys.then((value) => { this.setState({ keys: value }); @@ -149,10 +151,11 @@ class Welcome extends React.Component { Welcome.propTypes = { - transitPublicKey: PropTypes.func.isRequired, + account: PropTypes.object, + networkName: PropTypes.string.isRequired, location: PropTypes.object.isRequired, history: PropTypes.object.isRequired, - account: PropTypes.object, + transitPublicKey: PropTypes.func.isRequired, }; Welcome.defaultProps = { @@ -163,8 +166,12 @@ Welcome.defaultProps = { export default withRouter(connect( (state) => ({ account: state.global.get('account'), + networkName: state.global.getIn(['network', 'name']), }), (dispatch) => ({ - transitPublicKey: () => dispatch(transitPublicKey()), + transitPublicKey: (accountId, networkName) => dispatch(transitPublicKey( + accountId, + networkName, + )), }), )(Welcome)); From 5168a5b77b84c73f2d0db4ac5847939110197c90 Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Thu, 8 Aug 2019 12:29:43 +0300 Subject: [PATCH 06/21] [BRG-439] fix incorrect notification after subscription (#8) * [BRG-439] fix incorrect notification after subscription * [BRG-439] add randomatic to get unique id notification --- extension/IdHelper.js | 12 ++++++++++++ extension/inpage.js | 32 ++++++++++++++++++++------------ package.json | 1 + src/constants/GlobalConstants.js | 3 +++ 4 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 extension/IdHelper.js diff --git a/extension/IdHelper.js b/extension/IdHelper.js new file mode 100644 index 00000000..f0cd956a --- /dev/null +++ b/extension/IdHelper.js @@ -0,0 +1,12 @@ +import * as randomize from 'randomatic'; +import { LENGTH_ID_MESSAGE, PATTERN_ID_MESSAGE } from '../src/constants/GlobalConstants'; + +class IdHelper { + + static getId() { + return randomize(PATTERN_ID_MESSAGE, LENGTH_ID_MESSAGE); + } + +} + +export default IdHelper; diff --git a/extension/inpage.js b/extension/inpage.js index d63d4802..03c462eb 100644 --- a/extension/inpage.js +++ b/extension/inpage.js @@ -9,18 +9,19 @@ import { PING_TIMEOUT, } from '../src/constants/GlobalConstants'; +import IdHelper from './IdHelper'; + const requestQueue = []; const networkSubscribers = []; const accountSubscribers = []; - /** * network subscription * */ const networkSubscription = () => { - const id = Date.now(); + const id = IdHelper.getId(); const callback = ({ data }) => { /** @@ -38,7 +39,7 @@ const networkSubscription = () => { }; const accountSubscription = () => { - const id = Date.now(); + const id = IdHelper.getId(); const callback = ({ data }) => { /** @@ -60,7 +61,8 @@ const accountSubscription = () => { * @returns {Promise} */ const getCurrentNetwork = () => { - const id = Date.now(); + const id = IdHelper.getId(); + const result = new Promise((resolve, reject) => { const callback = ({ data }) => { if (data.error) { @@ -87,7 +89,8 @@ const getCurrentNetwork = () => { * @returns {Promise} */ const subscribeSwitchNetwork = (subscriberCb) => { - const id = Date.now(); + const id = IdHelper.getId(); + const result = new Promise((resolve, reject) => { if (!lodash.isFunction(subscriberCb)) { reject(new Error('Is not a function')); @@ -121,7 +124,8 @@ const subscribeSwitchNetwork = (subscriberCb) => { }; const subscribeSwitchAccount = (subscriberCb) => { - const id = Date.now(); + const id = IdHelper.getId(); + const result = new Promise((resolve, reject) => { if (!lodash.isFunction(subscriberCb)) { reject(new Error('Is not a function')); @@ -174,7 +178,8 @@ echojslib.echo.connect = (url, params) => { apis: ['database', 'network_broadcast', 'history', 'registration', 'asset', 'login', 'network_node'], }; - const id = Date.now(); + const id = IdHelper.getId(); + const result = new Promise((resolve, reject) => { const cb = async ({ data }) => { @@ -219,7 +224,8 @@ const onMessage = (event) => { * @returns {Promise} */ const sendTransaction = (options) => { - const id = Date.now(); + const id = IdHelper.getId(); + const result = new Promise((resolve, reject) => { const cb = ({ data }) => { @@ -248,7 +254,8 @@ const sendTransaction = (options) => { * @returns {Promise} */ const getAccounts = () => { - const id = Date.now(); + const id = IdHelper.getId(); + const result = new Promise((resolve, reject) => { const cb = ({ data }) => { @@ -270,7 +277,7 @@ const getAccounts = () => { }; const proofOfAuthority = (message, accountId) => { - const id = Date.now(); + const id = IdHelper.getId(); const result = new Promise((resolve, reject) => { const cb = ({ data }) => { @@ -300,7 +307,8 @@ const proofOfAuthority = (message, accountId) => { * @returns {Promise} */ const getAccess = () => { - const id = Date.now(); + const id = IdHelper.getId(); + const result = new Promise((resolve, reject) => { const cb = ({ data }) => { @@ -339,7 +347,7 @@ class Signat { } echojslib.Transaction.prototype.signWithBridge = async function signWithBridge() { - const id = Date.now(); + const id = IdHelper.getId(); if (!this.hasAllFees) { await this.setRequiredFees(); diff --git a/package.json b/package.json index 18c57c9e..68f49092 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "moment": "^2.23.0", "prop-types": "^15.6.1", "query-string": "^6.2.0", + "randomatic": "^3.1.1", "react": "^16.5.2", "react-bootstrap": "^0.32.4", "react-copy-to-clipboard": "^5.0.1", diff --git a/src/constants/GlobalConstants.js b/src/constants/GlobalConstants.js index 7c5c2cf3..b7c2f5c9 100644 --- a/src/constants/GlobalConstants.js +++ b/src/constants/GlobalConstants.js @@ -151,3 +151,6 @@ export const SCRYPT_ALGORITHM_PARAMS = { }; export const ALGORITHM_IV_BYTES_LENGTH = 16; export const STORE = 'keyval'; + +export const PATTERN_ID_MESSAGE = '*'; +export const LENGTH_ID_MESSAGE = 10; From be2c5aa6c8c6a11683b4a9403e070dbbbb4dfab6 Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Thu, 8 Aug 2019 16:32:37 +0300 Subject: [PATCH 07/21] [BRG-442] fix empty window extension, when sing transaction in popup (#7) * [BRG-442] fix signTransaction * [BRG-442] fix show incoming transaction in extension * [BRG-442] fix * [BRG-442] delete request if incorrect dataShow * [BRG-442] fix * [BRG-442] fix cancel request after failure transaction * [BRG-442] fix --- src/actions/SignActions.js | 26 +++++++++----- src/components/Require/index.jsx | 1 - src/constants/RouterConstants.js | 1 + src/containers/Send/ErrorTransaction.jsx | 29 +++++++++++---- src/containers/SignTransaction/index.jsx | 45 +++++++++++++++++++----- src/reducers/GlobalReducer.js | 4 +-- 6 files changed, 80 insertions(+), 26 deletions(-) diff --git a/src/actions/SignActions.js b/src/actions/SignActions.js index a55dd97d..c2855927 100644 --- a/src/actions/SignActions.js +++ b/src/actions/SignActions.js @@ -373,17 +373,15 @@ export const loadRequests = () => async (dispatch) => { const { pathname } = history.location; const requests = JSON.parse(JSON.stringify(echoService.getRequests())); - if (!requests.length) { return null; } - const dataToShow = await getFetchedData(requests[0].options); - dispatch(batchActions([ GlobalReducer.actions.set({ field: 'sign', value: new Map({ + loading: true, goTo: !NOT_RETURNED_PATHS.includes(pathname) ? pathname : null, transactions: new List(requests), }), @@ -397,15 +395,25 @@ export const loadRequests = () => async (dispatch) => { }), }, }), - GlobalReducer.actions.setIn({ - field: 'sign', - params: { - dataToShow: new Map(dataToShow), - }, - }), ])); + + const dataToShow = await getFetchedData(requests[0].options); + + dispatch(GlobalReducer.actions.setIn({ + field: 'sign', + params: { + dataToShow: new Map(dataToShow), + }, + })); } catch (err) { console.warn('Loading requests error', err); + } finally { + dispatch(GlobalReducer.actions.setIn({ + field: 'sign', + params: { + loading: false, + }, + })); } return null; diff --git a/src/components/Require/index.jsx b/src/components/Require/index.jsx index 8130db69..bbe9576c 100644 --- a/src/components/Require/index.jsx +++ b/src/components/Require/index.jsx @@ -156,5 +156,4 @@ export function required(Component) { connected: state.global.get('connected'), loading: state.global.get('loading'), }))(RequiredComponent); - } diff --git a/src/constants/RouterConstants.js b/src/constants/RouterConstants.js index ba939c4e..e7c77c71 100644 --- a/src/constants/RouterConstants.js +++ b/src/constants/RouterConstants.js @@ -36,6 +36,7 @@ export const SEND_PATH = '/send'; export const SUCCESS_SEND_PATH = '/send/success'; export const SUCCESS_SEND_INDEX_PATH = '/send/success?index=1'; export const ERROR_SEND_PATH = '/send/error'; +export const PARSE_ERROR_SEND_PATH = '/send/error?parse=1'; export const NETWORK_ERROR_SEND_PATH = '/send/error?network=1'; export const ACCOUNT_ERROR_SEND_PATH = '/send/error?account=1'; diff --git a/src/containers/Send/ErrorTransaction.jsx b/src/containers/Send/ErrorTransaction.jsx index 50f6a075..71234417 100644 --- a/src/containers/Send/ErrorTransaction.jsx +++ b/src/containers/Send/ErrorTransaction.jsx @@ -1,16 +1,17 @@ import React from 'react'; +import { connect } from 'react-redux'; import { Button } from 'semantic-ui-react'; import PropTypes from 'prop-types'; import query from 'query-string'; -import { closePopup, globals } from '../../actions/SignActions'; +import { cancelTransaction, closePopup, globals } from '../../actions/SignActions'; import { NOT_LOGGED_STATUS, DISCONNECT_STATUS, POPUP_WINDOW_TYPE } from '../../constants/GlobalConstants'; import { INDEX_PATH } from '../../constants/RouterConstants'; class ErrorTransaction extends React.PureComponent { - onClick(e, network, account) { + onClick(e, network, account, parse) { if (!this.props.isReturn) { closePopup(DISCONNECT_STATUS); } @@ -19,11 +20,12 @@ class ErrorTransaction extends React.PureComponent { closePopup(NOT_LOGGED_STATUS); } else if (network) { closePopup(DISCONNECT_STATUS); + } else if (parse) { + this.props.cancel(this.props.transaction.get('id')); } else { closePopup(); } - if (globals.WINDOW_TYPE === POPUP_WINDOW_TYPE) { this.props.history.goBack(); @@ -36,7 +38,7 @@ class ErrorTransaction extends React.PureComponent { } render() { - const { network, account } = query.parse(this.props.location.search); + const { network, account, parse } = query.parse(this.props.location.search); const { isReturn } = this.props; @@ -51,6 +53,14 @@ class ErrorTransaction extends React.PureComponent { ); } + if (parse) { + error = ( +
+
Transaction can't be processed +
+ ); + } + if (account) { error = (
You have to add account first
); } @@ -66,7 +76,7 @@ class ErrorTransaction extends React.PureComponent { +
+ + + + +
+

Subscribe switch network

+
+ +
+
+ + + +
+

Subscribe switch account

+
+ +
+
+ + -
+

Accounts

-
+
+
@@ -23,14 +51,14 @@

Transfer

id="transfer-fromAddress" name="transfer-fromAddress" placeholder="from" - value="1.2.73" + value="1.2.1204" /> Contract id="contract-registrar" name="contract-registrar" placeholder="registrar" - value="1.2.73" + value="1.2.1204" /> Contract name="contract-code" placeholder="code" style="width: 600px; height: 150px;" - >86be3f800000000000000000000000000000000000000000000000000000000000000001 + >a4136862000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000066461737361640000000000000000000000000000000000000000000000000000
@@ -114,7 +142,7 @@

Contract

- +

Create Contract

@@ -123,7 +151,7 @@

Create Contract

id="contactCreate-fromAddress" name="transfer-fromAddress" placeholder="from" - value="1.2.73" + value="1.2.1204" /> Create Contract name="contract-code" placeholder="code" style="width: 600px; height: 150px;" - >606060405260126006556000600755341561001957600080fd5b604051602080610dd283398101604052808051600160a060020a03331660008181526001602052604080822082905590805560048054600160a060020a0319168317905591935091507fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed94905160405180910390a2600555610d338061009f6000396000f3006060604052600436106101485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde03811461014d57806307da68f514610172578063095ea7b31461018757806313af4035146101bd57806318160ddd146101dc57806323b872dd146101ef578063313ce5671461021757806340c10f191461022a57806342966c681461024c5780635ac801fe1461026257806370a082311461027857806375f12b21146102975780637a9e5e4b146102aa5780638da5cb5b146102c957806395d89b41146102f85780639dc29fac1461030b578063a0712d681461032d578063a9059cbb14610343578063b753a98c14610365578063bb35783b14610387578063be9a6555146103af578063bf7e214f146103c2578063daea85c5146103d5578063dd62ed3e146103f4578063f2d5d56b14610419575b600080fd5b341561015857600080fd5b61016061043b565b60405190815260200160405180910390f35b341561017d57600080fd5b610185610441565b005b341561019257600080fd5b6101a9600160a060020a03600435166024356104e0565b604051901515815260200160405180910390f35b34156101c857600080fd5b610185600160a060020a036004351661050d565b34156101e757600080fd5b61016061058c565b34156101fa57600080fd5b6101a9600160a060020a0360043581169060243516604435610592565b341561022257600080fd5b610160610707565b341561023557600080fd5b610185600160a060020a036004351660243561070d565b341561025757600080fd5b6101856004356107d3565b341561026d57600080fd5b6101856004356107e0565b341561028357600080fd5b610160600160a060020a0360043516610806565b34156102a257600080fd5b6101a9610821565b34156102b557600080fd5b610185600160a060020a0360043516610831565b34156102d457600080fd5b6102dc6108b0565b604051600160a060020a03909116815260200160405180910390f35b341561030357600080fd5b6101606108bf565b341561031657600080fd5b610185600160a060020a03600435166024356108c5565b341561033857600080fd5b610185600435610a33565b341561034e57600080fd5b6101a9600160a060020a0360043516602435610a3d565b341561037057600080fd5b610185600160a060020a0360043516602435610a4a565b341561039257600080fd5b610185600160a060020a0360043581169060243516604435610a5a565b34156103ba57600080fd5b610185610a6b565b34156103cd57600080fd5b6102dc610b04565b34156103e057600080fd5b6101a9600160a060020a0360043516610b13565b34156103ff57600080fd5b610160600160a060020a0360043581169060243516610b39565b341561042457600080fd5b610185600160a060020a0360043516602435610b64565b60075481565b61045733600035600160e060020a031916610b6f565b151561046257600080fd5b600435602435808233600160a060020a031660008035600160e060020a0319169034903660405183815260406020820181815290820183905260608201848480828437820191505094505050505060405180910390a450506004805474ff0000000000000000000000000000000000000000191660a060020a179055565b60045460009060a060020a900460ff16156104fa57600080fd5b6105048383610c7b565b90505b92915050565b61052333600035600160e060020a031916610b6f565b151561052e57600080fd5b6004805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a038381169190911791829055167fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed9460405160405180910390a250565b60005490565b60045460009060a060020a900460ff16156105ac57600080fd5b33600160a060020a031684600160a060020a0316141580156105f65750600160a060020a038085166000908152600260209081526040808320339094168352929052205460001914155b1561065457600160a060020a038085166000908152600260209081526040808320339094168352929052205461062c9083610ce7565b600160a060020a03808616600090815260026020908152604080832033909416835292905220555b600160a060020a0384166000908152600160205260409020546106779083610ce7565b600160a060020a0380861660009081526001602052604080822093909355908516815220546106a69083610cf7565b600160a060020a03808516600081815260016020526040908190209390935591908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b60065481565b61072333600035600160e060020a031916610b6f565b151561072e57600080fd5b60045460a060020a900460ff161561074557600080fd5b600160a060020a0382166000908152600160205260409020546107689082610cf7565b600160a060020a0383166000908152600160205260408120919091555461078f9082610cf7565b600055600160a060020a0382167f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d41213968858260405190815260200160405180910390a25050565b6107dd33826108c5565b50565b6107f633600035600160e060020a031916610b6f565b151561080157600080fd5b600755565b600160a060020a031660009081526001602052604090205490565b60045460a060020a900460ff1681565b61084733600035600160e060020a031916610b6f565b151561085257600080fd5b6003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a038381169190911791829055167f1abebea81bfa2637f28358c371278fb15ede7ea8dd28d2e03b112ff6d936ada460405160405180910390a250565b600454600160a060020a031681565b60055481565b6108db33600035600160e060020a031916610b6f565b15156108e657600080fd5b60045460a060020a900460ff16156108fd57600080fd5b33600160a060020a031682600160a060020a0316141580156109475750600160a060020a038083166000908152600260209081526040808320339094168352929052205460001914155b156109a557600160a060020a038083166000908152600260209081526040808320339094168352929052205461097d9082610ce7565b600160a060020a03808416600090815260026020908152604080832033909416835292905220555b600160a060020a0382166000908152600160205260409020546109c89082610ce7565b600160a060020a038316600090815260016020526040812091909155546109ef9082610ce7565b600055600160a060020a0382167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca58260405190815260200160405180910390a25050565b6107dd338261070d565b6000610504338484610592565b610a55338383610592565b505050565b610a65838383610592565b50505050565b610a8133600035600160e060020a031916610b6f565b1515610a8c57600080fd5b600435602435808233600160a060020a031660008035600160e060020a0319169034903660405183815260406020820181815290820183905260608201848480828437820191505094505050505060405180910390a450506004805474ff000000000000000000000000000000000000000019169055565b600354600160a060020a031681565b60045460009060a060020a900460ff1615610b2d57600080fd5b61050782600019610c7b565b600160a060020a03918216600090815260026020908152604080832093909416825291909152205490565b610a55823383610592565b600030600160a060020a031683600160a060020a03161415610b9357506001610507565b600454600160a060020a0384811691161415610bb157506001610507565b600354600160a060020a03161515610bcb57506000610507565b600354600160a060020a031663b70096138430856000604051602001526040517c010000000000000000000000000000000000000000000000000000000063ffffffff8616028152600160a060020a039384166004820152919092166024820152600160e060020a03199091166044820152606401602060405180830381600087803b1515610c5957600080fd5b6102c65a03f11515610c6a57600080fd5b505050604051805190509050610507565b600160a060020a03338116600081815260026020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b8082038281111561050757600080fd5b8082018281101561050757600080fd00a165627a7a72305820c3b70a68c1ccfc4b88f478523cfc01b3108a40e2c6d0132d5b736b0c3034972800294d4b520000000000000000000000000000000000000000000000000000000000 + >606060405234156200001057600080fd5b604051620016d8380380620016d8833981016040528080519060200190919080518201919060200180519060200190919080518201919050505b83600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550836003819055508260009080519060200190620000ad9291906200012e565b508060019080519060200190620000c69291906200012e565b5081600260006101000a81548160ff021916908360ff16021790555033600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b50505050620001dd565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200017157805160ff1916838001178555620001a2565b82800160010185558215620001a2579182015b82811115620001a157825182559160200191906001019062000184565b5b509050620001b19190620001b5565b5090565b620001da91905b80821115620001d6576000816000905550600101620001bc565b5090565b90565b6114eb80620001ed6000396000f300606060405236156100d9576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100e2578063095ea7b31461017157806318160ddd146101cb57806323b872dd146101f4578063313ce5671461026d5780633bed33ce1461029c57806342966c68146102bf5780636623fc46146102fa57806370a08231146103355780638da5cb5b1461038257806395d89b41146103d7578063a9059cbb14610466578063cd4217c1146104a8578063d7a78db8146104f5578063dd62ed3e14610530575b6100e05b5b565b005b34156100ed57600080fd5b6100f561059c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101365780820151818401525b60208101905061011a565b50505050905090810190601f1680156101635780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561017c57600080fd5b6101b1600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061063a565b604051808215151515815260200191505060405180910390f35b34156101d657600080fd5b6101de6106d6565b6040518082815260200191505060405180910390f35b34156101ff57600080fd5b610253600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506106dc565b604051808215151515815260200191505060405180910390f35b341561027857600080fd5b610280610b01565b604051808260ff1660ff16815260200191505060405180910390f35b34156102a757600080fd5b6102bd6004808035906020019091905050610b14565b005b34156102ca57600080fd5b6102e06004808035906020019091905050610bd6565b604051808215151515815260200191505060405180910390f35b341561030557600080fd5b61031b6004808035906020019091905050610d29565b604051808215151515815260200191505060405180910390f35b341561034057600080fd5b61036c600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610ef6565b6040518082815260200191505060405180910390f35b341561038d57600080fd5b610395610f0e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156103e257600080fd5b6103ea610f34565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561042b5780820151818401525b60208101905061040f565b50505050905090810190601f1680156104585780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561047157600080fd5b6104a6600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610fd2565b005b34156104b357600080fd5b6104df600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611260565b6040518082815260200191505060405180910390f35b341561050057600080fd5b6105166004808035906020019091905050611278565b604051808215151515815260200191505060405180910390f35b341561053b57600080fd5b610586600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611445565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106325780601f1061060757610100808354040283529160200191610632565b820191906000526020600020905b81548152906001019060200180831161061557829003601f168201915b505050505081565b6000808211151561064a57600080fd5b81600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600190505b92915050565b60035481565b6000808373ffffffffffffffffffffffffffffffffffffffff16141561070157600080fd5b60008211151561071057600080fd5b81600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561075c57600080fd5b600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020540110156107e957600080fd5b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111561087257600080fd5b6108bb600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361146a565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610947600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611484565b600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a10600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361146a565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190505b9392505050565b600260009054906101000a900460ff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610b7057600080fd5b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f193505050501515610bd257600080fd5b5b50565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610c2457600080fd5b600082111515610c3357600080fd5b610c7c600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361146a565b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610ccb6003548361146a565b6003819055503373ffffffffffffffffffffffffffffffffffffffff167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5836040518082815260200191505060405180910390a2600190505b919050565b600081600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610d7757600080fd5b600082111515610d8657600080fd5b610dcf600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361146a565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e5b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611484565b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff167f2cfce4af01bcb9d6cf6c84ee1b7c491100b8695368264146a94d71e10a63083f836040518082815260200191505060405180910390a2600190505b919050565b60056020528060005260406000206000915090505481565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610fca5780601f10610f9f57610100808354040283529160200191610fca565b820191906000526020600020905b815481529060010190602001808311610fad57829003601f168201915b505050505081565b60008273ffffffffffffffffffffffffffffffffffffffff161415610ff657600080fd5b60008111151561100557600080fd5b80600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561105157600080fd5b600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205481600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020540110156110de57600080fd5b611127600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548261146a565b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506111b3600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482611484565b600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35b5050565b60066020528060005260406000206000915090505481565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156112c657600080fd5b6000821115156112d557600080fd5b61131e600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361146a565b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506113aa600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483611484565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff167ff97a274face0b5517365ad396b1fdba6f68bd3135ef603e44272adba3af5a1e0836040518082815260200191505060405180910390a2600190505b919050565b6007602052816000526040600020602052806000526040600020600091509150505481565b6000611478838311156114af565b81830390505b92915050565b60008082840190506114a484821015801561149f5750838210155b6114af565b8091505b5092915050565b8015156114bb57600080fd5b5b505600a165627a7a72305820082734e053ffbdf2a3195354a3210dff3723c239a1e76ae3be0936f6aed31bee0029000000000000000000000000000000000000000000a56fa5b99019a5c80000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000003424e4200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003424e420000000000000000000000000000000000000000000000000000000000
@@ -160,7 +188,7 @@

Create Contract

- +

Create account

@@ -169,7 +197,7 @@

Create account

id="createAccount-registrar" name="createAccount-registrar" placeholder="registrar" - value="1.2.73" + value="1.2.1204" /> Create account /> Create account placeholder="voitingAccount" value="1.2.5" /> - -
- -
- + +

Update account

@@ -228,14 +242,14 @@

Update account

id="updateAccount-registrar" name="createAccount-registrar" placeholder="registrar" - value="1.2.73" + value="1.2.1204" /> Update account />
- + +

Upgrade account

@@ -265,13 +280,14 @@

Upgrade account

id="upgradeAccount-registrar" name="upgradeAccount-registrar" placeholder="registrar" - value="1.2.73" + value="1.2.1204" />
- + +

Sign message

@@ -280,42 +296,95 @@

Sign message

id="signMessage-account" name="signMessage-account" placeholder="account" - value="1.2.37" + value="1.2.1204" />
+ + diff --git a/extension/background.js b/extension/background.js index c8c8bcc5..97891ca0 100644 --- a/extension/background.js +++ b/extension/background.js @@ -289,7 +289,13 @@ const onMessage = (request, sender, sendResponse) => { triggerPopup(INCOMING_CONNECTION_PATH, providerNotification); return true; } else if (request.method === 'getAccess') { - sendResponse({ id: request.id, status: processedOrigins[hostname] }); + const isAccess = processedOrigins[hostname]; + if (isAccess) { + sendResponse({ id: request.id, status: isAccess }); + } else { + sendResponse({ id: request.id, status: isAccess, error: { isAccess: false } }); + } + return true; } @@ -426,7 +432,6 @@ export const onResponse = (err, id, status) => { removeTransaction(id); - return null; } diff --git a/src/actions/GlobalActions.js b/src/actions/GlobalActions.js index 432452b0..d8305136 100644 --- a/src/actions/GlobalActions.js +++ b/src/actions/GlobalActions.js @@ -187,7 +187,8 @@ export const chooseProviderAccess = (id, status) => (dispatch) => { const emitter = echoService.getEmitter(); try { - emitter.emit('providerResponse', null, id, status); + const error = status ? null : { isAccess: false }; + emitter.emit('providerResponse', error, id, status); } catch (err) { dispatch(set('error', FormatHelper.formatError(err))); } diff --git a/src/actions/SignActions.js b/src/actions/SignActions.js index c2855927..ae6541f8 100644 --- a/src/actions/SignActions.js +++ b/src/actions/SignActions.js @@ -209,6 +209,8 @@ export const removeTransaction = (id, isClose) => async (dispatch, getState) => current: null, }, })); + + return; } const dataToShow = await getFetchedData(transactions.get(0).options); @@ -546,7 +548,7 @@ export const approve = (operations, id) => async (dispatch, getState) => { dispatch(removeTransaction(id)); - emitter.emit('response', `Error: ${err}`, id, ERROR_STATUS); + emitter.emit('response', err, id, ERROR_STATUS); emitter.emit('windowRequest', id, globals.WINDOW_TYPE); diff --git a/src/components/Require/index.jsx b/src/components/Require/index.jsx index bbe9576c..0bf3eded 100644 --- a/src/components/Require/index.jsx +++ b/src/components/Require/index.jsx @@ -117,7 +117,7 @@ export function required(Component) { return null; } - if (!isLogin && !(isProviderApproval || isSign || isSignMessage)) { + if (!isLogin && !isProviderApproval && !isSign && !isSignMessage) { return null; } diff --git a/src/constants/ErrorsConstants.js b/src/constants/ErrorsConstants.js index c352a6c2..078680b5 100644 --- a/src/constants/ErrorsConstants.js +++ b/src/constants/ErrorsConstants.js @@ -1,2 +1,2 @@ -export const SIGN_MEASSAGE_ERROR = 'You have to add account first'; +export const ERROR_ACTIVE_ACCOUNT = 'You have to add account first'; export const SIGN_MEASSAGE_CANCELED = 'Signature canceled'; diff --git a/src/containers/Send/ErrorTransaction.jsx b/src/containers/Send/ErrorTransaction.jsx index 71234417..e188e5bc 100644 --- a/src/containers/Send/ErrorTransaction.jsx +++ b/src/containers/Send/ErrorTransaction.jsx @@ -8,6 +8,7 @@ import { cancelTransaction, closePopup, globals } from '../../actions/SignAction import { NOT_LOGGED_STATUS, DISCONNECT_STATUS, POPUP_WINDOW_TYPE } from '../../constants/GlobalConstants'; import { INDEX_PATH } from '../../constants/RouterConstants'; +import { ERROR_ACTIVE_ACCOUNT } from '../../constants/ErrorsConstants'; class ErrorTransaction extends React.PureComponent { @@ -62,7 +63,7 @@ class ErrorTransaction extends React.PureComponent { } if (account) { - error = (
You have to add account first
); + error = (
{ERROR_ACTIVE_ACCOUNT}
); } return ( diff --git a/src/containers/SignMessage/index.jsx b/src/containers/SignMessage/index.jsx index c0fd3b26..aee99b34 100644 --- a/src/containers/SignMessage/index.jsx +++ b/src/containers/SignMessage/index.jsx @@ -5,7 +5,7 @@ import { connect } from 'react-redux'; import CustomScroll from 'react-custom-scroll'; import _ from 'lodash'; -import { SIGN_MEASSAGE_ERROR } from '../../constants/ErrorsConstants'; +import { ERROR_ACTIVE_ACCOUNT } from '../../constants/ErrorsConstants'; import { chooseSignMessageResponse } from '../../actions/GlobalActions'; import { INDEX_PATH } from '../../constants/RouterConstants'; @@ -41,7 +41,7 @@ class Sign extends React.Component { if (!accounts.get(network).size || typeof signerIndex === 'undefined') { this.setState({ - accountError: SIGN_MEASSAGE_ERROR, + accountError: ERROR_ACTIVE_ACCOUNT, }); return; } diff --git a/src/containers/SignTransaction/index.jsx b/src/containers/SignTransaction/index.jsx index 45e9ac65..19dbfd53 100644 --- a/src/containers/SignTransaction/index.jsx +++ b/src/containers/SignTransaction/index.jsx @@ -14,7 +14,7 @@ import { globals, } from '../../actions/SignActions'; -import { INDEX_PATH, NETWORK_ERROR_SEND_PATH, PARSE_ERROR_SEND_PATH } from '../../constants/RouterConstants'; +import { ACCOUNT_ERROR_SEND_PATH, INDEX_PATH, NETWORK_ERROR_SEND_PATH, PARSE_ERROR_SEND_PATH } from '../../constants/RouterConstants'; import { POPUP_WINDOW_TYPE } from '../../constants/GlobalConstants'; import { operationFields, operationKeys, operationTypes } from '../../constants/OperationConstants'; @@ -44,8 +44,6 @@ class SignTransaction extends React.Component { return null; } - this.loadInfo(); - return null; } @@ -155,7 +153,14 @@ class SignTransaction extends React.Component { const account = this.props.accounts .find((value) => options[0][1][operationKeys[type]] === value.id); + if (!account) { + this.props.history.push(ACCOUNT_ERROR_SEND_PATH); + return null; + } + this.props.set('signAccount', new Map(account)); + + return null; } render() { From 7d73b0364e254d9e6f97d709891bfc44b2cbe62a Mon Sep 17 00:00:00 2001 From: Anastasia Rudenko Date: Thu, 8 Aug 2019 16:47:44 +0300 Subject: [PATCH 09/21] up version v1.10 (#10) --- config/manifest.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/manifest.json b/config/manifest.json index 7aec3b52..ae538d7c 100644 --- a/config/manifest.json +++ b/config/manifest.json @@ -18,7 +18,7 @@ "96": "images/96.png", "128": "images/128.png" }, - "version": "1.9.4", + "version": "1.10.0", "background": { "scripts": [ "background.js" diff --git a/package.json b/package.json index 68f49092..81b1e7b4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "echo-bridge", "description": "The bridge between your web site and the Echo", - "version": "1.9.4", + "version": "1.10.0", "scripts": { "start": "cross-env NODE_ENV=local webpack-dev-server --mode development --progress --colors --history-api-fallback --hot --inline --port 8081", "build": "cross-env NODE_ENV=production webpack --progress --display-error-details --colors --mode production", From 4297f47f98b899ca7fb2cfb4fd7d9124e66f800b Mon Sep 17 00:00:00 2001 From: Anastasia Rudenko Date: Fri, 16 Aug 2019 21:48:37 +0300 Subject: [PATCH 10/21] [BRG-447] move to Echo 0.9 (#12) --- examples/examples.md | 6 +- examples/index.html | 57 +------ package.json | 2 +- src/actions/BalanceActions.js | 4 +- src/actions/GlobalActions.js | 2 +- src/actions/SignActions.js | 2 +- src/constants/OperationConstants.js | 25 +-- src/constants/TransactionConstants.js | 192 +++-------------------- src/helpers/ValidateTransactionHelper.js | 2 +- 9 files changed, 44 insertions(+), 248 deletions(-) diff --git a/examples/examples.md b/examples/examples.md index 7bf7e520..a544bc75 100644 --- a/examples/examples.md +++ b/examples/examples.md @@ -7,7 +7,7 @@ const tr = window.echojslib.echo.createTransaction(); const bytecode = '606060405260126006556000600755341561001957600080fd5b604051602080610dd283398101604052808051600160a060020a03331660008181526001602052604080822082905590805560048054600160a060020a0319168317905591935091507fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed94905160405180910390a2600555610d338061009f6000396000f3006060604052600436106101485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde03811461014d57806307da68f514610172578063095ea7b31461018757806313af4035146101bd57806318160ddd146101dc57806323b872dd146101ef578063313ce5671461021757806340c10f191461022a57806342966c681461024c5780635ac801fe1461026257806370a082311461027857806375f12b21146102975780637a9e5e4b146102aa5780638da5cb5b146102c957806395d89b41146102f85780639dc29fac1461030b578063a0712d681461032d578063a9059cbb14610343578063b753a98c14610365578063bb35783b14610387578063be9a6555146103af578063bf7e214f146103c2578063daea85c5146103d5578063dd62ed3e146103f4578063f2d5d56b14610419575b600080fd5b341561015857600080fd5b61016061043b565b60405190815260200160405180910390f35b341561017d57600080fd5b610185610441565b005b341561019257600080fd5b6101a9600160a060020a03600435166024356104e0565b604051901515815260200160405180910390f35b34156101c857600080fd5b610185600160a060020a036004351661050d565b34156101e757600080fd5b61016061058c565b34156101fa57600080fd5b6101a9600160a060020a0360043581169060243516604435610592565b341561022257600080fd5b610160610707565b341561023557600080fd5b610185600160a060020a036004351660243561070d565b341561025757600080fd5b6101856004356107d3565b341561026d57600080fd5b6101856004356107e0565b341561028357600080fd5b610160600160a060020a0360043516610806565b34156102a257600080fd5b6101a9610821565b34156102b557600080fd5b610185600160a060020a0360043516610831565b34156102d457600080fd5b6102dc6108b0565b604051600160a060020a03909116815260200160405180910390f35b341561030357600080fd5b6101606108bf565b341561031657600080fd5b610185600160a060020a03600435166024356108c5565b341561033857600080fd5b610185600435610a33565b341561034e57600080fd5b6101a9600160a060020a0360043516602435610a3d565b341561037057600080fd5b610185600160a060020a0360043516602435610a4a565b341561039257600080fd5b610185600160a060020a0360043581169060243516604435610a5a565b34156103ba57600080fd5b610185610a6b565b34156103cd57600080fd5b6102dc610b04565b34156103e057600080fd5b6101a9600160a060020a0360043516610b13565b34156103ff57600080fd5b610160600160a060020a0360043581169060243516610b39565b341561042457600080fd5b610185600160a060020a0360043516602435610b64565b60075481565b61045733600035600160e060020a031916610b6f565b151561046257600080fd5b600435602435808233600160a060020a031660008035600160e060020a0319169034903660405183815260406020820181815290820183905260608201848480828437820191505094505050505060405180910390a450506004805474ff0000000000000000000000000000000000000000191660a060020a179055565b60045460009060a060020a900460ff16156104fa57600080fd5b6105048383610c7b565b90505b92915050565b61052333600035600160e060020a031916610b6f565b151561052e57600080fd5b6004805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a038381169190911791829055167fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed9460405160405180910390a250565b60005490565b60045460009060a060020a900460ff16156105ac57600080fd5b33600160a060020a031684600160a060020a0316141580156105f65750600160a060020a038085166000908152600260209081526040808320339094168352929052205460001914155b1561065457600160a060020a038085166000908152600260209081526040808320339094168352929052205461062c9083610ce7565b600160a060020a03808616600090815260026020908152604080832033909416835292905220555b600160a060020a0384166000908152600160205260409020546106779083610ce7565b600160a060020a0380861660009081526001602052604080822093909355908516815220546106a69083610cf7565b600160a060020a03808516600081815260016020526040908190209390935591908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b60065481565b61072333600035600160e060020a031916610b6f565b151561072e57600080fd5b60045460a060020a900460ff161561074557600080fd5b600160a060020a0382166000908152600160205260409020546107689082610cf7565b600160a060020a0383166000908152600160205260408120919091555461078f9082610cf7565b600055600160a060020a0382167f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d41213968858260405190815260200160405180910390a25050565b6107dd33826108c5565b50565b6107f633600035600160e060020a031916610b6f565b151561080157600080fd5b600755565b600160a060020a031660009081526001602052604090205490565b60045460a060020a900460ff1681565b61084733600035600160e060020a031916610b6f565b151561085257600080fd5b6003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a038381169190911791829055167f1abebea81bfa2637f28358c371278fb15ede7ea8dd28d2e03b112ff6d936ada460405160405180910390a250565b600454600160a060020a031681565b60055481565b6108db33600035600160e060020a031916610b6f565b15156108e657600080fd5b60045460a060020a900460ff16156108fd57600080fd5b33600160a060020a031682600160a060020a0316141580156109475750600160a060020a038083166000908152600260209081526040808320339094168352929052205460001914155b156109a557600160a060020a038083166000908152600260209081526040808320339094168352929052205461097d9082610ce7565b600160a060020a03808416600090815260026020908152604080832033909416835292905220555b600160a060020a0382166000908152600160205260409020546109c89082610ce7565b600160a060020a038316600090815260016020526040812091909155546109ef9082610ce7565b600055600160a060020a0382167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca58260405190815260200160405180910390a25050565b6107dd338261070d565b6000610504338484610592565b610a55338383610592565b505050565b610a65838383610592565b50505050565b610a8133600035600160e060020a031916610b6f565b1515610a8c57600080fd5b600435602435808233600160a060020a031660008035600160e060020a0319169034903660405183815260406020820181815290820183905260608201848480828437820191505094505050505060405180910390a450506004805474ff000000000000000000000000000000000000000019169055565b600354600160a060020a031681565b60045460009060a060020a900460ff1615610b2d57600080fd5b61050782600019610c7b565b600160a060020a03918216600090815260026020908152604080832093909416825291909152205490565b610a55823383610592565b600030600160a060020a031683600160a060020a03161415610b9357506001610507565b600454600160a060020a0384811691161415610bb157506001610507565b600354600160a060020a03161515610bcb57506000610507565b600354600160a060020a031663b70096138430856000604051602001526040517c010000000000000000000000000000000000000000000000000000000063ffffffff8616028152600160a060020a039384166004820152919092166024820152600160e060020a03199091166044820152606401602060405180830381600087803b1515610c5957600080fd5b6102c65a03f11515610c6a57600080fd5b505050604051805190509050610507565b600160a060020a03338116600081815260026020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b8082038281111561050757600080fd5b8082018281101561050757600080fd00a165627a7a72305820c3b70a68c1ccfc4b88f478523cfc01b3108a40e2c6d0132d5b736b0c3034972800294d4b520000000000000000000000000000000000000000000000000000000000'; -tr.addOperation(echojslib.constants.OPERATIONS_IDS.CREATE_CONTRACT, { +tr.addOperation(echojslib.constants.OPERATIONS_IDS.CONTRACT_CREATE, { code: bytecode, eth_accuracy: false, registrar: '1.2.1', @@ -24,10 +24,10 @@ await tr.broadcast(); ```javascript const tr = window.echojslib.echo.createTransaction(); -tr.addOperation(echojslib.constants.OPERATIONS_IDS.CALL_CONTRACT, { +tr.addOperation(echojslib.constants.OPERATIONS_IDS.CONTRACT_CALL, { registrar: '1.2.1', code: '86be3f80' + '0000000000000000000000000000000000000000000000000000000000000001', // setVariable(uint256) - callee: '1.14.1', // contract id + callee: '1.9.1', // contract id value: { asset_id: '1.3.0', amount: 0 }, }); diff --git a/examples/index.html b/examples/index.html index 14dc0754..a28654e4 100644 --- a/examples/index.html +++ b/examples/index.html @@ -104,7 +104,7 @@

Contract

id="contract-receiver" name="contract-receiver" placeholder="callee" - value="1.14.442" + value="1.9.442" /> Update account - -
-

Upgrade account

-
- - -
-
-
-

Sign message

@@ -439,7 +423,7 @@

Sign message

$("#contract-click").click(function(e) { if (!isAccess) return; const transaction = { - type: window.echojslib.constants.OPERATIONS_IDS.CALL_CONTRACT, + type: window.echojslib.constants.OPERATIONS_IDS.CONTRACT_CALL, registrar: jQuery("#contract-registrar")[0].value, code: jQuery("#contract-code")[0].value, value: { @@ -461,7 +445,7 @@

Sign message

const tr = window.echojslib.echo.createTransaction(); - tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.CALL_CONTRACT, { + tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.CONTRACT_CALL, { registrar: transaction.registrar, value: { asset_id: transaction.value.asset_id, @@ -494,7 +478,7 @@

Sign message

$("#contactCreate-click").click(function (e) { if (!isAccess) return; const transaction = { - type: window.echojslib.constants.OPERATIONS_IDS.CREATE_CONTRACT, + type: window.echojslib.constants.OPERATIONS_IDS.CONTRACT_CREATE, registrar: jQuery("#contactCreate-fromAddress")[0].value, code: jQuery("#contactCreate-code")[0].value, value: { @@ -512,7 +496,7 @@

Sign message

const tr = window.echojslib.echo.createTransaction(); - tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.CREATE_CONTRACT, { + tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.CONTRACT_CREATE, { registrar: transaction.registrar, value: { amount: transaction.value.amount, @@ -629,37 +613,6 @@

Sign message

}); }); - $("#upgradeAccount-click").click(function (e) { - if (!isAccess) return; - const transaction = { - account_to_upgrade: jQuery("#upgradeAccount-registrar")[0].value, - upgrade_to_lifetime_member: true - }; - - const tr = window.echojslib.echo.createTransaction(); - - tr.addOperation(window.echojslib.constants.OPERATIONS_IDS.ACCOUNT_UPGRADE, transaction); - - tr.signWithBridge() - .then(result => { - result.broadcast() - .then((res) => { - jQuery("#upgradeAccount-info").html( - `

RESULT: ${JSON.stringify(res)}

` - ); - }).catch(err => { - jQuery("#upgradeAccount-info").html( - `

ERROR: ${JSON.stringify(err)}

` - ); - }); - }) - .catch(err => { - jQuery("#upgradeAccount-info").html( - `

ERROR: ${JSON.stringify(err)}

` - ); - }); - }); - $("#signMessage-click").click(function (e) { if (!isAccess) return; echojslib.extension.proofOfAuthority('This is example message!', jQuery("#signMessage-account")[0].value) diff --git a/package.json b/package.json index 81b1e7b4..c8ba75f6 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "classnames": "^2.2.6", "config": "^1.30.0", "crypto-random-string": "^1.0.0", - "echojs-lib": "^1.4.0", + "echojs-lib": "^1.6.0-rc.2", "events": "^3.0.0", "file-loader": "^1.1.11", "focus-trap-react": "^4.0.1", diff --git a/src/actions/BalanceActions.js b/src/actions/BalanceActions.js index 1bac908e..34efb67b 100644 --- a/src/actions/BalanceActions.js +++ b/src/actions/BalanceActions.js @@ -264,7 +264,7 @@ export const setFeeFormValue = () => async (dispatch, getState) => { }, callee: receiver, registrar: fromAccount, - type: OPERATIONS_IDS.CALL_CONTRACT, + type: OPERATIONS_IDS.CONTRACT_CALL, value: { amount: 0, asset_id: assets.get(balances.getIn([selectedFeeBalance, 'asset_type'])), @@ -376,7 +376,7 @@ export const send = () => async (dispatch, getState) => { }, callee: receiver, registrar: fromAccount, - type: OPERATIONS_IDS.CALL_CONTRACT, + type: OPERATIONS_IDS.CONTRACT_CALL, value: { asset_id: coreAsset, amount: 0, diff --git a/src/actions/GlobalActions.js b/src/actions/GlobalActions.js index d8305136..31e56f28 100644 --- a/src/actions/GlobalActions.js +++ b/src/actions/GlobalActions.js @@ -446,7 +446,7 @@ export const loadInfo = () => async (dispatch, getState) => { Object.entries(tokens).forEach(([accountId, tokensArray]) => { tokensArray.forEach((id) => { - stateTokens = stateTokens.setIn([accountId, `1.14.${id}`], new Map({})); + stateTokens = stateTokens.setIn([accountId, `1.9.${id}`], new Map({})); }); }); diff --git a/src/actions/SignActions.js b/src/actions/SignActions.js index ae6541f8..1a6dd144 100644 --- a/src/actions/SignActions.js +++ b/src/actions/SignActions.js @@ -48,7 +48,7 @@ const getOperationFee = async (type, transaction) => { let tr = echoService.getChainLib().createTransaction(); - if (type === OPERATIONS_IDS.CALL_CONTRACT) { + if (type === OPERATIONS_IDS.CONTRACT_CALL) { options.fee = undefined; } diff --git a/src/constants/OperationConstants.js b/src/constants/OperationConstants.js index bdcb4867..1540b07d 100644 --- a/src/constants/OperationConstants.js +++ b/src/constants/OperationConstants.js @@ -76,18 +76,6 @@ export const operationFields = { field: 'key_auths', }, }, - upgradeAccount: { - account_to_upgrade: { - type: 'account_id', - }, - fee: { - type: 'asset_object', - hasProperties: 'asset_id', - }, - upgrade_to_lifetime_member: { - field: 'string', - }, - }, }; export const operationFieldsSend = { @@ -111,7 +99,7 @@ export const operationFieldsSend = { hasProperties: ['amount', 'asset_id'], }, }, - [OPERATIONS_IDS.CALL_CONTRACT]: { + [OPERATIONS_IDS.CONTRACT_CALL]: { fee: { type: 'asset_object', required: false, @@ -143,8 +131,7 @@ export const operationKeys = { createContract: 'registrar', createAccount: 'registrar', updateAccount: 'account', - upgradeAccount: 'account_to_upgrade', - [OPERATIONS_IDS.CALL_CONTRACT]: 'registrar', + [OPERATIONS_IDS.CONTRACT_CALL]: 'registrar', }; export const operationTypes = { @@ -154,11 +141,11 @@ export const operationTypes = { }, contract: { name: 'Contract call', - code: OPERATIONS_IDS.CALL_CONTRACT, + code: OPERATIONS_IDS.CONTRACT_CALL, }, createContract: { name: 'Contract create', - code: OPERATIONS_IDS.CREATE_CONTRACT, + code: OPERATIONS_IDS.CONTRACT_CREATE, }, createAccount: { name: 'Account create', @@ -168,10 +155,6 @@ export const operationTypes = { name: 'Update account', code: OPERATIONS_IDS.ACCOUNT_UPDATE, }, - upgradeAccount: { - name: 'Upgrade account', - code: OPERATIONS_IDS.ACCOUNT_UPGRADE, - }, }; export const historyOperations = [ diff --git a/src/constants/TransactionConstants.js b/src/constants/TransactionConstants.js index c114c863..cd2e1d28 100644 --- a/src/constants/TransactionConstants.js +++ b/src/constants/TransactionConstants.js @@ -11,46 +11,6 @@ export default { asset: 'amount.asset_id', }, }, - limit_order_create: { - value: OPERATIONS_IDS.LIMIT_ORDER_CREATE, - name: 'Place order', - options: { - from: 'seller', - subject: null, - value: 'amount_to_sell.amount', - asset: 'amount_to_sell.asset_id', - }, - }, - limit_order_cancel: { - value: OPERATIONS_IDS.LIMIT_ORDER_CANCEL, - name: 'Cancel order', - options: { - from: 'fee_paying_account', - subject: ['order', 'name'], - value: null, - asset: null, - }, - }, - call_order_update: { - value: OPERATIONS_IDS.CALL_ORDER_UPDATE, - name: 'Update margin', - options: { - from: 'funding_account', - subject: null, - value: null, - asset: null, - }, - }, - fill_order: { - value: OPERATIONS_IDS.FILL_ORDER, - name: 'Fill order', - options: { - from: 'account_id', - subject: ['order_id', null], - value: 'pays.amount', - asset: 'pays.asset_id', - }, - }, account_create: { value: OPERATIONS_IDS.ACCOUNT_CREATE, name: 'Account created', @@ -81,16 +41,6 @@ export default { asset: null, }, }, - account_upgrade: { - value: OPERATIONS_IDS.ACCOUNT_UPGRADE, - name: 'Upgrade Account', - options: { - from: 'account_to_upgrade', - subject: null, - value: null, - asset: null, - }, - }, account_transfer: { value: OPERATIONS_IDS.ACCOUNT_TRANSFER, name: 'Transfer Account', @@ -171,26 +121,6 @@ export default { asset: 'asset_id', }, }, - asset_settle: { - value: OPERATIONS_IDS.ASSET_SETTLE, - name: 'Asset settlement', - options: { - from: 'account', - subject: null, - value: 'amount.amount', - asset: 'amount.asset_id', - }, - }, - asset_global_settle: { - value: OPERATIONS_IDS.ASSET_GLOBAL_SETTLE, - name: 'Global asset settlement', - options: { - from: 'issuer', - subject: null, - value: 'settle_price', - asset: 'asset_to_settle', - }, - }, asset_publish_feed: { value: OPERATIONS_IDS.ASSET_PUBLISH_FEED, name: 'Publish feed', @@ -231,46 +161,6 @@ export default { asset: null, }, }, - withdraw_permission_create: { - value: OPERATIONS_IDS.WITHDRAW_PERMISSION_CREATE, - name: 'Create withdrawal permission', - options: { - from: 'withdraw_from_account', - subject: null, - value: null, - asset: null, - }, - }, - withdraw_permission_update: { - value: OPERATIONS_IDS.WITHDRAW_PERMISSION_UPDATE, - name: 'Update withdrawal permission', - options: { - from: 'withdraw_from_account', - subject: null, - value: null, - asset: null, - }, - }, - withdraw_permission_claim: { - value: OPERATIONS_IDS.WITHDRAW_PERMISSION_CLAIM, - name: 'Claim withdrawal permission', - options: { - from: 'withdraw_from_account', - subject: ['withdraw_to_account', 'name'], - value: 'amount_to_withdraw.amount', - asset: 'amount_to_withdraw.asset_id', - }, - }, - withdraw_permission_delete: { - value: OPERATIONS_IDS.WITHDRAW_PERMISSION_DELETE, - name: 'Delete withdrawal permission', - options: { - from: 'withdraw_from_account', - subject: null, - value: null, - asset: null, - }, - }, committee_member_create: { value: OPERATIONS_IDS.COMMITTEE_MEMBER_CREATE, name: 'Create committee member', @@ -321,26 +211,6 @@ export default { asset: 'amount.asset_id', }, }, - custom: { - value: OPERATIONS_IDS.CUSTOM, - name: 'Custom', - options: { - from: 'payer', - subject: null, - value: null, - asset: null, - }, - }, - assert: { - value: OPERATIONS_IDS.ASSERT, - name: 'Assert operation', - options: { - from: 'fee_paying_account', - subject: null, - value: null, - asset: null, - }, - }, balance_claim: { value: OPERATIONS_IDS.BALANCE_CLAIM, name: 'Claim balance', @@ -361,16 +231,6 @@ export default { asset: 'amount.asset_id', }, }, - asset_settle_cancel: { - value: OPERATIONS_IDS.ASSET_SETTLE_CANCEL, - name: 'Cancel asset settlement', - options: { - from: 'account', - subject: null, - value: 'amount.amount', - asset: 'amount.asset_id', - }, - }, asset_claim_fees: { value: OPERATIONS_IDS.ASSET_CLAIM_FEES, name: 'Claim asset fees', @@ -382,7 +242,7 @@ export default { }, }, contract: { - value: OPERATIONS_IDS.CREATE_CONTRACT, + value: OPERATIONS_IDS.CONTRACT_CREATE, name: 'Contract created', options: { from: 'registrar', @@ -391,9 +251,9 @@ export default { asset: 'value.asset_id', }, }, - call_contract: { - value: OPERATIONS_IDS.CALL_CONTRACT, - name: 'Call contract', + contract_call: { + value: OPERATIONS_IDS.CONTRACT_CALL, + name: 'Contract call', options: { from: 'registrar', subject: null, @@ -412,7 +272,7 @@ export default { }, }, change_sidechain_config: { - value: OPERATIONS_IDS.CHANGE_SIDECHAIN_CONFIG, + value: OPERATIONS_IDS.SIDECHAIN_CHANGE_CONFIG, name: 'Change sidechain config', options: { from: null, @@ -441,9 +301,9 @@ export default { asset: 'amount.asset_id', }, }, - generate_eth_address: { - value: OPERATIONS_IDS.GENERATE_ETH_ADDRESS, - name: 'Generate eth address', + sidechain_eth_create_address: { + value: OPERATIONS_IDS.SIDECHAIN_ETH_CREATE_ADDRESS, + name: 'Sidechain eth create address', options: { from: 'account', subject: null, @@ -451,9 +311,9 @@ export default { asset: null, }, }, - create_eth_address: { - value: OPERATIONS_IDS.CREATE_ETH_ADDRESS, - name: 'Create eth address', + sidechain_eth_approve_address: { + value: OPERATIONS_IDS.SIDECHAIN_ETH_APPROVE_ADDRESS, + name: 'Sidechain eth approve address', options: { from: 'account', subject: null, @@ -461,9 +321,9 @@ export default { asset: null, }, }, - deposit_eth: { - value: OPERATIONS_IDS.DEPOSIT_ETH, - name: 'Deposit eth', + sidechain_eth_deposit: { + value: OPERATIONS_IDS.SIDECHAIN_ETH_DEPOSIT, + name: 'Sidechain eth deposit', options: { from: 'committee_member_id', subject: ['account', 'name'], @@ -471,9 +331,9 @@ export default { asset: null, }, }, - withdraw_eth: { - value: OPERATIONS_IDS.WITHDRAW_ETH, - name: 'Withdraw eth', + sidechain_eth_withdraw: { + value: OPERATIONS_IDS.SIDECHAIN_ETH_WITHDRAW, + name: 'Sidechain eth withdraw', options: { from: 'account', subject: ['eth_addr'], @@ -481,9 +341,9 @@ export default { asset: null, }, }, - approve_withdraw_eth: { - value: OPERATIONS_IDS.APPROVE_WITHDRAW_ETH, - name: 'Approve withdraw eth', + sidechain_eth_approve_withdraw: { + value: OPERATIONS_IDS.SIDECHAIN_ETH_APPROVE_WITHDRAW, + name: 'Sidechain eth approve withdraw', options: { from: 'committee_member_id', subject: ['withdraw_id'], @@ -512,7 +372,7 @@ export default { }, }, sidechain_issue: { - value: OPERATIONS_IDS.SIDECHAIN_ISSUE, + value: OPERATIONS_IDS.SIDECHAIN_ETH_ISSUE, name: 'Sidechain issue', options: { from: 'account', @@ -522,7 +382,7 @@ export default { }, }, sidechain_burn: { - value: OPERATIONS_IDS.SIDECHAIN_BURN, + value: OPERATIONS_IDS.SIDECHAIN_ETH_BURN, name: 'Sidechain burn', options: { from: 'account', @@ -532,7 +392,7 @@ export default { }, }, register_erc20_token: { - value: OPERATIONS_IDS.REGISTER_ERC20_TOKEN, + value: OPERATIONS_IDS.SIDECHAIN_ERC20_REGISTER_TOKEN, name: 'Register ERC20 token', options: { from: 'account', @@ -542,7 +402,7 @@ export default { }, }, deposit_erc20_token: { - value: OPERATIONS_IDS.DEPOSIT_ERC20_TOKEN, + value: OPERATIONS_IDS.SIDECHAIN_ERC20_DEPOSIT_TOKEN, name: 'Deposit ERC20 token', options: { from: 'account', @@ -552,7 +412,7 @@ export default { }, }, withdraw_erc20_token: { - value: OPERATIONS_IDS.WITHDRAW_ERC20_TOKEN, + value: OPERATIONS_IDS.SIDECHAIN_ERC20_WITHDRAW_TOKEN, name: 'Withdraw ERC20 token', options: { from: 'account', @@ -562,7 +422,7 @@ export default { }, }, approve_erc20_token_withdraw: { - value: OPERATIONS_IDS.APPROVE_ERC20_TOKEN_WITHDRAW, + value: OPERATIONS_IDS.SIDECHAIN_ERC20_APPROVE_TOKEN_WITHDRAW, name: 'Approve ERC20 token withdraw', options: { from: 'account', diff --git a/src/helpers/ValidateTransactionHelper.js b/src/helpers/ValidateTransactionHelper.js index 1baa3863..86a124fe 100644 --- a/src/helpers/ValidateTransactionHelper.js +++ b/src/helpers/ValidateTransactionHelper.js @@ -6,7 +6,7 @@ class ValidateTransactionHelper { id = id.split('.'); - if (id.length !== 3 || parseInt(id[2], 10).toString() !== id[2] || id.splice(0, 2).join('.') !== '1.14') { + if (id.length !== 3 || parseInt(id[2], 10).toString() !== id[2] || id.splice(0, 2).join('.') !== '1.9') { return 'Invalid contract ID'; } From 72ddb1ed6ad9745ee7e6099531ad272aad1b1661 Mon Sep 17 00:00:00 2001 From: Anastasia Rudenko Date: Fri, 16 Aug 2019 21:53:55 +0300 Subject: [PATCH 11/21] up version v1.10.1 (#13) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c8ba75f6..243cee30 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "echo-bridge", "description": "The bridge between your web site and the Echo", - "version": "1.10.0", + "version": "1.10.1", "scripts": { "start": "cross-env NODE_ENV=local webpack-dev-server --mode development --progress --colors --history-api-fallback --hot --inline --port 8081", "build": "cross-env NODE_ENV=production webpack --progress --display-error-details --colors --mode production", From 1fd2ac6e7c1af52e5b4a605a01164d340e6bb1f1 Mon Sep 17 00:00:00 2001 From: Pulyak Viktor Date: Sat, 17 Aug 2019 20:16:15 +0300 Subject: [PATCH 12/21] Added uploading artifacts to release (#15) --- .gitlab-ci.yml | 2 ++ .travis.yml | 29 +++++++++++++++++++++-------- package.json | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 353af18b..4df5fd08 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,5 +14,7 @@ build.publish: - 'curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -H "Content-Length: 0" -X POST -v "https://www.googleapis.com/chromewebstore/v1.1/items/${CHROME_APP_ID}/publish?publishTarget=default"' only: - tags + except: + - /^.*rc.*$/ tags: - docker diff --git a/.travis.yml b/.travis.yml index ccb5143b..84e503f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,14 +21,27 @@ jobs: if: branch IN (develop, master) AND type = pull_request script: npm run test +# - stage: build +# name: "Build Artifacts" +# if: (branch = master OR branch = develop) AND type = push +# addons: +# artifacts: +# working_dir: build/zip/ +# paths: +# - echo_bridge.zip +# script: +# - npm run build-ext +# - "echo \"Download URL: https://${ARTIFACTS_BUCKET}.s3.amazonaws.com/echoprotocol/bridge-extension/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/echo_bridge.zip\"" + - stage: build - name: "Build Artifacts" - if: (branch = master OR tag IS present) AND type = push - addons: - artifacts: - working_dir: build/zip/ - paths: - - echo_bridge.zip + name: "Build Tag Artifacts" + if: tag IS present script: - npm run build-ext - - "echo \"Download URL: https://${ARTIFACTS_BUCKET}.s3.amazonaws.com/echoprotocol/bridge-extension/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/echo_bridge.zip\"" + deploy: + provider: releases + api_key: $GITHUB_OAUTH_TOKEN + file: build/zip/echo_bridge.zip + skip_cleanup: true + on: + tags: true diff --git a/package.json b/package.json index 243cee30..8cd0de0d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "echo-bridge", "description": "The bridge between your web site and the Echo", - "version": "1.10.1", + "version": "1.10.1-rc.1", "scripts": { "start": "cross-env NODE_ENV=local webpack-dev-server --mode development --progress --colors --history-api-fallback --hot --inline --port 8081", "build": "cross-env NODE_ENV=production webpack --progress --display-error-details --colors --mode production", From 0168f21ba48167f08e86dba56beb636d82839f02 Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Mon, 26 Aug 2019 11:23:16 +0300 Subject: [PATCH 13/21] [BRG-454] fix redirect aftre logout (#19) --- src/actions/GlobalActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/GlobalActions.js b/src/actions/GlobalActions.js index 31e56f28..64da5887 100644 --- a/src/actions/GlobalActions.js +++ b/src/actions/GlobalActions.js @@ -377,7 +377,7 @@ export const onLogout = (name) => async (dispatch, getState) => { await dispatch(initAccount(accounts.getIn([networkName, 0]))); emitter.emit('activeAccountResponse', accounts.getIn([networkName, 0])); - history.push(CREATE_ACCOUNT_PATH); + history.push(INDEX_PATH); } catch (err) { dispatch(set('error', FormatHelper.formatError(err))); } From cf4ed061be3bdd60387d477474135f2c8c575581 Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Mon, 26 Aug 2019 15:51:29 +0300 Subject: [PATCH 14/21] [BRG-449] fix account create in example.page (#20) --- examples/index.html | 2 -- src/containers/SignTransaction/index.jsx | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/index.html b/examples/index.html index a28654e4..7fd719e8 100644 --- a/examples/index.html +++ b/examples/index.html @@ -530,8 +530,6 @@

Sign message

if (!isAccess) return; const transaction = { registrar: jQuery("#createAccount-registrar")[0].value, - referrer: jQuery("#createAccount-registrar")[0].value, - referrer_percent: 0, echorand_key: jQuery("#createAccount-echorandKey")[0].value, name: jQuery("#createAccount-name")[0].value, active: { diff --git a/src/containers/SignTransaction/index.jsx b/src/containers/SignTransaction/index.jsx index 19dbfd53..892bb513 100644 --- a/src/containers/SignTransaction/index.jsx +++ b/src/containers/SignTransaction/index.jsx @@ -44,6 +44,8 @@ class SignTransaction extends React.Component { return null; } + this.loadInfo(); + return null; } From 8d30288c66e7f4f9dcd32eb1493dae037ed1db11 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 26 Aug 2019 16:52:09 +0300 Subject: [PATCH 15/21] [BRG-448] start app is not connected to chain (#18) * [BRG-448] start app is not connected to chain * fix --- extension/background.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/background.js b/extension/background.js index 97891ca0..5270ceaf 100644 --- a/extension/background.js +++ b/extension/background.js @@ -102,7 +102,7 @@ const getNetwork = async () => { const createSocket = async (url) => { if (!url) { - const network = await getNetwork(); + const network = await storage.get('current_network') || NETWORKS[0]; ({ url } = network); diff --git a/package.json b/package.json index 8cd0de0d..8e82ed40 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "classnames": "^2.2.6", "config": "^1.30.0", "crypto-random-string": "^1.0.0", - "echojs-lib": "^1.6.0-rc.2", + "echojs-lib": "^1.6.0", "events": "^3.0.0", "file-loader": "^1.1.11", "focus-trap-react": "^4.0.1", From fae536fcfd178921f91971d29ef9defc48ccfabb Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Tue, 27 Aug 2019 16:06:12 +0300 Subject: [PATCH 16/21] [BRG-456] add checking erc20 token (#16) * [BRG-456] add checking erc20 token * [BRG-456] fix hash * [BRG-456] fix * [BRG-456] add decimals, symbol hash to check erc20 token --- src/actions/BalanceActions.js | 9 +++++++++ src/constants/GlobalConstants.js | 13 +++++++++++++ src/helpers/ValidateTransactionHelper.js | 15 +++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/actions/BalanceActions.js b/src/actions/BalanceActions.js index 34efb67b..b043a97e 100644 --- a/src/actions/BalanceActions.js +++ b/src/actions/BalanceActions.js @@ -621,6 +621,15 @@ export const watchToken = (contractId) => async (dispatch, getState) => { } const accountId = getState().global.getIn(['account', 'id']); + const [, { code }] = contract; + + const isErc20Token = ValidateTransactionHelper.isErc20Contract(code); + + if (!isErc20Token) { + dispatch(setFormError(FORM_WATCH_TOKEN, 'contractId', 'Invalid token contract')); + dispatch(GlobalReducer.actions.set({ field: 'loading', value: false })); + return null; + } const { symbol, precision, balance } = await getTokenDetails(contractId, accountId); diff --git a/src/constants/GlobalConstants.js b/src/constants/GlobalConstants.js index b7c2f5c9..e28247e4 100644 --- a/src/constants/GlobalConstants.js +++ b/src/constants/GlobalConstants.js @@ -154,3 +154,16 @@ export const STORE = 'keyval'; export const PATTERN_ID_MESSAGE = '*'; export const LENGTH_ID_MESSAGE = 10; + +export const ERC20_HASHES = { + 'totalSupply()': '18160ddd', + 'balanceOf(address)': '70a08231', + 'allowance(address,address)': 'dd62ed3e', + 'transfer(address,uint256)': 'a9059cbb', + 'approve(address,uint256)': '095ea7b3', + 'transferFrom(address,address,uint256)': '23b872dd', + 'Transfer(address,address,uint256)': 'ddf252ad', + 'decimals()': '313ce567', + 'symbol()': '95d89b41', +}; + diff --git a/src/helpers/ValidateTransactionHelper.js b/src/helpers/ValidateTransactionHelper.js index 86a124fe..9d551da9 100644 --- a/src/helpers/ValidateTransactionHelper.js +++ b/src/helpers/ValidateTransactionHelper.js @@ -1,4 +1,5 @@ import BN from 'bignumber.js'; +import { ERC20_HASHES } from '../constants/GlobalConstants'; class ValidateTransactionHelper { @@ -73,6 +74,20 @@ class ValidateTransactionHelper { return null; } + /** + * + * @param {String} scriptHex + * @returns {boolean} + */ + static isErc20Contract(scriptHex) { + if (scriptHex) { + const hashes = Object.values(ERC20_HASHES); + return hashes.every((hash) => scriptHex.includes(hash)); + } + + return false; + } + } export default ValidateTransactionHelper; From f2e923c7516e628810b12bc9255c1229ee5f9d3c Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Tue, 27 Aug 2019 18:36:24 +0300 Subject: [PATCH 17/21] [BRG-461] fix getAccess from the same hostname (#21) * [BRG-461] fix getAccess from the same hostname * [BRG-461] cache map in content page to save result getAccess * [BRG-461] delete cb when tab discard * [BRG-461] delete cb when tab close * [BRG-461] delete parse --- extension/background.js | 43 +++++++++++++++++++++++++++++++------- extension/contentscript.js | 30 ++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/extension/background.js b/extension/background.js index 5270ceaf..145beeb7 100644 --- a/extension/background.js +++ b/extension/background.js @@ -65,6 +65,8 @@ let signMessageRequests = []; const providerNotification = new NotificationManager(); const signNotification = new NotificationManager(); +const tabUrls = {}; + const connectSubscribe = (status) => { try { switch (status) { @@ -261,11 +263,24 @@ const resolveAccounts = async () => { */ const onMessage = (request, sender, sendResponse) => { const { hostname } = urlParse(sender.tab.url); + const { id: tabId } = sender.tab; request = JSON.parse(JSON.stringify(request)); if (!request.method || !request.appId || request.appId !== APP_ID) return false; + if (request.method === 'closeTab') { + const indexFindRequest = providerRequests.findIndex((rq) => rq.origin === hostname); + if (indexFindRequest === -1) return true; + const indexTabId = providerRequests[indexFindRequest].tabs + .findIndex((id) => id === tabId); + if (indexTabId === -1) return true; + providerRequests[indexFindRequest].cbs.splice(indexTabId, 1); + providerRequests[indexFindRequest].ids.splice(indexTabId, 1); + providerRequests[indexFindRequest].tabs.splice(indexTabId, 1); + return true; + } + if (typeof processedOrigins[hostname] !== 'boolean') { if (request.method !== 'getAccess') { @@ -273,12 +288,20 @@ const onMessage = (request, sender, sendResponse) => { return true; } - if (providerRequests.find((p) => p.origin === hostname)) { - sendResponse({ id: request.id, error: 'Access has already requested' }); + const indexRequest = providerRequests.findIndex((p) => p.origin === hostname); + if (indexRequest !== -1) { + providerRequests[indexRequest].ids.push(request.id); + providerRequests[indexRequest].cbs.push(sendResponse); + providerRequests[indexRequest].tabs.push(tabId); return true; } - providerRequests.push({ origin: hostname, id: request.id, cb: sendResponse }); + providerRequests.push({ + origin: hostname, + tabs: [tabId], + ids: [request.id], + cbs: [sendResponse], + }); setBadge(); @@ -619,15 +642,16 @@ const onSwitchActiveAccount = (res) => { * @param {Boolean} status */ export const onProviderApproval = (err, id, status) => { - const request = providerRequests.find((r) => String(r.id) === id); + const request = providerRequests.find(({ ids }) => String(ids[0]) === id); if (!request) { return; } - request.cb({ error: err, id: request.id, status }); - providerRequests = providerRequests.filter((p) => p.id !== request.id); + request.ids.forEach((rId, index) => request.cbs[index]({ error: err, id: rId, status })); + + providerRequests = providerRequests.filter(({ ids }) => ids[0] !== request.ids[0]); processedOrigins[request.origin] = status; if (!providerRequests.length) { @@ -713,8 +737,8 @@ window.getList = () => requestQueue.map(({ id, data }) => ({ id, options: data } window.getPrivateKey = () => PrivateKey; window.getAes = () => aes; window.Transaction = () => Transaction; -window.getProviderMap = () => providerRequests.reduce((map, { id, origin }) => { - map[id] = origin; +window.getProviderMap = () => providerRequests.reduce((map, { ids: [reqId], origin }) => { + map[reqId] = origin; return map; }, {}); @@ -737,3 +761,6 @@ crypto.on('unlocked', onPinUnlock); extensionizer.runtime.onInstalled.addListener(onFirstInstall); extensionizer.browserAction.setBadgeText({ text: 'BETA' }); + + + diff --git a/extension/contentscript.js b/extension/contentscript.js index 6ad45e0b..6e8378ff 100644 --- a/extension/contentscript.js +++ b/extension/contentscript.js @@ -2,6 +2,7 @@ const extensionizer = require('./extensionizer'); const { APP_ID } = require('../src/constants/GlobalConstants'); +const getAccessRequest = {}; /** * inpage script injection to web page @@ -49,14 +50,28 @@ const onResponse = (res, origin = '*') => { * On Inpage message * @param event */ -const onMessage = (event) => { - - const { data } = event; +const onMessage = async (event) => { + const { data, origin } = event; if (data.target !== 'content' || !data.appId || data.appId !== APP_ID) return; try { - extensionizer.runtime.sendMessage(data, (res) => onResponse(res, event.origin)); + if (data.method !== 'getAccess') { + extensionizer.runtime.sendMessage(data, (res) => onResponse(res, event.origin)); + return; + } + if (!getAccessRequest[origin]) { + getAccessRequest[origin] = new Promise((resolve) => { + extensionizer.runtime.sendMessage(data, (res) => { + onResponse(res, event.origin); + resolve(res); + }); + }); + } else { + const result = await getAccessRequest[origin]; + result.id = event.data.id; + onResponse(result, event.origin); + } } catch (err) { if (err.message.match(/Invocation of form runtime\.connect/) && err.message.match(/doesn't match definition runtime\.connect/)) { console.error('Connection to background error, please reload the page', err); @@ -66,5 +81,12 @@ const onMessage = (event) => { } }; +window.addEventListener('beforeunload', () => { + extensionizer.runtime.sendMessage({ + method: 'closeTab', + appId: APP_ID, + }); +}); + window.addEventListener('message', onMessage, false); From f3220e9df496403f2bb562cc3df6b9b752d5ffa3 Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Wed, 28 Aug 2019 10:42:37 +0300 Subject: [PATCH 18/21] [BRG-450] show loading in create account when account creating (#17) * [BRG-450] show loading in create account when account creating * [BRG-450] check state loading header in create account * [BRG-450] fix loading * [BRG-450] fix check loading sign up * [BRG-450] fix reset storage draft --- extension/background.js | 5 ++++- src/actions/ChainStoreAction.js | 18 +++++++++++++++++- src/actions/GlobalActions.js | 4 ++-- src/containers/App.jsx | 5 +++-- src/containers/CreateAccount/index.jsx | 6 +++++- src/reducers/FormReducer.js | 1 + 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/extension/background.js b/extension/background.js index 145beeb7..e91efdba 100644 --- a/extension/background.js +++ b/extension/background.js @@ -201,10 +201,12 @@ const createNotification = (title = '', message = '') => { */ const createAccount = async (name, path) => { try { + storageSetDraft(FORM_SIGN_UP, 'loading', true); const network = await getNetwork(); const { error, example } = await validateAccountExist(name); if (error) { + storageSetDraft(FORM_SIGN_UP, 'loading', false); storageSetDraft(FORM_SIGN_UP, 'error', { error, example }); emitter.emit('offerName', error, example); return null; @@ -219,8 +221,9 @@ const createAccount = async (name, path) => { storage.remove(DRAFT_STORAGE_KEY); } catch (err) { await emitter.emit('addAccountError', FormatHelper.formatError(err)); - storageSetDraft(FORM_SIGN_UP, 'error', { error: FormatHelper.formatError(err), example: '' }); + } finally { + storageSetDraft(FORM_SIGN_UP, 'loading', false); } return null; diff --git a/src/actions/ChainStoreAction.js b/src/actions/ChainStoreAction.js index 3c79b8cb..fd431bcc 100644 --- a/src/actions/ChainStoreAction.js +++ b/src/actions/ChainStoreAction.js @@ -6,6 +6,8 @@ import BalanceReducer from '../reducers/BalanceReducer'; import BlockchainReducer from '../reducers/BlockchainReducer'; import { initAssetsBalances, updateTokens } from './BalanceActions'; +import { setValue } from './FormActions'; +import { storageGetDraft } from './GlobalActions'; import echoService from '../services/echo'; @@ -15,13 +17,16 @@ import { } from '../constants/GlobalConstants'; import ChainStoreCacheNames from '../constants/ChainStoreConstants'; import { CONNECTION_ERROR_PATH } from '../constants/RouterConstants'; +import { FORM_SIGN_UP } from '../constants/FormConstants'; import storage from '../services/storage'; import history from '../history'; -import FormatHelper from '../helpers/FormatHelper'; import { updateHistory } from './HistoryActions'; +import FormatHelper from '../helpers/FormatHelper'; + + /** * copy object from ChainStore lib to redux every time when triggered, check connection * @returns {Function} @@ -38,6 +43,17 @@ export const subscribe = () => (dispatch) => { dispatch(updateHistory()); }; +/** + * check loading create account + * @returns {Function} + */ +export const checkActiveLoading = () => async (dispatch) => { + const draftStorage = await storageGetDraft(); + const signUp = draftStorage[FORM_SIGN_UP]; + const loading = signUp && signUp.loading; + dispatch(setValue(FORM_SIGN_UP, 'loading', loading)); + dispatch(GlobalReducer.actions.set({ field: 'loading', value: loading })); +}; /** * connect socket current network * @returns {Function} diff --git a/src/actions/GlobalActions.js b/src/actions/GlobalActions.js index 64da5887..97e06556 100644 --- a/src/actions/GlobalActions.js +++ b/src/actions/GlobalActions.js @@ -6,7 +6,7 @@ import { initCrypto, setCryptoInfo, getCryptoInfo, removeCryptoInfo } from './Cr import history from '../history'; import { setFormError, setValue, toggleLoading } from './FormActions'; -import { disconnect, connect } from './ChainStoreAction'; +import { disconnect, connect, checkActiveLoading } from './ChainStoreAction'; import { getTokenDetails, initAssetsBalances, removeBalances } from './BalanceActions'; import { globals, loadRequests } from './SignActions'; @@ -680,8 +680,8 @@ export const switchAccountNetwork = (accountName, network) => async (dispatch) = */ export const globalInit = () => async (dispatch) => { await dispatch(connect()); - await dispatch(initCrypto()); + dispatch(checkActiveLoading()); }; /** diff --git a/src/containers/App.jsx b/src/containers/App.jsx index ef8fc334..64da2903 100644 --- a/src/containers/App.jsx +++ b/src/containers/App.jsx @@ -15,7 +15,6 @@ import { PIN_PATHS, SIGN_TRANSACTION_PATH, CONNECTION_ERROR_PATH } from '../cons import bridgeLogo from '../assets/images/bridge-logo-hor-bw.svg'; - class App extends React.Component { @@ -40,7 +39,9 @@ class App extends React.Component { } renderApp() { - const { children, loading, pathname } = this.props; + const { + children, loading, pathname, + } = this.props; return (
diff --git a/src/containers/CreateAccount/index.jsx b/src/containers/CreateAccount/index.jsx index bbe7192a..173d814a 100644 --- a/src/containers/CreateAccount/index.jsx +++ b/src/containers/CreateAccount/index.jsx @@ -67,7 +67,11 @@ class CreateAccount extends React.Component { } componentWillUnmount() { - storageRemoveDraft(); + const { accounts, networkName } = this.props; + if (accounts.get(networkName).size) { + storageRemoveDraft(); + } + this.props.clearForm(); } diff --git a/src/reducers/FormReducer.js b/src/reducers/FormReducer.js index 27ba932f..7584754d 100644 --- a/src/reducers/FormReducer.js +++ b/src/reducers/FormReducer.js @@ -19,6 +19,7 @@ const DEFAULT_FIELDS = Map({ const DEFAULT_FORM_FIELDS = { [FORM_SIGN_UP]: Map({ + loading: false, accountName: { error: null, example: '', From ea845f4bfbec7dc18d29e2be08c3f29092efdd20 Mon Sep 17 00:00:00 2001 From: Alina Lozyuk <32218750+AlinaLoz@users.noreply.github.com> Date: Wed, 28 Aug 2019 12:04:56 +0300 Subject: [PATCH 19/21] [BRG-462] fix show uncoming transactions (#22) * [BRG-462] fix show uncoming transactions * [BRG-462] fix load info in sign transaction * [BRG-462] fix dataToShow --- src/actions/SignActions.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/actions/SignActions.js b/src/actions/SignActions.js index 1a6dd144..997511d5 100644 --- a/src/actions/SignActions.js +++ b/src/actions/SignActions.js @@ -206,6 +206,7 @@ export const removeTransaction = (id, isClose) => async (dispatch, getState) => dispatch(GlobalReducer.actions.setIn({ field: 'sign', params: { + transactions: new List(), current: null, }, })); @@ -296,13 +297,7 @@ export const requestHandler = (id, options) => async (dispatch, getState) => { return null; } - // const error = await dispatch(validateTransaction(options)); - // if (error) { - // emitter.emit('response', `${error}`, id, ERROR_STATUS); - // return null; - // } - - const transactions = getState().global.getIn(['sign', 'transactions']); + let transactions = getState().global.getIn(['sign', 'transactions']); if (!transactions.size) { dispatch(GlobalReducer.actions.setIn({ @@ -314,12 +309,17 @@ export const requestHandler = (id, options) => async (dispatch, getState) => { }), }, })); - // await dispatch(setTransaction({ id, options })); } + transactions = transactions.push({ id, options }); + + const dataToShow = await getFetchedData(transactions.get(0).options); dispatch(GlobalReducer.actions.setIn({ field: 'sign', - params: { transactions: transactions.push({ id, options }) }, + params: { + transactions, + dataToShow: new Map(dataToShow), + }, })); return null; From 573ffeb90b810def36210cbe32248e63aef710b3 Mon Sep 17 00:00:00 2001 From: Anastasia Rudenko Date: Wed, 28 Aug 2019 18:53:01 +0300 Subject: [PATCH 20/21] up version v1.10.2 (#23) --- config/manifest.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/manifest.json b/config/manifest.json index ae538d7c..f960dd35 100644 --- a/config/manifest.json +++ b/config/manifest.json @@ -18,7 +18,7 @@ "96": "images/96.png", "128": "images/128.png" }, - "version": "1.10.0", + "version": "1.10.2", "background": { "scripts": [ "background.js" diff --git a/package.json b/package.json index 8e82ed40..88b5f094 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "echo-bridge", "description": "The bridge between your web site and the Echo", - "version": "1.10.1-rc.1", + "version": "1.10.2", "scripts": { "start": "cross-env NODE_ENV=local webpack-dev-server --mode development --progress --colors --history-api-fallback --hot --inline --port 8081", "build": "cross-env NODE_ENV=production webpack --progress --display-error-details --colors --mode production", From 228535e33d8e357f442552937de7576bf5317ecf Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 29 Aug 2019 11:16:26 +0300 Subject: [PATCH 21/21] [BRG-465] change license to Echo Technological Solutions LLC (#28) --- LICENSE | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 618eaab4..c7ef468b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) ECHO DEVELOPMENT LTD +Copyright (c) Echo Technological Solutions LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 8d43369a..689b8fe3 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ ED25519.verifyMessage(signature, message, publicKey); The MIT License (MIT) -Copyright (c) ECHO DEVELOPMENT LTD +Copyright (c) Echo Technological Solutions LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in