diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 4cd2af62e..9a74e02ed 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -622,5 +622,17 @@ angular.module('copayApp.services') storage.remove('MercadoLibreGiftCards-' + network, cb); }; + root.setReceivedTransactions = function(walletId, txIds, cb) { + storage.set('receivedTxs-' + walletId, txIds, cb); + } + + root.getReceivedTransactions = function(walletId, cb) { + storage.get('receivedTxs-' + walletId, cb); + } + + root.removeReceivedTransactions = function(walletId, cb) { + storage.remove('receivedTxs-' + walletId, cb); + } + return root; }); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 118c138bb..85d11371e 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, intelTEE, storageService, configService, rateService, uxLanguage, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txFormatService, $ionicModal, $state, bwcService, bitcore, popupService) { +angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, intelTEE, storageService, configService, rateService, uxLanguage, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txFormatService, $ionicModal, $state, bwcService, bitcore, popupService, firebaseEventsService) { // Ratio low amount warning (fee/amount) in incoming TX var LOW_AMOUNT_RATIO = 0.15; @@ -488,9 +488,43 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; + function createReceivedEvents(newTxs) { + storageService.getReceivedTransactions(walletId, function(err, txIds) { + if (!txIds) { + txIds = []; + } else { + txIds = JSON.parse(txIds); + } + + var newReceived = lodash.filter(newTxs, function(t) { + return t.action === 'received'; + }); + + var newReceivedTxIds = lodash.map(newReceived, function(t) { + return t.txid; + }); + + var notInStorage = lodash.filter(newReceivedTxIds, function(t) { + return !lodash.includes(txIds, t); + }); + + lodash.each(notInStorage, function(t) { + firebaseEventsService.logEvent('received_bitcoin', { coin: wallet.coin }); + }); + + var receivedTransactions = txIds.concat(notInStorage); + + storageService.setReceivedTransactions(walletId, receivedTransactions, function() { + $log.debug('Received transactions saved'); + }); + }); + } + getNewTxs([], 0, function(err, txs) { if (err) return cb(err); + createReceivedEvents(txs); + var newHistory = lodash.uniq(lodash.compact(txs.concat(confirmedTxs)), function(x) { return x.txid; });