mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
wallet sync fix
This commit is contained in:
parent
722acdad35
commit
e50e189443
@ -11,6 +11,10 @@ module.exports = IdentityManager
|
|||||||
var provider = null
|
var provider = null
|
||||||
var pubsub = new EventEmitter()
|
var pubsub = new EventEmitter()
|
||||||
|
|
||||||
|
pubsub.on('block', function(){
|
||||||
|
updateIdentities()
|
||||||
|
})
|
||||||
|
|
||||||
function IdentityManager(opts){
|
function IdentityManager(opts){
|
||||||
opts = opts || {}
|
opts = opts || {}
|
||||||
providerEngine = opts.providerEngine
|
providerEngine = opts.providerEngine
|
||||||
@ -32,24 +36,41 @@ function IdentityManager(opts){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// plugin popup
|
||||||
|
IdentityManager.prototype.getState = getState
|
||||||
|
IdentityManager.prototype.subscribe = subscribe
|
||||||
|
IdentityManager.prototype.submitPassword = submitPassword
|
||||||
|
IdentityManager.prototype.setSelectedAddress = setSelectedAddress
|
||||||
|
IdentityManager.prototype.signTransaction = signTransaction
|
||||||
|
IdentityManager.prototype.setLocked = setLocked
|
||||||
|
// eth rpc
|
||||||
|
IdentityManager.prototype.getAccounts = getAccounts
|
||||||
|
IdentityManager.prototype.confirmTransaction = confirmTransaction
|
||||||
|
// etc
|
||||||
|
IdentityManager.prototype.newBlock = newBlock
|
||||||
|
IdentityManager.prototype.setProvider = setProvider
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function setProvider(_provider){
|
function setProvider(_provider){
|
||||||
provider = _provider
|
provider = _provider
|
||||||
}
|
}
|
||||||
|
|
||||||
function newBlock(block){
|
function newBlock(block){
|
||||||
pubsub.emit('block', block)
|
pubsub.emit('block', block)
|
||||||
updateIdentities()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// on new block, update our accounts (but only if we're unlocked)
|
// on new block, update our accounts (but only if we're unlocked)
|
||||||
function subscribe(cb){
|
function subscribe(cb){
|
||||||
pubsub.on('block', sendUpdateState)
|
pubsub.on('block', sendUpdateState)
|
||||||
|
// we're not unsubbing
|
||||||
|
// this causes errors and potentially breaks shit
|
||||||
|
// we should emit on change instead
|
||||||
|
// and background should handle unsubbing
|
||||||
function sendUpdateState(){
|
function sendUpdateState(){
|
||||||
if (!isUnlocked()) return
|
if (!isUnlocked()) return
|
||||||
updateIdentities(function(){
|
var state = _getState()
|
||||||
var state = _getState()
|
cb(state)
|
||||||
cb(state)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +173,11 @@ function updateIdentity(address, cb){
|
|||||||
function getTxCount(address, cb){
|
function getTxCount(address, cb){
|
||||||
provider.sendAsync(createPayload({
|
provider.sendAsync(createPayload({
|
||||||
method: 'eth_getTransactionCount',
|
method: 'eth_getTransactionCount',
|
||||||
params: [address],
|
// we actually want the pending txCount
|
||||||
|
// but pending is broken in provider-engine
|
||||||
|
// https://github.com/MetaMask/provider-engine/issues/11
|
||||||
|
// params: [address, 'pending'],
|
||||||
|
params: [address, 'latest'],
|
||||||
}), function(err, res){
|
}), function(err, res){
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
if (res.error) return cb(res.error)
|
if (res.error) return cb(res.error)
|
||||||
@ -163,7 +188,7 @@ function getTxCount(address, cb){
|
|||||||
function getAccountBalance(address, cb){
|
function getAccountBalance(address, cb){
|
||||||
provider.sendAsync(createPayload({
|
provider.sendAsync(createPayload({
|
||||||
method: 'eth_getBalance',
|
method: 'eth_getBalance',
|
||||||
params: [address],
|
params: [address, 'latest'],
|
||||||
}), function(err, res){
|
}), function(err, res){
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
if (res.error) return cb(res.error)
|
if (res.error) return cb(res.error)
|
||||||
|
@ -17,7 +17,7 @@ function StreamProvider(){
|
|||||||
// public
|
// public
|
||||||
|
|
||||||
StreamProvider.prototype.send = function(payload){
|
StreamProvider.prototype.send = function(payload){
|
||||||
throw new Error('StreamProvider - does not support synchronous RPC calls')
|
throw new Error('StreamProvider - does not support synchronous RPC calls. called: "'+payload.method+'"')
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamProvider.prototype.sendAsync = function(payload, callback){
|
StreamProvider.prototype.sendAsync = function(payload, callback){
|
||||||
|
Loading…
Reference in New Issue
Block a user