-
Notifications
You must be signed in to change notification settings - Fork 312
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
Blocked people from sending to addresses listed in CityOfZion/phishing #887
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
// @flow | ||
import { wallet } from 'neon-js' | ||
import { map, extend } from 'lodash' | ||
import fetch from 'node-fetch' | ||
|
||
import { ASSETS } from './constants' | ||
import { toBigNumber } from './math' | ||
|
||
const MIN_PASSPHRASE_LEN = 4 | ||
|
||
let addressBlacklist: Array<string> | null = null | ||
export const isInBlacklist = (address: string): Promise<boolean> => { | ||
if (addressBlacklist !== null) return Promise.resolve(addressBlacklist.includes(address)) | ||
return fetch('https://raw.githubusercontent.com/CityOfZion/phishing/master/blockedAddresses.json') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could write this with axios and async/await syntax in a pretty direct manner: import axios from 'axios'
export const isInBlacklist = async (address: string): Promise<boolean> => {
if (addressBlacklist === null) {
const { data } = await axios.get('https://raw.githubusercontent.com/CityOfZion/phishing/master/blockedAddresses.json')
addressBlacklist = data
}
return addressBlacklist.includes(address)
} |
||
.catch(() => false) | ||
.then(res => res.json()) | ||
.then(blacklist => { | ||
addressBlacklist = blacklist | ||
return blacklist.includes(address) | ||
}) | ||
} | ||
|
||
export const validatePassphraseLength = (passphrase: string): boolean => | ||
passphrase.length >= MIN_PASSPHRASE_LEN | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ | |
"isomorphic-fetch": "2.2.1", | ||
"lodash": "4.17.4", | ||
"neon-js": "git+https://github.com/cityofzion/neon-js.git#3.3.3", | ||
"node-fetch": "^2.1.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have |
||
"qrcode": "0.9.0", | ||
"raf": "3.4.0", | ||
"react": "16.1.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6598,6 +6598,10 @@ node-fetch@^1.0.1: | |
encoding "^0.1.11" | ||
is-stream "^1.0.1" | ||
|
||
node-fetch@^2.1.1: | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.1.tgz#369ca70b82f50c86496104a6c776d274f4e4a2d4" | ||
|
||
[email protected]: | ||
version "0.7.1" | ||
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.1.tgz#9da611ea08982f4b94206b3beb4cc9665f20c300" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI using async/await syntax here can remove a layer of nesting and improve the readability. We've been favoring this syntax over raw promises throughout the codebase.
You would first need to change the method signature to include
async
, i.e.:Then the skeleton of this function simply becomes:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, making that function async/await removes access to the "this" variable. I get
Cannot read property 'showErrorNotification' of undefined
orReferenceError: _this11 is not defined
. There's a weird workaround to this in withAddressCheck.jsx, but applying it breaks other methods within the class. There's another promise ".then" in the same file, presumably for the same reason.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, that should be fixable by using
async function(...) { ... }
instead ofasync (...) => { ... }
. Regardless, I can probably merge this as-is and look into it afterwards.