Skip to content

Commit

Permalink
update cc-wallet-core
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Dec 1, 2014
1 parent cb69752 commit 30013d1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cc-wallet-engine",
"version": "0.1.4",
"version": "0.1.5",
"description": "",
"main": "./src/index.js",
"keywords": [],
Expand All @@ -17,7 +17,7 @@
"dependencies": {
"bip39": "^2.1.0",
"browser-request": "^0.3.2",
"cc-wallet-core": "git://github.com/chromaway/cc-wallet-core.git#v0.2.6",
"cc-wallet-core": "git://github.com/chromaway/cc-wallet-core.git#v0.2.7",
"crypto-js": "^3.1.2-5",
"delayed": "^1.0.1",
"lodash": "^2.4.1",
Expand Down
7 changes: 7 additions & 0 deletions src/HistoryEntryModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ function HistoryEntryModel(historyEntry) {
this.historyEntry = historyEntry
}

/**
* @return {cc-wallet-core.history.HistoryEntry}
*/
HistoryEntryModel.prototype.getHistoryEntry = function () {
return this.historyEntry
}

/**
* @return {string}
*/
Expand Down
38 changes: 15 additions & 23 deletions src/WalletEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var HistoryEntryModel = require('./HistoryEntryModel')
function WalletEngine(opts) {
var self = this
events.EventEmitter.call(self)
self.setMaxListeners(100) // 10 by default, 0 -- unlimited
SyncMixin.call(self)

opts = _.extend({
Expand Down Expand Up @@ -90,17 +91,11 @@ WalletEngine.prototype.setCallback = function (callback) {
/**
*/
WalletEngine.prototype._update = function () {
var self = this

if (!self.isSyncing()) {
return self._updateCallback()
if (this.isSyncing()) {
return this.once('syncStop', this._updateCallback.bind(this))
}

function onSyncStop() {
self.removeListener('syncStop', onSyncStop)
self._updateCallback()
}
self.on('syncStop', onSyncStop)
this._updateCallback()
}

/**
Expand Down Expand Up @@ -132,25 +127,22 @@ WalletEngine.prototype._initializeWalletEngine = function () {

self._assetModels = new AssetModels(self)
self._assetModels.on('error', function (error) { self.emit('error', error) })
self._assetModels.on('update', function () { self._update() })
self._assetModels.on('syncStart', function () { self._syncEnter() })
self._assetModels.on('syncStop', function () { self._syncExit() })
self._assetModels.on('update', function () {
self._update()
self._syncEnter()
self._wallet.getHistory(function (error, entries) {
self._syncExit()
if (error) { return }

function entryEqualFn(entry, index) { return entry.getTxId() === entries[index].getTxId() }
var isEqual = self._historyEntries.length === entries.length && self._historyEntries.every(entryEqualFn)
if (isEqual) { return }
self._wallet.on('historyUpdate', function () {
var entries = self._wallet.getHistory()

function entryEqualFn(entry, index) { return entry.getHistoryEntry().isEqual(entries[index]) }
var isEqual = self._historyEntries.length === entries.length && self._historyEntries.every(entryEqualFn)
if (isEqual) { return }

self._historyEntries = entries.map(function (entry) {
return new HistoryEntryModel(entry)
}).reverse()
self._historyEntries = entries.map(function (entry) {
return new HistoryEntryModel(entry)
}).reverse()

self._update()
})
self._update()
})

function subscribeCallback(error) {
Expand Down
19 changes: 10 additions & 9 deletions test/HistoryEntryModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ describe('HistoryEntryModel', function () {
wallet.on('error', function (error) { throw error })
wallet.getWallet().initialize('12355564466111166655222222222222')

// @todo N
wallet.getWallet().subscribeAndSyncAllAddresses(function (error) {
expect(error).to.be.null
wallet.on('historyUpdate', function () { console.log('historyUpdate') })

wallet.on('syncStop', function () {
var entries = wallet.getWallet().getHistory()

wallet.getWallet().getHistory(function (error, entries) {
expect(error).to.be.null
expect(entries).to.be.instanceof(Array).with.to.have.length(1)
historyEntry = new HistoryEntryModel(entries[0])

expect(entries).to.be.instanceof(Array).with.to.have.length(1)
historyEntry = new HistoryEntryModel(entries[0])
done()
})

done()
})
wallet.getWallet().subscribeAndSyncAllAddresses(function (error) {
expect(error).to.be.null
})
})

Expand Down

0 comments on commit 30013d1

Please sign in to comment.