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

feat(BCH): add bch to currency balance stats #531

Open
wants to merge 1 commit into
base: bch-archived
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ API.prototype.incrementLoginViaQrStats = function () {
return fetch(this.ROOT_URL + 'event?name=wallet_web_login_via_qr');
};

API.prototype.incrementBtcEthUsageStats = function (btcBalance, ethBalance) {
API.prototype.incrementCurrencyUsageStats = function (btcBalance, ethBalance, bchBalance) {
let base = this.ROOT_URL + 'event?name=wallet_login_balance';
let makeEventUrl = (btc, eth) => `${base}_btc_${btc ? 1 : 0}_eth_${eth ? 1 : 0}`;
fetch(makeEventUrl(btcBalance > 0, ethBalance > 0));
let makeEventUrl = (btc, eth, bch) => `${base}_btc_${btc ? 1 : 0}_eth_${eth ? 1 : 0}_bch_${bch ? 1 : 0}`;
fetch(makeEventUrl(btcBalance > 0, ethBalance > 0, bchBalance > 0));
};

API.prototype.getPriceChartData = function (params) {
Expand Down
25 changes: 15 additions & 10 deletions tests/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,41 @@ describe('API', () => {
});
});

describe('.incrementBtcEthUsageStats', () => {
describe('.incrementCurrencyUsageStats', () => {
let eventUrl = (event) => `https://blockchain.info/event?name=wallet_login_balance_${event}`

beforeEach(() => {
spyOn(window, 'fetch')
})

it('should make one request', () => {
API.incrementBtcEthUsageStats(0, 0)
API.incrementCurrencyUsageStats(0, 0)
expect(window.fetch).toHaveBeenCalledTimes(1)
})

it('should record correctly for btc=0, eth=0', () => {
API.incrementBtcEthUsageStats(0, 0)
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0_eth_0'))
API.incrementCurrencyUsageStats(0, 0)
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0_eth_0_bch_0'))
})

it('should record correctly for btc>0, eth=0', () => {
API.incrementBtcEthUsageStats(1, 0)
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_1_eth_0'))
API.incrementCurrencyUsageStats(1, 0)
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_1_eth_0_bch_0'))
})

it('should record correctly for btc=0, eth>0', () => {
API.incrementBtcEthUsageStats(0, 1)
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0_eth_1'))
API.incrementCurrencyUsageStats(0, 1)
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0_eth_1_bch_0'))
})

it('should record correctly for btc>0, eth>0', () => {
API.incrementBtcEthUsageStats(1, 1)
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_1_eth_1'))
API.incrementCurrencyUsageStats(1, 1)
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_1_eth_1_bch_0'))
})

it('should record correctly for bch>0', () => {
API.incrementCurrencyUsageStats(0, 0, 1)
JeffreyLeonard marked this conversation as resolved.
Show resolved Hide resolved
expect(window.fetch).toHaveBeenCalledWith(eventUrl('btc_0_eth_0_bch_1'))
})
})
});