commit
d9ef72cb7e
@ -1,61 +0,0 @@ |
|||||||
module.exports = setupDappAutoReload |
|
||||||
|
|
||||||
function setupDappAutoReload (web3, observable) { |
|
||||||
// export web3 as a global, checking for usage
|
|
||||||
let hasBeenWarned = false |
|
||||||
let reloadInProgress = false |
|
||||||
let lastTimeUsed |
|
||||||
let lastSeenNetwork |
|
||||||
|
|
||||||
global.web3 = new Proxy(web3, { |
|
||||||
get: (_web3, key) => { |
|
||||||
// show warning once on web3 access
|
|
||||||
if (!hasBeenWarned && key !== 'currentProvider') { |
|
||||||
console.warn('MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider \nhttps://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation') |
|
||||||
hasBeenWarned = true |
|
||||||
} |
|
||||||
// get the time of use
|
|
||||||
lastTimeUsed = Date.now() |
|
||||||
// return value normally
|
|
||||||
return _web3[key] |
|
||||||
}, |
|
||||||
set: (_web3, key, value) => { |
|
||||||
// set value normally
|
|
||||||
_web3[key] = value |
|
||||||
}, |
|
||||||
}) |
|
||||||
|
|
||||||
observable.subscribe(function (state) { |
|
||||||
// if reload in progress, no need to check reload logic
|
|
||||||
if (reloadInProgress) return |
|
||||||
|
|
||||||
const currentNetwork = state.networkVersion |
|
||||||
|
|
||||||
// set the initial network
|
|
||||||
if (!lastSeenNetwork) { |
|
||||||
lastSeenNetwork = currentNetwork |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
// skip reload logic if web3 not used
|
|
||||||
if (!lastTimeUsed) return |
|
||||||
|
|
||||||
// if network did not change, exit
|
|
||||||
if (currentNetwork === lastSeenNetwork) return |
|
||||||
|
|
||||||
// initiate page reload
|
|
||||||
reloadInProgress = true |
|
||||||
const timeSinceUse = Date.now() - lastTimeUsed |
|
||||||
// if web3 was recently used then delay the reloading of the page
|
|
||||||
if (timeSinceUse > 500) { |
|
||||||
triggerReset() |
|
||||||
} else { |
|
||||||
setTimeout(triggerReset, 500) |
|
||||||
} |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
// reload the page
|
|
||||||
function triggerReset () { |
|
||||||
global.location.reload() |
|
||||||
} |
|
@ -0,0 +1,24 @@ |
|||||||
|
const WritableStream = require('readable-stream').Writable |
||||||
|
const promiseToCallback = require('promise-to-callback') |
||||||
|
|
||||||
|
module.exports = createStreamSink |
||||||
|
|
||||||
|
|
||||||
|
function createStreamSink(asyncWriteFn, _opts) { |
||||||
|
return new AsyncWritableStream(asyncWriteFn, _opts) |
||||||
|
} |
||||||
|
|
||||||
|
class AsyncWritableStream extends WritableStream { |
||||||
|
|
||||||
|
constructor (asyncWriteFn, _opts) { |
||||||
|
const opts = Object.assign({ objectMode: true }, _opts) |
||||||
|
super(opts) |
||||||
|
this._asyncWriteFn = asyncWriteFn |
||||||
|
} |
||||||
|
|
||||||
|
// write from incomming stream to state
|
||||||
|
_write (chunk, encoding, callback) { |
||||||
|
promiseToCallback(this._asyncWriteFn(chunk, encoding))(callback) |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,6 @@ |
|||||||
|
Dear MetaMask Users, |
||||||
|
|
||||||
|
There have been several instances of high-profile legitimate websites such as BTC Manager and Games Workshop that have had their websites temporarily compromised. This involves showing a fake MetaMask window on the page asking for user's seed phrases. MetaMask will never open itself in this way and users are encouraged to report these instances immediately to either [our phishing blacklist](https://github.com/MetaMask/eth-phishing-detect/issues) or our support email at [support@metamask.io](support@metamask.io). |
||||||
|
|
||||||
|
Please read our full article on this ongoing issue at [https://medium.com/metamask/new-phishing-strategy-becoming-common-1b1123837168](https://medium.com/metamask/new-phishing-strategy-becoming-common-1b1123837168). |
||||||
|
|
@ -1,27 +0,0 @@ |
|||||||
var fs = require('fs') |
|
||||||
var path = require('path') |
|
||||||
var prompt = require('prompt') |
|
||||||
var open = require('open') |
|
||||||
var extend = require('extend') |
|
||||||
var notices = require('./notices.json') |
|
||||||
|
|
||||||
|
|
||||||
console.log('List of Notices') |
|
||||||
console.log(`ID \t DATE \t\t\t TITLE`) |
|
||||||
notices.forEach((notice) => { |
|
||||||
console.log(`${(' ' + notice.id).slice(-2)} \t ${notice.date} \t ${notice.title}`) |
|
||||||
}) |
|
||||||
prompt.get(['id'], (error, res) => { |
|
||||||
prompt.start() |
|
||||||
if (error) { |
|
||||||
console.log("Exiting...") |
|
||||||
process.exit() |
|
||||||
} |
|
||||||
var index = notices.findIndex((notice) => { return notice.id == res.id}) |
|
||||||
if (index === -1) { |
|
||||||
console.log('Notice not found. Exiting...') |
|
||||||
} |
|
||||||
notices.splice(index, 1) |
|
||||||
fs.unlink(`notices/archive/notice_${res.id}.md`) |
|
||||||
fs.writeFile(`notices/notices.json`, JSON.stringify(notices)) |
|
||||||
}) |
|
@ -1,33 +0,0 @@ |
|||||||
var fsp = require('fs-promise') |
|
||||||
var path = require('path') |
|
||||||
var prompt = require('prompt') |
|
||||||
var open = require('open') |
|
||||||
var extend = require('extend') |
|
||||||
var notices = require('./notices.json') |
|
||||||
var id = Number(require('./notice-nonce.json')) |
|
||||||
|
|
||||||
var date = new Date().toDateString() |
|
||||||
|
|
||||||
var notice = { |
|
||||||
read: false, |
|
||||||
date: date, |
|
||||||
} |
|
||||||
|
|
||||||
fsp.writeFile(`notices/archive/notice_${id}.md`,'Message goes here. Please write out your notice and save before proceeding at the command line.') |
|
||||||
.then(() => { |
|
||||||
open(`notices/archive/notice_${id}.md`) |
|
||||||
prompt.start() |
|
||||||
prompt.get(['title'], (err, result) => { |
|
||||||
notice.title = result.title |
|
||||||
fsp.readFile(`notices/archive/notice_${id}.md`) |
|
||||||
.then((body) => { |
|
||||||
notice.body = body.toString() |
|
||||||
notice.id = id |
|
||||||
notices.push(notice) |
|
||||||
return fsp.writeFile(`notices/notices.json`, JSON.stringify(notices)) |
|
||||||
}).then((completion) => { |
|
||||||
id += 1 |
|
||||||
return fsp.writeFile(`notices/notice-nonce.json`, id) |
|
||||||
}) |
|
||||||
}) |
|
||||||
}) |
|
@ -1 +0,0 @@ |
|||||||
4 |
|
@ -0,0 +1,34 @@ |
|||||||
|
// fs.readFileSync is inlined by browserify transform "brfs"
|
||||||
|
const fs = require('fs') |
||||||
|
|
||||||
|
module.exports = [ |
||||||
|
{ |
||||||
|
id: 0, |
||||||
|
read: false, |
||||||
|
date: 'Thu Feb 09 2017', |
||||||
|
title: 'Terms of Use', |
||||||
|
body: fs.readFileSync(__dirname + '/archive/notice_0.md', 'utf8'), |
||||||
|
}, |
||||||
|
{ |
||||||
|
id: 2, |
||||||
|
read: false, |
||||||
|
date: 'Mon May 08 2017', |
||||||
|
title: 'Privacy Notice', |
||||||
|
body: fs.readFileSync(__dirname + '/archive/notice_2.md', 'utf8'), |
||||||
|
}, |
||||||
|
{ |
||||||
|
id: 3, |
||||||
|
read: false, |
||||||
|
date: 'Tue Nov 28 2017', |
||||||
|
title: 'Seed Phrase Alert', |
||||||
|
firstVersion: '<=3.12.0', |
||||||
|
body: fs.readFileSync(__dirname + '/archive/notice_3.md', 'utf8'), |
||||||
|
}, |
||||||
|
{ |
||||||
|
id: 4, |
||||||
|
read: false, |
||||||
|
date: 'Wed Jun 13 2018', |
||||||
|
title: 'Phishing Warning', |
||||||
|
body: fs.readFileSync(__dirname + '/archive/notice_4.md', 'utf8'), |
||||||
|
} |
||||||
|
] |
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,17 @@ |
|||||||
|
const assert = require('assert') |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
assertRejects, |
||||||
|
} |
||||||
|
|
||||||
|
// assert.rejects added in node v10
|
||||||
|
async function assertRejects (asyncFn, regExp) { |
||||||
|
let f = () => {} |
||||||
|
try { |
||||||
|
await asyncFn() |
||||||
|
} catch (error) { |
||||||
|
f = () => { throw error } |
||||||
|
} finally { |
||||||
|
assert.throws(f, regExp) |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue