var Immutable = require("immutable");
var alt = require("../alt-instance");
var BlockchainActions = require("../actions/BlockchainActions");
import {
    Block, GlobalObject, DynGlobalObject
}
from "./tcomb_structs";


class BlockchainStore {
    constructor() {
        // This might not need to be an immutable map, a normal structure might suffice..
        this.blocks = Immutable.Map();
        this.latestBlocks = Immutable.List();
        this.dynGlobalObject = {};
        this.globalObject = {};

        this.bindListeners({
            onGetBlock: BlockchainActions.getBlock,
            onGetGlobals: BlockchainActions.subscribeGlobals,
            onGetLatest: BlockchainActions.getLatest
        });
    }

    onGetBlock(block) {
        if (!this.blocks.get(block.id)) {
            block.timestamp = new Date(block.timestamp);
            this.blocks = this.blocks.set(
                block.id,
                Block(block)
            );
        }
    }

    onGetLatest(block) {
        block.timestamp = new Date(block.timestamp);
        if (block.id > this.dynGlobalObject.head_block_number - 10) {
            this.latestBlocks = this.latestBlocks.unshift(Block(block));
            if (this.latestBlocks.size > 10) {
                this.latestBlocks = this.latestBlocks.pop();
            }
        }

    }

    onGetGlobals(objectArray) {
        objectArray.forEach(object => {
            if (object.id === "2.0.0") {
                this.globalObject = GlobalObject(object);
            } else if (object.id === "2.1.0") {
                object.time = new Date(object.time);
                object.next_maintenance_time = new Date(object.next_maintenance_time);
                this.dynGlobalObject = DynGlobalObject(object);
            }
        });
    }

}

module.exports = alt.createStore(BlockchainStore, "BlockchainStore");

@@ -134,16 +134,100 @@
 ions%22);%0A
+import BaseStore from %22./BaseStore%22;%0Aimport %7Boperations%7D from %22chain/chain_types%22;%0A%0A
 import %7B
@@ -227,16 +227,16 @@
 mport %7B%0A
-
     Bloc
@@ -296,16 +296,17 @@
 cts%22;%0A%0A%0A
+%0A
 class Bl
@@ -319,16 +319,33 @@
 inStore 
+extends BaseStore
 %7B%0A    co
@@ -354,24 +354,41 @@
 tructor() %7B%0A
+        super();%0A
         // T
@@ -814,16 +814,16 @@
 tLatest%0A
-
         
@@ -817,32 +817,493 @@
 test%0A        %7D);
+%0A%0A        this._export(%22getFee%22);%0A    %7D%0A%0A    getFee(op_type, options) %7B%0A        let op_code = operations%5Bop_type%5D;%0A%0A        let currentFees = this.globalObject.parameters.current_fees.parameters%5Bop_code%5D%5B1%5D;%0A%0A        let fee = 0;%0A        if (currentFees.fee) %7B%0A            fee += currentFees.fee;%0A        %7D%0A%0A        if (options) %7B%0A            for (let option of options) %7B%0A                fee += currentFees%5Boption%5D;%0A            %7D%0A        %7D%0A%0A        return fee;
 %0A    %7D%0A%0A    onGe

Add getFee method to BlockchainStore, calculates fees from global parameters object