{"size": 1680, "ext": "js", "max_stars_repo_path": "src/infrastructure/NotificationHandler.js", "max_stars_repo_name": "evias/nem2-sandbox-www", "max_stars_repo_stars_event_min_datetime": "2019-11-08T12:19:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-08T12:19:51.000Z", "max_issues_repo_path": "src/infrastructure/NotificationHandler.js", "max_issues_repo_name": "evias/nem2-sandbox-www", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/infrastructure/NotificationHandler.js", "max_forks_repo_name": "evias/nem2-sandbox-www", "max_forks_repo_forks_event_min_datetime": "2019-11-26T22:09:50.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-26T22:09:50.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 28.0, "max_line_length": 82, "alphanum_fraction": 0.6714285714}
/*
 * Copyright (c) 2019-present Grégory Saive for NEM
 *
 * Licensed under the Apache License, Version 2.0 (the "License ");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// internal dependencies
import Helpers from '../Helpers';

export default class NotificationHandler {

  static handlerByEvent(event) {
    switch(event) {
      default:
        return NotificationHandler.generic

      case 'newBlock':
        return NotificationHandler.newBlock

      case 'newConnection':
        return NotificationHandler.newConnection
    }
  }

  static generic(message, variant) {
    return {
      variant: variant && variant.length ? variant : 'info',
      message: message,
      time: Helpers.timestampToTime((new Date()).valueOf())
    }
  }

  static newBlock(block) {
    return {
      variant: 'success',
      message: 'New block added <strong>#' + block.height.compact() + '</strong>',
      time: Helpers.timestampToTime(block.timestamp.compact()),
      // extra information
      height: block.height.compact()
    }
  }

  static newConnection(nodeUrl) {
    return {
      variant: 'success',
      message: 'Node was changed to: ' + nodeUrl,
      time: Helpers.timestampToTime((new Date()).valueOf()),
    }
  }
}
