// @flow
import createLogger from '../../utils/logger';

const log = createLogger('api');

export default class Api {
  constructor() {
    this.emerald = Api.getConnector().connectEmerald();
    // this.emerald = new Vault(new VaultInMemoryProvider());
    this.geth = null;
  }

  updateGethUrl(url) {
    if (!url) {
      log.warn('Disconnecting from Geth');
      this.geth = null;
      return;
    }
    this.geth = Api.getConnector().connectEth(url);
  }

  updateChain(name) {
    this.geth = Api.getConnector().connectEthChain(name);
  }

  static getConnector() {
    const { remote } = global.require('electron');
    return remote.getGlobal('serverConnect');
  }
}

export const api = new Api();

@@ -84,16 +84,120 @@
 api');%0A%0A
+class NullConnect %7B%0A  connectEth(url) %7B%0A  %7D%0A%0A  connectEthChain(name) %7B%0A  %7D%0A%0A  connectEmerald() %7B%0A  %7D%0A%7D%0A%0A
 export d
@@ -680,54 +680,494 @@
     
-const %7B remote %7D = global.require('electron');
+// TODO workaround for testing, should be properly mocked%0A    if (typeof global.require !== 'function') %7B%0A      console.warn('Electron Remote is not available');%0A      return new NullConnect();%0A    %7D%0A    const %7B remote %7D = global.require('electron');%0A    // TODO workaround for testing, should be properly mocked%0A    if (typeof remote !== 'object' %7C%7C typeof remote.getGlobal !== 'function') %7B%0A      console.warn('Electron Remote is not available');%0A      return new NullConnect();%0A    %7D
 %0A   

jest test failed