Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.
Open
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
33 changes: 31 additions & 2 deletions src/app/services/dataBridge.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DataBridge {
*
* @params {services} - Angular services to inject
*/
constructor(Alert, Wallet, $timeout, $filter, Nodes, DataStore) {
constructor(Alert, Wallet, $timeout, $interval, $filter, Nodes, DataStore) {
'ngInject';

//// Service dependencies region ////
Expand All @@ -17,6 +17,7 @@ class DataBridge {
this._$timeout = $timeout;
this._Wallet = Wallet;
this._$filter = $filter;
this._$interval = $interval;
this._Nodes = Nodes;
this._DataStore = DataStore;

Expand Down Expand Up @@ -45,6 +46,11 @@ class DataBridge {
*/
this.renewalAlertTriggeredFor = {};

/**
* Handler to an unconfirmed transaction trigger/polling loop.
*/
this.unconfirmedTriggerLoop = undefined;

//// End properties region ////
}

Expand Down Expand Up @@ -312,6 +318,26 @@ class DataBridge {
}
};

let triggerUnconfirmedTransactionsReception = () => {
try {
let _address = this._Wallet.currentAccount.address;
// copied from nem-sdk/com/websockets/account.js/requestRecentTransactions
// TODO: call directly nem.com.websockets.requests.account.transactions.unconfirmed(connector) after it is implemented/exposed in nem-sdk
connector.stompClient.send("/w/api/account/transfers/unconfirmed", {}, "{'account':'" + _address + "'}");
for (let i = 0; i < this._DataStore.account.metaData.meta.cosignatoryOf.length; i++) {
let _address = this._DataStore.account.metaData.meta.cosignatoryOf[i].address;
// copied from nem-sdk/com/websockets/account.js/requestRecentTransactions
// TODO: call directly nem.com.websockets.requests.account.transactions.unconfirmed(connector) after it is implemented/exposed in nem-sdk
connector.stompClient.send("/w/api/account/transfers/unconfirmed", {}, "{'account':'" + _address + "'}");
}
} catch (e) {
console.error(e);
}
}

this.unconfirmedTriggerLoop = this._$interval(() => {
triggerUnconfirmedTransactionsReception();
}, 10000);//every 10s

// Set websockets callbacks
nem.com.websockets.subscribe.account.transactions.confirmed(connector, confirmedCallback);
Expand Down Expand Up @@ -339,6 +365,9 @@ class DataBridge {
* Reset DataBridge service properties
*/
reset() {
if (this.unconfirmedTriggerLoop) {
this._$interval.cancel(this.unconfirmedTriggerLoop);
}
this._DataStore.chain.time = undefined;
clearInterval(this.timeSyncInterval)
}
Expand Down Expand Up @@ -398,4 +427,4 @@ class DataBridge {
//// End methods region ////
}

export default DataBridge;
export default DataBridge;