import Network from '../../../utils/Network';
import Sinks from '../../../utils/sinks';
import helpers from '../../../utils/helpers';

class ExplorerApostillesCtrl {
    constructor(Wallet, $scope, NetworkRequests, Alert, $location, DataBridge) {
        'ngInject';

        // Wallet service
        this._Wallet = Wallet;
        // Network requests service
        this._NetworkRequests = NetworkRequests;
        // Alert service
        this._Alert = Alert;
        // DataBridge service
        this._DataBridge = DataBridge;
        // $location to redirect
        this._location = $location;

        // If no wallet show alert and redirect to home
        if (!this._Wallet.current) {
            this._Alert.noWalletLoaded();
            this._location.path('/');
            return;
        }

        // Array to get sink data
        this.sinkData = [];
        // Get sink depending of ntwork
        this.sink = Sinks.sinks.apostille[this._Wallet.network].toUpperCase().replace(/-/g, '');

        // Get incoming transactions of the sink account
        this.getSinkTransactions();

        // Public sink's apostilles pagination properties
        this.currentPageSink = 0;
        this.pageSizeSink = 5;
        this.numberOfPagesSink = function() {
            return Math.ceil(this.sinkData.length / this.pageSizeSink);
        }

    }

    /**
     * Get incoming transaction of the sink account
     */
    getSinkTransactions() {
        return this._NetworkRequests.getIncomingTxes(helpers.getHostname(this._Wallet.node), this.sink, "").then((data) => {
            this.sinkData = data.data;
        }, 
        (err) => {
            if(err.status === -1) {
                this._Alert.connectionError();
            } else {
                this._Alert.errorFetchingIncomingTxes(err.data.message);
            }
        });
    }

}

export default ExplorerApostillesCtrl;
@@ -1602,16 +1602,37 @@
 kData = 
+this.cleanApostilles(
 data.dat
@@ -1632,16 +1632,17 @@
 ata.data
+)
 ;%0A      
@@ -1857,16 +1857,16 @@
       %7D%0A
-
         
@@ -1876,16 +1876,1160 @@
 %0A    %7D%0A%0A
+    /**%0A     * Keep only HEX messages in transaction array%0A     */%0A    cleanApostilles(array) %7B%0A        let result = %5B%5D%0A        if(array.length) %7B%0A            for (let i = 0; i %3C array.length; i++)%7B%0A                if(array%5Bi%5D.transaction.type === 257) %7B%0A                    if(!array%5Bi%5D.transaction.message %7C%7C !array%5Bi%5D.transaction.message.payload %7C%7C array%5Bi%5D.transaction.message.payload.substring(0, 2) !== 'fe') %7B%0A                        //console.log(%22Not an apostille message%22)%0A                    %7D else %7B%0A                        result.push(array%5Bi%5D)%0A                    %7D%0A                %7D else if(array%5Bi%5D.transaction.type === 4100) %7B%0A                    if(!array%5Bi%5D.transaction.otherTrans.message%7C%7C !array%5Bi%5D.transaction.otherTrans.message.payload %7C%7C array%5Bi%5D.transaction.otherTrans.message.payload.substring(0, 2) !== 'fe') %7B%0A                        //console.log(%22Not an apostille message%22)%0A                    %7D else %7B%0A                      result.push(array%5Bi%5D)%0A                    %7D%0A                %7D%0A                if(i === array.length - 1) %7B%0A                  return result;%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A
 %7D%0A%0Aexpor

Clean apostilles explorer table to keep only HEX messages