Created
July 30, 2017 08:11
-
-
Save tranvictor/7f54d1c534688414af53b85934f736ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sync(ethereum, callback) { | |
var promise | |
promise = new Promise((resolve, reject) => { | |
const acc = this.shallowClone() | |
ethereum.getBalance(acc.address, (balance) => { | |
acc.balance = balance | |
resolve(acc) | |
}) | |
}) | |
promise = promise.then((acc) => { | |
return new Promise((resolve, reject) => { | |
ethereum.getNonce(acc.address, (nonce) => { | |
acc.nonce = nonce | |
if (acc.nonce > acc.manualNonce) { | |
acc.manualNonce = acc.nonce | |
} | |
resolve(acc) | |
}) | |
}) | |
}) | |
Object.keys(this.tokens).forEach((key) => { | |
promise = promise.then((acc) => { | |
return new Promise((resolve, reject) => { | |
acc.tokens[key].sync(ethereum, (token) => { | |
acc.tokens[key] = token | |
resolve(acc) | |
}) | |
}) | |
}) | |
}) | |
promise.then((acc) => { | |
callback(acc) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment