Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #455 from blockchain/bch-archived
Browse files Browse the repository at this point in the history
Treat archived imported addresses as active for BCH
  • Loading branch information
Mark Pfluger authored Oct 31, 2017
2 parents 8cf977c + 966939b commit 873be81
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/bch/bch-imported.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const sumNonNull = compose(reduce(add, 0), filter(x => x != null))

class BchImported extends BchSpendable {
get addresses () {
return this._wallet.spendableActiveAddresses
return this._wallet.spendableAddresses
}

get label () {
Expand Down
8 changes: 8 additions & 0 deletions src/blockchain-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ Object.defineProperties(Wallet.prototype, {
configurable: false,
get: function () { return this.activeKeys.map(function (k) { return k.address; }); }
},
'spendableAddresses': {
configurable: false,
get: function () {
return this.keys
.filter(function (k) { return !k.isWatchOnly; })
.map(function (k) { return k.address; });
}
},
'spendableActiveAddresses': {
configurable: false,
get: function () {
Expand Down
1 change: 1 addition & 0 deletions tests/__mocks__/blockchain-wallet.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BlockchainWalletMock {
this.addresses = Object.keys(addrs);
this.keys = this.addresses.map(a => addrs[a]);
this.activeKeys = this.keys.filter(k => !k.archived);
this.spendableAddresses = this.keys.filter(k => !k.isWatchOnly).map(k => k.address);
this.spendableActiveAddresses = this.activeKeys.filter(k => !k.isWatchOnly).map(k => k.address);

this.hdwallet = {
Expand Down
9 changes: 5 additions & 4 deletions tests/bch/bch-imported.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('BchImported', () => {
})

it('should have: addresses', () => {
expect(imported.addresses).toEqual(['1asdf'])
expect(imported.addresses).toEqual(['1asdf', '1arch'])
})

it('should have: label', () => {
Expand All @@ -35,21 +35,22 @@ describe('BchImported', () => {

it('should have: balance (with value)', () => {
spyOn(BchSpendable.prototype, 'getAddressBalance').and.returnValue(100)
expect(imported.balance).toEqual(100)
expect(imported.balance).toEqual(200)
expect(BchSpendable.prototype.getAddressBalance).toHaveBeenCalledWith('1asdf')
expect(BchSpendable.prototype.getAddressBalance).toHaveBeenCalledWith('1arch')
})

it('should be able to get the available balance', () => {
spyOn(BchSpendable.prototype, 'getAvailableBalance')
imported.getAvailableBalance(10)
expect(BchSpendable.prototype.getAvailableBalance).toHaveBeenCalledWith(['1asdf'], 10)
expect(BchSpendable.prototype.getAvailableBalance).toHaveBeenCalledWith(['1asdf', '1arch'], 10)
})

it('should be able to call createPayment()', () => {
let from = jasmine.createSpy('from')
spyOn(BchSpendable.prototype, 'createPayment').and.returnValue({ from })
imported.createPayment()
expect(from).toHaveBeenCalledWith(['1asdf'], '1asdf')
expect(from).toHaveBeenCalledWith(['1asdf', '1arch'], '1asdf')
expect(BchSpendable.prototype.createPayment).toHaveBeenCalledWith()
})
})
6 changes: 3 additions & 3 deletions tests/bch/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe('bch', () => {
expect(bch.importedAddresses).not.toEqual(null)
})

it('should not have importedAddresses if there are no spendable active addresses', () => {
wallet.spendableActiveAddresses = []
it('should not have importedAddresses if there are no spendable addresses', () => {
wallet.spendableAddresses = []
bch = BitcoinCashWallet.fromBlockchainWallet(wallet)
expect(bch.importedAddresses).toEqual(null)
})
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('bch', () => {

it('should call multiaddr with all addresses and xpubs', (done) => {
bch.getHistory().then(() => {
expect(BchApi.multiaddr).toHaveBeenCalledWith(['1asdf', 'xpub1', 'xpub2'], 50)
expect(BchApi.multiaddr).toHaveBeenCalledWith(['1asdf', '1arch', 'xpub1', 'xpub2'], 50)
done()
})
})
Expand Down
2 changes: 2 additions & 0 deletions tests/blockchain-wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ describe('Blockchain-Wallet', () => {

it('defaultPbkdf2Iterations', () => expect(wallet.defaultPbkdf2Iterations).toEqual(5000));

it('spendableAddresses', () => expect(wallet.spendableAddresses.length).toEqual(2));

it('spendableActiveAddresses', () => expect(wallet.spendableActiveAddresses.length).toEqual(1));
});

Expand Down

0 comments on commit 873be81

Please sign in to comment.