mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Linting to the max.
This commit is contained in:
parent
c664b8f11e
commit
23263bec7d
@ -6,7 +6,7 @@ const extension = require('./lib/extension')
|
|||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const inpageText = fs.readFileSync(path.join(__dirname + '/inpage.js')).toString()
|
const inpageText = fs.readFileSync(path.join(__dirname, 'inpage.js')).toString()
|
||||||
|
|
||||||
// Eventually this streaming injection could be replaced with:
|
// Eventually this streaming injection could be replaced with:
|
||||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction
|
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction
|
||||||
@ -20,9 +20,8 @@ if (shouldInjectWeb3()) {
|
|||||||
setupStreams()
|
setupStreams()
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupInjection(){
|
function setupInjection () {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// inject in-page script
|
// inject in-page script
|
||||||
var scriptTag = document.createElement('script')
|
var scriptTag = document.createElement('script')
|
||||||
scriptTag.src = extension.extension.getURL('scripts/inpage.js')
|
scriptTag.src = extension.extension.getURL('scripts/inpage.js')
|
||||||
@ -31,14 +30,12 @@ function setupInjection(){
|
|||||||
var container = document.head || document.documentElement
|
var container = document.head || document.documentElement
|
||||||
// append as first child
|
// append as first child
|
||||||
container.insertBefore(scriptTag, container.children[0])
|
container.insertBefore(scriptTag, container.children[0])
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Metamask injection failed.', e)
|
console.error('Metamask injection failed.', e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupStreams(){
|
function setupStreams () {
|
||||||
|
|
||||||
// setup communication to page and plugin
|
// setup communication to page and plugin
|
||||||
var pageStream = new LocalMessageDuplexStream({
|
var pageStream = new LocalMessageDuplexStream({
|
||||||
name: 'contentscript',
|
name: 'contentscript',
|
||||||
@ -65,14 +62,13 @@ function setupStreams(){
|
|||||||
mx.ignoreStream('provider')
|
mx.ignoreStream('provider')
|
||||||
mx.ignoreStream('publicConfig')
|
mx.ignoreStream('publicConfig')
|
||||||
mx.ignoreStream('reload')
|
mx.ignoreStream('reload')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldInjectWeb3(){
|
function shouldInjectWeb3 () {
|
||||||
return isAllowedSuffix(window.location.href)
|
return isAllowedSuffix(window.location.href)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAllowedSuffix(testCase) {
|
function isAllowedSuffix (testCase) {
|
||||||
var prohibitedTypes = ['xml', 'pdf']
|
var prohibitedTypes = ['xml', 'pdf']
|
||||||
var currentUrl = window.location.href
|
var currentUrl = window.location.href
|
||||||
var currentRegex
|
var currentRegex
|
||||||
|
@ -43,7 +43,7 @@ reloadStream.once('data', triggerReload)
|
|||||||
var pingChannel = inpageProvider.multiStream.createStream('pingpong')
|
var pingChannel = inpageProvider.multiStream.createStream('pingpong')
|
||||||
var pingStream = new PingStream({ objectMode: true })
|
var pingStream = new PingStream({ objectMode: true })
|
||||||
// wait for first successful reponse
|
// wait for first successful reponse
|
||||||
metamaskStream.once('_data', function(){
|
metamaskStream.once('_data', function () {
|
||||||
pingStream.pipe(pingChannel).pipe(pingStream)
|
pingStream.pipe(pingChannel).pipe(pingStream)
|
||||||
})
|
})
|
||||||
endOfStream(pingStream, triggerReload)
|
endOfStream(pingStream, triggerReload)
|
||||||
|
@ -46,7 +46,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getState() {
|
getState () {
|
||||||
const configManager = this.configManager
|
const configManager = this.configManager
|
||||||
const address = configManager.getSelectedAccount()
|
const address = configManager.getSelectedAccount()
|
||||||
const wallet = configManager.getWallet() // old style vault
|
const wallet = configManager.getWallet() // old style vault
|
||||||
@ -72,18 +72,18 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setStore(ethStore) {
|
setStore (ethStore) {
|
||||||
this.ethStore = ethStore
|
this.ethStore = ethStore
|
||||||
}
|
}
|
||||||
|
|
||||||
createNewVaultAndKeychain(password, entropy, cb) {
|
createNewVaultAndKeychain (password, entropy, cb) {
|
||||||
this.createNewVault(password, entropy, (err) => {
|
this.createNewVault(password, entropy, (err) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
this.createFirstKeyTree(password, cb)
|
this.createFirstKeyTree(password, cb)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
createNewVaultAndRestore(password, seed, cb) {
|
createNewVaultAndRestore (password, seed, cb) {
|
||||||
if (typeof password !== 'string') {
|
if (typeof password !== 'string') {
|
||||||
return cb('Password must be text.')
|
return cb('Password must be text.')
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
migrateAndGetKey(password) {
|
migrateAndGetKey (password) {
|
||||||
let key
|
let key
|
||||||
const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
|
const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
createNewVault(password, entropy, cb) {
|
createNewVault (password, entropy, cb) {
|
||||||
const configManager = this.configManager
|
const configManager = this.configManager
|
||||||
const salt = this.encryptor.generateSalt()
|
const salt = this.encryptor.generateSalt()
|
||||||
configManager.setSalt(salt)
|
configManager.setSalt(salt)
|
||||||
@ -151,7 +151,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
createFirstKeyTree(password, cb) {
|
createFirstKeyTree (password, cb) {
|
||||||
this.clearKeyrings()
|
this.clearKeyrings()
|
||||||
this.addNewKeyring('HD Key Tree', {n: 1}, (err) => {
|
this.addNewKeyring('HD Key Tree', {n: 1}, (err) => {
|
||||||
const firstKeyring = this.keyrings[0]
|
const firstKeyring = this.keyrings[0]
|
||||||
@ -179,7 +179,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
this.configManager.setSeedWords(seedWords)
|
this.configManager.setSeedWords(seedWords)
|
||||||
}
|
}
|
||||||
|
|
||||||
submitPassword(password, cb) {
|
submitPassword (password, cb) {
|
||||||
this.migrateAndGetKey(password)
|
this.migrateAndGetKey(password)
|
||||||
.then((key) => {
|
.then((key) => {
|
||||||
return this.unlockKeyrings(key)
|
return this.unlockKeyrings(key)
|
||||||
@ -196,7 +196,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
loadKey(password) {
|
loadKey (password) {
|
||||||
const salt = this.configManager.getSalt() || this.encryptor.generateSalt()
|
const salt = this.configManager.getSalt() || this.encryptor.generateSalt()
|
||||||
return this.encryptor.keyFromPassword(password + salt)
|
return this.encryptor.keyFromPassword(password + salt)
|
||||||
.then((key) => {
|
.then((key) => {
|
||||||
@ -206,7 +206,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewKeyring(type, opts, cb) {
|
addNewKeyring (type, opts, cb) {
|
||||||
const Keyring = this.getKeyringClassForType(type)
|
const Keyring = this.getKeyringClassForType(type)
|
||||||
const keyring = new Keyring(opts)
|
const keyring = new Keyring(opts)
|
||||||
const accounts = keyring.getAccounts()
|
const accounts = keyring.getAccounts()
|
||||||
@ -222,7 +222,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewAccount(keyRingNum = 0, cb) {
|
addNewAccount (keyRingNum = 0, cb) {
|
||||||
const ring = this.keyrings[keyRingNum]
|
const ring = this.keyrings[keyRingNum]
|
||||||
const accounts = ring.addAccounts(1)
|
const accounts = ring.addAccounts(1)
|
||||||
this.setupAccounts(accounts)
|
this.setupAccounts(accounts)
|
||||||
@ -235,7 +235,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
setupAccounts(accounts) {
|
setupAccounts (accounts) {
|
||||||
var arr = accounts || this.getAccounts()
|
var arr = accounts || this.getAccounts()
|
||||||
arr.forEach((account) => {
|
arr.forEach((account) => {
|
||||||
this.loadBalanceAndNickname(account)
|
this.loadBalanceAndNickname(account)
|
||||||
@ -244,13 +244,13 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
|
|
||||||
// Takes an account address and an iterator representing
|
// Takes an account address and an iterator representing
|
||||||
// the current number of named accounts.
|
// the current number of named accounts.
|
||||||
loadBalanceAndNickname(account) {
|
loadBalanceAndNickname (account) {
|
||||||
const address = normalize(account)
|
const address = normalize(account)
|
||||||
this.ethStore.addAccount(address)
|
this.ethStore.addAccount(address)
|
||||||
this.createNickname(address)
|
this.createNickname(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
createNickname(address) {
|
createNickname (address) {
|
||||||
const hexAddress = normalize(address)
|
const hexAddress = normalize(address)
|
||||||
var i = Object.keys(this.identities).length
|
var i = Object.keys(this.identities).length
|
||||||
const oldNickname = this.configManager.nicknameForWallet(address)
|
const oldNickname = this.configManager.nicknameForWallet(address)
|
||||||
@ -274,7 +274,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
persistAllKeyrings() {
|
persistAllKeyrings () {
|
||||||
const serialized = this.keyrings.map((k) => {
|
const serialized = this.keyrings.map((k) => {
|
||||||
return {
|
return {
|
||||||
type: k.type,
|
type: k.type,
|
||||||
@ -289,7 +289,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
unlockKeyrings(key) {
|
unlockKeyrings (key) {
|
||||||
const encryptedVault = this.configManager.getVault()
|
const encryptedVault = this.configManager.getVault()
|
||||||
return this.encryptor.decryptWithKey(key, encryptedVault)
|
return this.encryptor.decryptWithKey(key, encryptedVault)
|
||||||
.then((vault) => {
|
.then((vault) => {
|
||||||
@ -298,7 +298,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreKeyring(serialized) {
|
restoreKeyring (serialized) {
|
||||||
const { type, data } = serialized
|
const { type, data } = serialized
|
||||||
const Keyring = this.getKeyringClassForType(type)
|
const Keyring = this.getKeyringClassForType(type)
|
||||||
const keyring = new Keyring()
|
const keyring = new Keyring()
|
||||||
@ -311,7 +311,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
return keyring
|
return keyring
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeyringClassForType(type) {
|
getKeyringClassForType (type) {
|
||||||
const Keyring = this.keyringTypes.reduce((res, kr) => {
|
const Keyring = this.keyringTypes.reduce((res, kr) => {
|
||||||
if (kr.type() === type) {
|
if (kr.type() === type) {
|
||||||
return kr
|
return kr
|
||||||
@ -322,7 +322,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
return Keyring
|
return Keyring
|
||||||
}
|
}
|
||||||
|
|
||||||
getAccounts() {
|
getAccounts () {
|
||||||
const keyrings = this.keyrings || []
|
const keyrings = this.keyrings || []
|
||||||
return keyrings.map(kr => kr.getAccounts())
|
return keyrings.map(kr => kr.getAccounts())
|
||||||
.reduce((res, arr) => {
|
.reduce((res, arr) => {
|
||||||
@ -330,13 +330,13 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}, [])
|
}, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
setSelectedAddress(address, cb) {
|
setSelectedAddress (address, cb) {
|
||||||
var addr = normalize(address)
|
var addr = normalize(address)
|
||||||
this.configManager.setSelectedAccount(addr)
|
this.configManager.setSelectedAccount(addr)
|
||||||
cb(null, addr)
|
cb(null, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
addUnconfirmedTransaction(txParams, onTxDoneCb, cb) {
|
addUnconfirmedTransaction (txParams, onTxDoneCb, cb) {
|
||||||
var self = this
|
var self = this
|
||||||
const configManager = this.configManager
|
const configManager = this.configManager
|
||||||
|
|
||||||
@ -369,7 +369,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
], didComplete)
|
], didComplete)
|
||||||
|
|
||||||
// perform static analyis on the target contract code
|
// perform static analyis on the target contract code
|
||||||
function analyzeForDelegateCall(cb){
|
function analyzeForDelegateCall (cb) {
|
||||||
if (txParams.to) {
|
if (txParams.to) {
|
||||||
query.getCode(txParams.to, function (err, result) {
|
query.getCode(txParams.to, function (err, result) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
@ -388,8 +388,8 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function estimateGas(cb){
|
function estimateGas (cb) {
|
||||||
query.estimateGas(txParams, function(err, result){
|
query.estimateGas(txParams, function (err, result) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
txData.estimatedGas = self.addGasBuffer(result)
|
txData.estimatedGas = self.addGasBuffer(result)
|
||||||
cb()
|
cb()
|
||||||
@ -406,7 +406,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addUnconfirmedMessage(msgParams, cb) {
|
addUnconfirmedMessage (msgParams, cb) {
|
||||||
// create txData obj with parameters and meta data
|
// create txData obj with parameters and meta data
|
||||||
var time = (new Date()).getTime()
|
var time = (new Date()).getTime()
|
||||||
var msgId = createId()
|
var msgId = createId()
|
||||||
@ -428,7 +428,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
return msgId
|
return msgId
|
||||||
}
|
}
|
||||||
|
|
||||||
approveTransaction(txId, cb) {
|
approveTransaction (txId, cb) {
|
||||||
const configManager = this.configManager
|
const configManager = this.configManager
|
||||||
var approvalCb = this._unconfTxCbs[txId] || noop
|
var approvalCb = this._unconfTxCbs[txId] || noop
|
||||||
|
|
||||||
@ -441,7 +441,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
this.emit('update')
|
this.emit('update')
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelTransaction(txId, cb) {
|
cancelTransaction (txId, cb) {
|
||||||
const configManager = this.configManager
|
const configManager = this.configManager
|
||||||
var approvalCb = this._unconfTxCbs[txId] || noop
|
var approvalCb = this._unconfTxCbs[txId] || noop
|
||||||
|
|
||||||
@ -456,7 +456,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signTransaction(txParams, cb) {
|
signTransaction (txParams, cb) {
|
||||||
try {
|
try {
|
||||||
const address = normalize(txParams.from)
|
const address = normalize(txParams.from)
|
||||||
const keyring = this.getKeyringForAccount(address)
|
const keyring = this.getKeyringForAccount(address)
|
||||||
@ -492,7 +492,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signMessage(msgParams, cb) {
|
signMessage (msgParams, cb) {
|
||||||
try {
|
try {
|
||||||
const keyring = this.getKeyringForAccount(msgParams.from)
|
const keyring = this.getKeyringForAccount(msgParams.from)
|
||||||
const address = normalize(msgParams.from)
|
const address = normalize(msgParams.from)
|
||||||
@ -503,7 +503,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeyringForAccount(address) {
|
getKeyringForAccount (address) {
|
||||||
const hexed = normalize(address)
|
const hexed = normalize(address)
|
||||||
return this.keyrings.find((ring) => {
|
return this.keyrings.find((ring) => {
|
||||||
return ring.getAccounts()
|
return ring.getAccounts()
|
||||||
@ -512,19 +512,19 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelMessage(msgId, cb) {
|
cancelMessage (msgId, cb) {
|
||||||
if (cb && typeof cb === 'function') {
|
if (cb && typeof cb === 'function') {
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setLocked(cb) {
|
setLocked (cb) {
|
||||||
this.key = null
|
this.key = null
|
||||||
this.keyrings = []
|
this.keyrings = []
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
|
|
||||||
exportAccount(address, cb) {
|
exportAccount (address, cb) {
|
||||||
try {
|
try {
|
||||||
const keyring = this.getKeyringForAccount(address)
|
const keyring = this.getKeyringForAccount(address)
|
||||||
const privateKey = keyring.exportAccount(normalize(address))
|
const privateKey = keyring.exportAccount(normalize(address))
|
||||||
@ -534,19 +534,19 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addGasBuffer(gas) {
|
addGasBuffer (gas) {
|
||||||
const gasBuffer = new BN('100000', 10)
|
const gasBuffer = new BN('100000', 10)
|
||||||
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
|
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
|
||||||
const correct = bnGas.add(gasBuffer)
|
const correct = bnGas.add(gasBuffer)
|
||||||
return ethUtil.addHexPrefix(correct.toString(16))
|
return ethUtil.addHexPrefix(correct.toString(16))
|
||||||
}
|
}
|
||||||
|
|
||||||
clearSeedWordCache(cb) {
|
clearSeedWordCache (cb) {
|
||||||
this.configManager.setSeedWords(null)
|
this.configManager.setSeedWords(null)
|
||||||
cb(null, this.configManager.getSelectedAccount())
|
cb(null, this.configManager.getSelectedAccount())
|
||||||
}
|
}
|
||||||
|
|
||||||
clearKeyrings() {
|
clearKeyrings () {
|
||||||
let accounts
|
let accounts
|
||||||
try {
|
try {
|
||||||
accounts = Object.keys(this.ethStore._currentState.accounts)
|
accounts = Object.keys(this.ethStore._currentState.accounts)
|
||||||
@ -564,7 +564,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalize(address) {
|
function normalize (address) {
|
||||||
if (!address) return
|
if (!address) return
|
||||||
return ethUtil.addHexPrefix(address.toLowerCase())
|
return ethUtil.addHexPrefix(address.toLowerCase())
|
||||||
}
|
}
|
||||||
|
@ -9,17 +9,17 @@ const hdPathString = `m/44'/60'/0'/0`
|
|||||||
|
|
||||||
module.exports = class HdKeyring extends EventEmitter {
|
module.exports = class HdKeyring extends EventEmitter {
|
||||||
|
|
||||||
static type() {
|
static type () {
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(opts = {}) {
|
constructor (opts = {}) {
|
||||||
super()
|
super()
|
||||||
this.type = type
|
this.type = type
|
||||||
this.deserialize(opts)
|
this.deserialize(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
deserialize(opts = {}) {
|
deserialize (opts = {}) {
|
||||||
this.opts = opts || {}
|
this.opts = opts || {}
|
||||||
this.wallets = []
|
this.wallets = []
|
||||||
this.mnemonic = null
|
this.mnemonic = null
|
||||||
@ -34,26 +34,26 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initFromMnemonic(mnemonic) {
|
initFromMnemonic (mnemonic) {
|
||||||
this.mnemonic = mnemonic
|
this.mnemonic = mnemonic
|
||||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||||
this.hdWallet = hdkey.fromMasterSeed(seed)
|
this.hdWallet = hdkey.fromMasterSeed(seed)
|
||||||
this.root = this.hdWallet.derivePath(hdPathString)
|
this.root = this.hdWallet.derivePath(hdPathString)
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize() {
|
serialize () {
|
||||||
return {
|
return {
|
||||||
mnemonic: this.mnemonic,
|
mnemonic: this.mnemonic,
|
||||||
n: this.wallets.length,
|
n: this.wallets.length,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exportAccount(address) {
|
exportAccount (address) {
|
||||||
const wallet = this.getWalletForAccount(address)
|
const wallet = this.getWalletForAccount(address)
|
||||||
return wallet.getPrivateKey().toString('hex')
|
return wallet.getPrivateKey().toString('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
addAccounts(n = 1) {
|
addAccounts (n = 1) {
|
||||||
if (!this.root) {
|
if (!this.root) {
|
||||||
this.initFromMnemonic(bip39.generateMnemonic())
|
this.initFromMnemonic(bip39.generateMnemonic())
|
||||||
}
|
}
|
||||||
@ -69,12 +69,12 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
return newWallets.map(w => w.getAddress().toString('hex'))
|
return newWallets.map(w => w.getAddress().toString('hex'))
|
||||||
}
|
}
|
||||||
|
|
||||||
getAccounts() {
|
getAccounts () {
|
||||||
return this.wallets.map(w => w.getAddress().toString('hex'))
|
return this.wallets.map(w => w.getAddress().toString('hex'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx is an instance of the ethereumjs-transaction class.
|
// tx is an instance of the ethereumjs-transaction class.
|
||||||
signTransaction(address, tx) {
|
signTransaction (address, tx) {
|
||||||
const wallet = this.getWalletForAccount(address)
|
const wallet = this.getWalletForAccount(address)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
tx.sign(privKey)
|
tx.sign(privKey)
|
||||||
@ -82,7 +82,7 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For eth_sign, we need to sign transactions:
|
// For eth_sign, we need to sign transactions:
|
||||||
signMessage(withAccount, data) {
|
signMessage (withAccount, data) {
|
||||||
const wallet = this.getWalletForAccount(withAccount)
|
const wallet = this.getWalletForAccount(withAccount)
|
||||||
const message = ethUtil.removeHexPrefix(data)
|
const message = ethUtil.removeHexPrefix(data)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
@ -91,17 +91,14 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
return rawMsgSig
|
return rawMsgSig
|
||||||
}
|
}
|
||||||
|
|
||||||
getWalletForAccount(account) {
|
getWalletForAccount (account) {
|
||||||
return this.wallets.find((w) => {
|
return this.wallets.find((w) => {
|
||||||
const address = w.getAddress().toString('hex')
|
const address = w.getAddress().toString('hex')
|
||||||
return ((address === account) || (normalize(address) === account))
|
return ((address === account) || (normalize(address) === account))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalize(address) {
|
function normalize (address) {
|
||||||
return ethUtil.addHexPrefix(address.toLowerCase())
|
return ethUtil.addHexPrefix(address.toLowerCase())
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,22 @@ const sigUtil = require('../lib/sig-util')
|
|||||||
|
|
||||||
module.exports = class SimpleKeyring extends EventEmitter {
|
module.exports = class SimpleKeyring extends EventEmitter {
|
||||||
|
|
||||||
static type() {
|
static type () {
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(opts) {
|
constructor (opts) {
|
||||||
super()
|
super()
|
||||||
this.type = type
|
this.type = type
|
||||||
this.opts = opts || {}
|
this.opts = opts || {}
|
||||||
this.wallets = []
|
this.wallets = []
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize() {
|
serialize () {
|
||||||
return this.wallets.map(w => w.getPrivateKey().toString('hex'))
|
return this.wallets.map(w => w.getPrivateKey().toString('hex'))
|
||||||
}
|
}
|
||||||
|
|
||||||
deserialize(wallets = []) {
|
deserialize (wallets = []) {
|
||||||
this.wallets = wallets.map((w) => {
|
this.wallets = wallets.map((w) => {
|
||||||
var b = new Buffer(w, 'hex')
|
var b = new Buffer(w, 'hex')
|
||||||
const wallet = Wallet.fromPrivateKey(b)
|
const wallet = Wallet.fromPrivateKey(b)
|
||||||
@ -29,7 +29,7 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
addAccounts(n = 1) {
|
addAccounts (n = 1) {
|
||||||
var newWallets = []
|
var newWallets = []
|
||||||
for (var i = 0; i < n; i++) {
|
for (var i = 0; i < n; i++) {
|
||||||
newWallets.push(Wallet.generate())
|
newWallets.push(Wallet.generate())
|
||||||
@ -38,12 +38,12 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
|||||||
return newWallets.map(w => w.getAddress().toString('hex'))
|
return newWallets.map(w => w.getAddress().toString('hex'))
|
||||||
}
|
}
|
||||||
|
|
||||||
getAccounts() {
|
getAccounts () {
|
||||||
return this.wallets.map(w => w.getAddress().toString('hex'))
|
return this.wallets.map(w => w.getAddress().toString('hex'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx is an instance of the ethereumjs-transaction class.
|
// tx is an instance of the ethereumjs-transaction class.
|
||||||
signTransaction(address, tx) {
|
signTransaction (address, tx) {
|
||||||
const wallet = this.getWalletForAccount(address)
|
const wallet = this.getWalletForAccount(address)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
tx.sign(privKey)
|
tx.sign(privKey)
|
||||||
@ -51,7 +51,7 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For eth_sign, we need to sign transactions:
|
// For eth_sign, we need to sign transactions:
|
||||||
signMessage(withAccount, data) {
|
signMessage (withAccount, data) {
|
||||||
const wallet = this.getWalletForAccount(withAccount)
|
const wallet = this.getWalletForAccount(withAccount)
|
||||||
const message = ethUtil.removeHexPrefix(data)
|
const message = ethUtil.removeHexPrefix(data)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
@ -60,9 +60,8 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
|||||||
return rawMsgSig
|
return rawMsgSig
|
||||||
}
|
}
|
||||||
|
|
||||||
getWalletForAccount(account) {
|
getWalletForAccount (account) {
|
||||||
return this.wallets.find(w => w.getAddress().toString('hex') === account)
|
return this.wallets.find(w => w.getAddress().toString('hex') === account)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,17 +18,16 @@ function setupDappAutoReload (web3) {
|
|||||||
|
|
||||||
return handleResetRequest
|
return handleResetRequest
|
||||||
|
|
||||||
function handleResetRequest() {
|
function handleResetRequest () {
|
||||||
resetWasRequested = true
|
resetWasRequested = true
|
||||||
// ignore if web3 was not used
|
// ignore if web3 was not used
|
||||||
if (!pageIsUsingWeb3) return
|
if (!pageIsUsingWeb3) return
|
||||||
// reload after short timeout
|
// reload after short timeout
|
||||||
setTimeout(triggerReset, 500)
|
setTimeout(triggerReset, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reload the page
|
// reload the page
|
||||||
function triggerReset () {
|
function triggerReset () {
|
||||||
global.location.reload()
|
global.location.reload()
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ ConfigManager.prototype.getSalt = function () {
|
|||||||
return ('salt' in data) && data.salt
|
return ('salt' in data) && data.salt
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager.prototype.setSalt = function(salt) {
|
ConfigManager.prototype.setSalt = function (salt) {
|
||||||
var data = this.getData()
|
var data = this.getData()
|
||||||
data.salt = salt
|
data.salt = salt
|
||||||
this.setData(data)
|
this.setData(data)
|
||||||
@ -358,7 +358,6 @@ ConfigManager.prototype.updateConversionRate = function () {
|
|||||||
this.setConversionPrice(0)
|
this.setConversionPrice(0)
|
||||||
this.setConversionDate('N/A')
|
this.setConversionDate('N/A')
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager.prototype.setConversionPrice = function (price) {
|
ConfigManager.prototype.setConversionPrice = function (price) {
|
||||||
|
@ -42,7 +42,7 @@ function encryptWithKey (key, dataObj) {
|
|||||||
return global.crypto.subtle.encrypt({
|
return global.crypto.subtle.encrypt({
|
||||||
name: 'AES-GCM',
|
name: 'AES-GCM',
|
||||||
iv: vector,
|
iv: vector,
|
||||||
}, key, dataBuffer).then(function(buf){
|
}, key, dataBuffer).then(function (buf) {
|
||||||
var buffer = new Uint8Array(buf)
|
var buffer = new Uint8Array(buf)
|
||||||
var vectorStr = encodeBufferToBase64(vector)
|
var vectorStr = encodeBufferToBase64(vector)
|
||||||
var vaultStr = encodeBufferToBase64(buffer)
|
var vaultStr = encodeBufferToBase64(buffer)
|
||||||
@ -63,13 +63,13 @@ function decryptWithKey (key, text) {
|
|||||||
const encryptedData = decodeBase64ToBuffer(parts[0])
|
const encryptedData = decodeBase64ToBuffer(parts[0])
|
||||||
const vector = decodeBase64ToBuffer(parts[1])
|
const vector = decodeBase64ToBuffer(parts[1])
|
||||||
return crypto.subtle.decrypt({name: 'AES-GCM', iv: vector}, key, encryptedData)
|
return crypto.subtle.decrypt({name: 'AES-GCM', iv: vector}, key, encryptedData)
|
||||||
.then(function(result){
|
.then(function (result) {
|
||||||
const decryptedData = new Uint8Array(result)
|
const decryptedData = new Uint8Array(result)
|
||||||
const decryptedStr = convertArrayBufferViewtoString(decryptedData)
|
const decryptedStr = convertArrayBufferViewtoString(decryptedData)
|
||||||
const decryptedObj = JSON.parse(decryptedStr)
|
const decryptedObj = JSON.parse(decryptedStr)
|
||||||
return decryptedObj
|
return decryptedObj
|
||||||
})
|
})
|
||||||
.catch(function(reason) {
|
.catch(function (reason) {
|
||||||
throw new Error('Incorrect password')
|
throw new Error('Incorrect password')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ function convertArrayBufferViewtoString (buffer) {
|
|||||||
function keyFromPassword (password) {
|
function keyFromPassword (password) {
|
||||||
var passBuffer = convertStringToArrayBufferView(password)
|
var passBuffer = convertStringToArrayBufferView(password)
|
||||||
return global.crypto.subtle.digest('SHA-256', passBuffer)
|
return global.crypto.subtle.digest('SHA-256', passBuffer)
|
||||||
.then(function (passHash){
|
.then(function (passHash) {
|
||||||
return global.crypto.subtle.importKey('raw', passHash, {name: 'AES-GCM'}, false, ['encrypt', 'decrypt'])
|
return global.crypto.subtle.importKey('raw', passHash, {name: 'AES-GCM'}, false, ['encrypt', 'decrypt'])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ function encodeBufferToBase64 (buf) {
|
|||||||
|
|
||||||
function decodeBase64ToBuffer (base64) {
|
function decodeBase64ToBuffer (base64) {
|
||||||
var buf = new Uint8Array(atob(base64).split('')
|
var buf = new Uint8Array(atob(base64).split('')
|
||||||
.map(function(c) {
|
.map(function (c) {
|
||||||
return c.charCodeAt(0)
|
return c.charCodeAt(0)
|
||||||
}))
|
}))
|
||||||
return buf
|
return buf
|
||||||
|
@ -11,7 +11,7 @@ module.exports = class IdentityStoreMigrator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
oldSeedForPassword( password ) {
|
oldSeedForPassword (password) {
|
||||||
const hasOldVault = this.hasOldVault()
|
const hasOldVault = this.hasOldVault()
|
||||||
const configManager = this.configManager
|
const configManager = this.configManager
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ module.exports = class IdentityStoreMigrator {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
serializeVault() {
|
serializeVault () {
|
||||||
const mnemonic = this.idStore._idmgmt.getSeed()
|
const mnemonic = this.idStore._idmgmt.getSeed()
|
||||||
const n = this.idStore._getAddresses().length
|
const n = this.idStore._getAddresses().length
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ module.exports = class IdentityStoreMigrator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasOldVault() {
|
hasOldVault () {
|
||||||
const wallet = this.configManager.getWallet()
|
const wallet = this.configManager.getWallet()
|
||||||
return wallet
|
return wallet
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
|
|||||||
], didComplete)
|
], didComplete)
|
||||||
|
|
||||||
// perform static analyis on the target contract code
|
// perform static analyis on the target contract code
|
||||||
function analyzeForDelegateCall(cb){
|
function analyzeForDelegateCall (cb) {
|
||||||
if (txParams.to) {
|
if (txParams.to) {
|
||||||
query.getCode(txParams.to, (err, result) => {
|
query.getCode(txParams.to, (err, result) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
@ -256,16 +256,16 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function estimateGas(cb){
|
function estimateGas (cb) {
|
||||||
var estimationParams = extend(txParams)
|
var estimationParams = extend(txParams)
|
||||||
// 1 billion gas for estimation
|
// 1 billion gas for estimation
|
||||||
var gasLimit = '0x3b9aca00'
|
var gasLimit = '0x3b9aca00'
|
||||||
estimationParams.gas = gasLimit
|
estimationParams.gas = gasLimit
|
||||||
query.estimateGas(estimationParams, function(err, result){
|
query.estimateGas(estimationParams, function (err, result) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
if (result === estimationParams.gas) {
|
if (result === estimationParams.gas) {
|
||||||
txData.simulationFails = true
|
txData.simulationFails = true
|
||||||
query.getBlockByNumber('latest', true, function(err, block){
|
query.getBlockByNumber('latest', true, function (err, block) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
txData.estimatedGas = block.gasLimit
|
txData.estimatedGas = block.gasLimit
|
||||||
txData.txParams.gas = block.gasLimit
|
txData.txParams.gas = block.gasLimit
|
||||||
|
@ -39,7 +39,7 @@ function MetamaskInpageProvider (connectionStream) {
|
|||||||
|
|
||||||
self.idMap = {}
|
self.idMap = {}
|
||||||
// handle sendAsync requests via asyncProvider
|
// handle sendAsync requests via asyncProvider
|
||||||
self.sendAsync = function(payload, cb){
|
self.sendAsync = function (payload, cb) {
|
||||||
// rewrite request ids
|
// rewrite request ids
|
||||||
var request = eachJsonMessage(payload, (message) => {
|
var request = eachJsonMessage(payload, (message) => {
|
||||||
var newId = createRandomId()
|
var newId = createRandomId()
|
||||||
@ -48,7 +48,7 @@ function MetamaskInpageProvider (connectionStream) {
|
|||||||
return message
|
return message
|
||||||
})
|
})
|
||||||
// forward to asyncProvider
|
// forward to asyncProvider
|
||||||
asyncProvider.sendAsync(request, function(err, res){
|
asyncProvider.sendAsync(request, function (err, res) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
// transform messages to original ids
|
// transform messages to original ids
|
||||||
eachJsonMessage(res, (message) => {
|
eachJsonMessage(res, (message) => {
|
||||||
@ -119,7 +119,7 @@ function remoteStoreWithLocalStorageCache (storageKey) {
|
|||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRandomId(){
|
function createRandomId () {
|
||||||
const extraDigits = 3
|
const extraDigits = 3
|
||||||
// 13 time digits
|
// 13 time digits
|
||||||
const datePart = new Date().getTime() * Math.pow(10, extraDigits)
|
const datePart = new Date().getTime() * Math.pow(10, extraDigits)
|
||||||
@ -129,7 +129,7 @@ function createRandomId(){
|
|||||||
return datePart + extraPart
|
return datePart + extraPart
|
||||||
}
|
}
|
||||||
|
|
||||||
function eachJsonMessage(payload, transformFn){
|
function eachJsonMessage (payload, transformFn) {
|
||||||
if (Array.isArray(payload)) {
|
if (Array.isArray(payload)) {
|
||||||
return payload.map(transformFn)
|
return payload.map(transformFn)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module.exports = function isPopupOrNotification() {
|
module.exports = function isPopupOrNotification () {
|
||||||
const url = window.location.href
|
const url = window.location.href
|
||||||
if (url.match(/popup.html$/)) {
|
if (url.match(/popup.html$/)) {
|
||||||
return 'popup'
|
return 'popup'
|
||||||
|
@ -15,12 +15,9 @@ function show () {
|
|||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
if (popup) {
|
if (popup) {
|
||||||
|
|
||||||
// bring focus to existing popup
|
// bring focus to existing popup
|
||||||
extension.windows.update(popup.id, { focused: true })
|
extension.windows.update(popup.id, { focused: true })
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// create new popup
|
// create new popup
|
||||||
extension.windows.create({
|
extension.windows.create({
|
||||||
url: 'notification.html',
|
url: 'notification.html',
|
||||||
@ -29,12 +26,11 @@ function show () {
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWindows(cb) {
|
function getWindows (cb) {
|
||||||
// Ignore in test environment
|
// Ignore in test environment
|
||||||
if (!extension.windows) {
|
if (!extension.windows) {
|
||||||
return cb()
|
return cb()
|
||||||
@ -45,14 +41,14 @@ function getWindows(cb) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPopup(cb) {
|
function getPopup (cb) {
|
||||||
getWindows((err, windows) => {
|
getWindows((err, windows) => {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
cb(null, getPopupIn(windows))
|
cb(null, getPopupIn(windows))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPopupIn(windows) {
|
function getPopupIn (windows) {
|
||||||
return windows ? windows.find((win) => {
|
return windows ? windows.find((win) => {
|
||||||
return (win && win.type === 'popup' &&
|
return (win && win.type === 'popup' &&
|
||||||
win.height === height &&
|
win.height === height &&
|
||||||
@ -60,7 +56,7 @@ function getPopupIn(windows) {
|
|||||||
}) : null
|
}) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
function closePopup() {
|
function closePopup () {
|
||||||
getPopup((err, popup) => {
|
getPopup((err, popup) => {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
if (!popup) return
|
if (!popup) return
|
||||||
|
@ -87,23 +87,6 @@ module.exports = class MetamaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onRpcRequest (stream, originDomain, request) {
|
onRpcRequest (stream, originDomain, request) {
|
||||||
|
|
||||||
/* Commented out for Parity compliance
|
|
||||||
* Parity does not permit additional keys, like `origin`,
|
|
||||||
* and Infura is not currently filtering this key out.
|
|
||||||
var payloads = Array.isArray(request) ? request : [request]
|
|
||||||
payloads.forEach(function (payload) {
|
|
||||||
// Append origin to rpc payload
|
|
||||||
payload.origin = originDomain
|
|
||||||
// Append origin to signature request
|
|
||||||
if (payload.method === 'eth_sendTransaction') {
|
|
||||||
payload.params[0].origin = originDomain
|
|
||||||
} else if (payload.method === 'eth_sign') {
|
|
||||||
payload.params.push({ origin: originDomain })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
|
||||||
// handle rpc request
|
// handle rpc request
|
||||||
this.provider.sendAsync(request, function onPayloadHandled (err, response) {
|
this.provider.sendAsync(request, function onPayloadHandled (err, response) {
|
||||||
logger(err, request, response)
|
logger(err, request, response)
|
||||||
@ -217,7 +200,7 @@ module.exports = class MetamaskController {
|
|||||||
newUnsignedTransaction (txParams, onTxDoneCb) {
|
newUnsignedTransaction (txParams, onTxDoneCb) {
|
||||||
const keyringController = this.keyringController
|
const keyringController = this.keyringController
|
||||||
|
|
||||||
let err = this.enforceTxValidations(txParams)
|
const err = this.enforceTxValidations(txParams)
|
||||||
if (err) return onTxDoneCb(err)
|
if (err) return onTxDoneCb(err)
|
||||||
keyringController.addUnconfirmedTransaction(txParams, onTxDoneCb, (err, txData) => {
|
keyringController.addUnconfirmedTransaction(txParams, onTxDoneCb, (err, txData) => {
|
||||||
if (err) return onTxDoneCb(err)
|
if (err) return onTxDoneCb(err)
|
||||||
@ -291,7 +274,6 @@ module.exports = class MetamaskController {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error in checking TOS change.')
|
console.error('Error in checking TOS change.')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
agreeToDisclaimer (cb) {
|
agreeToDisclaimer (cb) {
|
||||||
@ -373,7 +355,7 @@ module.exports = class MetamaskController {
|
|||||||
this.configManager.createShapeShiftTx(depositAddress, depositType)
|
this.configManager.createShapeShiftTx(depositAddress, depositType)
|
||||||
}
|
}
|
||||||
|
|
||||||
getNetwork(err) {
|
getNetwork (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.state.network = 'loading'
|
this.state.network = 'loading'
|
||||||
this.sendUpdate()
|
this.sendUpdate()
|
||||||
@ -405,4 +387,3 @@ module.exports = class MetamaskController {
|
|||||||
return this.state.network
|
return this.state.network
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
|||||||
module.exports = initializePopup
|
module.exports = initializePopup
|
||||||
|
|
||||||
|
|
||||||
function initializePopup(connectionStream){
|
function initializePopup (connectionStream) {
|
||||||
// setup app
|
// setup app
|
||||||
connectToAccountManager(connectionStream, setupApp)
|
connectToAccountManager(connectionStream, setupApp)
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ function setupWeb3Connection (connectionStream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupControllerConnection (connectionStream, cb) {
|
function setupControllerConnection (connectionStream, cb) {
|
||||||
// this is a really sneaky way of adding EventEmitter api
|
// this is a really sneaky way of adding EventEmitter api
|
||||||
// to a bi-directional dnode instance
|
// to a bi-directional dnode instance
|
||||||
var eventEmitter = new EventEmitter()
|
var eventEmitter = new EventEmitter()
|
||||||
var accountManagerDnode = Dnode({
|
var accountManagerDnode = Dnode({
|
||||||
|
@ -18,7 +18,7 @@ var portStream = new PortStream(pluginPort)
|
|||||||
|
|
||||||
startPopup(portStream)
|
startPopup(portStream)
|
||||||
|
|
||||||
function closePopupIfOpen(name) {
|
function closePopupIfOpen (name) {
|
||||||
if (name !== 'notification') {
|
if (name !== 'notification') {
|
||||||
notification.closePopup()
|
notification.closePopup()
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ var actions = {
|
|||||||
module.exports = actions
|
module.exports = actions
|
||||||
|
|
||||||
var background = null
|
var background = null
|
||||||
function _setBackgroundConnection(backgroundConnection) {
|
function _setBackgroundConnection (backgroundConnection) {
|
||||||
background = backgroundConnection
|
background = backgroundConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,6 @@ App.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
App.prototype.renderAppBar = function () {
|
App.prototype.renderAppBar = function () {
|
||||||
|
|
||||||
if (window.METAMASK_UI_TYPE === 'notification') {
|
if (window.METAMASK_UI_TYPE === 'notification') {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -367,7 +366,6 @@ App.prototype.renderPrimary = function () {
|
|||||||
|
|
||||||
// show initialize screen
|
// show initialize screen
|
||||||
if (!props.isInitialized || props.forgottenPassword) {
|
if (!props.isInitialized || props.forgottenPassword) {
|
||||||
|
|
||||||
// show current view
|
// show current view
|
||||||
switch (props.currentView.name) {
|
switch (props.currentView.name) {
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ const actions = require('../actions')
|
|||||||
const isValidAddress = require('../util').isValidAddress
|
const isValidAddress = require('../util').isValidAddress
|
||||||
module.exports = connect(mapStateToProps)(CoinbaseForm)
|
module.exports = connect(mapStateToProps)(CoinbaseForm)
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps (state) {
|
||||||
return {
|
return {
|
||||||
selectedAccount: state.selectedAccount,
|
selectedAccount: state.selectedAccount,
|
||||||
warning: state.appState.warning,
|
warning: state.appState.warning,
|
||||||
@ -16,7 +16,7 @@ function mapStateToProps(state) {
|
|||||||
|
|
||||||
inherits(CoinbaseForm, Component)
|
inherits(CoinbaseForm, Component)
|
||||||
|
|
||||||
function CoinbaseForm() {
|
function CoinbaseForm () {
|
||||||
Component.call(this)
|
Component.call(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,6 @@ CoinbaseForm.prototype.toCoinbase = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoinbaseForm.prototype.renderLoading = function () {
|
CoinbaseForm.prototype.renderLoading = function () {
|
||||||
|
|
||||||
return h('img', {
|
return h('img', {
|
||||||
style: {
|
style: {
|
||||||
width: '27px',
|
width: '27px',
|
||||||
@ -134,9 +133,8 @@ CoinbaseForm.prototype.renderLoading = function () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidAmountforCoinBase(amount) {
|
function isValidAmountforCoinBase (amount) {
|
||||||
amount = parseFloat(amount)
|
amount = parseFloat(amount)
|
||||||
|
|
||||||
if (amount) {
|
if (amount) {
|
||||||
if (amount <= 5 && amount > 0) {
|
if (amount <= 5 && amount > 0) {
|
||||||
return {
|
return {
|
||||||
|
@ -50,12 +50,10 @@ CopyButton.prototype.render = function () {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyButton.prototype.debounceRestore = function() {
|
CopyButton.prototype.debounceRestore = function () {
|
||||||
|
|
||||||
this.setState({ copied: true })
|
this.setState({ copied: true })
|
||||||
clearTimeout(this.timeout)
|
clearTimeout(this.timeout)
|
||||||
this.timeout = setTimeout(() => {
|
this.timeout = setTimeout(() => {
|
||||||
this.setState({ copied: false })
|
this.setState({ copied: false })
|
||||||
}, 850)
|
}, 850)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ DropMenuItem.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DropMenuItem.prototype.activeNetworkRender = function () {
|
DropMenuItem.prototype.activeNetworkRender = function () {
|
||||||
let activeNetwork = this.props.activeNetworkRender
|
const activeNetwork = this.props.activeNetworkRender
|
||||||
let { provider } = this.props
|
const { provider } = this.props
|
||||||
let providerType = provider ? provider.type : null
|
const providerType = provider ? provider.type : null
|
||||||
if (activeNetwork === undefined) return
|
if (activeNetwork === undefined) return
|
||||||
|
|
||||||
switch (this.props.label) {
|
switch (this.props.label) {
|
||||||
|
@ -22,7 +22,6 @@ Network.prototype.render = function () {
|
|||||||
let iconName, hoverText
|
let iconName, hoverText
|
||||||
|
|
||||||
if (networkNumber === 'loading') {
|
if (networkNumber === 'loading') {
|
||||||
|
|
||||||
return h('img.network-indicator', {
|
return h('img.network-indicator', {
|
||||||
title: 'Attempting to connect to blockchain.',
|
title: 'Attempting to connect to blockchain.',
|
||||||
onClick: (event) => this.props.onClick(event),
|
onClick: (event) => this.props.onClick(event),
|
||||||
@ -32,7 +31,6 @@ Network.prototype.render = function () {
|
|||||||
},
|
},
|
||||||
src: 'images/loading.svg',
|
src: 'images/loading.svg',
|
||||||
})
|
})
|
||||||
|
|
||||||
} else if (providerName === 'mainnet') {
|
} else if (providerName === 'mainnet') {
|
||||||
hoverText = 'Main Ethereum Network'
|
hoverText = 'Main Ethereum Network'
|
||||||
iconName = 'ethereum-network'
|
iconName = 'ethereum-network'
|
||||||
|
@ -30,22 +30,22 @@ PendingTx.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
`),
|
`),
|
||||||
|
|
||||||
txData.simulationFails ?
|
txData.simulationFails
|
||||||
h('.error', {
|
? h('.error', {
|
||||||
style: {
|
style: {
|
||||||
marginLeft: 50,
|
marginLeft: 50,
|
||||||
fontSize: '0.9em',
|
fontSize: '0.9em',
|
||||||
},
|
},
|
||||||
}, 'Transaction Error. Exception thrown in contract code.')
|
}, 'Transaction Error. Exception thrown in contract code.')
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
state.insufficientBalance ?
|
state.insufficientBalance
|
||||||
h('span.error', {
|
? h('span.error', {
|
||||||
style: {
|
style: {
|
||||||
marginLeft: 50,
|
marginLeft: 50,
|
||||||
fontSize: '0.9em',
|
fontSize: '0.9em',
|
||||||
},
|
},
|
||||||
}, 'Insufficient balance for transaction')
|
}, 'Insufficient balance for transaction')
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
// send + cancel
|
// send + cancel
|
||||||
@ -57,10 +57,10 @@ PendingTx.prototype.render = function () {
|
|||||||
},
|
},
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
state.insufficientBalance ?
|
state.insufficientBalance
|
||||||
h('button.btn-green', {
|
? h('button.btn-green', {
|
||||||
onClick: state.buyEth,
|
onClick: state.buyEth,
|
||||||
}, 'Buy Ether')
|
}, 'Buy Ether')
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
h('button.confirm', {
|
h('button.confirm', {
|
||||||
|
@ -8,7 +8,7 @@ const Qr = require('./qr-code')
|
|||||||
const isValidAddress = require('../util').isValidAddress
|
const isValidAddress = require('../util').isValidAddress
|
||||||
module.exports = connect(mapStateToProps)(ShapeshiftForm)
|
module.exports = connect(mapStateToProps)(ShapeshiftForm)
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps (state) {
|
||||||
return {
|
return {
|
||||||
selectedAccount: state.selectedAccount,
|
selectedAccount: state.selectedAccount,
|
||||||
warning: state.appState.warning,
|
warning: state.appState.warning,
|
||||||
@ -25,7 +25,6 @@ function ShapeshiftForm () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShapeshiftForm.prototype.render = function () {
|
ShapeshiftForm.prototype.render = function () {
|
||||||
|
|
||||||
return h(ReactCSSTransitionGroup, {
|
return h(ReactCSSTransitionGroup, {
|
||||||
className: 'css-transition-group',
|
className: 'css-transition-group',
|
||||||
transitionName: 'main',
|
transitionName: 'main',
|
||||||
@ -34,7 +33,6 @@ ShapeshiftForm.prototype.render = function () {
|
|||||||
}, [
|
}, [
|
||||||
this.props.qrRequested ? h(Qr, {key: 'qr'}) : this.renderMain(),
|
this.props.qrRequested ? h(Qr, {key: 'qr'}) : this.renderMain(),
|
||||||
])
|
])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapeshiftForm.prototype.renderMain = function () {
|
ShapeshiftForm.prototype.renderMain = function () {
|
||||||
|
@ -26,7 +26,6 @@ function ShiftListItem () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShiftListItem.prototype.render = function () {
|
ShiftListItem.prototype.render = function () {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h('.transaction-list-item.flex-row', {
|
h('.transaction-list-item.flex-row', {
|
||||||
style: {
|
style: {
|
||||||
|
@ -11,7 +11,6 @@ function Tooltip () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tooltip.prototype.render = function () {
|
Tooltip.prototype.render = function () {
|
||||||
|
|
||||||
const props = this.props
|
const props = this.props
|
||||||
const { position, title, children } = props
|
const { position, title, children } = props
|
||||||
|
|
||||||
@ -20,5 +19,4 @@ Tooltip.prototype.render = function () {
|
|||||||
title,
|
title,
|
||||||
fixed: false,
|
fixed: false,
|
||||||
}, children)
|
}, children)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ TransactionListItem.prototype.render = function () {
|
|||||||
style: {
|
style: {
|
||||||
fontSize: '27px',
|
fontSize: '27px',
|
||||||
},
|
},
|
||||||
}) : h( '.pop-hover', {
|
}) : h('.pop-hover', {
|
||||||
onClick: (event) => {
|
onClick: (event) => {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
if (!isTx || isPending) return
|
if (!isTx || isPending) return
|
||||||
|
@ -41,7 +41,7 @@ function rootReducer (state, action) {
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
window.logState = function() {
|
window.logState = function () {
|
||||||
var stateString = JSON.stringify(window.METAMASK_CACHED_LOG_STATE, null, 2)
|
var stateString = JSON.stringify(window.METAMASK_CACHED_LOG_STATE, null, 2)
|
||||||
console.log(stateString)
|
console.log(stateString)
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,6 @@ function reduceApp (state, action) {
|
|||||||
warning: null,
|
warning: null,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
notification.closePopup()
|
notification.closePopup()
|
||||||
|
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module.exports = function(address, network) {
|
module.exports = function (address, network) {
|
||||||
const net = parseInt(network)
|
const net = parseInt(network)
|
||||||
let link
|
let link
|
||||||
|
|
||||||
|
@ -8,23 +8,22 @@
|
|||||||
// Nickname keys must be stored in lower case.
|
// Nickname keys must be stored in lower case.
|
||||||
const nicknames = {}
|
const nicknames = {}
|
||||||
|
|
||||||
module.exports = function(addr, identities = {}) {
|
module.exports = function (addr, identities = {}) {
|
||||||
|
|
||||||
const address = addr.toLowerCase()
|
const address = addr.toLowerCase()
|
||||||
const ids = hashFromIdentities(identities)
|
const ids = hashFromIdentities(identities)
|
||||||
|
|
||||||
return addrFromHash(address, ids) || addrFromHash(address, nicknames)
|
return addrFromHash(address, ids) || addrFromHash(address, nicknames)
|
||||||
}
|
}
|
||||||
|
|
||||||
function hashFromIdentities(identities) {
|
function hashFromIdentities (identities) {
|
||||||
const result = {}
|
const result = {}
|
||||||
for (let key in identities) {
|
for (const key in identities) {
|
||||||
result[key] = identities[key].name
|
result[key] = identities[key].name
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function addrFromHash(addr, hash) {
|
function addrFromHash (addr, hash) {
|
||||||
const address = addr.toLowerCase()
|
const address = addr.toLowerCase()
|
||||||
return hash[address] || null
|
return hash[address] || null
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,6 @@ function jsNumberForAddress (address) {
|
|||||||
return seed
|
return seed
|
||||||
}
|
}
|
||||||
|
|
||||||
function toDataUri(identiconSrc){
|
function toDataUri (identiconSrc) {
|
||||||
return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(identiconSrc)
|
return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(identiconSrc)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user