From 93612cf08049b734446f3a16554cf1e64ef73110 Mon Sep 17 00:00:00 2001 From: Matt Huggins Date: Sat, 24 Mar 2018 12:03:42 -0500 Subject: [PATCH 1/2] Updated react-hot-loader to fix async autobind functions --- app/components/Modals/SendModal/SendModal.jsx | 39 ++++++------ app/index.js | 21 +------ config/webpack.config.dev.js | 1 - package.json | 2 +- webpack.config.js | 1 - yarn.lock | 63 +++++-------------- 6 files changed, 37 insertions(+), 90 deletions(-) diff --git a/app/components/Modals/SendModal/SendModal.jsx b/app/components/Modals/SendModal/SendModal.jsx index 5fca298b0..08f803150 100644 --- a/app/components/Modals/SendModal/SendModal.jsx +++ b/app/components/Modals/SendModal/SendModal.jsx @@ -7,7 +7,7 @@ import AddRecipientDisplay from './AddRecipientDisplay' import ConfirmDisplay from './ConfirmDisplay' import withAddressCheck from './withAddressCheck' -import { validateTransactionBeforeSending, getTokenBalancesMap, isInBlacklist } from '../../../core/wallet' +import { validateTransactionBeforeSending, getTokenBalancesMap, isBlacklisted } from '../../../core/wallet' import { ASSETS } from '../../../core/constants' import { toBigNumber } from '../../../core/math' @@ -107,27 +107,28 @@ export default class SendModal extends Component { }) } - handleConfirmAddRecipient = (entry: SendEntryType) => { + handleConfirmAddRecipient = async (entry: SendEntryType) => { const { showErrorNotification } = this.props const { balances } = this.state - isInBlacklist(entry.address).then(inBlacklist => { - if (inBlacklist) { - showErrorNotification({ message: 'You have attempted enter a phishing address.' }) - } else { - const error = validateTransactionBeforeSending(balances[entry.symbol], entry) - if (error) { - showErrorNotification({ message: error }) - } else { - const newBalance = toBigNumber(balances[entry.symbol]).minus(entry.amount).toString() - - this.setState({ - entries: [...this.state.entries, entry], - balances: { ...balances, [entry.symbol]: newBalance }, - display: DISPLAY_MODES.CONFIRM - }) - } - } + if (await isBlacklisted(entry.address)) { + showErrorNotification({ message: 'You have attempted enter a phishing address.' }) + return + } + + const error = validateTransactionBeforeSending(balances[entry.symbol], entry) + + if (error) { + showErrorNotification({ message: error }) + return + } + + const newBalance = toBigNumber(balances[entry.symbol]).minus(entry.amount).toString() + + this.setState({ + entries: [...this.state.entries, entry], + balances: { ...balances, [entry.symbol]: newBalance }, + display: DISPLAY_MODES.CONFIRM }) } diff --git a/app/index.js b/app/index.js index b26004c43..41108296a 100644 --- a/app/index.js +++ b/app/index.js @@ -1,27 +1,10 @@ import 'raf/polyfill' import React from 'react' import { render } from 'react-dom' -import { AppContainer } from 'react-hot-loader' + import store from './store/configureStore' import Root from './Root' import './styles/tippy.compiled.global.css' import './styles/main.global.scss' -render( - - - , - document.getElementById('root') -) - -if (module.hot) { - module.hot.accept('./Root', () => { - const NewRoot = require('./Root').default - render( - - - , - document.getElementById('root') - ) - }) -} +render(, document.getElementById('root')) diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js index 6b167b44c..83a7369ce 100644 --- a/config/webpack.config.dev.js +++ b/config/webpack.config.dev.js @@ -30,7 +30,6 @@ module.exports = { target: 'electron-renderer', entry: [ 'babel-polyfill', - 'react-hot-loader/patch', `webpack-dev-server/client?http://localhost:${port}/`, 'webpack/hot/only-dev-server', path.join(__dirname, '..', 'app/index.js') diff --git a/package.json b/package.json index a13ac7f81..a2ca30bed 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "react-click-outside": "3.0.0", "react-data-grid": "2.0.73", "react-dom": "16.1.1", - "react-hot-loader": "3.1.1", + "react-hot-loader": "4.0.0", "react-icons": "2.2.7", "react-modal": "3.1.2", "react-notification-system": "0.2.16", diff --git a/webpack.config.js b/webpack.config.js index dca525e7a..73ff302bb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,7 +10,6 @@ module.exports = { entry: [ 'webpack-dev-server/client?http://localhost:3000', 'webpack/hot/only-dev-server', - 'react-hot-loader/patch', path.join(__dirname, 'app/index.js') ], externals: { diff --git a/yarn.lock b/yarn.lock index 1e0f85106..fddccbc39 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3516,12 +3516,6 @@ error-ex@^1.2.0, error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -error-stack-parser@^1.3.6: - version "1.3.6" - resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-1.3.6.tgz#e0e73b93e417138d1cd7c0b746b1a4a14854c292" - dependencies: - stackframe "^0.3.1" - es-abstract@^1.5.1, es-abstract@^1.6.1, es-abstract@^1.7.0: version "1.10.0" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.10.0.tgz#1ecb36c197842a00d8ee4c2dfd8646bb97d60864" @@ -4069,7 +4063,7 @@ fast-json-stable-stringify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" -fast-levenshtein@~2.0.4: +fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.4: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" @@ -4790,7 +4784,7 @@ hoek@4.x.x: version "4.2.1" resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.1.tgz#9634502aa12c445dd5a7c5734b572bb8738aacbb" -hoist-non-react-statics@^2.1.1, hoist-non-react-statics@^2.2.1, hoist-non-react-statics@^2.3.0, hoist-non-react-statics@^2.3.1: +hoist-non-react-statics@^2.1.1, hoist-non-react-statics@^2.2.1, hoist-non-react-statics@^2.3.0, hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz#d2ca2dfc19c5a91c5a6615ce8e564ef0347e2a40" @@ -6238,7 +6232,7 @@ lodash@4.17.4: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" -lodash@^4.0.0, lodash@^4.0.1, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1, lodash@^4.8.0, lodash@~4.17.4: +lodash@^4.0.0, lodash@^4.0.1, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.8.0, lodash@~4.17.4: version "4.17.5" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511" @@ -8012,10 +8006,6 @@ react-data-grid@2.0.73: version "2.0.73" resolved "https://registry.yarnpkg.com/react-data-grid/-/react-data-grid-2.0.73.tgz#8c718b2cc5f3c2f7e34485d55b08e7bdcabfbb20" -react-deep-force-update@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-2.1.1.tgz#8ea4263cd6455a050b37445b3f08fd839d86e909" - react-dom@16.1.1: version "16.1.1" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.1.1.tgz#b2e331b6d752faf1a2d31399969399a41d8d45f8" @@ -8025,15 +8015,15 @@ react-dom@16.1.1: object-assign "^4.1.1" prop-types "^15.6.0" -react-hot-loader@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-3.1.1.tgz#e06db8cd0841c41e3ab0b395b2b774126fc8914e" +react-hot-loader@4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/react-hot-loader/-/react-hot-loader-4.0.0.tgz#3452fa9bc0d0ba9dfc5b0ccfa25101ca8dbd2de2" dependencies: + fast-levenshtein "^2.0.6" global "^4.3.0" - react-deep-force-update "^2.1.1" - react-proxy "^3.0.0-alpha.0" - redbox-react "^1.3.6" - source-map "^0.6.1" + hoist-non-react-statics "^2.5.0" + prop-types "^15.6.0" + shallowequal "^1.0.2" react-icon-base@2.1.0: version "2.1.0" @@ -8060,12 +8050,6 @@ react-notification-system@0.2.16: object-assign "^4.0.1" prop-types "^15.5.6" -react-proxy@^3.0.0-alpha.0: - version "3.0.0-alpha.1" - resolved "https://registry.yarnpkg.com/react-proxy/-/react-proxy-3.0.0-alpha.1.tgz#4400426bcfa80caa6724c7755695315209fa4b07" - dependencies: - lodash "^4.6.1" - react-redux@5.0.6: version "5.0.6" resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.0.6.tgz#23ed3a4f986359d68b5212eaaa681e60d6574946" @@ -8257,15 +8241,6 @@ recompose@^0.26.0: hoist-non-react-statics "^2.3.1" symbol-observable "^1.0.4" -redbox-react@^1.3.6: - version "1.5.0" - resolved "https://registry.yarnpkg.com/redbox-react/-/redbox-react-1.5.0.tgz#04dab11557d26651bf3562a67c22ace56c5d3967" - dependencies: - error-stack-parser "^1.3.6" - object-assign "^4.0.1" - prop-types "^15.5.4" - sourcemapped-stacktrace "^1.1.6" - redent@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde" @@ -8891,6 +8866,10 @@ shallow-clone@^0.1.2: lazy-cache "^0.2.3" mixin-object "^2.0.1" +shallowequal@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/shallowequal/-/shallowequal-1.0.2.tgz#1561dbdefb8c01408100319085764da3fcf83f8f" + shebang-command@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" @@ -9069,10 +9048,6 @@ source-map-url@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.3.0.tgz#7ecaf13b57bcd09da8a40c5d269db33799d4aaf9" -source-map@0.5.6: - version "0.5.6" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" - source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.1: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -9093,12 +9068,6 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" -sourcemapped-stacktrace@^1.1.6: - version "1.1.8" - resolved "https://registry.yarnpkg.com/sourcemapped-stacktrace/-/sourcemapped-stacktrace-1.1.8.tgz#6b7a3f1a6fb15f6d40e701e23ce404553480d688" - dependencies: - source-map "0.5.6" - spawn-rx@^2.0.10: version "2.0.12" resolved "https://registry.yarnpkg.com/spawn-rx/-/spawn-rx-2.0.12.tgz#b6285294499426089beea0c3c1ec32d7fc57a376" @@ -9206,10 +9175,6 @@ stack-utils@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-1.0.1.tgz#d4f33ab54e8e38778b0ca5cfd3b3afb12db68620" -stackframe@^0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-0.3.1.tgz#33aa84f1177a5548c8935533cbfeb3420975f5a4" - stat-mode@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/stat-mode/-/stat-mode-0.2.2.tgz#e6c80b623123d7d80cf132ce538f346289072502" From 3a2d2638da2d83d99f6e6f84bb5478d87ee3e6e5 Mon Sep 17 00:00:00 2001 From: Matt Huggins Date: Sat, 24 Mar 2018 12:03:50 -0500 Subject: [PATCH 2/2] Updated blacklist check to use async/await --- app/{ => Root}/Root.jsx | 3 ++- app/Root/index.js | 5 +++++ app/core/wallet.js | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) rename app/{ => Root}/Root.jsx (90%) create mode 100644 app/Root/index.js diff --git a/app/Root.jsx b/app/Root/Root.jsx similarity index 90% rename from app/Root.jsx rename to app/Root/Root.jsx index 63f107fda..af656fb65 100644 --- a/app/Root.jsx +++ b/app/Root/Root.jsx @@ -1,9 +1,10 @@ // @flow import React from 'react' import { Provider } from 'react-redux' -import Routes from './Routes' import { BrowserRouter } from 'react-router-dom' +import Routes from '../Routes' + type Props = { store: Object, } diff --git a/app/Root/index.js b/app/Root/index.js new file mode 100644 index 000000000..9b2d05b4e --- /dev/null +++ b/app/Root/index.js @@ -0,0 +1,5 @@ +import { hot } from 'react-hot-loader' + +import Root from './Root' + +export default hot(module)(Root) diff --git a/app/core/wallet.js b/app/core/wallet.js index a93c2d487..726a074ec 100644 --- a/app/core/wallet.js +++ b/app/core/wallet.js @@ -9,7 +9,8 @@ import { toBigNumber } from './math' const MIN_PASSPHRASE_LEN = 4 let addressBlacklist: Array | null = null -export const isInBlacklist = async (address: string): Promise => { + +export const isBlacklisted = async (address: string): Promise => { if (addressBlacklist === null) { const { data } = await axios.get('https://raw.githubusercontent.com/CityOfZion/phishing/master/blockedAddresses.json') addressBlacklist = data