Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixed autobind for async/await in react components #914

Merged
merged 2 commits into from
Mar 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Root.jsx → app/Root/Root.jsx
Original file line number Diff line number Diff line change
@@ -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,
}
Expand Down
5 changes: 5 additions & 0 deletions app/Root/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { hot } from 'react-hot-loader'

import Root from './Root'

export default hot(module)(Root)
39 changes: 20 additions & 19 deletions app/components/Modals/SendModal/SendModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -107,27 +107,28 @@ export default class SendModal extends Component<Props, State> {
})
}

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
})
}

Expand Down
3 changes: 2 additions & 1 deletion app/core/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { toBigNumber } from './math'
const MIN_PASSPHRASE_LEN = 4

let addressBlacklist: Array<string> | null = null
export const isInBlacklist = async (address: string): Promise<boolean> => {

export const isBlacklisted = async (address: string): Promise<boolean> => {
if (addressBlacklist === null) {
const { data } = await axios.get('https://raw.githubusercontent.com/CityOfZion/phishing/master/blockedAddresses.json')
addressBlacklist = data
Expand Down
21 changes: 2 additions & 19 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -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(
<AppContainer>
<Root store={store} />
</AppContainer>,
document.getElementById('root')
)

if (module.hot) {
module.hot.accept('./Root', () => {
const NewRoot = require('./Root').default
render(
<AppContainer>
<NewRoot store={store} />
</AppContainer>,
document.getElementById('root')
)
})
}
render(<Root store={store} />, document.getElementById('root'))
1 change: 0 additions & 1 deletion config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
63 changes: 14 additions & 49 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -4790,7 +4784,7 @@ [email protected]:
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"

Expand Down Expand Up @@ -6238,7 +6232,7 @@ [email protected]:
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"

Expand Down Expand Up @@ -8012,10 +8006,6 @@ [email protected]:
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"

[email protected]:
version "16.1.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.1.1.tgz#b2e331b6d752faf1a2d31399969399a41d8d45f8"
Expand All @@ -8025,15 +8015,15 @@ [email protected]:
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"

[email protected]:
version "2.1.0"
Expand All @@ -8060,12 +8050,6 @@ [email protected]:
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"

[email protected]:
version "5.0.6"
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.0.6.tgz#23ed3a4f986359d68b5212eaaa681e60d6574946"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"

[email protected]:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

[email protected], 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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down