Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tranvictor/7f54d1c534688414af53b85934f736ae to your computer and use it in GitHub Desktop.
Save tranvictor/7f54d1c534688414af53b85934f736ae to your computer and use it in GitHub Desktop.
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